aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java50
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java3
2 files changed, 42 insertions, 11 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) {