mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
Throw PseudonymRequestFailed exception with error message
This will throw an exception with error message describing what the error is instead of having a more generic NoSuchElementException to be thrown if Optional.get() has no value after calling findFirst() on an empty stream.
This commit is contained in:
parent
5bd26b894c
commit
9921e1e684
@ -108,12 +108,19 @@ public class GpasPseudonymGenerator implements Generator {
|
||||
|
||||
@NotNull
|
||||
public static String unwrapPseudonym(Parameters gPasPseudonymResult) {
|
||||
Identifier pseudonym = (Identifier) gPasPseudonymResult.getParameter().stream().findFirst()
|
||||
.get().getPart().stream().filter(a -> a.getName().equals("pseudonym")).findFirst()
|
||||
.orElseGet(ParametersParameterComponent::new).getValue();
|
||||
final var parameters = gPasPseudonymResult.getParameter().stream().findFirst();
|
||||
|
||||
if (parameters.isEmpty()) {
|
||||
throw new PseudonymRequestFailed("Empty HL7 parameters, cannot find first one");
|
||||
}
|
||||
|
||||
final var identifier = (Identifier) parameters.get().getPart().stream()
|
||||
.filter(a -> a.getName().equals("pseudonym"))
|
||||
.findFirst()
|
||||
.orElseGet(ParametersParameterComponent::new).getValue();
|
||||
|
||||
// pseudonym
|
||||
return pseudonym.getSystem() + "|" + pseudonym.getValue();
|
||||
return identifier.getSystem() + "|" + identifier.getValue();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user