diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-08 15:02:17 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-08 15:10:57 +0200 |
commit | 1c4112e016dbd0a0378c947d556f880c447ffa90 (patch) | |
tree | bc444bf72c724a57f70928f2ce781bc30d0982b5 /src | |
parent | abb3eb3a21cace569620e11d06273409aca9a747 (diff) | |
download | moa-zs-1c4112e016dbd0a0378c947d556f880c447ffa90.tar.gz moa-zs-1c4112e016dbd0a0378c947d556f880c447ffa90.tar.bz2 moa-zs-1c4112e016dbd0a0378c947d556f880c447ffa90.zip |
WIP delivery request validation
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java | 50 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java | 3 | ||||
-rw-r--r-- | src/main/resources/mzs/mzs_mypersondata_en.xsd | 1 |
3 files changed, 42 insertions, 12 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java index 18642e7..4b62164 100644 --- a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java +++ b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java @@ -1,12 +1,17 @@ package at.gv.egiz.moazs; import at.gv.zustellung.app2mzs.xsd.ConfigType; -import at.gv.zustellung.app2mzs.xsd.ConfigType.ConfigTypeBuilder; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.DeliveryRequestTypeBuilder; +import at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType; +import at.gv.zustellung.msg.xsd.SenderProfile; import org.springframework.stereotype.Component; +import org.springframework.util.Assert; import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static org.springframework.util.Assert.isTrue; +import static org.springframework.util.Assert.notNull; @Component public class DeliveryPreprocessor { @@ -21,23 +26,52 @@ public class DeliveryPreprocessor { */ public DeliveryRequestType preProcess(DeliveryRequestType request) { - validateRequest(request); + validate(request); return new DeliveryRequestTypeBuilder(request) .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) .build(); } - private void validateRequest(DeliveryRequestType request) { - if (request.getMetaData() == null) - throw new IllegalArgumentException("Metadata is missing."); + private void validate(DeliveryRequestType request) { + validate(request.getSender()); - if (request.getMetaData().getAppDeliveryID() == null) - throw new IllegalArgumentException("AppDeliveryID is missing."); + notNull(request.getReceiver(), "Receiver is missing."); + notNull(request.getPayload(), "Payloads are missing."); + notNull(request.getMetaData(), "Metadata is missing."); + notNull(request.getMetaData().getAppDeliveryID(), "AppDeliveryID is missing."); + + } + + private void validate(DeliveryRequestType.Sender sender) { + notNull(sender, "Sender is missing."); + + isTrue(sender.getSenderProfile() != null ^ sender.getCorporateBody() != null , + "Either SenderProfile or CorporateBody (but not both) need to be defined."); + + if(sender.getSenderProfile() != null) + validate(sender.getSenderProfile()); + else + validate(sender.getCorporateBody()); + } + + private void validate(SenderProfile profile) { + notNull(profile.getProfileID(), "ProfileID is missing."); + } + + private void validate(CorporateBodyType body) { + notNull(body.getIdentification(), "Identification is missing."); + notNull(body.getFullName(), "FullName is missing."); + isTrue(body.getIdentification().size() > 0, "No Identification provided."); + isTrue(body.getIdentification().size() <= 1, "Too many means of Identification were provided."); + + var id = body.getIdentification().get(0); + notNull(id.getType(), "Identification Type is missing"); + notNull(id.getValue(), "Identification Value is missing"); } private ConfigType initDefaultConfig() { - return new ConfigTypeBuilder() + return configTypeBuilder() .withPerformQueryPersonRequest(false) .build(); } diff --git a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java index 912ee4f..f7157da 100644 --- a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java +++ b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java @@ -72,9 +72,6 @@ public class Mzs2MsgConverter { private JAXBElement<? extends AbstractSenderPersonType> extractSenderPerson(at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender sender) { - Assert.isTrue(sender.getSenderProfile() != null || sender.getCorporateBody() != null, - "Neither SenderProfile nor CorporateBody are given"); - var builder = senderCorporateBodyTypeBuilder(); if(sender.getSenderProfile() != null) { diff --git a/src/main/resources/mzs/mzs_mypersondata_en.xsd b/src/main/resources/mzs/mzs_mypersondata_en.xsd index f8021db..dc829fe 100644 --- a/src/main/resources/mzs/mzs_mypersondata_en.xsd +++ b/src/main/resources/mzs/mzs_mypersondata_en.xsd @@ -75,7 +75,6 @@ </xs:element> </xs:sequence> <xs:attribute name="Id" type="xs:ID" use="optional"/> - <xs:anyAttribute namespace="##other"/> </xs:complexType> <xs:complexType name="AbstractPersonType" abstract="true"> <xs:annotation> |