diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-08-28 13:34:41 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-08-28 13:36:35 +0200 |
commit | 70e8a1b80fea9d61c46dbd55aa1b461a8bb3a0f7 (patch) | |
tree | d653c457ebf7331d7aa07b9c6f1ea122312480e3 /src/main | |
parent | ff0a32339c4e8dbc81be89a38990f3963c285121 (diff) | |
download | moa-zs-70e8a1b80fea9d61c46dbd55aa1b461a8bb3a0f7.tar.gz moa-zs-70e8a1b80fea9d61c46dbd55aa1b461a8bb3a0f7.tar.bz2 moa-zs-70e8a1b80fea9d61c46dbd55aa1b461a8bb3a0f7.zip |
Fixes and Refactoring
- JAXB Hack: Handle InterruptionException properly (as in [1], "Dont
swallow Interrupts")
- Mzs2MsgConverter: Rename convert(Person) to
convertReceiverPerson(Person) to emphasize that this method can only
be used to convert Receiver Persons (Reminder: Receiver Persons are
PhysicalPersons / CorporateBodies. SenderPersons can also be
Authorities)
- Mzs2MsgConverter: Remove assertion because not needed anymore.
- Refactor: Move mzs:DeliveryRequest validation out ouf augmenter and
into service.
- Refactor: Create a single entry point for validating a
mzs:DeliveryRequest.
- Remove unused imports.
- Fix log messages.
[1] https://www.ibm.com/developerworks/java/library/j-jtp05236/index.html?ca=drs-#2.1
Diffstat (limited to 'src/main')
8 files changed, 36 insertions, 34 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/MoaZS.java b/src/main/java/at/gv/egiz/moazs/MoaZS.java index e4e4acc..fca62f4 100644 --- a/src/main/java/at/gv/egiz/moazs/MoaZS.java +++ b/src/main/java/at/gv/egiz/moazs/MoaZS.java @@ -6,9 +6,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import java.net.URL; -import java.net.URLClassLoader; - @SpringBootApplication public class MoaZS extends SpringBootServletInitializer { 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 1e84e43..ded83ff 100644 --- a/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java +++ b/src/main/java/at/gv/egiz/moazs/client/TnvzHelper.java @@ -135,7 +135,7 @@ public class TnvzHelper { if (receiver.getIdentification() == null) { builder - .withPerson(converter.convert(receiver.getPerson())) + .withPerson(converter.convertReceiverPerson(receiver.getPerson())) .withAustrianAddressesOnly(receiver.getAustrianAddressesOnly()); var postalAddress = findPostalAddress(receiver.getAddress()); diff --git a/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java b/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java index 5615131..1141f5e 100644 --- a/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java +++ b/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java @@ -53,7 +53,7 @@ public class MoaSigConfig { if(System.getProperty(MOA_SPSS_CONFIG_FILE_PROPERTY) == null) { var realFile = new File(fileUtils.determinePath(spssConfigFilePath)); - log.debug("spssConfigFilePath.getCanonicalPath(): ", realFile.getCanonicalPath()); + log.debug("spssConfigFilePath.getCanonicalPath(): {}", realFile.getCanonicalPath()); if(realFile.exists() && realFile.canRead()) { log.debug(SET_PROPERTY_MSG_TEMPLATE, MOA_SPSS_CONFIG_FILE_PROPERTY, realFile.getCanonicalPath()); diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java index 4796844..7dc0f25 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java @@ -24,17 +24,15 @@ public class DeliveryRequestAugmenter { private final ConfigUtil util; private final Map<String, ConfigType> configs; - private final MzsDeliveryRequestValidator validator; private final Marshaller mzsMarshaller; private static final String CONFIG_MISSING_ERROR_MSG = "Delivery request configuration is missing."; @Autowired public DeliveryRequestAugmenter(Map<String, ConfigType> deliveryRequestConfigs, ConfigUtil util, - MzsDeliveryRequestValidator validator, Marshaller mzsMarshaller) { + Marshaller mzsMarshaller) { this.configs = deliveryRequestConfigs; this.util = util; - this.validator = validator; this.mzsMarshaller = mzsMarshaller; } @@ -61,14 +59,10 @@ public class DeliveryRequestAugmenter { trace("Augmented config", augmentedConfig); - validator.isConfigProfileComplete(augmentedConfig); - var augmentedRequest = deliveryRequestTypeBuilder(request) .withConfig(augmentedConfig) .build(); - validator.isTnvzComplete(augmentedRequest); - return augmentedRequest; } diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java b/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java index 67086a2..b0568d7 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/MzsDeliveryRequestValidator.java @@ -12,6 +12,17 @@ import static java.lang.String.format; @Component public class MzsDeliveryRequestValidator { + + /** + * Checks if request is valid and can be processed. + * @param request + * @throws MoaZSException if the request is invalid. + */ + public void isRequestValid(DeliveryRequestType request) { + isTnvzComplete(request); + isConfigProfileComplete(request.getConfig()); + } + /** * Checks if the mandatory fields that are needed to send a tnvz:QueryPersonRequest are present. * @param request 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 f2e6861..07df9f8 100644 --- a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java +++ b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java @@ -134,7 +134,7 @@ public class Mzs2MsgConverter { var builder = receiverBuilder() .withPreAdviceNote(receiver.getPreAdviceNote()) .withAdditionalCriteria(receiver.getAdditionalCriteria()) - .withPerson(convert(receiver.getPerson())) + .withPerson(convertReceiverPerson(receiver.getPerson())) .withAddress(convertAddresses(receiver.getAddress())); if (receiver.getIdentification() != null) builder.withIdentification(convert(receiver.getIdentification())); @@ -250,15 +250,11 @@ public class Mzs2MsgConverter { //------------ PERSONS -------------------- - public JAXBElement<? extends AbstractPersonType> convert( + public JAXBElement<? extends AbstractPersonType> convertReceiverPerson( JAXBElement<? extends at.gv.zustellung.app2mzs.xsd.persondata.AbstractPersonType> jaxbPerson) { var mzsPerson = jaxbPerson.getValue(); - //todo: move this to mzs - Assert.isTrue(personIsPhysical(mzsPerson) || personIsCorporateBody(mzsPerson), - "Person is neither a PhysicalPerson nor a CorporateBody."); - if (personIsPhysical(mzsPerson)) { var msgPerson = convert((at.gv.zustellung.app2mzs.xsd.persondata.PhysicalPersonType) mzsPerson); return personFactory.createPhysicalPerson(msgPerson); @@ -272,10 +268,6 @@ public class Mzs2MsgConverter { return person instanceof at.gv.zustellung.app2mzs.xsd.persondata.PhysicalPersonType; } - private boolean personIsCorporateBody(at.gv.zustellung.app2mzs.xsd.persondata.AbstractPersonType person) { - return person instanceof at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType; - } - public CorporateBodyType convert(at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType corporateBody) { return corporateBodyTypeBuilder() .withFullName(corporateBody.getFullName()) diff --git a/src/main/java/at/gv/egiz/moazs/service/MzsService.java b/src/main/java/at/gv/egiz/moazs/service/MzsService.java index a0e6248..fc1f804 100644 --- a/src/main/java/at/gv/egiz/moazs/service/MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/service/MzsService.java @@ -2,6 +2,7 @@ package at.gv.egiz.moazs.service; import at.gv.egiz.moazs.backend.MsgResponseSinkHub; import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; +import at.gv.egiz.moazs.preprocess.MzsDeliveryRequestValidator; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Msg2MzsConverter; import at.gv.egiz.moazs.scheme.RequestStatusResponse; @@ -43,16 +44,18 @@ public class MzsService implements App2MzsPortType { private final DeliveryRequestAugmenter augmenter; private final Msg2MzsConverter converter; private final MsgResponseSinkHub hub; + private final MzsDeliveryRequestValidator validator; @Autowired public MzsService(DeliveryRepository repository, Consumer<String> deliveryRequestBackend, DeliveryRequestAugmenter augmenter, Msg2MzsConverter converter, - MsgResponseSinkHub hub) { + MsgResponseSinkHub hub, MzsDeliveryRequestValidator validator) { this.repository = repository; this.backend = deliveryRequestBackend; this.augmenter = augmenter; this.converter = converter; this.hub = hub; + this.validator = validator; } @Override @@ -63,6 +66,8 @@ public class MzsService implements App2MzsPortType { var completeRequest = augmenter.augment(deliveryRequest); + validator.isRequestValid(completeRequest); + var requestProcessed = supplyAsync(() -> process(completeRequest)); try { @@ -80,7 +85,7 @@ public class MzsService implements App2MzsPortType { return converter.convert(status, binaryStatus); } catch (TimeoutException e) { - return handleAssyncStatus(appDeliveryID, completeRequest, requestProcessed); + return applySinkHubToAsyncResponse(appDeliveryID, completeRequest, requestProcessed); } catch (Exception e) { var message = format(MZS_SERVICE_ERROR_MSG, appDeliveryID); @@ -89,16 +94,6 @@ public class MzsService implements App2MzsPortType { } - private DeliveryResponseType handleAssyncStatus(String appDeliveryID, DeliveryRequestType request, - CompletableFuture<RequestStatusResponse> requestProcessed) { - - log.info(format(SERVICE_TIME_OUT_REACHED_MSG, appDeliveryID)); - var sinkParams = request.getConfig().getMsgResponseSinks(); - requestProcessed.thenAcceptAsync(response -> hub.applySinks(response, sinkParams)); - - return generatePartialSuccessResponse(appDeliveryID); - } - private RequestStatusResponse process(DeliveryRequestType deliveryRequest) { var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID(); @@ -113,6 +108,16 @@ public class MzsService implements App2MzsPortType { } + private DeliveryResponseType applySinkHubToAsyncResponse(String appDeliveryID, DeliveryRequestType request, + CompletableFuture<RequestStatusResponse> requestProcessed) { + + log.info(format(SERVICE_TIME_OUT_REACHED_MSG, appDeliveryID)); + var sinkParams = request.getConfig().getMsgResponseSinks(); + requestProcessed.thenAcceptAsync(response -> hub.applySinks(response, sinkParams)); + + return generatePartialSuccessResponse(appDeliveryID); + } + private DeliveryResponseType generatePartialSuccessResponse(String appDeliveryId) { var partial = partialSuccessTypeBuilder() diff --git a/src/main/java/at/gv/egiz/moazs/util/JAXBClassNotFoundFix.java b/src/main/java/at/gv/egiz/moazs/util/JAXBClassNotFoundFix.java index 9e72286..c91860b 100644 --- a/src/main/java/at/gv/egiz/moazs/util/JAXBClassNotFoundFix.java +++ b/src/main/java/at/gv/egiz/moazs/util/JAXBClassNotFoundFix.java @@ -13,6 +13,8 @@ public class JAXBClassNotFoundFix { private static final Logger log = LoggerFactory.getLogger(JAXBClassNotFoundFix.class); + private JAXBClassNotFoundFix() {} + /** * Solves JAXB's "ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory" in Java >= 9 * by running func in a dedicated thread which has its context classloader replaced with a classloader that finds @@ -44,6 +46,7 @@ public class JAXBClassNotFoundFix { t.join(); } catch (InterruptedException ex) { log.error("Interrupted. ", ex); + throw moaZSException("Interrupted. ", ex); } if (error[0] != null) { |