aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java b/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java
index 884be3e..de22805 100644
--- a/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java
+++ b/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java
@@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.zustellung.tnvz.xsd.PersonQueryType.MetaData.metaDataBuilder;
import static at.gv.zustellung.tnvz.xsd.PersonQueryType.personQueryTypeBuilder;
import static at.gv.zustellung.tnvz.xsd.QueryPersonRequest.QueryEntryList.queryEntryListBuilder;
@@ -52,21 +53,19 @@ public class TnvzHelper {
* {@code tvnzPort}, validates the tnvz's response and extracts the {@code Identification} Element.
* @param mzsRequest Data source for the QueryPersonRequest
* @param tvnzPort Client for communicating with the tnvz service
- * @param exceptionBuilder Utility to collect information and build a meaningful exception in case of errors.
* @throws MoaZSException in case of an error.
* @return
*/
public IdentificationType performQueryPersonRequest(DeliveryRequestType mzsRequest,
- TNVZServicePort tvnzPort,
- MoaZSException.Builder exceptionBuilder) {
+ TNVZServicePort tvnzPort) {
var tvnzQuery = buildQuery(mzsRequest);
var tvnzResponse = tvnzPort.queryPerson(tvnzQuery);
- verifyResponse(tvnzResponse, exceptionBuilder);
+ verifyResponse(tvnzResponse);
var tvnzResult = getResult(tvnzResponse);
var typesInRequest = extractListOfMimemtypesIn(mzsRequest);
- checkMimetypes(tvnzResult, typesInRequest, exceptionBuilder);
+ checkMimetypes(tvnzResult, typesInRequest);
return tvnzResult.getSuccess().getIdentification();
}
@@ -170,30 +169,26 @@ public class TnvzHelper {
.collect(toSet());
}
- private void verifyResponse(QueryPersonResponse tvnzResponse, MoaZSException.Builder mzsBuilder) {
+ private void verifyResponse(QueryPersonResponse tvnzResponse) {
var error = tvnzResponse.getError();
if (error != null) {
- throw mzsBuilder.withErrorCode(error.getCode())
- .withMessage(error.getText())
- .build();
+ throw MoaZSException.moaZSException(error.getText(), error.getCode());
}
var results = tvnzResponse.getQueryResultList().getQueryResult();
if (results.isEmpty()) {
- throw mzsBuilder.withErrorCode(MoaZSException.ERROR_MZS_NO_TNVZ_PERSON_QUERY_RESULTS)
- .withMessage(MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG)
- .build();
+ throw MoaZSException.moaZSException(MZS_NO_TNVZ_PERSON_QUERY_RESULTS_ERROR_MSG,
+ MoaZSException.ERROR_MZS_NO_TNVZ_PERSON_QUERY_RESULTS);
}
var tnvzResult = results.get(0);
- mzsBuilder.withPreAdviceNoteSent(tnvzResult);
if (tnvzResult.getError() != null) {
var info = tnvzResult.getError().getErrorInfo();
- throw mzsBuilder.withErrorCode(info.getCode())
- .withMessage(RECEIVER_NOT_ADRESSABLE_ERROR_MSG, info.getText())
- .build();
+ var message = String.format(RECEIVER_NOT_ADRESSABLE_ERROR_MSG, info.getText());
+ var code = info.getCode();
+ throw moaZSException(message, code, tnvzResult.getError().getPreAdviceNoteSent());
}
}
@@ -201,14 +196,14 @@ public class TnvzHelper {
return tvnzResponse.getQueryResultList().getQueryResult().get(0);
}
- private void checkMimetypes(PersonResultType tnvzResult, Set<String> typesInRequest, MoaZSException.Builder mzsBuilder) {
+ private void checkMimetypes(PersonResultType tnvzResult, Set<String> typesInRequest) {
var mismatchedTypes = findMimeTypeMismatches(tnvzResult, typesInRequest);
if (!mismatchedTypes.isEmpty()) {
var acceptedTypesString = join(",", getAcceptedTypes(tnvzResult));
var mismatchedTypesString = join(",", mismatchedTypes);
- throw mzsBuilder.withErrorCode(MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH)
- .withMessage(MIMETYPE_MISSMATCH_ERROR_MSG, mismatchedTypesString, acceptedTypesString)
- .build();
+ var message = String.format(MIMETYPE_MISSMATCH_ERROR_MSG, mismatchedTypesString, acceptedTypesString);
+ var code = MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH;
+ throw MoaZSException.moaZSException(message, code);
}
}