diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-28 10:48:20 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-28 10:48:20 +0200 |
commit | e1f365955aa22cdf8e44429af2b744388ce0c05b (patch) | |
tree | 71fec813cce57d4a74650dec259685052c405190 /src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java | |
parent | 695ab1f836160d40c4352a2c3127f4f687912817 (diff) | |
download | moa-zs-e1f365955aa22cdf8e44429af2b744388ce0c05b.tar.gz moa-zs-e1f365955aa22cdf8e44429af2b744388ce0c05b.tar.bz2 moa-zs-e1f365955aa22cdf8e44429af2b744388ce0c05b.zip |
Integrate Sign.Verification and Improve Error Handling of Pipeline
- Ensure proper communication of errors between pipeline and mzs
service by converting MoaZSExceptions into DeliveryRequestStatus
messages.
- Revise MoaZSException: Add optional fields; those fields are a)
helpful to construct meaningful error messages and b) optional
because, depending on where an exception appears, either existent or
non-existent and thus optional. Add inner-class Builder.
- Integrate Signature Verification into pipeline and add Stub for
SignatureVerification.
- Move TNVZResponse's Mimetype check into dedicated class (Reason:
separate abstration layers).
- Update api changes in testcases.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java new file mode 100644 index 0000000..9992246 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzResultVerifier.java @@ -0,0 +1,63 @@ +package at.gv.egiz.moazs.tnvz; + +import at.gv.egiz.moazs.MoaZSException; +import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; +import at.gv.zustellung.tnvz.xsd.PersonResultType; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.List; + +import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; +import static java.lang.String.join; +import static java.util.stream.Collectors.toSet; + +@Component +public class TnvzResultVerifier { + + public void verify(DeliveryRequestType request, PersonResultType result) { + + if (result.getError() != null) { + var info = result.getError().getErrorInfo(); + throw moaZSExceptionBuilder("Receiver is not addressable. Reason: %s", info.getText()) + .withErrorCode(info.getCode()) + .withMzsRequest(request) + .withTnvzResult(result) + .build(); + } + + var mismatchedTypes = findMimeTypeMismatches(result, request); + + if (!mismatchedTypes.isEmpty()) { + var template = "Request contains attachment of type(s) %s, but receiver only accepts attachments" + + " of type(s) %s."; + var acceptedTypesString = join(",", getAcceptedTypes(result)); + var mismatchedTypesString = join(",", mismatchedTypes); + throw moaZSExceptionBuilder(template, mismatchedTypesString, acceptedTypesString) + .withErrorCode(MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH) + .withMzsRequest(request) + .withTnvzResult(result) + .build(); + } + } + + private Collection<String> findMimeTypeMismatches(PersonResultType result, DeliveryRequestType request) { + var acceptedTypes = getAcceptedTypes(result); + + if (acceptedTypes.contains("*/*")) { + return List.of(); + } + + var typesInRequest = request.getPayload().stream() + .map(DeliveryRequestType.Payload::getMIMEType) + .collect(toSet()); + + typesInRequest.removeAll(acceptedTypes); + + return typesInRequest; + } + + private List<String> getAcceptedTypes(PersonResultType result) { + return result.getSuccess().getMimeTypeList().getMimeType(); + } +} |