aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.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/scheme/RequestStatusResponse.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/scheme/RequestStatusResponse.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java b/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
index 14e22ad..8a4b590 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
@@ -6,11 +6,13 @@ import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
import at.gv.zustellung.msg.xsd.ErrorInfoType;
import at.gv.zustellung.msg.xsd.ObjectFactory;
+import org.springframework.lang.Nullable;
import javax.xml.bind.JAXBElement;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.egiz.moazs.util.NullCoalesce.coalesce;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Error.errorBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
@@ -26,10 +28,19 @@ public class RequestStatusResponse extends MsgResponse<DeliveryRequestStatusType
public RequestStatusResponse(DeliveryRequestStatusType status) {
this.status = status;
- this.answer = coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()).get();
+ this.answer = getAnswer(status);
super.id = createResponseId(answer.getAppDeliveryID(), ID_SUFFIX);
}
+ /**
+ * Convenience method to access DeliveryAnswerType's base fields of Success, PartialSuccess or Error.
+ * @param status
+ * @return Success, PartialSuccess, or Error casted to DeliveryAnswerType
+ */
+ public static DeliveryAnswerType getAnswer(DeliveryRequestStatusType status) {
+ return coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()).get();
+ }
+
public static String getResponseID(String appDeliveryID) {
return appDeliveryID + ID_SUFFIX;
}
@@ -60,31 +71,42 @@ public class RequestStatusResponse extends MsgResponse<DeliveryRequestStatusType
}
@Override
- public MsgResponse<DeliveryRequestStatusType> generateError(MoaZSException exception) {
- return generateErrorFromException(exception);
+ public MsgResponse<DeliveryRequestStatusType> generateError(String text, String code) {
+ var auxException = moaZSException(text, code);
+ return generateError(auxException, answer);
}
- public static MsgResponse<DeliveryRequestStatusType> generateErrorFromException(MoaZSException exception) {
+ /**
+ * Creates A MsgResponse with a DeliveryRequestStatus of type error and merges fields from
+ * {@code exception} and {@code answer}
+ * @param exception
+ * @param answer
+ * @return
+ */
+ public static MsgResponse<DeliveryRequestStatusType> generateError(MoaZSException exception,
+ @Nullable DeliveryAnswerType answer) {
ErrorInfoType info = errorInfoTypeBuilder()
.withText(exception.getMessage())
- .withCode(exception.getErrorCode())
+ .withCode(exception.getCode())
.build();
- DeliveryRequestStatusType.Error error = errorBuilder()
- .withErrorInfo(info)
- .withAppDeliveryID(exception.getAppDeliveryID())
- .withDeliverySystem(exception.getDeliverySystem())
- .withGZ(exception.getGz())
+ var errorBuilder = errorBuilder()
.withPreAdviceNoteSent(exception.getPreAdviceNoteSent())
- .withZSDeliveryID(exception.getZsDeliveryID())
- .build();
-
- var status = deliveryRequestStatusTypeBuilder()
- .withError(error)
- .withVersion(NameSpace.MSG_VERSION)
+ .withErrorInfo(info);
+
+ if (answer != null) {
+ errorBuilder
+ .withAppDeliveryID(answer.getAppDeliveryID())
+ .withDeliverySystem(answer.getDeliverySystem())
+ .withZSDeliveryID(answer.getZSDeliveryID())
+ .withGZ(answer.getGZ());
+ }
+
+ var errorStatus = deliveryRequestStatusTypeBuilder()
+ .withError(errorBuilder.build())
.build();
- return new RequestStatusResponse(status);
+ return new RequestStatusResponse(errorStatus);
}
@Override