aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/MoaZSException.java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:17:21 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:27:40 +0200
commitf2e1263702901581512131ea587fad7a2ba45baa (patch)
treeb92a38f758fecb039de184963116017921d2e314 /src/main/java/at/gv/egiz/moazs/MoaZSException.java
parent896195cc9b287a3f41008cc85997b9c2209120b8 (diff)
downloadmoa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.gz
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.bz2
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.zip
Put MoaZSException on Diet & Handle Edge Cases
Reason: MoaZSException (and: its builder) were used to collect intermediary results while stepping through the delivery request backend. These results were needed to generate meaningful responses towards the sender application in case of error. However, the builder sprawled over too many interfaces (e.g. DeliveryRequestBackend and TNVZHelper) and it became difficult to understand from where intermediary results originated. Solution: Put MoaZSException on diet: - Remove all DeliveryAnswer fields from MoaZSException and refactor code base to ensure that the removed fields get sourced by other means. - Remove Builder since amount of parameters is manageable. Refactor DeliveryRequestBackend: - Instead of passing down the builder and using MoaZSException as the only source for intermediary results, we collect available results at the outermost stack frame (DeliveryRequestBackend.accept) and only retrieve results via exception if those results appear somewhere down the stack frame (E.g. PredviceNoteSent). We collect available results with the "fallbackAnswerBuilder" and switch to the msg client response, once received. Refactor MsgResponseBackend: - Handle cases (response missing, binary response missing) properly. - Integrate changes from MsgResponse.generateError() Refactor TVNZHelper: - Remove MoaZSExceptionBuilder from all interfaces. Refactor MsgResponse.generateError: - Change interface such that it's more intuitive. - Implement NotificationResponse.generateError. - Implement RequestStatusResponse.generateError. Others: - Replace all invocations against MoaZSException.Builder.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/MoaZSException.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/MoaZSException.java158
1 files changed, 21 insertions, 137 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/MoaZSException.java b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
index dbb2894..499dc14 100644
--- a/src/main/java/at/gv/egiz/moazs/MoaZSException.java
+++ b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
@@ -1,167 +1,51 @@
package at.gv.egiz.moazs;
-import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
import at.gv.zustellung.msg.xsd.PreAdviceNoteSentType;
-import at.gv.zustellung.tnvz.xsd.PersonResultType;
import org.springframework.lang.Nullable;
public class MoaZSException extends RuntimeException {
public static final String ERROR_MZS_MIMETYPE_MISSMATCH = "8001";
public static final String ERROR_MZS_NO_TNVZ_PERSON_QUERY_RESULTS = "8002";
+ public static final String ERROR_MZS_BINARY_RESPONSE_MISSING = "8003";
+ public static final String ERROR_MZS_RESPONSE_MISSING = "8004";
public static final String ERROR_MOASP_SIGNATURE_INVALID = "7001";
- @Nullable
- private final String errorCode;
- @Nullable
- private final PreAdviceNoteSentType preAdviceNoteSent;
- @Nullable
- private final String deliverySystem;
- @Nullable
- private final String gz;
- @Nullable
- private final String zsDeliveryID;
- @Nullable
- private final String appDeliveryID;
+ @Nullable private final String code;
+ @Nullable private final PreAdviceNoteSentType preAdviceNoteSent;
- private MoaZSException(Builder builder) {
- super(builder.message, builder.cause);
- this.errorCode = builder.errorCode;
- this.preAdviceNoteSent = builder.preAdviceNoteSent;
- this.deliverySystem = builder.deliverySystem;
- this.gz = builder.gz;
- this.zsDeliveryID = builder.zsDeliveryID;
- this.appDeliveryID = builder.appDeliveryID;
+ private MoaZSException(String message, Throwable cause, @Nullable String code, @Nullable PreAdviceNoteSentType preAdviceNoteSent) {
+ super(message, cause);
+ this.code = code;
+ this.preAdviceNoteSent = preAdviceNoteSent;
}
- public static MoaZSException moaZSException(String message, Throwable cause) {
- return moaZSExceptionBuilder(message).withCause(cause).build();
- }
-
- public static MoaZSException moaZSException(String formatString, Object... objects) {
- return moaZSExceptionBuilder(formatString, objects).build();
- }
-
- public static MoaZSException moaZSException(String message) {
- return moaZSExceptionBuilder(message).build();
- }
-
- public static Builder moaZSExceptionBuilder(String formatString, Object... objects) {
- return new Builder().withMessage(String.format(formatString, objects));
+ @Nullable public String getCode() {
+ return code;
}
- public static Builder moaZSExceptionBuilder(String message) {
- return new Builder().withMessage(message);
- }
-
- public static Builder moaZSExceptionBuilder() {
- return new Builder();
- }
-
- @Nullable
- public String getErrorCode() {
- return errorCode;
- }
-
- @Nullable
- public PreAdviceNoteSentType getPreAdviceNoteSent() {
+ @Nullable public PreAdviceNoteSentType getPreAdviceNoteSent() {
return preAdviceNoteSent;
}
- @Nullable
- public String getDeliverySystem() {
- return deliverySystem;
+ public static MoaZSException moaZSException(String message, Throwable cause) {
+ return new MoaZSException(message, cause, null, null);
}
- @Nullable
- public String getGz() {
- return gz;
+ public static MoaZSException moaZSException(String message) {
+ return new MoaZSException(message, null, null, null);
}
- @Nullable
- public String getZsDeliveryID() {
- return zsDeliveryID;
+ public static MoaZSException moaZSException(String message, String code) {
+ return new MoaZSException(message, null, code, null);
}
- @Nullable
- public String getAppDeliveryID() {
- return appDeliveryID;
+ public static MoaZSException moaZSException(String message, String code, Throwable cause) {
+ return new MoaZSException(message, cause, code, null);
}
- public static class Builder {
-
- private String message;
- private Throwable cause;
- private String errorCode;
- private PreAdviceNoteSentType preAdviceNoteSent;
- private String deliverySystem;
- private String gz;
- private String zsDeliveryID;
- private String appDeliveryID;
-
- private Builder() {
- }
-
- public Builder(MoaZSException exception){
- this.message = exception.getMessage();
- this.cause = exception.getCause();
- this.errorCode = exception.getErrorCode();
- this.preAdviceNoteSent = exception.getPreAdviceNoteSent();
- this.deliverySystem = exception.getDeliverySystem();
- this.gz = exception.getGz();
- this.zsDeliveryID = exception.getZsDeliveryID();
- this.appDeliveryID = exception.getAppDeliveryID();
- }
-
- public Builder withMessage(String message) {
- this.message = message;
- return this;
- }
-
- public Builder withMessage(String formatString, Object... objects ) {
- this.message = String.format(formatString, objects);
- return this;
- }
-
- public Builder withCause(Throwable cause) {
- this.cause = cause;
- return this;
- }
-
- public Builder withErrorCode(String errorCode) {
- this.errorCode = errorCode;
- return this;
- }
-
- public Builder withPreAdviceNoteSent(PersonResultType personResult) {
- if (personResult.getError() != null) {
- this.preAdviceNoteSent = personResult.getError().getPreAdviceNoteSent();
- }
- return this;
- }
-
- public Builder withDeliverySystem(at.gv.zustellung.app2mzs.xsd.DeliveryRequestType mzsRequest) {
- this.deliverySystem = mzsRequest.getConfig().getMSGClient().getURL();
- return this;
- }
-
-
- public Builder withAllParametersInAnswer(DeliveryAnswerType answer) {
- this.deliverySystem = answer.getDeliverySystem();
- this.gz = answer.getGZ();
- this.zsDeliveryID = answer.getZSDeliveryID();
- this.appDeliveryID = answer.getAppDeliveryID();
- return this;
- }
-
- public Builder withAppDeliveryID(String appDeliveryID) {
- this.appDeliveryID = appDeliveryID;
- return this;
- }
-
- public MoaZSException build() {
- return new MoaZSException(this);
- }
+ public static MoaZSException moaZSException(String message, String code, PreAdviceNoteSentType preAdviceNoteSent) {
+ return new MoaZSException(message, null, code, preAdviceNoteSent);
}
}