From 4ee8eef34f11a4aef7d9f0894b7b3868aa92f005 Mon Sep 17 00:00:00 2001 From: gmanifavas Date: Fri, 15 May 2020 18:35:07 +0300 Subject: [PATCH 01/61] [UNIONVMS-4595] Edit request for report forwarding. --- .../uvms/rules/model/mapper/RulesModuleRequestMapper.java | 2 +- model/src/main/resources/contract/RulesModuleService.wsdl | 2 +- .../rules/service/bean/activity/RulesFaReportServiceBean.java | 4 ++-- .../uvms/rules/service/bean/RulesFAReportServiceBeanTest.java | 2 +- .../uvms/rules/service/bean/RulesMessageServiceBeanTest.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java index a9e115296..420ef253c 100755 --- a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java +++ b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java @@ -54,7 +54,7 @@ public static String createSetFLUXFAReportMessageRequest(PluginType type, String SetFLUXFAReportMessageRequest request = new SetFLUXFAReportMessageRequest(); request.setMethod(RulesModuleMethod.SET_FLUX_FA_REPORT); request.setRequest(fluxFAReportMessage); - request.setType(type); + request.setPluginType(type); populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, onValue); return JAXBMarshaller.marshallJaxBObjectToString(request); } diff --git a/model/src/main/resources/contract/RulesModuleService.wsdl b/model/src/main/resources/contract/RulesModuleService.wsdl index 8a1c52190..6bec107f0 100755 --- a/model/src/main/resources/contract/RulesModuleService.wsdl +++ b/model/src/main/resources/contract/RulesModuleService.wsdl @@ -83,7 +83,7 @@ - + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java index 3f090b701..734e1c4b2 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java @@ -142,7 +142,7 @@ public void evaluateIncomingFLUXFAReport(SetFLUXFAReportMessageRequest request) if (hasPermissions) { rulesDaoBean.saveFaIdsPerTripList(faIdsPerTripsFromMessage); log.debug(" Request has permissions. Going to send FaReportMessage to Activity Module..."); - sendRequestToActivity(requestStr, request.getType(), MessageType.FLUX_FA_REPORT_MESSAGE, exchangeLogGuid); + sendRequestToActivity(requestStr, request.getPluginType(), MessageType.FLUX_FA_REPORT_MESSAGE, exchangeLogGuid); Set result = idsFromIncomingMessage.stream().filter(faDocumentID -> !FAUUIDType.FA_REPORT_REF_ID.equals(faDocumentID.getType())) .collect(Collectors.toSet()); @@ -158,7 +158,7 @@ public void evaluateIncomingFLUXFAReport(SetFLUXFAReportMessageRequest request) FLUXResponseMessage fluxResponseMessage = fluxMessageHelper.generateFluxResponseMessageForFaReport(faReportValidationResult, fluxfaReportMessage); XPathRepository.INSTANCE.clear(faReportFacts); - exchangeServiceBean.evaluateAndSendToExchange(fluxResponseMessage, request, request.getType(), fluxMessageHelper.isCorrectUUID(messageGUID), MDC.getCopyOfContextMap()); + exchangeServiceBean.evaluateAndSendToExchange(fluxResponseMessage, request, request.getPluginType(), fluxMessageHelper.isCorrectUUID(messageGUID), MDC.getCopyOfContextMap()); } catch (UnmarshalException e) { log.error(" Error while trying to parse FLUXFAReportMessage received message! It is malformed! Reason : {{}}", e.getMessage()); diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesFAReportServiceBeanTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesFAReportServiceBeanTest.java index 9475049d1..7092eea76 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesFAReportServiceBeanTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesFAReportServiceBeanTest.java @@ -68,7 +68,7 @@ public class RulesFAReportServiceBeanTest { @Before public void before(){ fluxfaReportMessageRequest = new SetFLUXFAReportMessageRequest(); - fluxfaReportMessageRequest.setType(PluginType.FLUX); + fluxfaReportMessageRequest.setPluginType(PluginType.FLUX); fluxfaReportMessageRequest.setLogGuid("guid"); rulesFaReportServiceBean.init(); Whitebox.setInternalState(rulesFaReportServiceBean, "fluxMessageHelper", fluxMessageHelper); diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMessageServiceBeanTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMessageServiceBeanTest.java index 066f38ad8..c5414aa65 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMessageServiceBeanTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMessageServiceBeanTest.java @@ -169,7 +169,7 @@ public void testSetFLUXFAReportMessageReceived(){ SetFLUXFAReportMessageRequest req = new SetFLUXFAReportMessageRequest(); req.setRequest(IOUtils.toString(new FileInputStream(testXmlPath))); - req.setType(PluginType.MANUAL); + req.setPluginType(PluginType.MANUAL); req.setMethod(RulesModuleMethod.SET_FLUX_FA_REPORT); req.setLogGuid("SOME-GUID"); messageServiceBean.evaluateIncomingFLUXFAReport(req); From e7387a0b69f73a02d3da648402a9ab320527d71d Mon Sep 17 00:00:00 2001 From: PAPATHEODOROU Constantinos Date: Wed, 8 Jul 2020 17:25:34 +0300 Subject: [PATCH 02/61] [UNIONVMS-4698] - Send Flux movement report --- .../bean/RulesEventMessageConsumerBean.java | 7 ++++++ .../event/SendFluxMovementReportEvent.java | 25 +++++++++++++++++++ .../mapper/RulesModuleRequestMapper.java | 10 ++++++++ .../contract/RulesModuleService.wsdl | 15 +++++++++++ .../uvms/rules/service/EventService.java | 2 ++ .../service/bean/RulesEventServiceBean.java | 12 +++++++++ .../movement/RulesMovementProcessorBean.java | 11 ++++++++ .../mapper/ExchangeMovementMapper.java | 15 +++++++++++ 8 files changed, 97 insertions(+) create mode 100644 message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java index 166b87b6d..02cbac50f 100644 --- a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java @@ -109,6 +109,10 @@ public class RulesEventMessageConsumerBean implements MessageListener { @GetFLUXMDRSyncMessageResponseEvent private Event getFluxMdrSynchMessageResponse; + @Inject + @SendFluxMovementReportEvent + private Event sendFluxMovementReportEvent; + @Inject @ErrorEvent private Event errorEvent; @@ -167,6 +171,9 @@ public void onMessage(Message message) { case GET_FLUX_MDR_SYNC_RESPONSE : getFluxMdrSynchMessageResponse.fire(eventMessage); break; + case SEND_FLUX_MOVEMENT_REPORT: + sendFluxMovementReportEvent.fire(eventMessage); + break; default: LOG.error("[ Request method '{}' is not implemented ]", method.name()); errorEvent.fire(new EventMessage(textMessage, ModuleResponseMapper.createFaultMessage(FaultCode.RULES_MESSAGE, "Method not implemented:" + method.name()))); diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java new file mode 100644 index 000000000..0755a6be9 --- /dev/null +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java @@ -0,0 +1,25 @@ +/* +Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries +© European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can +redistribute it and/or modify it under the terms of the GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in +the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a +copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.message.event; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE }) +public @interface SendFluxMovementReportEvent { + +} \ No newline at end of file diff --git a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java index 420ef253c..54ea9a2be 100755 --- a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java +++ b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java @@ -98,6 +98,16 @@ public static String createSendFaQueryMessageRequest(String faQueryMessageStr, S return JAXBMarshaller.marshallJaxBObjectToString(request); } + public static String createSendFluxMovementReportMessageRequest(PluginType type, String forwardPositionMessageStr, String username, String logId, String fluxDataFlow, + String senderOrReceiver) throws RulesModelMapperException { + SendFLUXMovementReportRequest request = new SendFLUXMovementReportRequest(); + request.setMethod(RulesModuleMethod.SEND_FLUX_MOVEMENT_REPORT); + request.setRequest(forwardPositionMessageStr); + request.setType(type); + populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, null); + return JAXBMarshaller.marshallJaxBObjectToString(request); + } + @Deprecated // Use the populateCommonProperties() with 10 parameters! private static void populateCommonProperties(RulesBaseRequest request, String username, String logId, String fluxDataFlow, String senderOrReceiver, String onValue) { request.setFluxDataFlow(fluxDataFlow); diff --git a/model/src/main/resources/contract/RulesModuleService.wsdl b/model/src/main/resources/contract/RulesModuleService.wsdl index 6bec107f0..f74970ec5 100755 --- a/model/src/main/resources/contract/RulesModuleService.wsdl +++ b/model/src/main/resources/contract/RulesModuleService.wsdl @@ -50,6 +50,8 @@ + + @@ -276,6 +278,19 @@ + + + + + + + + + + + + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java index 11380db10..4841faa2c 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java @@ -66,4 +66,6 @@ public interface EventService { void sendSalesResponseEvent(@Observes @SendSalesResponseEvent EventMessage message); void getValidationResultsByRawGuid(@Observes @GetValidationResultsByRawGuid EventMessage message); + + void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java index ae5a2afcc..2c0a1a4b0 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java @@ -312,6 +312,18 @@ public void getValidationResultsByRawGuid(@Observes @GetValidationResultsByRawGu } } + @Override + public void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message) { + log.info(" Received SendFluxMovementReportEvent.."); + TextMessage jmsRequestMessage = message.getJmsMessage(); + SendFLUXMovementReportRequest request = (SendFLUXMovementReportRequest) message.getRulesBaseRequest(); + try { + rulesService.sendMovementReport(request, jmsRequestMessage.getJMSMessageID()); + } catch (RulesServiceException | JMSException e) { + log.error(" Error when forwarding movement report {}", e.getMessage()); + } + } + @SuppressWarnings("unused") private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) { try { diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index 2b7b3ce5e..733b61764 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -42,6 +42,7 @@ import eu.europa.ec.fisheries.schema.rules.customrule.v1.UpdateSubscriptionType; import eu.europa.ec.fisheries.schema.rules.mobileterminal.v1.IdList; import eu.europa.ec.fisheries.schema.rules.module.v1.GetTicketsAndRulesByMovementsResponse; +import eu.europa.ec.fisheries.schema.rules.module.v1.SendFLUXMovementReportRequest; import eu.europa.ec.fisheries.schema.rules.module.v1.SetFLUXMovementReportRequest; import eu.europa.ec.fisheries.schema.rules.movement.v1.MovementSourceType; import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType; @@ -183,6 +184,16 @@ public class RulesMovementProcessorBean { @AlarmReportCountEvent private Event alarmReportCountEvent; + public void sendMovementReport(SendFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException { + log.info("Sending Movement Report to exchange"); + try { + String exchangeMessageText = ExchangeMovementMapper.mapToFluxMovementReport(request.getRequest(), request.getUsername(), request.getSenderOrReceiver(), request.getFluxDataFlow(), request.getLogGuid()); + exchangeProducer.sendModuleMessage(exchangeMessageText, consumer.getDestination()); + } catch (ExchangeModelMapperException | MessageException e) { + log.error("Error while send movement report to exchnge", e); + } + } + public void setMovementReportReceived(SetFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException { FLUXVesselPositionMessage fluxVesselPositionMessage; String pluginType = request.getType().name(); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java index 5aed9d815..4e5a8b25c 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java @@ -16,6 +16,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.schema.exchange.module.v1.ExchangeModuleMethod; import eu.europa.ec.fisheries.schema.exchange.module.v1.ProcessedMovementResponse; import eu.europa.ec.fisheries.schema.exchange.module.v1.ProcessedMovementResponseBatch; +import eu.europa.ec.fisheries.schema.exchange.module.v1.SendFLUXMovementReportRequest; import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetId; import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetIdType; import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetType; @@ -31,6 +32,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.exchange.model.mapper.JAXBMarshaller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; public class ExchangeMovementMapper { @@ -130,6 +132,19 @@ public static String mapToProcessedMovementResponseBatch(List Date: Tue, 14 Jul 2020 23:35:38 +0300 Subject: [PATCH 03/61] [UNIONVMS-4709] Modifications for the alert output of Subscriptions Signed-off-by: lsotiriadis --- .../bean/RulesEventMessageConsumerBean.java | 7 ++ .../event/CreateAlarmReceivedEvent.java | 25 +++++ .../contract/RulesModuleService.wsdl | 14 +++ .../rules/rest/service/AlarmRestResource.java | 6 ++ .../uvms/rules/service/EventService.java | 2 + .../service/bean/RulesEventServiceBean.java | 16 +++ .../bean/alarms/AlarmReportsServiceBean.java | 100 ++++++++++++++++++ .../movement/MovementsRulesValidator.java | 8 +- .../movement/RulesMovementProcessorBean.java | 3 + 9 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java index 02cbac50f..e3631b0a8 100644 --- a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java @@ -113,6 +113,10 @@ public class RulesEventMessageConsumerBean implements MessageListener { @SendFluxMovementReportEvent private Event sendFluxMovementReportEvent; + @Inject + @CreateAlarmReceivedEvent + private Event createAlarmReceivedEvent; + @Inject @ErrorEvent private Event errorEvent; @@ -174,6 +178,9 @@ public void onMessage(Message message) { case SEND_FLUX_MOVEMENT_REPORT: sendFluxMovementReportEvent.fire(eventMessage); break; + case CREATE_ALARMS_REPORT_REQUEST : + createAlarmReceivedEvent.fire(eventMessage); + break; default: LOG.error("[ Request method '{}' is not implemented ]", method.name()); errorEvent.fire(new EventMessage(textMessage, ModuleResponseMapper.createFaultMessage(FaultCode.RULES_MESSAGE, "Method not implemented:" + method.name()))); diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java new file mode 100644 index 000000000..4d8b03ab2 --- /dev/null +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java @@ -0,0 +1,25 @@ +/* +Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries +© European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can +redistribute it and/or modify it under the terms of the GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in +the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a +copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.message.event; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE }) +public @interface CreateAlarmReceivedEvent { + +} \ No newline at end of file diff --git a/model/src/main/resources/contract/RulesModuleService.wsdl b/model/src/main/resources/contract/RulesModuleService.wsdl index f74970ec5..8f256d959 100755 --- a/model/src/main/resources/contract/RulesModuleService.wsdl +++ b/model/src/main/resources/contract/RulesModuleService.wsdl @@ -64,6 +64,7 @@ + @@ -380,6 +381,19 @@ + + + + + + + + + + + + + diff --git a/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java b/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java index 607fa4237..79c57189c 100644 --- a/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java +++ b/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java @@ -12,6 +12,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The package eu.europa.ec.fisheries.uvms.rules.rest.service; import javax.ejb.EJB; +import javax.ejb.EJBException; import javax.ejb.Stateless; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; @@ -135,6 +136,11 @@ public ResponseDto reprocessAlarm(final List alarmGuidList) { LOG.error("[ Error when reprocessing. ] {} ", e.getMessage()); return ErrorHandler.getFault(e); } + catch (EJBException e) { + LOG.error("[ Error when reprocessing. ] {} ", e.getMessage()); + Exception cause = e.getCausedByException(); + return ErrorHandler.getFault(cause instanceof EJBException ? ((EJBException)cause).getCausedByException() : cause); + } } /** diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java index 4841faa2c..941e838bc 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java @@ -68,4 +68,6 @@ public interface EventService { void getValidationResultsByRawGuid(@Observes @GetValidationResultsByRawGuid EventMessage message); void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message); + + void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMessage message); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java index 2c0a1a4b0..2010a47cf 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java @@ -35,6 +35,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFAResponseServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaQueryServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaReportServiceBean; +import eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.AlarmReportsServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MdrRulesMessageServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.RulesMovementProcessorBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.sales.SalesRulesMessageServiceBean; @@ -86,6 +87,9 @@ public class RulesEventServiceBean implements EventService { @EJB private SalesRulesMessageServiceBean salesRulesMessageServiceBean; + @EJB + private AlarmReportsServiceBean alarmReportsServiceBean; + @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void pingReceived(@Observes @PingReceivedEvent EventMessage eventMessage) { @@ -324,6 +328,18 @@ public void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent E } } + @Override + public void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMessage message) { + log.info("Received event to create alarm.."); + try { + CreateAlarmsReportRequest request = (CreateAlarmsReportRequest) message.getRulesBaseRequest(); + alarmReportsServiceBean.createAlarmReport(request); + } catch (RulesServiceException e) { + log.error(" Error when creating creating alarm {}", e.getMessage()); + } + } + + @SuppressWarnings("unused") private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) { try { diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java new file mode 100644 index 000000000..fd4888430 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java @@ -0,0 +1,100 @@ +/* + * + * Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020. + * + * This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + * the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + * + */ + +package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms; + +import eu.europa.ec.fisheries.remote.RulesDomainModel; +import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmReportType; +import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmStatusType; +import eu.europa.ec.fisheries.schema.rules.module.v1.CreateAlarmsReportRequest; +import eu.europa.ec.fisheries.uvms.audit.model.exception.AuditModelMarshallException; +import eu.europa.ec.fisheries.uvms.audit.model.mapper.AuditLogMapper; +import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException; +import eu.europa.ec.fisheries.uvms.commons.notifications.NotificationMessage; +import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesAuditProducerBean; +import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditObjectTypeEnum; +import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditOperationEnum; +import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelException; +import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent; +import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent; +import eu.europa.ec.fisheries.uvms.rules.service.exception.InputArgumentException; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; +import lombok.extern.slf4j.Slf4j; + +import javax.ejb.EJB; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.enterprise.event.Event; +import javax.inject.Inject; + +@Stateless +@LocalBean +@Slf4j +public class AlarmReportsServiceBean { + + @Inject + @AlarmReportEvent + private Event alarmReportEvent; + + @Inject + @AlarmReportCountEvent + private Event alarmReportCountEvent; + + @EJB + private RulesAuditProducerBean auditProducer; + + @EJB + private RulesResponseConsumer consumer; + + @EJB + private RulesDomainModel rulesDomainModel; + + public void createAlarmReport(CreateAlarmsReportRequest request) throws RulesServiceException { + for (AlarmReportType alarmReport : request.getAlarm()) { + validate(alarmReport); + createAlarmReport(alarmReport); + } + } + + private void validate(AlarmReportType alarmReportType) throws RulesServiceException { + if(alarmReportType == null) throw new InputArgumentException("AlarmReportType cannot be null"); + if(alarmReportType.getAlarmItem().isEmpty()) throw new InputArgumentException("AlarmItem list was empty"); + } + + private void createAlarmReport(AlarmReportType alarmReport) { + try { + alarmReport.setStatus(AlarmStatusType.OPEN); +// alarmReport.setUpdatedBy("UVMS"); +// alarmReport.setPluginType(fact.getPluginType()); + alarmReport.setInactivatePosition(false); + AlarmReportType createdAlarmReport = rulesDomainModel.createAlarmReport(alarmReport); + // Notify long-polling clients of the new alarm report + alarmReportEvent.fire(new NotificationMessage("guid", createdAlarmReport.getGuid())); + // Notify long-polling clients of the change (no value since FE will need to fetch it) + alarmReportCountEvent.fire(new NotificationMessage("alarmCount", null)); + sendAuditMessage(AuditObjectTypeEnum.ALARM, AuditOperationEnum.CREATE, createdAlarmReport.getGuid(), null, alarmReport.getUpdatedBy()); + } catch (RulesModelException e) { + log.error("[ Failed to create alarm! ] {}", e.getMessage()); + } + } + + private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) { + try { + String message = AuditLogMapper.mapToAuditLog(type.getValue(), operation.getValue(), affectedObject, comment, username); + auditProducer.sendModuleMessage(message, consumer.getDestination()); + } + catch (AuditModelMarshallException | MessageException e) { + log.error("[ Error when sending message to Audit. ] {}", e.getMessage()); + } + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java index 345c4352a..ea19f6ec3 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java @@ -11,7 +11,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The */ package eu.europa.ec.fisheries.uvms.rules.service.bean.movement; -import javax.annotation.PostConstruct; import javax.ejb.*; import java.io.InputStream; import java.util.List; @@ -26,7 +25,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact; import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; import eu.europa.ec.fisheries.uvms.rules.service.mapper.CustomRuleParser; -import lombok.extern.slf4j.Slf4j; import org.drools.template.parser.DefaultTemplateContainer; import org.drools.template.parser.TemplateContainer; import org.drools.template.parser.TemplateDataListener; @@ -34,11 +32,15 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import org.kie.api.builder.KieFileSystem; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) -@Slf4j public class MovementsRulesValidator { + + private final static Logger log = LoggerFactory.getLogger(MovementsRulesValidator.class); + // private static final String SANITY_RESOURCE_DRL_FILE = "/rules/SanityRules.drl"; private static final String CUSTOM_RULE_DRL_FILE = "src/main/resources/rules/CustomRules.drl"; private static final String CUSTOM_RULE_TEMPLATE = "/templates/CustomRulesTemplate." + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index 733b61764..93521a294 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -1069,6 +1069,9 @@ public String reprocessAlarm(List alarmGuids, String username) throws Ru continue; } + if(alarm.getAlarmItem().stream().map(a -> a.getRuleGuid() == null).findAny().orElse(false)) { + throw new RulesServiceException("Cannot reprocess an alarm that is not rule originated"); + } // Mark the alarm as REPROCESSED before reprocessing. That will create a new alarm (if still wrong) with the items remaining. alarm.setStatus(AlarmStatusType.REPROCESSED); alarm = updateAlarmStatus(alarm); From b74a515b0ffffd8407f1af408f20ae3a39eec17f Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 29 Apr 2020 16:13:22 +0300 Subject: [PATCH 04/61] [UNIONVMS-4575] movementType is now populated from MDR-Cache --- .../movement/FLUXVesselPositionMapper.java | 44 +++++-------------- .../movement/RulesMovementProcessorBean.java | 44 +++++++++++++++++-- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java index 50e07d7c0..c4830e97a 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java @@ -45,11 +45,6 @@ public class FLUXVesselPositionMapper { private static final String ASSET_UVI_CODE = "UVI"; private static final String ASSET_CFR_CODE = "CFR"; - private static final String MOVEMENTTYPE_POS = "POS"; - private static final String MOVEMENTTYPE_EXI = "EXI"; - private static final String MOVEMENTTYPE_ENT = "ENT"; - private static final String MOVEMENTTYPE_MAN = "MAN"; - /** * The transformations happening in the * 1. Plugin From FLUXVesselPositionMessage to List @@ -62,11 +57,11 @@ public class FLUXVesselPositionMapper { * @param registerClassName * @return */ - public static List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType) { + public static List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType, Map mapToMovementType) { VesselTransportMeansType positionReport = fluxVesselPositionMessage.getVesselTransportMeans(); List rowMovements = new ArrayList<>(); for (VesselPositionEventType col : positionReport.getSpecifiedVesselPositionEvents()) { - MovementBaseType baseMovement = mapResponse(col, positionReport,pluginType); + MovementBaseType baseMovement = mapResponse(col, positionReport,pluginType ,mapToMovementType); RawMovementType rawMovement = MovementMapper.getInstance().getMapper().map(baseMovement, RawMovementType.class); final eu.europa.ec.fisheries.schema.rules.asset.v1.AssetId assetId = rawMovement.getAssetId(); if (assetId != null && assetId.getAssetIdList() != null) { @@ -83,13 +78,13 @@ public static List mapToRawMovementTypes(FLUXVesselPositionMess return rowMovements; } - private static MovementBaseType mapResponse(VesselPositionEventType response, VesselTransportMeansType report, String pluginType) { + private static MovementBaseType mapResponse(VesselPositionEventType response, VesselTransportMeansType report, String pluginType, Map mapToMovementType) { MovementBaseType movement = new MovementBaseType(); HashMap extractAssetIds = extractAssetIds(report.getIDS()); movement.setAssetId(mapToAssetId(extractAssetIds)); movement.setExternalMarking(extractAssetIds.get(ASSET_EXT_MARKING_CODE)); movement.setIrcs(extractAssetIds.get(ASSET_IRCS_CODE)); - movement.setMovementType(mapToMovementTypeFromPositionType(movement, response.getTypeCode())); + movement.setMovementType(mapToMovementTypeFromPositionType(response.getTypeCode(),mapToMovementType)); setFlagState(movement, report.getRegistrationVesselCountry()); movement.setPosition(mapToMovementPoint(response.getSpecifiedVesselGeographicalCoordinate())); if (response.getObtainedOccurrenceDateTime() != null) { @@ -125,31 +120,14 @@ private static void setCourseAndSpeed(VesselPositionEventType response, Movement } } - private static MovementTypeType mapToMovementTypeFromPositionType(MovementBaseType movement, CodeType vessPosTypeCode) { - MovementTypeType movType; - if (vessPosTypeCode != null) { - switch (vessPosTypeCode.getValue()) { - case MOVEMENTTYPE_POS: - movType = MovementTypeType.POS; - break; - case MOVEMENTTYPE_EXI: - movType = MovementTypeType.EXI; - break; - case MOVEMENTTYPE_ENT: - movType = MovementTypeType.ENT; - break; - case MOVEMENTTYPE_MAN: - movType = MovementTypeType.MAN; - break; - default: - movType = null; - log.error("[ERROR] Movement type couldn't be mapped", vessPosTypeCode.getValue()); - } - } else { - movType = MovementTypeType.POS; - log.error("[ERROR] Couldn't map to movementType, vessPosTypeCode was null!"); + private static MovementTypeType mapToMovementTypeFromPositionType(CodeType vessPosTypeCode, Map mapToMovementType) { + MovementTypeType movementTypeType = mapToMovementType.get(vessPosTypeCode.getValue()); + if(movementTypeType != null){ + return movementTypeType; } - return movType; + + log.warn("Movement type couldn't be mapped: "+ vessPosTypeCode.getValue()); + return null; } private static MovementPoint mapToMovementPoint(VesselGeographicalCoordinateType coordinate) { diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index 93521a294..cc5242ceb 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -10,13 +10,14 @@ * copy of the GNU General Public License along with the IFDM Suite. If not, see . */ - package eu.europa.ec.fisheries.uvms.rules.service.bean.movement; +package eu.europa.ec.fisheries.uvms.rules.service.bean.movement; import eu.europa.ec.fisheries.remote.RulesDomainModel; import eu.europa.ec.fisheries.schema.config.module.v1.SettingsListResponse; import eu.europa.ec.fisheries.schema.config.types.v1.SettingType; import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementRefType; import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementRefTypeType; +import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementTypeType; import eu.europa.ec.fisheries.schema.exchange.movement.v1.SetReportMovementType; import eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType; import eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType; @@ -88,10 +89,12 @@ import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMapperException; import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException; import eu.europa.ec.fisheries.uvms.rules.model.mapper.JAXBMarshaller; +import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MDRCache; import eu.europa.ec.fisheries.uvms.rules.service.business.MovementFact; import eu.europa.ec.fisheries.uvms.rules.service.business.PreviousReportFact; import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact; import eu.europa.ec.fisheries.uvms.rules.service.business.RulesUtil; +import eu.europa.ec.fisheries.uvms.rules.service.constants.MDRAcronymType; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent; import eu.europa.ec.fisheries.uvms.rules.service.event.TicketCountEvent; @@ -111,6 +114,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation; import javax.ejb.EJB; import javax.ejb.LocalBean; @@ -132,8 +136,11 @@ @Slf4j public class RulesMovementProcessorBean { - private static final double VICINITY_RADIUS = 0.05; private static final long TWENTYFOUR_HOURS_IN_MILLISEC = 86400000; + private static final String MOVEMENTTYPE_POS = "POS"; + private static final String MOVEMENTTYPE_EXI = "EXIT"; + private static final String MOVEMENTTYPE_ENT = "ENTRY"; + private static final String MOVEMENTTYPE_MAN = "MANUAL"; @EJB private RulesResponseConsumer consumer; @@ -184,6 +191,36 @@ public class RulesMovementProcessorBean { @AlarmReportCountEvent private Event alarmReportCountEvent; + private Map mapToMovementType; + + @Inject + void setMdrCache(MDRCache mdrCache) { + mapToMovementType = new HashMap<>(); + List mdrCacheEntries = mdrCache.getEntry(MDRAcronymType.FLUX_VESSEL_POSITION_TYPE); + mdrCacheEntries.stream().map(ObjectRepresentation::getFields) + .forEach(t -> t.forEach( s -> { + if ("code".equals(s.getColumnName())) { + String columnValue = s.getColumnValue(); + switch (columnValue) { + case MOVEMENTTYPE_POS: + mapToMovementType.put(columnValue, MovementTypeType.POS); + break; + case MOVEMENTTYPE_EXI: + mapToMovementType.put(columnValue, MovementTypeType.EXI); + break; + case MOVEMENTTYPE_ENT: + mapToMovementType.put(columnValue, MovementTypeType.ENT); + break; + case MOVEMENTTYPE_MAN: + mapToMovementType.put(columnValue, MovementTypeType.MAN); + break; + default: + log.warn("Movement type couldn't be mapped: "+ columnValue); + } + } + })); + } + public void sendMovementReport(SendFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException { log.info("Sending Movement Report to exchange"); try { @@ -201,8 +238,7 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri String registeredPluginClassName = request.getRegisteredClassName(); try { fluxVesselPositionMessage = JAXBUtils.unMarshallMessage(request.getRequest(), FLUXVesselPositionMessage.class, null); - List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, registeredPluginClassName,pluginType); - + List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, registeredPluginClassName,pluginType,mapToMovementType); // If no movements were received then there is no sense to continue, so just going to update the exchange log status to FAILED! if (CollectionUtils.isEmpty(movementReportsList)) { log.warn("The list of rawMovements is EMPTY! Not going to proceed neither validation not sending to Movement Module!"); From e506c7f5a5b405dc2b28eb971328ec26d3771a64 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 30 Apr 2020 09:54:32 +0300 Subject: [PATCH 05/61] [UNIONVMS-4575] Test for the RulesMovementProcessorBean.setMovementReportReceived --- .../movement/FLUXVesselPositionMapper.java | 9 +- .../movement/RulesMovementProcessorBean.java | 5 +- .../RulesMovementProcessorBeanTest.java | 106 ++++++++++++++++-- 3 files changed, 103 insertions(+), 17 deletions(-) rename service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/{ => movement}/RulesMovementProcessorBeanTest.java (77%) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java index c4830e97a..c7122c79e 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; @Slf4j public class FLUXVesselPositionMapper { @@ -121,13 +122,7 @@ private static void setCourseAndSpeed(VesselPositionEventType response, Movement } private static MovementTypeType mapToMovementTypeFromPositionType(CodeType vessPosTypeCode, Map mapToMovementType) { - MovementTypeType movementTypeType = mapToMovementType.get(vessPosTypeCode.getValue()); - if(movementTypeType != null){ - return movementTypeType; - } - - log.warn("Movement type couldn't be mapped: "+ vessPosTypeCode.getValue()); - return null; + return Optional.ofNullable(vessPosTypeCode).map(CodeType::getValue).map(mapToMovementType::get).orElse(null); } private static MovementPoint mapToMovementPoint(VesselGeographicalCoordinateType coordinate) { diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index cc5242ceb..bc2eae448 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -279,14 +279,13 @@ private void enrichAndSenMovementsAsBatch(List rawMovements, St if (movementBatchResponse != null && SimpleResponse.OK.equals(movementBatchResponse.getResponse())) { // Here when ready needs to happen the validation with the list returned from movements! movementBatchResponse.getMovements(); status = ExchangeLogStatusTypeType.SUCCESSFUL; - sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); } else { status = ExchangeLogStatusTypeType.FAILED; - sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); } + sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); updateRequestMessageStatusInExchange(exchangeLogGuid, status); } catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException e) { - throw new RulesServiceException(e.getMessage()); + throw new RulesServiceException(e.getMessage(), e); } } diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMovementProcessorBeanTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java similarity index 77% rename from service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMovementProcessorBeanTest.java rename to service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java index e4b05c697..a343aac7a 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesMovementProcessorBeanTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java @@ -9,11 +9,18 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . */ -package eu.europa.ec.fisheries.uvms.rules.service.bean; +package eu.europa.ec.fisheries.uvms.rules.service.bean.movement; import eu.europa.ec.fisheries.remote.RulesDomainModel; +import eu.europa.ec.fisheries.schema.mobileterminal.module.v1.MobileTerminalBatchListResponse; +import eu.europa.ec.fisheries.schema.movement.common.v1.SimpleResponse; +import eu.europa.ec.fisheries.schema.movement.module.v1.CreateMovementBatchRequest; +import eu.europa.ec.fisheries.schema.movement.module.v1.CreateMovementBatchResponse; +import eu.europa.ec.fisheries.schema.movement.v1.MovementTypeType; import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmReportType; import eu.europa.ec.fisheries.schema.rules.customrule.v1.CustomRuleType; +import eu.europa.ec.fisheries.schema.rules.exchange.v1.PluginType; +import eu.europa.ec.fisheries.schema.rules.module.v1.SetFLUXMovementReportRequest; import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType; import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery; import eu.europa.ec.fisheries.schema.rules.search.v1.TicketQuery; @@ -22,17 +29,22 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.schema.rules.source.v1.GetTicketListByQueryResponse; import eu.europa.ec.fisheries.schema.rules.ticket.v1.TicketStatusType; import eu.europa.ec.fisheries.schema.rules.ticket.v1.TicketType; +import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException; +import eu.europa.ec.fisheries.uvms.commons.message.impl.JAXBUtils; import eu.europa.ec.fisheries.uvms.commons.notifications.NotificationMessage; import eu.europa.ec.fisheries.uvms.rules.message.constants.DataSourceQueue; import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer; import eu.europa.ec.fisheries.uvms.rules.message.producer.RulesMessageProducer; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesExchangeProducerBean; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesMobilTerminalProducerBean; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesMovementProducerBean; import eu.europa.ec.fisheries.uvms.rules.model.dto.AlarmListResponseDto; import eu.europa.ec.fisheries.uvms.rules.model.dto.TicketListResponseDto; import eu.europa.ec.fisheries.uvms.rules.model.mapper.RulesDataSourceRequestMapper; import eu.europa.ec.fisheries.uvms.rules.model.mapper.RulesDataSourceResponseMapper; -import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.RulesMovementProcessorBean; -import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.MovementValidationServiceBean; +import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MDRCache; import eu.europa.ec.fisheries.uvms.rules.service.business.PreviousReportFact; +import eu.europa.ec.fisheries.uvms.rules.service.constants.MDRAcronymType; import eu.europa.ec.fisheries.uvms.rules.service.constants.ServiceConstants; import org.junit.Before; import org.junit.Ignore; @@ -45,13 +57,25 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.mdr.communication.ColumnDataType; +import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselPositionEventType; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType; +import un.unece.uncefact.data.standard.unqualifieddatatype._18.CodeType; import javax.enterprise.event.Event; +import javax.jms.JMSException; import javax.jms.TextMessage; +import javax.xml.bind.JAXBException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.UUID; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; @@ -64,11 +88,15 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The @PrepareForTest({RulesDataSourceRequestMapper.class, RulesDataSourceResponseMapper.class}) public class RulesMovementProcessorBeanTest { + private static final String USERNAME = "USERNAME"; + @Mock RulesMessageProducer mockProducer; @Mock RulesResponseConsumer mockConsumer; @Mock + RulesMobilTerminalProducerBean mobileTerminalProducer; + @Mock Event ticketEvent; @Mock Event ticketUpdateEvent; @@ -78,6 +106,12 @@ public class RulesMovementProcessorBeanTest { MovementValidationServiceBean mockValidationServiceBean; @Mock Event alarmReportCountEvent; + @Mock + RulesMovementProducerBean movementProducer; + @Mock + MDRCache mdrCache; + @Mock + RulesExchangeProducerBean exchangeProducer; @InjectMocks RulesMovementProcessorBean rulesMovementProcessorBean; @@ -499,15 +533,73 @@ public void testGetTicketByGuid() throws Exception { TicketType mock = mock(TicketType.class); when(rulesDomainModel.getTicketByGuid(guid)).thenReturn(mock); rulesMovementProcessorBean.getTicketByGuid(guid); - } - public void testReprocessAlarm() throws Exception { + @Test + public void testSetMovementReportReceived() throws Exception { + mockStatic(RulesDataSourceRequestMapper.class); + setupMdrCache(); + SetFLUXMovementReportRequest request = new SetFLUXMovementReportRequest(); + request.setType(PluginType.FLUX); + request.setUsername(USERNAME); + setupFluxVesselPositionMessage(request); + setupMobileTerminalConversation(); + setupMovementModuleConversation(); + String messageGuid = UUID.randomUUID().toString(); + + rulesMovementProcessorBean.setMovementReportReceived(request, messageGuid); + + ArgumentCaptor createMovementRequestCaptor = ArgumentCaptor.forClass(String.class); + verify(movementProducer).sendModuleMessage(createMovementRequestCaptor.capture(), any()); + CreateMovementBatchRequest createMovementBatchRequest = JAXBUtils.unMarshallMessage(createMovementRequestCaptor.getValue(), CreateMovementBatchRequest.class); + assertNotNull(createMovementBatchRequest); + assertNotNull(createMovementBatchRequest.getMovement()); + assertEquals(1, createMovementBatchRequest.getMovement().size()); + assertEquals(MovementTypeType.MAN, createMovementBatchRequest.getMovement().get(0).getMovementType()); + } + private void setupMdrCache() { + List mdrCacheEntries = Arrays.asList( + new ObjectRepresentation(Collections.singletonList(new ColumnDataType("code", "POS", null))), + new ObjectRepresentation(Collections.singletonList(new ColumnDataType("code", "EXIT", null))), + new ObjectRepresentation(Collections.singletonList(new ColumnDataType("code", "ENTRY", null))), + new ObjectRepresentation(Collections.singletonList(new ColumnDataType("code", "MANUAL", null))) + ); + when(mdrCache.getEntry(MDRAcronymType.FLUX_VESSEL_POSITION_TYPE)).thenReturn(mdrCacheEntries); + rulesMovementProcessorBean.setMdrCache(mdrCache); } - public void testSetMovementReportReceived() throws Exception { + private void setupFluxVesselPositionMessage(SetFLUXMovementReportRequest request) throws JAXBException { + FLUXVesselPositionMessage fluxVesselPositionMessage = new FLUXVesselPositionMessage(); + VesselTransportMeansType vesselTransportMeans = new VesselTransportMeansType(); + fluxVesselPositionMessage.setVesselTransportMeans(vesselTransportMeans); + VesselPositionEventType vesselPositionEvent = new VesselPositionEventType(); + vesselPositionEvent.setTypeCode(new CodeType()); + vesselPositionEvent.getTypeCode().setValue("MANUAL"); + vesselTransportMeans.getSpecifiedVesselPositionEvents().add(vesselPositionEvent); + request.setRequest(JAXBUtils.marshallJaxBObjectToString(fluxVesselPositionMessage, "UTF-8", true)); + } + private void setupMobileTerminalConversation() throws MessageException, JMSException, JAXBException { + String getMobileTerminalMessageId = UUID.randomUUID().toString(); + when(mobileTerminalProducer.sendModuleMessage(anyString(), any())).thenReturn(getMobileTerminalMessageId); + TextMessage getMobileTerminalResponse = mock(TextMessage.class); + String textMessageCorrelationID = UUID.randomUUID().toString(); + when(getMobileTerminalResponse.getJMSCorrelationID()).thenReturn(textMessageCorrelationID); + MobileTerminalBatchListResponse mobileTerminalBatchListResponse = new MobileTerminalBatchListResponse(); + when(getMobileTerminalResponse.getText()).thenReturn(JAXBUtils.marshallJaxBObjectToString(mobileTerminalBatchListResponse, "UTF-8", true)); + when(mockConsumer.getMessage(eq(getMobileTerminalMessageId), eq(TextMessage.class))).thenReturn(getMobileTerminalResponse); } -} \ No newline at end of file + private void setupMovementModuleConversation() throws MessageException, JMSException, JAXBException { + String movementMessageId = UUID.randomUUID().toString(); + when(movementProducer.sendModuleMessage(anyString(), any())).thenReturn(movementMessageId); + TextMessage movJmsResponse = mock(TextMessage.class); + String movJmsResponseCorrId = UUID.randomUUID().toString(); + when(movJmsResponse.getJMSCorrelationID()).thenReturn(movJmsResponseCorrId); + CreateMovementBatchResponse createMovementBatchResponse = new CreateMovementBatchResponse(); + createMovementBatchResponse.setResponse(SimpleResponse.OK); + when(movJmsResponse.getText()).thenReturn(JAXBUtils.marshallJaxBObjectToString(createMovementBatchResponse, "UTF-8", true)); + when(mockConsumer.getMessage(eq(movementMessageId), eq(TextMessage.class), anyLong())).thenReturn(movJmsResponse); + } +} From 1b6356a909590b4d06e362eee8ac0536cdb8cb8f Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Thu, 30 Apr 2020 18:20:28 +0300 Subject: [PATCH 06/61] [UNIONVMS-4574] added ext marking to mapper --- .../rules/service/bean/movement/FLUXVesselPositionMapper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java index c7122c79e..ef7132936 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java @@ -42,6 +42,7 @@ public class FLUXVesselPositionMapper { private static final String ASSET_EXT_MARKING_CODE = "EXT_MARKING"; + public static final String ASSET_EXT_MARK = "EXT_MARK"; private static final String ASSET_IRCS_CODE = "IRCS"; private static final String ASSET_UVI_CODE = "UVI"; private static final String ASSET_CFR_CODE = "CFR"; @@ -175,6 +176,9 @@ private static AssetId mapToAssetId(Map vesselIds) { case ASSET_UVI_CODE: assetIdList.add(mapToVesselId(AssetIdType.IMO, vesselId.getValue())); break; + case ASSET_EXT_MARK: + case ASSET_EXT_MARKING_CODE: + break; default: log.error("VesselId type not mapped {}", vesselId.getKey()); } From 3aa74a15f79c11749e92a95b8691af9218c50092 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 13 Apr 2020 15:07:41 +0300 Subject: [PATCH 07/61] [UNIONVMS-4489] static initialization of XSD files for faster processing --- .../mapper/RulesFLUXMessageHelper.java | 26 +++-------- .../mapper/xpath/util/SchemaInitializer.java | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/xpath/util/SchemaInitializer.java diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java index 390c6b81f..5357a4ca3 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java @@ -50,15 +50,16 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import static eu.europa.ec.fisheries.uvms.rules.entity.FAUUIDType.FA_REPORT_REF_ID; import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.RESPONSE_IDS; import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER; +import static eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.SchemaInitializer.SCHEMA_MAP; import static java.util.Collections.singletonList; @Slf4j public class RulesFLUXMessageHelper { public static final String FLUX_LOCAL_NATION_CODE = "flux_local_nation_code"; - private static final String FLUXFAREPORT_MESSAGE_3P1_XSD = "xsd/contract/fa/data/standard/FLUXFAReportMessage_3p1.xsd"; - private static final String FLUXFAQUERY_MESSAGE_3P0_XSD = "xsd/contract/fa/data/standard/FLUXFAQueryMessage_3p0.xsd"; - private static final String FLUXFARESPONSE_MESSAGE_6P0_XSD = "xsd/contract/fa/data/standard/FLUXResponseMessage_6p0.xsd"; + public static final String FLUXFAREPORT_MESSAGE_3P1_XSD = "xsd/contract/fa/data/standard/FLUXFAReportMessage_3p1.xsd"; + public static final String FLUXFAQUERY_MESSAGE_3P0_XSD = "xsd/contract/fa/data/standard/FLUXFAQueryMessage_3p0.xsd"; + public static final String FLUXFARESPONSE_MESSAGE_6P0_XSD = "xsd/contract/fa/data/standard/FLUXResponseMessage_6p0.xsd"; private static final String DASH = "-"; private FAReportQueryResponseIdsMapper faIdsMapper = new FAReportQueryResponseIdsMapperImpl(); @@ -203,7 +204,7 @@ public Set mapToResponseToFADocumentID(FLUXResponseMessage fluxRes public FLUXFAReportMessage unMarshallAndValidateSchema(String request) throws UnmarshalException { try { - return JAXBUtils.unMarshallMessage(request, FLUXFAReportMessage.class, loadXSDSchema(FLUXFAREPORT_MESSAGE_3P1_XSD)); + return JAXBUtils.unMarshallMessage(request, FLUXFAReportMessage.class, SCHEMA_MAP.get(FLUXFAREPORT_MESSAGE_3P1_XSD)); } catch (Exception e) { throw new UnmarshalException(e.getCause().getLocalizedMessage()); } @@ -211,7 +212,7 @@ public FLUXFAReportMessage unMarshallAndValidateSchema(String request) throws Un public FLUXFAQueryMessage unMarshallFaQueryMessage(String request) throws UnmarshalException { try { - return JAXBUtils.unMarshallMessage(request, FLUXFAQueryMessage.class, loadXSDSchema(FLUXFAQUERY_MESSAGE_3P0_XSD)); + return JAXBUtils.unMarshallMessage(request, FLUXFAQueryMessage.class, SCHEMA_MAP.get(FLUXFAQUERY_MESSAGE_3P0_XSD)); } catch (Exception e) { throw new UnmarshalException(e.getCause().getLocalizedMessage()); } @@ -219,25 +220,12 @@ public FLUXFAQueryMessage unMarshallFaQueryMessage(String request) throws Unmars public FLUXResponseMessage unMarshallFluxResponseMessage(String request) throws UnmarshalException { try { - return JAXBUtils.unMarshallMessage(request, FLUXResponseMessage.class, loadXSDSchema(FLUXFARESPONSE_MESSAGE_6P0_XSD)); + return JAXBUtils.unMarshallMessage(request, FLUXResponseMessage.class, SCHEMA_MAP.get(FLUXFARESPONSE_MESSAGE_6P0_XSD)); } catch (Exception e) { throw new UnmarshalException(e.getCause().getLocalizedMessage()); } } - public Schema loadXSDSchema(String xsdLocation) throws UnmarshalException { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - URL resource = RulesFLUXMessageHelper.class.getClassLoader().getResource(xsdLocation); - if (resource != null) { - try { - return sf.newSchema(resource); - } catch (SAXException e) { - throw new UnmarshalException(e.getMessage(), e); - } - } - throw new UnmarshalException("ERROR WHILE TRYING TO LOOKUP XSD SCHEMA"); - } - public String getIDs(FLUXResponseMessage fluxResponseMessageObj) { String id = null; if (fluxResponseMessageObj != null){ diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/xpath/util/SchemaInitializer.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/xpath/util/SchemaInitializer.java new file mode 100644 index 000000000..87be0da69 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/xpath/util/SchemaInitializer.java @@ -0,0 +1,44 @@ +package eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util; + +import eu.europa.ec.fisheries.uvms.rules.service.mapper.RulesFLUXMessageHelper; +import org.xml.sax.SAXException; + +import javax.xml.XMLConstants; +import javax.xml.bind.UnmarshalException; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import java.net.URL; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + + +public class SchemaInitializer { + + public static final Map SCHEMA_MAP; + + static { + try { + HashMap schemaMap = new HashMap<>(); + schemaMap.put(RulesFLUXMessageHelper.FLUXFAREPORT_MESSAGE_3P1_XSD, SchemaInitializer.loadXSDSchema(RulesFLUXMessageHelper.FLUXFAREPORT_MESSAGE_3P1_XSD)); + schemaMap.put(RulesFLUXMessageHelper.FLUXFAQUERY_MESSAGE_3P0_XSD, SchemaInitializer.loadXSDSchema(RulesFLUXMessageHelper.FLUXFAQUERY_MESSAGE_3P0_XSD)); + schemaMap.put(RulesFLUXMessageHelper.FLUXFARESPONSE_MESSAGE_6P0_XSD, SchemaInitializer.loadXSDSchema(RulesFLUXMessageHelper.FLUXFARESPONSE_MESSAGE_6P0_XSD)); + SCHEMA_MAP = Collections.unmodifiableMap(schemaMap); + } catch (UnmarshalException e) { + throw new RuntimeException("Cannot initialize XSD", e); + } + } + + private static Schema loadXSDSchema(String xsdLocation) throws UnmarshalException { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL resource = RulesFLUXMessageHelper.class.getClassLoader().getResource(xsdLocation); + if (resource != null) { + try { + return sf.newSchema(resource); + } catch (SAXException e) { + throw new UnmarshalException(e.getMessage(), e); + } + } + throw new UnmarshalException("ERROR WHILE TRYING TO LOOKUP XSD SCHEMA"); + } +} From 6411a9b3d2598e0c4a44f0b944ad1230966f1709 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Wed, 29 Apr 2020 15:01:45 +0300 Subject: [PATCH 08/61] [UNIONVMS-4577] Use the slimmed XSDs --- .../uvms/rules/service/mapper/RulesFLUXMessageHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java index 5357a4ca3..60a9c530f 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/RulesFLUXMessageHelper.java @@ -57,9 +57,9 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The public class RulesFLUXMessageHelper { public static final String FLUX_LOCAL_NATION_CODE = "flux_local_nation_code"; - public static final String FLUXFAREPORT_MESSAGE_3P1_XSD = "xsd/contract/fa/data/standard/FLUXFAReportMessage_3p1.xsd"; - public static final String FLUXFAQUERY_MESSAGE_3P0_XSD = "xsd/contract/fa/data/standard/FLUXFAQueryMessage_3p0.xsd"; - public static final String FLUXFARESPONSE_MESSAGE_6P0_XSD = "xsd/contract/fa/data/standard/FLUXResponseMessage_6p0.xsd"; + public static final String FLUXFAREPORT_MESSAGE_3P1_XSD = "xsd/contract/slim/FLUXFAReportMessage_3p1.xsd"; + public static final String FLUXFAQUERY_MESSAGE_3P0_XSD = "xsd/contract/slim/FLUXFAQueryMessage_3p0.xsd"; + public static final String FLUXFARESPONSE_MESSAGE_6P0_XSD = "xsd/contract/slim/FLUXResponseMessage_6p0.xsd"; private static final String DASH = "-"; private FAReportQueryResponseIdsMapper faIdsMapper = new FAReportQueryResponseIdsMapperImpl(); From 9376dc94db96cfc69629b4b59f2a571535a5a3d5 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 13 May 2020 14:37:55 +0300 Subject: [PATCH 09/61] [UNIONVMS-4576] JMS messages are sent with JMSXGroupID option --- .../bean/movement/RulesMovementProcessorBean.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index bc2eae448..298fffa6e 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -127,6 +127,7 @@ import java.nio.file.AccessDeniedException; import java.util.*; import java.util.concurrent.*; +import java.util.stream.Collectors; import static eu.europa.ec.fisheries.uvms.movement.model.exception.ErrorCode.MOVEMENT_DUPLICATE_ERROR; @@ -684,7 +685,9 @@ private CreateMovementBatchResponse sendBatchToMovement(List asset, List< try { String createMovementRequest = MovementModuleRequestMapper.mapToCreateMovementBatchRequest(movementBatch, username); log.debug("Send CreateMovementRequest message to Movement"); - String messageId = movementProducer.sendModuleMessage(createMovementRequest, consumer.getDestination()); + warnOnMultipleConnectIds(connectIds); + String connectId = connectIds.get(0); + String messageId = movementProducer.sendModuleMessageInGroup(createMovementRequest, consumer.getDestination(), connectId); TextMessage movJmsResponse = consumer.getMessage(messageId, TextMessage.class, 2400000L); log.debug("Received response message"); movementSimpleResponse = MovementModuleResponseMapper.mapToCreateMovementBatchResponse(movJmsResponse); @@ -704,6 +707,16 @@ private CreateMovementBatchResponse sendBatchToMovement(List asset, List< } } + private void warnOnMultipleConnectIds(List connectIds) { + if (connectIds.size() == 1) { + return; + } + Set uniqueConnectIds = new HashSet<>(connectIds); + if (uniqueConnectIds.size() > 1) { + log.warn("*** connectIds with {} different elements, the JMSXGroupId will be wrong! The first two elements are: {} ***", uniqueConnectIds.size(), uniqueConnectIds.stream().limit(2).collect(Collectors.joining(",","[","]"))); + } + } + private List collectConnectIdsFromAssetList(List assets, List rawMovements) { List connectIdsList = new ArrayList<>(); int index = 0; From aa51a508cd75f483dd450b548d1dc70e3d18b70b Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 16 Jul 2020 16:04:05 +0300 Subject: [PATCH 10/61] [UNIONVMS-4576] Corrected test --- .../service/bean/movement/RulesMovementProcessorBeanTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java index a343aac7a..17c7007d7 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java @@ -550,7 +550,7 @@ public void testSetMovementReportReceived() throws Exception { rulesMovementProcessorBean.setMovementReportReceived(request, messageGuid); ArgumentCaptor createMovementRequestCaptor = ArgumentCaptor.forClass(String.class); - verify(movementProducer).sendModuleMessage(createMovementRequestCaptor.capture(), any()); + verify(movementProducer).sendModuleMessageInGroup(createMovementRequestCaptor.capture(), any(), anyString()); CreateMovementBatchRequest createMovementBatchRequest = JAXBUtils.unMarshallMessage(createMovementRequestCaptor.getValue(), CreateMovementBatchRequest.class); assertNotNull(createMovementBatchRequest); assertNotNull(createMovementBatchRequest.getMovement()); @@ -593,7 +593,7 @@ private void setupMobileTerminalConversation() throws MessageException, JMSExcep private void setupMovementModuleConversation() throws MessageException, JMSException, JAXBException { String movementMessageId = UUID.randomUUID().toString(); - when(movementProducer.sendModuleMessage(anyString(), any())).thenReturn(movementMessageId); + when(movementProducer.sendModuleMessageInGroup(anyString(), any(), anyString())).thenReturn(movementMessageId); TextMessage movJmsResponse = mock(TextMessage.class); String movJmsResponseCorrId = UUID.randomUUID().toString(); when(movJmsResponse.getJMSCorrelationID()).thenReturn(movJmsResponseCorrId); From a86d957eea52bf085ecce975852a01ce96f49c9b Mon Sep 17 00:00:00 2001 From: lsotiriadis Date: Wed, 15 Jul 2020 19:03:46 +0300 Subject: [PATCH 11/61] [UNIONVMS-4709] Displaying alarms as notifications (Tickets) Signed-off-by: lsotiriadis --- .../uvms/rules/bean/RulesDomainModelBean.java | 6 +- .../uvms/rules/constant/UvmsConstants.java | 1 + .../uvms/rules/dao/bean/RulesDaoBean.java | 16 +- .../fisheries/uvms/rules/entity/Ticket.java | 3 +- .../search/TicketSearchFieldMapper.java | 88 +++----- .../bean/RulesEventMessageConsumerBean.java | 7 + .../event/CreateTicketsReceivedEvent.java | 25 +++ .../src/main/resources/contract/Movement.xsd | 1 + .../contract/RulesModuleService.wsdl | 3 +- .../communication/JmsMovementClient.java | 72 +++++++ .../communication/ManagedObjectsProducer.java | 33 +++ .../communication/MovementClient.java | 28 +++ .../movement/communication/MovementQueue.java | 25 +++ .../communication/MovementSender.java | 28 +++ .../communication/MovementSenderImpl.java | 62 ++++++ .../uvms/rules/service/EventService.java | 2 + .../service/bean/RulesEventServiceBean.java | 17 +- ...erviceBean.java => AlarmsServiceBean.java} | 78 +++++-- .../bean/alarms/RawMovementTypeMapper.java | 54 +++++ .../MovementValidationServiceBean.java | 5 +- .../bean/alarms/AlarmsServiceBeanTest.java | 196 ++++++++++++++++++ 21 files changed, 659 insertions(+), 91 deletions(-) create mode 100644 message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java rename service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/{AlarmReportsServiceBean.java => AlarmsServiceBean.java} (60%) create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java create mode 100644 service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBeanTest.java diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java index f11c900f5..964278016 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java @@ -47,6 +47,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.UUID; @Stateless public class RulesDomainModelBean implements RulesDomainModel { @@ -782,10 +783,7 @@ public long getNumberOfOpenTickets(String userName) throws RulesModelException { LOG.info("[INFO] Counting open tickets"); try { List validRuleGuids = rulesDao.getCustomRulesForTicketsByUser(userName); - if (!validRuleGuids.isEmpty()) { - return rulesDao.getNumberOfOpenTickets(validRuleGuids); - } - return 0; + return rulesDao.getNumberOfOpenTickets(validRuleGuids); } catch (DaoException e) { LOG.error("[ERROR] Error when counting open tickets {}", e.getMessage()); throw new RulesModelException(e.getMessage(), e); diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java index a372419a0..ec6ddd2e2 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java @@ -18,6 +18,7 @@ public final class UvmsConstants { public static final String FIND_ALARM_BY_GUID = "AlarmReport.findByGuid"; public static final String COUNT_OPEN_ALARMS = "AlarmReport.countOpenAlarms"; public static final String COUNT_OPEN_TICKETS = "AlarmReport.countOpenTickets"; + public static final String COUNT_OPEN_TICKETS_NO_RULES = "AlarmReport.countOpenTicketsNoRules"; public static final String FIND_ALARM_REPORT_BY_ASSET_GUID_AND_RULE_GUID = "AlarmReport.findByAssetGuidRuleGuid"; public static final String GET_RUNNABLE_CUSTOM_RULES = "CustomRule.getValidCustomRule"; public static final String LIST_CUSTOM_RULES_BY_USER = "CustomRule.listCustomRules"; // rule engine diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java index 104a59e3a..4480afe2d 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java @@ -19,7 +19,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceException; import javax.persistence.TransactionRequiredException; import javax.persistence.TypedQuery; import java.util.ArrayList; @@ -131,10 +130,6 @@ public List getTicketsByMovements(List movements) throws DaoExce TypedQuery query = em.createNamedQuery(UvmsConstants.FIND_TICKETS_BY_MOVEMENTS, Ticket.class); query.setParameter("movements", movements); return query.getResultList(); - } catch (NoResultException e) { - // TODO: Return empty list??? - log.error("[ No tickets found for movements ]"); - throw new NoEntityFoundException("[ No tickets found for movements ]", e); } catch (Exception e) { log.error("[ERROR] when getting Ticket by movements. {}", e.getMessage()); throw new DaoException("[ERROR] when getting Ticket by movements. ", e); @@ -160,8 +155,6 @@ public List getCustomRulesForTicketsByUser(String owner) throws DaoExcep TypedQuery query = em.createNamedQuery(UvmsConstants.FIND_CUSTOM_RULE_GUID_FOR_TICKETS, String.class); query.setParameter("owner", owner); return query.getResultList(); - } catch (NoResultException e) { - return new ArrayList<>(); } catch (Exception e) { log.error("[ERROR] when getting Tickets by userName. {}", e.getMessage()); throw new DaoException("[ERROR] when getting Tickets by userName. ", e); @@ -182,8 +175,13 @@ public long getNumberOfOpenAlarms() throws DaoException { @Override public long getNumberOfOpenTickets(List validRuleGuids) throws DaoException { try { - TypedQuery query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS, Long.class); - query.setParameter("validRuleGuids", validRuleGuids); + TypedQuery query; + if (validRuleGuids.isEmpty()) { + query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS_NO_RULES, Long.class); + } else { + query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS, Long.class); + query.setParameter("validRuleGuids", validRuleGuids); + } return query.getSingleResult(); } catch (NoResultException e) { return 0; diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java index 613001b11..a280e2d0b 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java @@ -27,7 +27,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The @NamedQueries({ @NamedQuery(name = UvmsConstants.FIND_TICKET_BY_GUID, query = "SELECT t FROM Ticket t WHERE t.guid = :guid"), @NamedQuery(name = UvmsConstants.FIND_TICKET_BY_ASSET_AND_RULE, query = "SELECT t FROM Ticket t WHERE t.assetGuid = :assetGuid and status <> 'CLOSED' and ruleGuid = :ruleGuid"), - @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND t.ruleGuid IN :validRuleGuids"), + @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND (t.ruleGuid IN :validRuleGuids OR t.ruleGuid IS NULL)"), + @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS_NO_RULES, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND t.ruleGuid IS NULL"), @NamedQuery(name = UvmsConstants.FIND_TICKETS_BY_MOVEMENTS, query = "SELECT t FROM Ticket t where t.movementGuid IN :movements"), @NamedQuery(name = UvmsConstants.COUNT_TICKETS_BY_MOVEMENTS, query = "SELECT count(t) FROM Ticket t where t.movementGuid IN :movements"), @NamedQuery(name = UvmsConstants.COUNT_ASSETS_NOT_SENDING, query = "SELECT count(t) FROM Ticket t where t.ruleGuid = :ruleGuid") diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java index f1ddd382d..1d4b53d83 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java @@ -21,7 +21,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; @@ -40,42 +40,13 @@ public class TicketSearchFieldMapper { */ public static String createSelectSearchSql(List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException { StringBuilder selectBuffer = new StringBuilder(); - selectBuffer.append("SELECT ") - .append(TicketSearchTables.TICKET.getTableAlias()) - .append(" FROM ") - .append(TicketSearchTables.TICKET.getTableName()) - .append(" ") - .append(TicketSearchTables.TICKET.getTableAlias()) - .append(" "); - if (searchFields != null && !searchFields.isEmpty()) { - selectBuffer.append(createSearchSql(searchFields, isDynamic)); - - selectBuffer.append(" AND "); - } else { - selectBuffer.append(" WHERE "); - } - selectBuffer.append(TicketSearchTables.TICKET.getTableAlias()) - .append(".") - .append(TicketSearchField.RULE_GUID.getFieldName()); - - selectBuffer.append(" IN ( "); - selectBuffer.append("'").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'"); - for (String validRuleGuid : validRuleGuids) { - selectBuffer.append(", "); - selectBuffer.append("'").append(validRuleGuid).append("'"); - } - selectBuffer.append(" )"); - - selectBuffer - .append(" ORDER BY ") - .append(TicketSearchTables.TICKET.getTableAlias()) - .append(".") - .append(TicketSearchField.FROM_DATE.getFieldName()) - .append(" DESC"); - LOG.info("[ SQL: ] {}", selectBuffer.toString()); - return selectBuffer.toString(); + selectBuffer.append("SELECT {ticket_alias} "); + queryBody(selectBuffer,searchFields,validRuleGuids,isDynamic); + selectBuffer.append("ORDER BY {ticket_alias}.{from_date} DESC"); + String query = replaceTemplates(selectBuffer); + LOG.info("[ SQL: ] {}", query); + return query; } - /** * * Creates a JPQL count query based on the search fields. This is used for @@ -88,33 +59,34 @@ public static String createSelectSearchSql(List searchFields, */ public static String createCountSearchSql(List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException { StringBuilder countBuffer = new StringBuilder(); - countBuffer.append("SELECT COUNT(") - .append(TicketSearchTables.TICKET.getTableAlias()) - .append(") FROM ") - .append(TicketSearchTables.TICKET.getTableName()) - .append(" ") - .append(TicketSearchTables.TICKET.getTableAlias()) - .append(" "); + countBuffer.append("SELECT COUNT({ticket_alias}) "); + queryBody(countBuffer,searchFields,validRuleGuids,isDynamic); + String query = replaceTemplates(countBuffer); + LOG.debug("[ COUNT SQL: ]{}", query); + return query; + } + + private static void queryBody(StringBuilder buffer,List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException { + buffer.append("FROM {ticket_table} {ticket_alias} "); if (searchFields != null && !searchFields.isEmpty()) { - countBuffer.append(createSearchSql(searchFields, isDynamic)); - countBuffer.append(" AND "); + buffer.append(createSearchSql(searchFields, isDynamic)); + buffer.append(" AND "); } else { - countBuffer.append(" WHERE "); + buffer.append(" WHERE "); } - countBuffer.append(TicketSearchTables.TICKET.getTableAlias()) - .append(".") - .append(TicketSearchField.RULE_GUID.getFieldName()); - - countBuffer.append(" IN ( "); - countBuffer.append("'").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'"); + buffer.append("({ticket_alias}.{rule_guid} IN ('").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'"); for (String validRuleGuid : validRuleGuids) { - countBuffer.append(", "); - countBuffer.append("'").append(validRuleGuid).append("'"); + buffer.append(",'").append(validRuleGuid).append("'"); } - countBuffer.append(" )"); + buffer.append(" ) OR {ticket_alias}.{rule_guid} IS NULL) "); + } - LOG.debug("[ COUNT SQL: ]{}", countBuffer.toString()); - return countBuffer.toString(); + private static String replaceTemplates(StringBuilder buffer) { + return buffer.toString() + .replace("{ticket_table}",TicketSearchTables.TICKET.getTableName()) + .replace("{ticket_alias}",TicketSearchTables.TICKET.getTableAlias()) + .replace("{rule_guid}",TicketSearchField.RULE_GUID.getFieldName()) + .replace("{from_date}",TicketSearchField.FROM_DATE.getFieldName()); } /** @@ -291,7 +263,7 @@ private static HashMap> combineSearch if (values.containsKey(search.getField())) { values.get(search.getField()).add(search); } else { - values.put(search.getField(), new ArrayList(Arrays.asList(search))); + values.put(search.getField(), new ArrayList<>(Collections.singletonList(search))); } } return values; diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java index e3631b0a8..f591b909a 100644 --- a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java @@ -117,6 +117,10 @@ public class RulesEventMessageConsumerBean implements MessageListener { @CreateAlarmReceivedEvent private Event createAlarmReceivedEvent; + @Inject + @CreateTicketsReceivedEvent + private Event createTicketsReceivedEvent; + @Inject @ErrorEvent private Event errorEvent; @@ -181,6 +185,9 @@ public void onMessage(Message message) { case CREATE_ALARMS_REPORT_REQUEST : createAlarmReceivedEvent.fire(eventMessage); break; + case CREATE_TICKETS_REQUEST: + createTicketsReceivedEvent.fire(eventMessage); + break; default: LOG.error("[ Request method '{}' is not implemented ]", method.name()); errorEvent.fire(new EventMessage(textMessage, ModuleResponseMapper.createFaultMessage(FaultCode.RULES_MESSAGE, "Method not implemented:" + method.name()))); diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java new file mode 100644 index 000000000..6e532a037 --- /dev/null +++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java @@ -0,0 +1,25 @@ +/* +Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries +© European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can +redistribute it and/or modify it under the terms of the GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in +the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a +copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.message.event; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE }) +public @interface CreateTicketsReceivedEvent { + +} \ No newline at end of file diff --git a/model/src/main/resources/contract/Movement.xsd b/model/src/main/resources/contract/Movement.xsd index 7a8b9feb0..45e3866a0 100755 --- a/model/src/main/resources/contract/Movement.xsd +++ b/model/src/main/resources/contract/Movement.xsd @@ -18,6 +18,7 @@ + diff --git a/model/src/main/resources/contract/RulesModuleService.wsdl b/model/src/main/resources/contract/RulesModuleService.wsdl index 8f256d959..fcb9cd058 100755 --- a/model/src/main/resources/contract/RulesModuleService.wsdl +++ b/model/src/main/resources/contract/RulesModuleService.wsdl @@ -65,6 +65,7 @@ + @@ -400,7 +401,7 @@ - + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java new file mode 100644 index 000000000..01ab501bc --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java @@ -0,0 +1,72 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest; +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse; +import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException; +import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException; +import eu.europa.ec.fisheries.uvms.movement.model.mapper.JAXBMarshaller; +import eu.europa.ec.fisheries.uvms.rules.message.consumer.bean.RulesResponseConsumerBean; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesProducerBean; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceTechnicalException; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.jms.Queue; +import javax.jms.TextMessage; + +/** + * JMS implementation of the {@link MovementClient}. + */ +@ApplicationScoped +public class JmsMovementClient implements MovementClient { + + private RulesProducerBean rulesProducerBean; + private RulesResponseConsumerBean rulesResponseConsumerBean; + private Queue movementQueue; + + /** + * Injection constructor. + * + * @param rulesProducerBean The rules module producer bean + * @param rulesResponseConsumerBean The rules module consumer bean + * @param movementQueue The movement specific queue created by ManagedObjectsProducer + */ + @Inject + public JmsMovementClient(RulesProducerBean rulesProducerBean, RulesResponseConsumerBean rulesResponseConsumerBean, @MovementQueue Queue movementQueue) { + this.rulesProducerBean = rulesProducerBean; + this.rulesResponseConsumerBean = rulesResponseConsumerBean; + this.movementQueue = movementQueue; + } + + /** + * Constructor for frameworks. + */ + @SuppressWarnings("unused") + JmsMovementClient() { + // NOOP + } + + @Override + public FindRawMovementsResponse findRawMovements(FindRawMovementsRequest request) throws MovementModelException { + try { + String correlationId = rulesProducerBean.sendMessageToSpecificQueue(JAXBMarshaller.marshallJaxBObjectToString(request), movementQueue, rulesResponseConsumerBean.getDestination()); + FindRawMovementsResponse response = null; + if (correlationId != null) { + TextMessage textMessage = rulesResponseConsumerBean.getMessage(correlationId, TextMessage.class); + response = JAXBMarshaller.unmarshallTextMessage(textMessage, FindRawMovementsResponse.class); + } + return response; + } catch (MessageException e) { + throw new RulesServiceTechnicalException("error while calling findRawMovements", e); + } + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java new file mode 100644 index 000000000..bd1e5ad8d --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java @@ -0,0 +1,33 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import eu.europa.ec.fisheries.uvms.commons.message.api.MessageConstants; + +import javax.annotation.Resource; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Produces; +import javax.jms.Queue; + +/** + * Introduces various Movement-related application server objects into CDI. + */ +@Dependent +class ManagedObjectsProducer { + + @Resource(mappedName = "java:/" + MessageConstants.QUEUE_MODULE_MOVEMENT) + private Queue movementQueue; + + @Produces @ApplicationScoped @MovementQueue + public Queue getMovementQueue() { + return movementQueue; + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java new file mode 100644 index 000000000..159a1e08d --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java @@ -0,0 +1,28 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest; +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse; +import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException; + +/** + * Low-level client to interesting Movement module services. + */ +public interface MovementClient { + + /** + * Call @{@code FIND_RAW_MOVEMENTS} + * + * @param request the movement module request + * @return The movement module response + */ + FindRawMovementsResponse findRawMovements(FindRawMovementsRequest request) throws MovementModelException; +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java new file mode 100644 index 000000000..ad763f289 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java @@ -0,0 +1,25 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Qualifier for injecting the Movement queue. + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +public @interface MovementQueue { +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java new file mode 100644 index 000000000..0aeb94868 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java @@ -0,0 +1,28 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; + +import java.util.List; + +/** + * Service for sending messages to Movement. + */ +public interface MovementSender { + + + /** + * @param guildList the guid list used to filter and fetch movements + * @return a list of {@code MovementBaseType} + */ + List findRawMovements(List guildList) throws RulesServiceException; +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java new file mode 100644 index 000000000..d667c91f5 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java @@ -0,0 +1,62 @@ +/* + Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + + This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + */ +package eu.europa.ec.fisheries.uvms.rules.movement.communication; + +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest; +import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse; +import eu.europa.ec.fisheries.schema.movement.module.v1.MovementModuleMethod; +import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType; +import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import java.util.List; + +/** + * Implementation of {@link MovementSender}. + */ +@ApplicationScoped +class MovementSenderImpl implements MovementSender { + + private MovementClient movementClient; + + /** + * Injection constructor + * + * @param movementClient The low-level client to the services of the activity module + */ + @Inject + public MovementSenderImpl(MovementClient movementClient) { + this.movementClient = movementClient; + } + + /** + * Constructor for frameworks. + */ + @SuppressWarnings("unused") + MovementSenderImpl() { + // NOOP + } + + @Override + public List findRawMovements(List guildList) throws RulesServiceException { + try { + FindRawMovementsRequest request = new FindRawMovementsRequest(); + request.setMethod(MovementModuleMethod.FIND_RAW_MOVEMENTS); + request.getMovementGuids().addAll(guildList); + FindRawMovementsResponse response = null; + response = movementClient.findRawMovements(request); + return response != null ? response.getResponse() : null; + } catch (MovementModelException e) { + throw new RulesServiceException("error converting to movement model", e); + } + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java index 941e838bc..8f2424292 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java @@ -70,4 +70,6 @@ public interface EventService { void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message); void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMessage message); + + void createTicketsReceivedEvent(@Observes @CreateTicketsReceivedEvent EventMessage message); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java index 2010a47cf..006dc783c 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java @@ -35,7 +35,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFAResponseServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaQueryServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaReportServiceBean; -import eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.AlarmReportsServiceBean; +import eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.AlarmsServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MdrRulesMessageServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.RulesMovementProcessorBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.sales.SalesRulesMessageServiceBean; @@ -88,7 +88,7 @@ public class RulesEventServiceBean implements EventService { private SalesRulesMessageServiceBean salesRulesMessageServiceBean; @EJB - private AlarmReportsServiceBean alarmReportsServiceBean; + private AlarmsServiceBean alarmsServiceBean; @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @@ -333,7 +333,18 @@ public void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMe log.info("Received event to create alarm.."); try { CreateAlarmsReportRequest request = (CreateAlarmsReportRequest) message.getRulesBaseRequest(); - alarmReportsServiceBean.createAlarmReport(request); + alarmsServiceBean.createAlarmReport(request); + } catch (RulesServiceException e) { + log.error(" Error when creating creating alarm {}", e.getMessage()); + } + } + + @Override + public void createTicketsReceivedEvent(@Observes @CreateTicketsReceivedEvent EventMessage message) { + log.info("Received event to create tickets.."); + try { + CreateTicketRequest request = (CreateTicketRequest) message.getRulesBaseRequest(); + alarmsServiceBean.createTickets(request); } catch (RulesServiceException e) { log.error(" Error when creating creating alarm {}", e.getMessage()); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java similarity index 60% rename from service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java rename to service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java index fd4888430..066f47c39 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmReportsServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java @@ -13,9 +13,13 @@ package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms; import eu.europa.ec.fisheries.remote.RulesDomainModel; +import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType; import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmReportType; import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmStatusType; import eu.europa.ec.fisheries.schema.rules.module.v1.CreateAlarmsReportRequest; +import eu.europa.ec.fisheries.schema.rules.module.v1.CreateTicketRequest; +import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType; +import eu.europa.ec.fisheries.schema.rules.ticket.v1.TicketType; import eu.europa.ec.fisheries.uvms.audit.model.exception.AuditModelMarshallException; import eu.europa.ec.fisheries.uvms.audit.model.mapper.AuditLogMapper; import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException; @@ -25,6 +29,7 @@ import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditObjectTypeEnum; import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditOperationEnum; import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelException; +import eu.europa.ec.fisheries.uvms.rules.movement.communication.MovementSender; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent; import eu.europa.ec.fisheries.uvms.rules.service.exception.InputArgumentException; @@ -36,11 +41,19 @@ import javax.ejb.Stateless; import javax.enterprise.event.Event; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.RawMovementTypeMapper.enrichRawMovement; @Stateless @LocalBean @Slf4j -public class AlarmReportsServiceBean { +public class AlarmsServiceBean { @Inject @AlarmReportEvent @@ -59,25 +72,38 @@ public class AlarmReportsServiceBean { @EJB private RulesDomainModel rulesDomainModel; - public void createAlarmReport(CreateAlarmsReportRequest request) throws RulesServiceException { - for (AlarmReportType alarmReport : request.getAlarm()) { - validate(alarmReport); - createAlarmReport(alarmReport); + @Inject + private MovementSender movementSender; + + public void createTickets(CreateTicketRequest request) throws RulesServiceException { + List ticketTypes = request.getTickets(); + for (TicketType ticketType : ticketTypes) { + try { + rulesDomainModel.createTicket(ticketType); + } catch (RulesModelException e) { + throw new RulesServiceException("Error creating ticket",e); + } } } - private void validate(AlarmReportType alarmReportType) throws RulesServiceException { - if(alarmReportType == null) throw new InputArgumentException("AlarmReportType cannot be null"); - if(alarmReportType.getAlarmItem().isEmpty()) throw new InputArgumentException("AlarmItem list was empty"); + public List createAlarmReport(CreateAlarmsReportRequest request) throws RulesServiceException { + validateAndEnrichAlarmReportsWithMovementInfo(request.getAlarm()); + List reportTypeList = new ArrayList<>(); + for (AlarmReportType alarmReport : request.getAlarm()) { + reportTypeList.add(createAlarmReport(alarmReport)); + } + return reportTypeList; } - private void createAlarmReport(AlarmReportType alarmReport) { + private AlarmReportType createAlarmReport(AlarmReportType alarmReport) { + AlarmReportType createdAlarmReport = null; try { alarmReport.setStatus(AlarmStatusType.OPEN); -// alarmReport.setUpdatedBy("UVMS"); -// alarmReport.setPluginType(fact.getPluginType()); + alarmReport.setUpdatedBy(alarmReport.getUpdatedBy()); + alarmReport.setPluginType(alarmReport.getPluginType()); alarmReport.setInactivatePosition(false); - AlarmReportType createdAlarmReport = rulesDomainModel.createAlarmReport(alarmReport); + + createdAlarmReport = rulesDomainModel.createAlarmReport(alarmReport); // Notify long-polling clients of the new alarm report alarmReportEvent.fire(new NotificationMessage("guid", createdAlarmReport.getGuid())); // Notify long-polling clients of the change (no value since FE will need to fetch it) @@ -86,6 +112,7 @@ private void createAlarmReport(AlarmReportType alarmReport) { } catch (RulesModelException e) { log.error("[ Failed to create alarm! ] {}", e.getMessage()); } + return createdAlarmReport; } private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) { @@ -97,4 +124,31 @@ private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum opera log.error("[ Error when sending message to Audit. ] {}", e.getMessage()); } } + + private void validateAndEnrichAlarmReportsWithMovementInfo(List alarmReports){ + Map existingGuidListMap = alarmReports.stream() + .map(this::validateAndGetRowMovement) + .filter(not(RawMovementType::isGuidGenerated)) + .collect(Collectors.toMap(RawMovementType::getGuid, Function.identity())); + if(existingGuidListMap.isEmpty()) return; + + List movementBaseTypes = movementSender.findRawMovements(new ArrayList<>(existingGuidListMap.keySet())); + if(movementBaseTypes == null || movementBaseTypes.isEmpty()) return; + + movementBaseTypes.forEach(mb -> enrichRawMovement(existingGuidListMap.get(mb.getGuid()),mb)); + } + + private RawMovementType validateAndGetRowMovement(AlarmReportType alarmReportType){ + validate(alarmReportType); + return alarmReportType.getRawMovement(); + } + + private void validate(AlarmReportType alarmReportType) throws RulesServiceException { + if(alarmReportType == null) throw new InputArgumentException("AlarmReportType cannot be null"); + if(alarmReportType.getAlarmItem().isEmpty()) throw new InputArgumentException("AlarmItem list was empty"); + } + + private static Predicate not(Predicate t) { + return t.negate(); + } } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java new file mode 100644 index 000000000..0299aeb48 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java @@ -0,0 +1,54 @@ +/* + * + * Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020. + * + * This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + * the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + * + */ + +package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms; + +import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType; +import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType; + +public class RawMovementTypeMapper { + public static void enrichRawMovement(RawMovementType rawMovementType, MovementBaseType movementBaseType) { + if(movementBaseType.getActivity() != null){ + rawMovementType.setActivity(toActivityType(movementBaseType.getActivity())); + } + rawMovementType.setPosition(toPoint(movementBaseType.getPosition())); + rawMovementType.setPositionTime(movementBaseType.getPositionTime()); + rawMovementType.setReportedCourse(movementBaseType.getReportedCourse()); + rawMovementType.setReportedSpeed(movementBaseType.getReportedSpeed()); + if(movementBaseType.getSource() != null){ + rawMovementType.setSource(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementSourceType.valueOf(movementBaseType.getSource().name())); + } + if(movementBaseType.getMovementType() != null){ + rawMovementType.setMovementType(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementTypeType.valueOf(movementBaseType.getMovementType().name())); + } + rawMovementType.setTripNumber(movementBaseType.getTripNumber()); + rawMovementType.setStatus(movementBaseType.getStatus()); + } + + static eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType toActivityType(eu.europa.ec.fisheries.schema.movement.v1.MovementActivityType movementActivityType){ + eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType activityType = new eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType(); + activityType.setCallback(movementActivityType.getCallback()); + activityType.setMessageId(movementActivityType.getMessageId()); + if(movementActivityType.getMessageType() != null){ + activityType.setMessageType(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityTypeType.valueOf(movementActivityType.getMessageType().name())); + } + return activityType; + } + static eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint toPoint(eu.europa.ec.fisheries.schema.movement.v1.MovementPoint movementPoint){ + eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint point = new eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint(); + point.setAltitude(movementPoint.getAltitude()); + point.setLatitude(movementPoint.getLatitude()); + point.setLongitude(movementPoint.getLongitude()); + return point; + } + +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java index 8a9ef2f8f..2d2c3d3a5 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java @@ -574,11 +574,10 @@ public long getNumberOfOpenAlarmReports() throws RulesServiceException, RulesFau @Override public long getNumberOfOpenTickets(String userName) throws RulesServiceException, RulesFaultException { try { - long numberOfOpenTickets = rulesDomainModel.getNumberOfOpenTickets(userName); - return numberOfOpenTickets; + return rulesDomainModel.getNumberOfOpenTickets(userName); } catch (RulesModelException e) { LOG.error("[ Error when getting number of open tickets ] {}", e.getMessage()); - throw new RulesServiceException("[ Error when getting number of open alarms. ]"); + throw new RulesServiceException("[ Error when getting number of open alarms. ]",e); } } diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBeanTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBeanTest.java new file mode 100644 index 000000000..47060c381 --- /dev/null +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBeanTest.java @@ -0,0 +1,196 @@ +/* + * + * Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020. + * + * This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of + * the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + * + */ +package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms; + +import eu.europa.ec.fisheries.remote.RulesDomainModel; +import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType; +import eu.europa.ec.fisheries.schema.movement.v1.MovementPoint; +import eu.europa.ec.fisheries.schema.movement.v1.MovementTypeType; +import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmItemType; +import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmReportType; +import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmStatusType; +import eu.europa.ec.fisheries.schema.rules.asset.v1.AssetId; +import eu.europa.ec.fisheries.schema.rules.asset.v1.AssetIdList; +import eu.europa.ec.fisheries.schema.rules.asset.v1.AssetIdType; +import eu.europa.ec.fisheries.schema.rules.asset.v1.AssetType; +import eu.europa.ec.fisheries.schema.rules.module.v1.CreateAlarmsReportRequest; +import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType; +import eu.europa.ec.fisheries.uvms.commons.notifications.NotificationMessage; +import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer; +import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesAuditProducerBean; +import eu.europa.ec.fisheries.uvms.rules.movement.communication.MovementSender; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; +import lombok.SneakyThrows; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import javax.enterprise.event.Event; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.AdditionalAnswers.returnsFirstArg; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +/** + * Tests for the {@link AlarmsServiceBeanTest}. + */ +@RunWith(MockitoJUnitRunner.class) +public class AlarmsServiceBeanTest { + + private static final String DELTA_GUID = "97a40d34-45ea-11e7-bec7-4c32759615eb"; + @Mock + private RulesDomainModel rulesDomainModel; + @Mock + private Event alarmReportEvent; + @Mock + private Event alarmReportCountEvent; + @Mock + private RulesAuditProducerBean auditProducer; + @Mock + private RulesResponseConsumer consumer; + @Mock + private MovementSender movementSender; + + @InjectMocks + private AlarmsServiceBean sut; + + @Test(expected = RulesServiceException.class) + public void testCreateAlarmReportWithoutAlarmItemAndExpectServiceException(){ + CreateAlarmsReportRequest request = request( + report( DELTA_GUID ,false)); + sut.createAlarmReport(request); + } + + @Test + @SneakyThrows + public void testCreateAlarmReportWithEnrichedDataOfMovementModule(){ + CreateAlarmsReportRequest request = request( + report( DELTA_GUID,false ,item("test"))); + List movementBaseTypes = new ArrayList<>(); + MovementBaseType responseItem = responseItem(DELTA_GUID); + movementBaseTypes.add(responseItem); + + when(movementSender.findRawMovements(any())).thenReturn(movementBaseTypes); + when(rulesDomainModel.createAlarmReport(any(AlarmReportType.class))).thenAnswer(returnsFirstArg()); + AlarmReportType createdReport = sut.createAlarmReport(request).get(0); + assertNotNull(createdReport.getRawMovement().getPosition()); + assertEquals(createdReport.getRawMovement().getMovementType().name(),responseItem.getMovementType().name()); + } + + @Test + @SneakyThrows + public void testCreateAlarmReportWithoutEnrichedDataOfMovementModule(){ + CreateAlarmsReportRequest request = request( + report( UUID.randomUUID().toString(),true ,item("test"))); + List movementBaseTypes = new ArrayList<>(); + MovementBaseType responseItem = responseItem(DELTA_GUID); + movementBaseTypes.add(responseItem); + + when(movementSender.findRawMovements(any())).thenReturn(movementBaseTypes); + when(rulesDomainModel.createAlarmReport(any(AlarmReportType.class))).thenAnswer(returnsFirstArg()); + AlarmReportType createdReport = sut.createAlarmReport(request).get(0); + assertNull(createdReport.getRawMovement().getPosition()); + } + + private static CreateAlarmsReportRequest request(AlarmReportType... reports){ + CreateAlarmsReportRequest request = new CreateAlarmsReportRequest(); + for(AlarmReportType report : reports) + request.getAlarm().add(report); + return request; + } + + private MovementBaseType responseItem(String guid){ + MovementBaseType movementBaseType = new MovementBaseType(); + movementBaseType.setGuid(guid); + movementBaseType.setDuplicate(false); + movementBaseType.setReportedCourse(180.0); + movementBaseType.setReportedSpeed(14.0); + MovementPoint movementPoint = new MovementPoint(); + movementPoint.setLongitude(41.17); + movementPoint.setLatitude(18.10); + movementBaseType.setPosition(movementPoint); + movementBaseType.setMovementType(MovementTypeType.POS); + movementBaseType.setPositionTime(new Date()); + return movementBaseType; + } + + private static AlarmReportType report(String assetGuid,boolean guidGenerated,AlarmItemType... items){ + AlarmReportType alarmReportType = new AlarmReportType(); + for(AlarmItemType item : items) + alarmReportType.getAlarmItem().add(item); + alarmReportType.setAssetGuid(assetGuid); + alarmReportType.setRawMovement(raw( rowData(assetGuid,guidGenerated,null,"XR003","SVK","SVK123456789","IRCS3"))); + alarmReportType.setStatus(AlarmStatusType.OPEN); + alarmReportType.setGuid(UUID.randomUUID().toString()); + return alarmReportType; + } + + private static RawMovementType raw(SubscriptionRowData rowData){ + RawMovementType raw = new RawMovementType(); + raw.setFlagState(rowData.flagState); + raw.setGuid(rowData.guid); + raw.setGuidGenerated(rowData.guidGenerated); + raw.setConnectId(rowData.connectId); + raw.setExternalMarking(rowData.extMark); + raw.setFlagState(rowData.extMark); + return raw; + } + + private static AlarmItemType item(String ruleName){ + AlarmItemType item = new AlarmItemType(); + item.setRuleName(ruleName); + item.setGuid(UUID.randomUUID().toString()); + return item; + } + + private static SubscriptionRowData rowData(String guid,boolean guidGenerated,String connectId,String extMark,String flagState,String cfr,String ircs){ + SubscriptionRowData rawData = new SubscriptionRowData(); + AssetId assetId = new AssetId(); + assetId.setAssetType(AssetType.VESSEL); + addVesselIdIfNotNull(assetId, AssetIdType.CFR, cfr); + addVesselIdIfNotNull(assetId, AssetIdType.IRCS, ircs); + rawData.assetId = assetId; + rawData.guid = guid; + rawData.guidGenerated = guidGenerated; + rawData.connectId = connectId; + rawData.extMark = extMark; + rawData.flagState = flagState; + return rawData; + } + + private static void addVesselIdIfNotNull(AssetId assetId, AssetIdType assetIdType, String value) { + if (value != null) { + AssetIdList assetIdList = new AssetIdList(); + assetIdList.setIdType(assetIdType); + assetIdList.setValue(value); + assetId.getAssetIdList().add(assetIdList); + } + } + + private static class SubscriptionRowData{ + AssetId assetId; + String guid; + boolean guidGenerated; + String connectId; + String extMark; + String flagState; + } +} From 560339b4a6e8e146fccd0c7bf2f9e29473d82138 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Thu, 17 Sep 2020 01:18:53 +0300 Subject: [PATCH 12/61] [UNIONVMS-4689] added value to AD for outgoing subscription messages --- .../rules/model/mapper/RulesModuleRequestMapper.java | 10 ++++++---- .../service/bean/activity/RulesFaQueryServiceBean.java | 2 +- .../bean/activity/RulesFaReportServiceBean.java | 2 +- .../bean/movement/RulesMovementProcessorBean.java | 4 ++-- .../rules/service/mapper/ExchangeMovementMapper.java | 4 +++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java index 54ea9a2be..9b3290612 100755 --- a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java +++ b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java @@ -59,12 +59,12 @@ public static String createSetFLUXFAReportMessageRequest(PluginType type, String return JAXBMarshaller.marshallJaxBObjectToString(request); } - public static String createSendFLUXFAReportMessageRequest(String fluxFAReportMessage, String username, String logId, String fluxDataFlow, - String senderOrReceiver, String onValue, boolean isEmpty) throws RulesModelMapperException { + public static String createSendFLUXFAReportMessageRequest(String fluxFAReportMessage, String username, String logId, String fluxDataFlow, String senderOrReceiver, String onValue, boolean isEmpty) throws RulesModelMapperException { SetFLUXFAReportMessageRequest request = new SetFLUXFAReportMessageRequest(); request.setMethod(RulesModuleMethod.SEND_FLUX_FA_REPORT); request.setRequest(fluxFAReportMessage); request.setIsEmptyReport(isEmpty); + request.setAd(senderOrReceiver); populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, onValue); return JAXBMarshaller.marshallJaxBObjectToString(request); } @@ -90,20 +90,22 @@ public static String createRcvFluxFaResponseMessageRequest(PluginType type, Stri } public static String createSendFaQueryMessageRequest(String faQueryMessageStr, String username, String logId, String fluxDataFlow, - String senderOrReceiver) throws RulesModelMapperException { + String senderOrReceiver, String ad) throws RulesModelMapperException { SetFaQueryMessageRequest request = new SetFaQueryMessageRequest(); request.setMethod(RulesModuleMethod.SEND_FLUX_FA_QUERY); request.setRequest(faQueryMessageStr); + request.setAd(ad); populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, null); return JAXBMarshaller.marshallJaxBObjectToString(request); } public static String createSendFluxMovementReportMessageRequest(PluginType type, String forwardPositionMessageStr, String username, String logId, String fluxDataFlow, - String senderOrReceiver) throws RulesModelMapperException { + String senderOrReceiver,String ad) throws RulesModelMapperException { SendFLUXMovementReportRequest request = new SendFLUXMovementReportRequest(); request.setMethod(RulesModuleMethod.SEND_FLUX_MOVEMENT_REPORT); request.setRequest(forwardPositionMessageStr); request.setType(type); + request.setAd(ad); populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, null); return JAXBMarshaller.marshallJaxBObjectToString(request); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java index bf2097ae0..7c621fbbb 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java @@ -208,7 +208,7 @@ public void evaluateOutgoingFAQuery(SetFaQueryMessageRequest request) { if (faQueryValidationReport != null && !faQueryValidationReport.isError()) { log.debug("The Validation of FaQueryMessage is successful, forwarding message to Exchange"); String exchangeReq = ExchangeModuleRequestMapper.createSendFaQueryMessageRequest(request.getRequest(), - "movement", logGuid, request.getFluxDataFlow(), request.getSenderOrReceiver(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST"); + "movement", logGuid, request.getFluxDataFlow(), request.getSenderOrReceiver(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", request.getAd() == null ? "IMPLEMENTTO_FROM_REQUEST" : request.getAd()); sendToExchange(exchangeReq); } else { log.debug("Validation resulted in errors. Not going to send msg to Exchange module.."); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java index 734e1c4b2..f6841ca04 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java @@ -196,7 +196,7 @@ public void evaluateOutgoingFaReport(SetFLUXFAReportMessageRequest request) { if (faReportValidationResult != null && !faReportValidationResult.isError()) { log.info(" The Validation of FLUXFAReportMessage is successful, forwarding message to Exchange"); sendToExchange(ExchangeModuleRequestMapper.createSendFaReportMessageRequest(request.getRequest(), "movement", logGuid, request.getFluxDataFlow(), - request.getSenderOrReceiver(), request.getOnValue(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST")); + request.getSenderOrReceiver(), request.getOnValue(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", request.getAd() == null ? "IMPLEMENTTO_FROM_REQUEST" : request.getAd())); } else { log.info(" Validation resulted in errors. Not going to send msg to Exchange module.."); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index 298fffa6e..ca5dd1abd 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -225,10 +225,10 @@ void setMdrCache(MDRCache mdrCache) { public void sendMovementReport(SendFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException { log.info("Sending Movement Report to exchange"); try { - String exchangeMessageText = ExchangeMovementMapper.mapToFluxMovementReport(request.getRequest(), request.getUsername(), request.getSenderOrReceiver(), request.getFluxDataFlow(), request.getLogGuid()); + String exchangeMessageText = ExchangeMovementMapper.mapToFluxMovementReport(request.getRequest(), request.getUsername(), request.getSenderOrReceiver(), request.getFluxDataFlow(), request.getLogGuid(),request.getAd()); exchangeProducer.sendModuleMessage(exchangeMessageText, consumer.getDestination()); } catch (ExchangeModelMapperException | MessageException e) { - log.error("Error while send movement report to exchnge", e); + log.error("Error while send movement report to exchange", e); } } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java index 4e5a8b25c..fde114989 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java @@ -132,7 +132,7 @@ public static String mapToProcessedMovementResponseBatch(List Date: Fri, 2 Oct 2020 19:40:23 +0300 Subject: [PATCH 13/61] [UNIONVMS-4313] Taking into account the condition TypeCode = DECLARATION --- .../v3.4/db-changelog-UNIONVMS-4313.xml | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml index 6512be3e8..a6347d8e8 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml @@ -23,4 +23,26 @@ - \ No newline at end of file + + + + + rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0601') + + + + rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0600') + + + + + + rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0601') + + + + rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0600') + + + + From 2a2554588124fdce4183097bd3b2b127d989d062 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Wed, 14 Oct 2020 22:01:10 +0300 Subject: [PATCH 14/61] [UNIONVMS-4764] null checking --- .../uvms/rules/bean/RulesDomainModelBean.java | 34 +++++++++++++++---- .../exception/DaoMappingRuntimeException.java | 14 ++++++++ .../rules/exception/DaoRuntimeException.java | 14 ++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java create mode 100644 domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java index 964278016..b32970cf0 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java @@ -31,6 +31,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.entity.*; import eu.europa.ec.fisheries.uvms.rules.exception.DaoException; import eu.europa.ec.fisheries.uvms.rules.exception.DaoMappingException; +import eu.europa.ec.fisheries.uvms.rules.exception.DaoMappingRuntimeException; +import eu.europa.ec.fisheries.uvms.rules.exception.DaoRuntimeException; import eu.europa.ec.fisheries.uvms.rules.exception.InputArgumentException; import eu.europa.ec.fisheries.uvms.rules.mapper.*; import eu.europa.ec.fisheries.uvms.rules.mapper.search.*; @@ -47,7 +49,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.UUID; +import java.util.Optional; @Stateless public class RulesDomainModelBean implements RulesDomainModel { @@ -809,18 +811,38 @@ public List getTicketsAndRulesByMovements(List moveme // TODO: This can be done more efficiently with some join stuff List tickets = rulesDao.getTicketsByMovements(movementGuids); for (Ticket ticket : tickets) { - CustomRule rule = rulesDao.getCustomRuleByGuid(ticket.getRuleGuid()); TicketType ticketType = TicketMapper.toTicketType(ticket); - CustomRuleType ruleType = CustomRuleMapper.toCustomRuleType(rule); TicketAndRuleType ticketsAndRule = new TicketAndRuleType(); ticketsAndRule.setTicket(ticketType); - ticketsAndRule.setRule(ruleType); + Optional.ofNullable(ticket.getRuleGuid()) + .map(this::getCustomRuleByGuid) + .map(this::toCustomRuleType) + .ifPresent(ticketsAndRule::setRule); ticketsAndRules.add(ticketsAndRule); } return ticketsAndRules; } catch (DaoException | DaoMappingException e) { - LOG.error("[ERROR] Error when getting list {}", e.getMessage()); throw new RulesModelException("[ERROR] Error when getting list.", e); + } catch (DaoRuntimeException dre) { + throw new RulesModelException("[ERROR] Error when getting list.", dre.unwrap()); + } catch (DaoMappingRuntimeException dmre) { + throw new RulesModelException("[ERROR] Error when getting list.", dmre.unwrap()); + } + } + + private CustomRule getCustomRuleByGuid(String id) { + try { + return rulesDao.getCustomRuleByGuid(id); + } catch (DaoException e) { + throw new DaoRuntimeException("", e); + } + } + + private CustomRuleType toCustomRuleType(CustomRule customRuleEntity) { + try { + return CustomRuleMapper.toCustomRuleType(customRuleEntity); + } catch (DaoMappingException e) { + throw new DaoMappingRuntimeException("", e); } } -} \ No newline at end of file +} diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java new file mode 100644 index 000000000..fe74bf9f3 --- /dev/null +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java @@ -0,0 +1,14 @@ +package eu.europa.ec.fisheries.uvms.rules.exception; + +/** + * RuntimeException wrapper for the {@link DaoMappingException} + */ +public class DaoMappingRuntimeException extends RuntimeException { + public DaoMappingRuntimeException(String s, DaoMappingException throwable) { + super(s, throwable); + } + + public DaoMappingException unwrap() { + return (DaoMappingException) getCause(); + } +} diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java new file mode 100644 index 000000000..c99051da0 --- /dev/null +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java @@ -0,0 +1,14 @@ +package eu.europa.ec.fisheries.uvms.rules.exception; + +/** + * RuntimeException wrapper for a {@link DaoException}. + */ +public class DaoRuntimeException extends RuntimeException { + public DaoRuntimeException(String s, DaoException throwable) { + super(s, throwable); + } + + public DaoException unwrap() { + return (DaoException) getCause(); + } +} From e268f8665d6042f61ffd5b324b79d8bac123b51d Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 21 Sep 2020 23:35:12 +0300 Subject: [PATCH 15/61] [UNIONVMS-4792] removed deprecated rules --- LIQUIBASE/changelog/db-changelog-master.xml | 3 + .../v3.4/db-changelog-UNIONVMS-4792.xml | 157 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 027eed847..79b5f9c14 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -58,4 +58,7 @@ + + + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml new file mode 100644 index 000000000..5e289db56 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml @@ -0,0 +1,157 @@ + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3e00e409b4324df0a430b6ce4a710dcc7a0e17ca Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 5 Oct 2020 15:12:04 +0300 Subject: [PATCH 16/61] [UNIONVMS-4793] added rules for flagged vessels --- LIQUIBASE/changelog/db-changelog-master.xml | 3 +- .../v3.4/db-changelog-UNIONVMS-4793.xml | 288 ++++++++++++++++++ .../asset/client/impl/AssetClientBean.java | 5 +- .../fact/VesselTransportMeansFact.java | 52 ++++ .../ActivityFaReportFactGenerator.java | 5 + .../mapper/fact/ActivityFactMapper.java | 17 +- .../business/ActivityFactMapperTest.java | 2 +- 7 files changed, 365 insertions(+), 7 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 79b5f9c14..ba91d018d 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -60,5 +60,6 @@ - + + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml new file mode 100644 index 000000000..e79cf0d93 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java index 790f72913..972466bec 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java @@ -66,8 +66,9 @@ public List findHistoryOfAssetBy(List String ircs = ids.get("IRCS"); String extMark = ids.get("EXT_MARK"); String iccat = ids.get("ICCAT"); - log.debug("Find history of asset by reportDate: {}, cfr: {}, regCountry: {}, ircs: {}, extMark: {}, iccat: {} ", reportDate, cfr, regCountry, ircs, extMark, iccat); - List assets = iAssetFacade.findHistoryOfAssetBy(reportDate, cfr, regCountry, ircs, extMark, iccat); + String uvi = ids.get("UVI"); + log.debug("Find history of asset by reportDate: {}, cfr: {}, regCountry: {}, ircs: {}, extMark: {}, uvi: {}", reportDate, cfr, regCountry, ircs, extMark, iccat,uvi); + List assets = iAssetFacade.findHistoryOfAssetBy(reportDate, cfr, regCountry, ircs, extMark, iccat,uvi); if (CollectionUtils.isNotEmpty(assets)) { vesselTransportMeansDto.setAsset(assets.get(0)); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java index 8dfb6fd88..94b2e166a 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java @@ -25,6 +25,8 @@ import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.ContactPerson; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.StructuredAddress; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.VesselPositionEvent; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.VesselTransportMeans; +import un.unece.uncefact.data.standard.unqualifieddatatype._20.IDType; @Data @EqualsAndHashCode(callSuper = false) @@ -41,6 +43,12 @@ public class VesselTransportMeansFact extends AbstractFact { private List specifiedContactPersons; private VesselTransportMeansDto transportMeans; private List vesselPositionEvents; + private IdType specifiedVesselCountryId; + private List specifiedIds; + private IdType relatedVesselCountryId; + private List relatedIds; + private VesselTransportMeans relatedVesselTransportMeans; + private VesselTransportMeans specifiedVesselTransportMeans; public VesselTransportMeansFact() { setFactType(); @@ -56,6 +64,50 @@ public boolean containsAtLeastOneCorrectIdOfTheRequired(String schemeId){ return containsValidSchemeId; } + public boolean containsAtLeastOneCorrectIdOfTheSpecified(String schemeId){ + boolean containsValidSchemeId = false; + for (IdType id : specifiedIds) { + if(schemeId.equals(id.getSchemeId()) && StringUtils.isNotEmpty(id.getValue())){ + containsValidSchemeId = true; + } + } + return containsValidSchemeId; + } + + public boolean containsAtLeastOneCorrectIdOfTheRelated(String schemeId){ + boolean containsValidSchemeId = false; + + if(relatedIds == null || relatedIds.isEmpty()){ + return true; + } + + for (IdType id : relatedIds) { + if(schemeId.equals(id.getSchemeId()) && StringUtils.isNotEmpty(id.getValue())){ + containsValidSchemeId = true; + } + } + return containsValidSchemeId; + } + + public boolean hasValueForVesselTransports(VesselTransportMeans relatedVesselTransportMeans,String value){ + if(relatedVesselTransportMeans == null ){ + return true; + } + + for(IDType id :relatedVesselTransportMeans.getIDS()){ + if(id == null || id.getSchemeID() == null){ + continue; + } + + if(value.equals(id.getSchemeID())){ + return true; + } + + } + + return false; + } + @Override public void setFactType() { this.factType = FactType.VESSEL_TRANSPORT_MEANS; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java index 876778f22..e88abb95f 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java @@ -169,6 +169,11 @@ private void enrichVesselTransoprtMeanFacts(List facts) { matches.set(false); } break; + case "UVI": + if(!StringUtils.equals(factIdValue, asset.getUvi())){ + matches.set(false); + } + break; } }); if(matches.get()){ diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 5a196976f..9f4158093 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -512,7 +512,7 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo xPathUtil.clear(); return null; } - VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, null); + VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, null,true); vesselTransportMeansFact.setIsFromFaReport(isCommingFromFaReportDocument); return vesselTransportMeansFact; } @@ -528,14 +528,15 @@ public List generateFactForVesselTransportMeans(List facts, - un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) { + un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType, + boolean isSpecifiedVesselTransportMeans) { if (vesselTransportMean == null) { xPathUtil.clear(); return null; @@ -585,6 +586,16 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo xPathUtil.appendWithoutWrapping(toBeAppendedAlways); generateFactsForVesselPositionEvents(vesselTransportMean.getSpecifiedVesselPositionEvents(), facts); + if(isSpecifiedVesselTransportMeans){ + vesselTransportMeansFact.setSpecifiedIds(vesselTransportMeansFact.getIds()); + vesselTransportMeansFact.setSpecifiedVesselCountryId(vesselTransportMeansFact.getRegistrationVesselCountryId()); + vesselTransportMeansFact.setSpecifiedVesselTransportMeans(vesselTransportMean); + } else { + vesselTransportMeansFact.setRelatedIds(vesselTransportMeansFact.getIds()); + vesselTransportMeansFact.setRelatedVesselCountryId(vesselTransportMeansFact.getRegistrationVesselCountryId()); + vesselTransportMeansFact.setRelatedVesselTransportMeans(vesselTransportMean); + } + return vesselTransportMeansFact; } diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java index ad04cb7dc..8e5a49864 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java @@ -714,7 +714,7 @@ public void testNullParameters() { final FaLandingFact faLandingFact = activityMapper.generateFactsForLanding(null, null); final List gearList = activityMapper.generateFactsForGearCharacteristics(null, new HashMap<>(), new HashMap<>()); final List fishingTripFacts = activityMapper.generateFactForFishingTrips(null, null); - final VesselTransportMeansFact vesselTransportMeansFact = activityMapper.generateFactForVesselTransportMean(null, new ArrayList<>(), null); + final VesselTransportMeansFact vesselTransportMeansFact = activityMapper.generateFactForVesselTransportMean(null, new ArrayList<>(), null,false); final List gearCharacteristicsFacts = activityMapper.generateFactsForGearCharacteristics(null, new HashMap<>(), new HashMap<>()); final FaResponseFact faResponseFact = new FaResponseFactMapper().generateFactsForFaResponse(null); final ValidationQualityAnalysisFact qualityAnalysisFact = activityMapper.generateFactsForValidationQualityAnalysis(null); From c7777aec66ade21c525fc400dd67066fabf7f539 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Tue, 22 Sep 2020 12:36:29 +0300 Subject: [PATCH 17/61] [UNIONVMS-4794] corrected wording issues --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4794.xml | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index ba91d018d..df3058df1 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -61,5 +61,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml new file mode 100644 index 000000000..3e0f7dbc6 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml @@ -0,0 +1,44 @@ + + + + + + br_id = 'FA-L03-00-0038' + + + + + + br_id = 'FA-L03-00-0038' + + + + + + + + br_id = 'FA-L02-00-0366' + + + + + + br_id = 'FA-L02-00-0366' + + + + + + + + br_id = 'FA-L02-00-0374' + + + + + + br_id = 'FA-L02-00-0374' + + + + From bddc9c5ccdd3b73cf71502984ab250ad43b28389 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 14 Oct 2020 20:09:06 +0300 Subject: [PATCH 18/61] [UNIONVMS-4795] rules to prevent missing master or agent name information --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4795.xml | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index df3058df1..3bcbffcfa 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -62,5 +62,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml new file mode 100644 index 000000000..62179bed4 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + From 44e2aaffe53ddee74244b4551100414e134b819b Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 5 Oct 2020 22:41:08 +0300 Subject: [PATCH 19/61] [UNIONVMS-4796] added rule for transhipments --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4796.xml | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 3bcbffcfa..7813fc4b8 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -63,5 +63,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml new file mode 100644 index 000000000..eb618d9e3 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + From 02a6f5cd8b0e7498a102dec7c81d110333acf478 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Tue, 6 Oct 2020 10:19:34 +0300 Subject: [PATCH 20/61] [UNIONVMS-4797] owner flux party/id rules --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4797.xml | 76 +++++++++++++++++++ .../fact/FluxFaReportMessageFact.java | 2 +- .../mapper/fact/ActivityFactMapper.java | 6 ++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 7813fc4b8..13bd5af77 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -64,5 +64,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml new file mode 100644 index 000000000..6ad31c7c2 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java index d13973811..b2487e821 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java @@ -32,11 +32,11 @@ public class FluxFaReportMessageFact extends AbstractFact { private String creationDateTimeString; private CodeType purposeCode; private List ownerFluxPartyIds; + private List relatedOwnerFluxPartyIds; private List faReportDocuments; private List nonUniqueIdsList; private List relatedFaQueryIDs; - public FluxFaReportMessageFact() { setFactType(); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 9f4158093..cbb782492 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -488,6 +488,12 @@ public FluxFaReportMessageFact generateFactForFluxFaReportMessage(FLUXFAReportMe fluxFaReportMessageFact.setRelatedFaQueryIDs(faQueryIds); xPathUtil.appendWithoutWrapping(partialXpath).append(REFERENCED_ID).storeInRepo(fluxFaReportMessageFact, "relatedFaQueryIDs"); + if(fluxfaReportMessage.getFLUXReportDocument() != null && fluxfaReportMessage.getFAReportDocuments() != null && !fluxfaReportMessage.getFAReportDocuments().isEmpty() + && fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument() != null && fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument().getOwnerFLUXParty() != null) { + fluxFaReportMessageFact.setRelatedOwnerFluxPartyIds(mapToIdTypes(fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument().getOwnerFLUXParty().getIDS())); + xPathUtil.appendWithoutWrapping(partialXpath).append(FA_REPORT_DOCUMENT,RELATED_FLUX_REPORT_DOCUMENT, OWNER_FLUX_PARTY, ID).storeInRepo(fluxFaReportMessageFact, "relatedOwnerFluxPartyIds"); + } + return fluxFaReportMessageFact; } From 84ab5df64f08fe5142e5bd85e12d78596f2c7076 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Fri, 9 Oct 2020 22:43:21 +0300 Subject: [PATCH 21/61] [UNIONVMS-4798] main area rules --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4798.xml | 376 ++++++++++++++++++ .../service/business/fact/FaCatchFact.java | 66 +++ .../mapper/fact/ActivityFactMapper.java | 17 + 4 files changed, 460 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 13bd5af77..f7dbf01f3 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -65,5 +65,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml new file mode 100644 index 000000000..f9617d0db --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index 84e483fdb..e37048cfe 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -14,7 +14,9 @@ package eu.europa.ec.fisheries.uvms.rules.service.business.fact; import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; +import java.util.Map; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; @@ -24,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.AAPProcess; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.AAPProduct; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXCharacteristic; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXLocation; @Data @@ -51,15 +54,78 @@ public class FaCatchFact extends AbstractFact { private CodeType categoryCode; private List appliedAAPProcessConversionFactorNumber; private List specifiedFLUXLocations; + private List fishingActivityRelatedFLUXLocations; + private List faCatchSpecifiedFLUXLocations; private List specifiedFluxLocationRFMOCodeList; private List appliedAAPProcess; private List destinationFLUXLocations; private List faCatchFluxLocationId; private List fishActRelatedFluxLocationIds; + private List fishingActivityFluxCharacteristic; + private List faCatchFluxCharacteristic; private boolean isSubActivity = false; + + public boolean containsAtMostXTypesOfLocation(List locations,String type,int times){ + + if(CollectionUtils.isEmpty(locations)){ + return true; + } + + int i =0; + + for(FLUXLocation location:locations){ + if(type.equals(location.getTypeCode().getValue())){ + i ++; + } + + if (i > times){ + return false; + } + } + + return true; + } + + + public boolean hasDuplicateLocationType(List locations){ + Map map = new HashMap<>(); + + if(CollectionUtils.isEmpty(locations)){ + return false; + } + + for(FLUXLocation location:locations){ + + if(map.get(location.getTypeCode().getValue()) == null){ + map.put(location.getTypeCode().getValue(),1); + } else { + return true; + } + + } + + return false; + } + + public boolean fluxCharacteristicContainsType(List fluxCharacteristics,String value){ + + if(CollectionUtils.isEmpty(fluxCharacteristics)){ + return true; + } + + for(FLUXCharacteristic fluxCharacteristic:fluxCharacteristics){ + + if(value.equals(fluxCharacteristic.getTypeCode().getValue())){ + return true; + } + } + + return false; + } + public boolean containsAtLeastOneGfcmGsaWithValidValue(List ids){ if(CollectionUtils.isEmpty(ids)){ return false; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index cbb782492..d898b3b75 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -957,6 +957,16 @@ public List generateFactsForFaCatch(FishingActivity activity, bool faCatchFact.setSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations()); xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION).storeInRepo(faCatchFact, "specifiedFLUXLocations"); + if(CollectionUtils.isNotEmpty(faCatch.getSpecifiedFLUXLocations())){ + faCatchFact.setFaCatchSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); + List fluxCharacteristics = faCatch.getSpecifiedFLUXLocations().stream() + .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) + .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); + faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics); + xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); + } + if (faCatch.getSpecifiedFLUXLocations() != null) { faCatchFact.setFaCatchFluxLocationId(mapFLUXLocationIDs(faCatch.getSpecifiedFLUXLocations())); } @@ -964,6 +974,13 @@ public List generateFactsForFaCatch(FishingActivity activity, bool if(CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)){ faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); + faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); + xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); + List fluxCharacteristics = fishActRelatedFluxLocations.stream() + .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) + .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); + faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); + xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION,APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); } xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds"); From cfda3c79546a72039178856a1b381aac404cb0ca Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 14 Oct 2020 14:10:43 +0300 Subject: [PATCH 22/61] [UNIONVMS-4799] added rules to prevent reporting multiple depths and gears for one fishing operation --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4799.xml | 146 ++++++++++++++++++ .../service/business/fact/FaCatchFact.java | 6 +- .../business/fact/FishingActivityFact.java | 12 +- .../mapper/fact/ActivityFactMapper.java | 7 +- 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index f7dbf01f3..df43d37cd 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -66,5 +66,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml new file mode 100644 index 000000000..28a49749f --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index e37048cfe..70f3682ef 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -28,6 +28,7 @@ import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.AAPProduct; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXCharacteristic; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXLocation; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingGear; @Data @EqualsAndHashCode(callSuper = false) @@ -63,11 +64,9 @@ public class FaCatchFact extends AbstractFact { private List fishActRelatedFluxLocationIds; private List fishingActivityFluxCharacteristic; private List faCatchFluxCharacteristic; + private List usedFishingGears; private boolean isSubActivity = false; - - - public boolean containsAtMostXTypesOfLocation(List locations,String type,int times){ if(CollectionUtils.isEmpty(locations)){ @@ -171,5 +170,4 @@ public void setFactType() { public boolean isSubActivity() { return isSubActivity; } - } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java index 3f638de75..962aca050 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java @@ -15,8 +15,8 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; -import java.util.Objects; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; @@ -53,6 +53,7 @@ public class FishingActivityFact extends AbstractFact { private CodeType faReportDocumentTypeCode; private List relatedFluxLocationRFMOCodeList; private List specifiedFaCatch; + private List specifiedFishingGears; private List relatedVesselTransportMeansRoleCodes; private List relFishActRelatedVesselTransportMeansRoleCodes; @@ -90,6 +91,15 @@ public boolean validDelimitedPeriod(List relatedFishingActiviti return isMatch; } + public boolean hasUniqueFluxCharacteristics(List fluxCharacteristicsTypeCode){ + if(fluxCharacteristicsTypeCode == null || fluxCharacteristicsTypeCode.isEmpty()){ + return true; + } + + HashSet listToSet = new HashSet(fluxCharacteristicsTypeCode); + return listToSet.size() == fluxCharacteristicsTypeCode.size(); + } + public boolean rfmoProvided(List relatedFLUXLocations) { if (CollectionUtils.isEmpty(relatedFLUXLocations)) { return true; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index d898b3b75..62e3445d6 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -329,8 +329,8 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc if(mainActivityType != null){ fishingActivityFact.setMainActivityType(mainActivityType.getValue()); - fishingActivityFact.setSpecifiedFaCatch(fishingActivity.getSpecifiedFACatches()); } + fishingActivityFact.setSpecifiedFaCatch(fishingActivity.getSpecifiedFACatches()); fishingActivityFact.setRelFishActRelatedVesselTransportMeansRoleCodes(mapToRelatedVTMCodes(fishingActivity.getRelatedFishingActivities())); fishingActivityFact.setRelatedVesselTransportMeansRoleCodes(extractRoleCodes(fishingActivity.getRelatedVesselTransportMeans())); fishingActivityFact.setFaRepDockSpecifiedVesselTransportMeansRoleCodes(extractRoleCodes(Collections.singletonList(faReportDocument.getSpecifiedVesselTransportMeans()))); @@ -388,6 +388,8 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc fishingActivityFact.setRelatedFluxLocationRFMOCodeList(getFLUXLocationRFMOCodes(fishingActivity.getRelatedFLUXLocations())); xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FLUX_LOCATION, REGIONAL_FISHERIES_MANAGEMENT_ORGANIZATION_CODE).storeInRepo(fishingActivityFact, RELATED_FLUX_LOCATION_RFMO_CODE_LIST_PROP); + fishingActivityFact.setSpecifiedFishingGears(fishingActivity.getSpecifiedFishingGears()); + xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FISHING_GEAR).storeInRepo(fishingActivityFact, "specifiedFishingGears"); return fishingActivityFact; } @@ -967,6 +969,9 @@ public List generateFactsForFaCatch(FishingActivity activity, bool xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); } + faCatchFact.setUsedFishingGears(faCatch.getUsedFishingGears()); + xPathUtil.appendWithoutWrapping(partialXPath).append(USED_FISHING_GEAR).storeInRepo(faCatchFact, "usedFishingGears"); + if (faCatch.getSpecifiedFLUXLocations() != null) { faCatchFact.setFaCatchFluxLocationId(mapFLUXLocationIDs(faCatch.getSpecifiedFLUXLocations())); } From 39078f10db953f446e6f60ab7926e74c9ef39fb8 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 14 Oct 2020 20:15:00 +0300 Subject: [PATCH 23/61] [UNIONVMS-4800] rules which check presence of DelimitedPeriod --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4800.xml | 45 +++++++++++++++++++ .../mapper/fact/ActivityFactMapper.java | 1 + 3 files changed, 47 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index df43d37cd..668360e70 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -67,5 +67,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml new file mode 100644 index 000000000..2128b8851 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + rule_id=:value + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 62e3445d6..f8080e1b3 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -324,6 +324,7 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc if (CollectionUtils.isNotEmpty(fishingActivity.getSpecifiedDelimitedPeriods())) { fishingActivityFact.setDelimitedPeriod(fishingActivity.getSpecifiedDelimitedPeriods().get(0)); } + xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD).storeInRepo(fishingActivityFact, "delimitedPeriod"); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, START_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodStartTime"); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, END_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodEndTime"); From f10d24badeceb9fae20a1e55f1e4e840eaea33ed Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Tue, 13 Oct 2020 17:57:03 +0300 Subject: [PATCH 24/61] [UNIONVMS-4801] modifying rules for roleCode in vesseltransportMeans only for specified fa not related --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4801.xml | 22 +++++++++++++++++++ .../fact/VesselTransportMeansFact.java | 8 +++++++ .../ActivityFaReportFactGenerator.java | 7 ++++-- .../mapper/fact/ActivityFactMapper.java | 19 ++++++++++++++++ .../business/ActivityFactMapperTest.java | 3 +++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 668360e70..86bcfc2ce 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -68,5 +68,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml new file mode 100644 index 000000000..2ef695fdb --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml @@ -0,0 +1,22 @@ + + + + + + rule_id=:value + + + + + + + + + rule_id=:value + + + + + + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java index 94b2e166a..a1547e284 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java @@ -33,6 +33,7 @@ public class VesselTransportMeansFact extends AbstractFact { private boolean isFromFaReport; + private boolean isFromParentFishingActivity; private CodeType fishingActivityType; private List ids; private IdType registrationVesselCountryId; @@ -119,4 +120,11 @@ public boolean getIsFromFaReport() { public void setIsFromFaReport(boolean fromFaReport) { isFromFaReport = fromFaReport; } + + public boolean getIsFromParentFishingActivity() { + return isFromParentFishingActivity; + } + public void setIsFromParentFishingActivity(boolean isFromParentFishingActivity) { + this.isFromParentFishingActivity = isFromParentFishingActivity; + } } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java index e88abb95f..4a304bf51 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java @@ -209,8 +209,11 @@ private Collection addFacts(List fishingActivitie facts.add(activityFactMapper.generateFishingActivityFact(fishingActivity, isSubActivity, faReportDocument, mainActivityType)); xPathUtil.appendWithoutWrapping(partialSpecFishActXpath); - facts.addAll(activityFactMapper.generateFactForVesselTransportMeans(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode())); - + if(isSubActivity) { + facts.addAll(activityFactMapper.generateFactForVesselTransportMeans(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode())); + } else { + facts.addAll(activityFactMapper.generateFactForVesselTransportMeansForParentFA(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode())); + } xPathUtil.appendWithoutWrapping(partialSpecFishActXpath); addFactsForVesselTransportMeansStructuresAddress(facts, fishingActivity.getRelatedVesselTransportMeans(), RELATED_VESSEL_TRANSPORT_MEANS); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index f8080e1b3..80be008cc 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -526,6 +526,25 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo return vesselTransportMeansFact; } + public List generateFactForVesselTransportMeansForParentFA(List vesselTransportMeans, List facts, + un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) { + if (CollectionUtils.isEmpty(vesselTransportMeans)) { + xPathUtil.clear(); + return emptyList(); + } + List list = new ArrayList<>(); + int index = 1; + String strToAppend = xPathUtil.getValue(); + for (VesselTransportMeans vesselTransportMean : vesselTransportMeans) { + VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, fishActType); + vesselTransportMeansFact.setIsFromParentFishingActivity(true); + xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "RoleCode"); + list.add(vesselTransportMeansFact); + index++; + } + return list; + } + public List generateFactForVesselTransportMeans(List vesselTransportMeans, List facts, un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) { if (CollectionUtils.isEmpty(vesselTransportMeans)) { diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java index 8e5a49864..b5034c9c3 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java @@ -10,6 +10,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The package eu.europa.ec.fisheries.uvms.rules.service.business; +import com.google.common.collect.Lists; import eu.europa.ec.fisheries.uvms.commons.message.impl.JAXBUtils; import eu.europa.ec.fisheries.uvms.mdr.model.exception.MdrModelMarshallException; import eu.europa.ec.fisheries.uvms.rules.service.business.fact.*; @@ -721,6 +722,7 @@ public void testNullParameters() { final FluxFaReportMessageFact fluxFaReportMessageFact = activityMapper.generateFactForFluxFaReportMessage(null); final List vesselTransportMeansFacts = activityMapper.generateFactForVesselTransportMeans(null, new ArrayList<>(), null); + final List vesselTransportMeansFactsFromParentFA = activityMapper.generateFactForVesselTransportMeansForParentFA(null, Lists.newArrayList(), null); final List structuredAddressFacts = activityMapper.generateFactsForStructureAddresses(null, null); final FishingGearFact fishingGearFact = activityMapper.generateFactsForFishingGear(null, null); final List fishingGearFacts = activityMapper.generateFactsForFishingGears(null, null , new HashMap<>(), new HashMap<>()); @@ -744,6 +746,7 @@ public void testNullParameters() { assertTrue(isEmpty(fishingTripFacts)); assertTrue(isEmpty(gearCharacteristicsFacts)); assertTrue(isEmpty(vesselTransportMeansFacts)); + assertTrue(isEmpty(vesselTransportMeansFactsFromParentFA)); assertTrue(isEmpty(structuredAddressFacts)); assertTrue(isEmpty(fishingGearFacts)); assertTrue(isEmpty(faReportDocumentFacts)); From 410fcadb9f9e1a5cc5009a175492fcf157609c3e Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 15 Oct 2020 17:38:14 +0300 Subject: [PATCH 25/61] [UNIONVMS-4802] Corrections for XPATH --- .../business/fact/FishingActivityFact.java | 23 +++++++++++++++++++ .../mapper/fact/ActivityFactMapper.java | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java index 962aca050..0fe551d76 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java @@ -17,6 +17,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; @@ -59,6 +61,8 @@ public class FishingActivityFact extends AbstractFact { private List relFishActRelatedVesselTransportMeansRoleCodes; private List faRepDockSpecifiedVesselTransportMeansRoleCodes; + private FishingActivity thisFishingActivity; + public FishingActivityFact() { setFactType(); } @@ -168,4 +172,23 @@ public boolean allDurationMeasuresHaveUnitCodeProvidedWhenValueIsProvided(){ return true; } + + public boolean hasPositionLocationForFaTypeCode(String fishingActivityTypeCode) { + if(!isSubActivity() || org.apache.commons.lang3.StringUtils.isEmpty(fishingActivityTypeCode)){ + return true; + } + if(thisFishingActivity != null && thisFishingActivity.getTypeCode() != null && fishingActivityTypeCode.equals(thisFishingActivity.getTypeCode().getValue())){ + List relatedFluxLocations = collectRelatedFluxLocations(thisFishingActivity); + return anyFluxLocationTypeCodeContainsValue(relatedFluxLocations, "POSITION"); + } + return true; + } + + private List collectRelatedFluxLocations(FishingActivity relatedFishingActivity) { + List nonNullFlucLocations = new ArrayList<>(); + if(relatedFishingActivity != null && CollectionUtils.isNotEmpty(relatedFishingActivity.getRelatedFLUXLocations())){ + nonNullFlucLocations = relatedFishingActivity.getRelatedFLUXLocations().stream().filter(Objects::nonNull).collect(Collectors.toList()); + } + return nonNullFlucLocations; + } } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 80be008cc..06a29e335 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -316,6 +316,7 @@ private FishingActivityType fetchActivityType(un.unece.uncefact.data.standard.un public FishingActivityFact generateFishingActivityFact(FishingActivity fishingActivity, boolean isSubActivity, FAReportDocument faReportDocument, un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType mainActivityType) { FishingActivityFact fishingActivityFact = new FishingActivityFact(); + fishingActivityFact.setThisFishingActivity(fishingActivity); fishingActivityFact.setSubActivity(isSubActivity); fishingActivityFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument != null ? faReportDocument.getTypeCode() : null)); @@ -339,6 +340,7 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FA_CATCH, TYPE_CODE).storeInRepo(fishingActivityFact, "specifiedFaCatch"); xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_VESSEL_TRANSPORT_MEANS, ROLE_CODE).storeInRepo(fishingActivityFact, "relatedVesselTransportMeansRoleCodes"); xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(fishingActivityFact, "relFishActRelatedVesselTransportMeansRoleCodes"); + xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(fishingActivityFact, "fishingActivityWithCorrectIndex"); fishingActivityFact.setRelatedFishingTrip(mapRelatedFishingTrips(fishingActivity.getRelatedFishingActivities())); xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FISHING_ACTIVITY, SPECIFIED_FISHING_TRIP).storeInRepo(fishingActivityFact, "relatedFishingTrip"); @@ -1470,6 +1472,8 @@ public FaFishingOperationFact generateFactsForFishingOperation(FishingActivity f faFishingOperationFact.setFishingGearRoleCodes(fishingGearRoleCodes); xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FISHING_ACTIVITY).appendWithIndex(VESSEL_RELATED_ACTIVITY_CODE, activityIndex) .storeInRepo(faFishingOperationFact, FISHING_GEAR_ROLE_CODES_PROP); + + activityIndex++; } faFishingOperationFact.setRelatedFishingActivitiesRelatedFLUXLocations(getRelatedFluxLocations(fishingActivity.getRelatedFishingActivities())); From 356dc0898d1d7bc57d0b731440e66d495a712a2d Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Tue, 13 Oct 2020 11:41:23 +0300 Subject: [PATCH 26/61] [UNIONVMS-4802] adding rules for relateing fishing activities with type codes GEAR_SHOT GEAR_RETREIVAL --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4802.xml | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 86bcfc2ce..07d1be0cd 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -69,5 +69,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml new file mode 100644 index 000000000..287c92fa7 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + br_id=:value + + + + + + + + + br_id=:value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + rule_id=:value + + + + + + + + br_id=:value + + + + + + + + br_id=:value + + + + + + br_id=:value + + + + + + id=:value + + + + + + id=:value + + + + + + + id=:value + + + + + + + id=:value + + + + + + + From 658d753dff9ce5764f70a22e4d22bd51c1abfd19 Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Fri, 9 Oct 2020 14:53:41 +0300 Subject: [PATCH 27/61] [UNIONVMS-4803]-rules for FLAPDocument/ID --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4803.xml | 119 +++++++++++++++ .../src/main/resources/contract/Template.xsd | 1 + .../rules/service/bean/ContainerType.java | 2 +- .../business/fact/FlapDocumentFact.java | 18 +++ .../ActivityFaReportFactGenerator.java | 4 + .../business/helper/DrtPathHelper.java | 1 + .../mapper/fact/ActivityFactMapper.java | 137 +++++++++++------- .../resources/templates/FaFlapDocument.drt | 35 +++++ .../business/ActivityFactMapperTest.java | 22 +++ 10 files changed, 284 insertions(+), 56 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java create mode 100644 service/src/main/resources/templates/FaFlapDocument.drt diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 07d1be0cd..9f5b61f16 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -70,5 +70,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml new file mode 100644 index 000000000..b3d5ea903 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + template_id=:value + + + + + + + diff --git a/model/src/main/resources/contract/Template.xsd b/model/src/main/resources/contract/Template.xsd index cfbb359f5..61604e8d6 100755 --- a/model/src/main/resources/contract/Template.xsd +++ b/model/src/main/resources/contract/Template.xsd @@ -47,6 +47,7 @@ + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java index bf9a17de0..38b2da827 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java @@ -26,7 +26,7 @@ public enum ContainerType { FactType.FA_RELOCATION, FactType.FA_DISCARD, FactType.FA_EXIT_FROM_SEA, FactType.FA_NOTIFICATION_OF_ARRIVAL, FactType.FA_ARRIVAL, FactType.FA_LANDING, FactType.FA_TRANSHIPMENT, FactType.FA_APPLIED_AAP_PROCESS, FactType.FA_NOTIFICATION_OF_TRANSHIPMENT_OR_RELOCATION, - FactType.FA_DECLARATION_OF_TRANSHIPMENT_OR_RELOCATION, FactType.SIMPLE_ID_TYPE_FACT, + FactType.FA_DECLARATION_OF_TRANSHIPMENT_OR_RELOCATION,FactType.FA_FLAP_DOCUMENT, FactType.SIMPLE_ID_TYPE_FACT, FactType.FA_VESSEL_POSITION_EVENT, FactType.FA_AAP_STOCK), FA_QUERY("faQuery", "ec.europa.eu.faQuery", FactType.FA_QUERY, diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java new file mode 100644 index 000000000..a7f93fcbf --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java @@ -0,0 +1,18 @@ +package eu.europa.ec.fisheries.uvms.rules.service.business.fact; + +import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class FlapDocumentFact extends AbstractFact { + + private IdType id; + + @Override + public void setFactType() { + this.factType = FactType.FA_FLAP_DOCUMENT; + } +} \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java index 4a304bf51..262b2d44f 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java @@ -19,6 +19,7 @@ import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType; import eu.europa.ec.fisheries.uvms.rules.service.business.VesselTransportMeansDto; +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.FlapDocumentFact; import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType; import eu.europa.ec.fisheries.uvms.rules.service.business.fact.VesselTransportMeansFact; import eu.europa.ec.fisheries.uvms.rules.service.constants.FaReportDocumentType; @@ -252,6 +253,9 @@ private Collection addFacts(List fishingActivitie xPathUtil.appendWithoutWrapping(partialSpecFishActXpath).append(DESTINATION_VESSEL_STORAGE_CHARACTERISTIC); facts.add(activityFactMapper.generateFactsForVesselStorageCharacteristic(fishingActivity.getDestinationVesselStorageCharacteristic())); + xPathUtil.appendWithoutWrapping(partialSpecFishActXpath); + facts.addAll(activityFactMapper.generateFactsForFlapDocuments(fishingActivity.getSpecifiedFLAPDocuments())); + xPathUtil.appendWithoutWrapping(partialSpecFishActXpath); facts.addAll(addFacts(fishingActivity.getRelatedFishingActivities(), faReportDocument, true, fishingActivity.getTypeCode())); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java index 40dddb269..4c9697add 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java @@ -40,6 +40,7 @@ public enum DrtPathHelper { FA_APPLIED_AAP_PROCESS("/templates/FaAppliedAAPProcess.drt"), FISHING_GEAR("/templates/FishingGear.drt"), FISHING_TRIP("/templates/FishingTrip.drt"), + FA_FLAP_DOCUMENT("/templates/FaFlapDocument.drt"), FLUX_CHARACTERISTIC("/templates/FluxCharacteristics.drt"), FLUX_FA_REPORT_MESSAGE("/templates/FluxFaReportMessage.drt"), FLUX_LOCATION("/templates/FluxLocation.drt"), diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 06a29e335..1aab8bc7e 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -11,6 +11,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The package eu.europa.ec.fisheries.uvms.rules.service.mapper.fact; +import com.google.common.collect.Lists; import eu.europa.ec.fisheries.uvms.commons.date.DateUtils; import eu.europa.ec.fisheries.uvms.commons.date.XMLDateUtils; import eu.europa.ec.fisheries.uvms.rules.dto.GearMatrix; @@ -114,6 +115,7 @@ public class ActivityFactMapper { private static final String RELATED_FLUX_LOCATIONS_ID_PROP = "relatedFluxLocationIDs"; private static final String FMC_MARKER_CODE = "FMCMarkerCode"; + public ActivityFactMapper() { setxPathUtil(new XPathStringWrapper()); } @@ -257,8 +259,8 @@ public List generateFactForFaReportDocuments(List HashMap> tripsPerFaTypeFromFasInReports = new HashMap<>(); tripsPerFaTypeFromFasInReports.put(FishingActivityType.ARRIVAL, new ArrayList<>()); tripsPerFaTypeFromFasInReports.put(FishingActivityType.DEPARTURE, new ArrayList<>()); - if (CollectionUtils.isEmpty(faReportDocuments)){ + if (CollectionUtils.isEmpty(faReportDocuments)) { return tripsPerFaTypeFromFasInReports; } int reportIndex = 1; for (FAReportDocument faReportDocument : faReportDocuments) { - if(CollectionUtils.isNotEmpty(faReportDocument.getSpecifiedFishingActivities())){ + if (CollectionUtils.isNotEmpty(faReportDocument.getSpecifiedFishingActivities())) { String faRepoDocTypeCode = ""; String faReportPurposeCode = ""; un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType faReportDocumentTypeCode = faReportDocument.getTypeCode(); - if (faReportDocumentTypeCode != null){ + if (faReportDocumentTypeCode != null) { faRepoDocTypeCode = faReportDocumentTypeCode.getValue(); } - if(faReportDocument.getRelatedFLUXReportDocument() != null && faReportDocument.getRelatedFLUXReportDocument().getPurposeCode() != null){ + if (faReportDocument.getRelatedFLUXReportDocument() != null && faReportDocument.getRelatedFLUXReportDocument().getPurposeCode() != null) { faReportPurposeCode = faReportDocument.getRelatedFLUXReportDocument().getPurposeCode().getValue(); } for (FishingActivity fishingActivity : faReportDocument.getSpecifiedFishingActivities()) { FishingActivityType activityType = fetchActivityType(fishingActivity.getTypeCode()); FishingTrip specifiedFishingTrip = fishingActivity.getSpecifiedFishingTrip(); - if(specifiedFishingTrip != null && CollectionUtils.isNotEmpty(specifiedFishingTrip.getIDS()) && "DECLARATION".equals(faRepoDocTypeCode) && !"5".equals(faReportPurposeCode) && - (FishingActivityType.DEPARTURE.equals(activityType) || FishingActivityType.ARRIVAL.equals(activityType))){ + if (specifiedFishingTrip != null && CollectionUtils.isNotEmpty(specifiedFishingTrip.getIDS()) && "DECLARATION".equals(faRepoDocTypeCode) && !"5".equals(faReportPurposeCode) && + (FishingActivityType.DEPARTURE.equals(activityType) || FishingActivityType.ARRIVAL.equals(activityType))) { tripsPerFaTypeFromFasInReports.get(activityType).add(new FaReportDocumentFact.TripIdAndReportIndex(specifiedFishingTrip.getIDS().get(0).getValue(), reportIndex)); } } @@ -303,10 +305,10 @@ private Map private FishingActivityType fetchActivityType(un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType typeCode) { FishingActivityType faType = null; - if(typeCode != null && StringUtils.isNotEmpty(typeCode.getValue())){ + if (typeCode != null && StringUtils.isNotEmpty(typeCode.getValue())) { try { faType = FishingActivityType.valueOf(typeCode.getValue()); - } catch(IllegalArgumentException ex){ + } catch (IllegalArgumentException ex) { log.error(ex.getMessage()); } } @@ -329,7 +331,7 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, START_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodStartTime"); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, END_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodEndTime"); - if(mainActivityType != null){ + if (mainActivityType != null) { fishingActivityFact.setMainActivityType(mainActivityType.getValue()); } fishingActivityFact.setSpecifiedFaCatch(fishingActivity.getSpecifiedFACatches()); @@ -398,14 +400,14 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc private List mapToRelatedVTMCodes(List fishingActivities) { List codes = new ArrayList<>(); - if(CollectionUtils.isEmpty(fishingActivities)){ + if (CollectionUtils.isEmpty(fishingActivities)) { return codes; } fishingActivities.forEach(fa -> { List relatedVesselTransportMeans = fa.getRelatedVesselTransportMeans(); - if(CollectionUtils.isNotEmpty(relatedVesselTransportMeans)){ + if (CollectionUtils.isNotEmpty(relatedVesselTransportMeans)) { relatedVesselTransportMeans.forEach(vtm -> { - if(vtm != null && vtm.getRoleCode() != null){ + if (vtm != null && vtm.getRoleCode() != null) { codes.add(mapToCodeType(vtm.getRoleCode())); } }); @@ -416,13 +418,13 @@ private List mapToRelatedVTMCodes(List fishingActivit private List extractRoleCodes(List vesselTransportMeans) { List roleCodes = new ArrayList<>(); - if(CollectionUtils.isEmpty(vesselTransportMeans)){ + if (CollectionUtils.isEmpty(vesselTransportMeans)) { return roleCodes; } vesselTransportMeans = vesselTransportMeans.stream() .filter(Objects::nonNull) .collect(Collectors.toList()); - vesselTransportMeans.forEach((trspMean)-> roleCodes.add(mapToCodeType(trspMean.getRoleCode()))); + vesselTransportMeans.forEach((trspMean) -> roleCodes.add(mapToCodeType(trspMean.getRoleCode()))); return roleCodes; } @@ -434,7 +436,7 @@ public DateTime mapToJodaDateTime(DateTimeType creationDateTime) { dateTimeOfCreationOfMessage = new DateTime(repDat); } else if (creationDateTime.getDateTimeString() != null && org.apache.commons.lang3.StringUtils.isNotEmpty(creationDateTime.getDateTimeString().getValue())) { try { - Date parsedDate = DateUtils.parseToUTCDate(creationDateTime.getDateTimeString().getValue(),creationDateTime.getDateTimeString().getFormat()); + Date parsedDate = DateUtils.parseToUTCDate(creationDateTime.getDateTimeString().getValue(), creationDateTime.getDateTimeString().getFormat()); dateTimeOfCreationOfMessage = new DateTime(parsedDate); } catch (IllegalArgumentException e) { log.warn("[WARN] Couldn't extract date from CreationDateTime of Message!", e); @@ -453,7 +455,7 @@ public FluxFaReportMessageFact generateFactForFluxFaReportMessage(FLUXFAReportMe fluxFaReportMessageFact.setSenderOrReceiver(senderReceiver); - if(fluxfaReportMessage.getFLUXReportDocument() != null){ + if (fluxfaReportMessage.getFLUXReportDocument() != null) { fluxFaReportMessageFact.setCreationDateOfMessage(mapToJodaDateTime(fluxfaReportMessage.getFLUXReportDocument().getCreationDateTime())); } @@ -577,7 +579,7 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo String toBeAppendedAlways = xPathUtil.getValue(); // Generate facts for ID Types. This is done so that we can have the right xPath to the specific ID that failed! - if(CollectionUtils.isNotEmpty(vesselTransportMean.getIDS())){ + if (CollectionUtils.isNotEmpty(vesselTransportMean.getIDS())) { generateFactsForSimpleIdTypes(facts, vesselTransportMean.getIDS(), toBeAppendedAlways); } @@ -640,7 +642,7 @@ private void generateFactsForVesselPositionEvents(List spec int index = 1; for (VesselPositionEvent specifiedVesselPositionEvent : specifiedVesselPositionEvents) { - if(specifiedVesselPositionEvent == null){ + if (specifiedVesselPositionEvent == null) { xPathUtil.clear(); continue; } @@ -674,7 +676,7 @@ private void generateFactsForVesselPositionEvents(List spec } private void generateFactsForSimpleIdTypes(List facts, List ids, String partialXpath) { - if(CollectionUtils.isEmpty(ids)){ + if (CollectionUtils.isEmpty(ids)) { return; } int index = 1; @@ -921,7 +923,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool faCatchFact.setFishingActivityTypeCode(mapToCodeType(activity.getTypeCode())); xPathUtil.appendWithoutWrapping(partialXPath).append(TYPE_CODE).storeInRepo(faCatchFact, FISHING_ACTIVITY_TYPE_CODE); - faCatchFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument!=null?faReportDocument.getTypeCode():null)); + faCatchFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument != null ? faReportDocument.getTypeCode() : null)); xPathUtil.append(FLUXFA_REPORT_MESSAGE, FA_REPORT_DOCUMENT).storeInRepo(faCatchFact, FA_REPORT_DOCUMENT_TYPE_CODE); partialXPath = xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(SPECIFIED_FA_CATCH, index).getValue(); @@ -999,7 +1001,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool } xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "faCatchFluxLocationId"); - if(CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)){ + if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)) { faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); @@ -1019,7 +1021,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool xPathUtil.appendWithoutWrapping(partialXPath).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fluxLocationId"); } - if(faReportDocument != null && faReportDocument.getSpecifiedVesselTransportMeans() != null && faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry() != null){ + if (faReportDocument != null && faReportDocument.getSpecifiedVesselTransportMeans() != null && faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry() != null) { faCatchFact.setFarepDocSpecVesselTrpmRegVesselCountryId(mapToIdType(faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry().getID())); } @@ -1038,14 +1040,14 @@ public List generateFactsForFaCatch(FishingActivity activity, bool } private void addFactsForAAPStock(List relatedAAPStocks, List facts) { - if(CollectionUtils.isEmpty(relatedAAPStocks)){ + if (CollectionUtils.isEmpty(relatedAAPStocks)) { xPathUtil.clear(); return; } String partialXpath = xPathUtil.getValue(); int index = 1; for (AAPStock relatedAAPStock : relatedAAPStocks) { - if(relatedAAPStock == null){ + if (relatedAAPStock == null) { xPathUtil.clear(); continue; } @@ -1058,7 +1060,7 @@ private void addFactsForAAPStock(List relatedAAPStocks, List facts) { - if(CollectionUtils.isEmpty(faCatch.getAppliedAAPProcesses())) { + if (CollectionUtils.isEmpty(faCatch.getAppliedAAPProcesses())) { xPathUtil.clear(); return; } @@ -1270,7 +1272,7 @@ public FaDepartureFact generateFactsForFaDeparture(FishingActivity fishingActivi List specifiedFishingGears = fishingActivity.getSpecifiedFishingGears(); List roleCodes = new ArrayList<>(); - if(CollectionUtils.isNotEmpty(specifiedFishingGears)){ + if (CollectionUtils.isNotEmpty(specifiedFishingGears)) { for (FishingGear fishingGear : specifiedFishingGears) { roleCodes.addAll(mapToCodeTypes(fishingGear.getRoleCodes())); } @@ -1287,7 +1289,7 @@ public FaDepartureFact generateFactsForFaDeparture(FishingActivity fishingActivi for (FACatch faCatch : specifiedFACatches) { CodeType codeType = mapToCodeType(faCatch.getTypeCode()); - if (codeType != null){ + if (codeType != null) { codeTypeList.add(codeType); } } @@ -1466,7 +1468,7 @@ public FaFishingOperationFact generateFactsForFishingOperation(FishingActivity f for (FishingActivity activity : relatedFishingActivities) { List fishingGearRoleCodes1 = getFishingGearRoleCodes(activity.getSpecifiedFishingGears()); List fishingGearRoleCodes = faFishingOperationFact.getFishingGearRoleCodes(); - if (CollectionUtils.isNotEmpty(fishingGearRoleCodes)){ + if (CollectionUtils.isNotEmpty(fishingGearRoleCodes)) { fishingGearRoleCodes.addAll(fishingGearRoleCodes1); } faFishingOperationFact.setFishingGearRoleCodes(fishingGearRoleCodes); @@ -1589,7 +1591,7 @@ private List getFishingActivityTypeCodeList(List fish List fishingActivityTypeCodes = new ArrayList<>(); for (FishingActivity activity : fishingActivities) { CodeType codeType = mapToCodeType(activity.getTypeCode()); - if(codeType != null){ + if (codeType != null) { fishingActivityTypeCodes.add(codeType); } } @@ -1627,7 +1629,7 @@ public FaRelocationFact generateFactsForRelocation(FishingActivity fishingActivi for (FLUXLocation fluxLocation : faCatch.getDestinationFLUXLocations()) { fluxLocationTypeCodes.add(mapToCodeType(fluxLocation.getTypeCode())); IdType idType = mapToIdType(fluxLocation.getID()); - if (idType != null){ + if (idType != null) { fluxLocationIds.add(idType); } destinationFluxLocations.add(fluxLocation); @@ -1832,7 +1834,7 @@ public FaNotificationOfArrivalFact generateFactsForPriorNotificationOfArrival(Fi FishingTrip specifiedFishingTrip = fishingActivity.getSpecifiedFishingTrip(); if (specifiedFishingTrip != null) { - if (CollectionUtils.isNotEmpty(specifiedFishingTrip.getSpecifiedDelimitedPeriods())){ + if (CollectionUtils.isNotEmpty(specifiedFishingTrip.getSpecifiedDelimitedPeriods())) { List specifiedDelimitedPeriods = specifiedFishingTrip.getSpecifiedDelimitedPeriods(); faNotificationOfArrivalFact.setDelimitedPeriods(specifiedDelimitedPeriods.get(0)); } @@ -2158,7 +2160,7 @@ public AbstractRelocationOrTranshipmentFact generateFactsForNotificationOrDeclar return null; } AbstractRelocationOrTranshipmentFact faNotificationOfRelocationOrTranshipmentFact; - if(FaReportDocumentType.DECLARATION.name().equals(faReportDocument.getTypeCode().getValue())){ + if (FaReportDocumentType.DECLARATION.name().equals(faReportDocument.getTypeCode().getValue())) { faNotificationOfRelocationOrTranshipmentFact = new FaDeclarationOfRelocationOrTranshipmentFact(); } else { faNotificationOfRelocationOrTranshipmentFact = new FaNotificationOfRelocationOrTranshipmentFact(); @@ -2244,6 +2246,31 @@ public ValidationQualityAnalysisFact generateFactsForValidationQualityAnalysis(V return qualityAnalysisFact; } + public List generateFactsForFlapDocuments(List specifiedFLAPDocuments) { + + if (CollectionUtils.isEmpty(specifiedFLAPDocuments)) { + xPathUtil.clear(); + return Lists.newArrayList(); + } + + return specifiedFLAPDocuments.stream().filter(Objects::nonNull).map(this::generateFactForFlapDocument).collect(Collectors.toList()); + } + + private FlapDocumentFact generateFactForFlapDocument(FLAPDocument flapDocument) { + final String partialXpath = xPathUtil.getValue(); + + FlapDocumentFact flapDocumentFact = new FlapDocumentFact(); + xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FLAP_DOCUMENT, ID).storeInRepo(flapDocumentFact, "id"); + if (flapDocument.getID() != null) { + IdType idType = new IdType(); + idType.setSchemeId(flapDocument.getID().getSchemeID()); + idType.setValue(flapDocument.getID().getValue()); + flapDocumentFact.setId(idType); + } + + return flapDocumentFact; + } + private List mapFromTextTypeToString(List txTypeList) { if (CollectionUtils.isEmpty(txTypeList)) { return Collections.emptyList(); @@ -2260,7 +2287,7 @@ public eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType mapToCod return null; } boolean notBlankValue = StringUtils.isNotBlank(codeType.getValue()); - if (notBlankValue){ + if (notBlankValue) { eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType codeType1 = new eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType(); codeType1.setListId(codeType.getListID()); codeType1.setValue(codeType.getValue()); @@ -2275,7 +2302,7 @@ public MeasureType mapToMeasureType(QuantityType quantityType) { } boolean notNullValue = quantityType.getValue() != null; - if (notNullValue){ + if (notNullValue) { MeasureType measureType1 = new MeasureType(); measureType1.setUnitCode(quantityType.getUnitCode()); measureType1.setValue(quantityType.getValue()); @@ -2310,7 +2337,7 @@ public List mapToIdTypes(List idTypes) { IdType idType = mapToIdType(iDType); if (idType != null) { IdType idType1 = mapToIdType(iDType); - if (idType1 != null){ + if (idType1 != null) { idTypeList.add(idType1); } } @@ -2337,7 +2364,7 @@ public List mapToMeasureType(List list = new ArrayList<>(); for (un.unece.uncefact.data.standard.unqualifieddatatype._20.MeasureType measureType : measureTypes) { MeasureType measureType1 = mapToMeasureType(measureType); - if (measureType1 != null){ + if (measureType1 != null) { list.add(measureType1); } } @@ -2659,7 +2686,7 @@ private List mapFluxLocationsToCodeTypes(List locations) if (CollectionUtils.isNotEmpty(locations)) { for (FLUXLocation fluxLocation : locations) { CodeType codeType = mapToCodeType(fluxLocation.getTypeCode()); - if(codeType != null){ + if (codeType != null) { typeCodes.add(codeType); } } @@ -2674,7 +2701,7 @@ private List mapDurationMeasure(List delimitedPeri for (DelimitedPeriod delimitedPeriod : delimitedPeriods) { if (delimitedPeriod.getDurationMeasure() != null) { MeasureType measureType = mapToMeasureType(delimitedPeriod.getDurationMeasure()); - if (measureType != null){ + if (measureType != null) { measureTypes.add(measureType); } } @@ -2715,7 +2742,7 @@ private List mapFromContactPartyToCodeType(List contactP codeTypes = new ArrayList<>(); for (ContactParty contactParty : contactPartyList) { List codeTypes1 = mapToCodeTypes(contactParty.getRoleCodes()); - if (CollectionUtils.isNotEmpty(codeTypes1)){ + if (CollectionUtils.isNotEmpty(codeTypes1)) { codeTypes.addAll(mapToCodeTypes(contactParty.getRoleCodes())); } } @@ -2814,7 +2841,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List case PACKAGING_UNIT_QUANTITY: if (aapProduct.getPackagingUnitQuantity() != null) { MeasureType measureType = mapToMeasureType(aapProduct.getPackagingUnitQuantity()); - if (measureType != null){ + if (measureType != null) { measureTypes.add(measureType); } } @@ -2822,7 +2849,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List case AVERAGE_WEIGHT_MEASURE: if (aapProduct.getPackagingUnitAverageWeightMeasure() != null) { MeasureType measureType = mapToMeasureType(aapProduct.getPackagingUnitAverageWeightMeasure()); - if (measureType != null){ + if (measureType != null) { measureTypes.add(measureType); } } @@ -2830,7 +2857,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List case WEIGHT_MEASURE: if (aapProduct.getWeightMeasure() != null) { MeasureType measureType = mapToMeasureType(aapProduct.getWeightMeasure()); - if (measureType != null){ + if (measureType != null) { measureTypes.add(measureType); } } @@ -2838,7 +2865,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List case UNIT_QUANTITY: if (aapProduct.getUnitQuantity() != null) { MeasureType measureType = mapToMeasureType(aapProduct.getUnitQuantity()); - if (measureType != null){ + if (measureType != null) { measureTypes.add(measureType); } } @@ -2859,7 +2886,7 @@ private List getAAPProductPackagingTypeCode(List appliedAA for (AAPProduct aapProduct : aapProcess.getResultAAPProducts()) { if (aapProduct.getPackagingTypeCode() != null) { CodeType codeType = mapToCodeType(aapProduct.getPackagingTypeCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -2891,7 +2918,7 @@ private List mapToFLUXCharacteristicsTypeCodes(List getApplicableFLUXCharacteristicsValueQuantity(List getFLUXLocationTypeCodes(List fluxLocations for (FLUXLocation fluxLocation : fluxLocations) { if (fluxLocation.getTypeCode() != null) { CodeType codeType = mapToCodeType(fluxLocation.getTypeCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -2939,7 +2966,7 @@ private List getFLUXLocationRFMOCodes(List fluxLocations for (FLUXLocation fluxLocation : fluxLocations) { if (fluxLocation.getRegionalFisheriesManagementOrganizationCode() != null) { CodeType codeType = mapToCodeType(fluxLocation.getRegionalFisheriesManagementOrganizationCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -2997,7 +3024,7 @@ private List getCodeTypesFromFaCatch(List faCatch, String met case CODE_TYPE_FOR_FACATCH_PROP: if (faCatches.getTypeCode() != null) { CodeType codeType = mapToCodeType(faCatches.getTypeCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -3005,7 +3032,7 @@ private List getCodeTypesFromFaCatch(List faCatch, String met case SPECIES_CODE_FOR_FACATCH_PROP: if (faCatches.getSpeciesCode() != null) { CodeType codeType = mapToCodeType(faCatches.getSpeciesCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -3031,7 +3058,7 @@ public List getFLAPDocumentIds(List flapDocuments) { if (flapDocument.getID() != null) { IdType idType = mapToIdType(flapDocument.getID()); - if (idType != null){ + if (idType != null) { idTypes.add(idType); } } @@ -3044,7 +3071,7 @@ private void mapSpecifiedFluxLocationsCodeTypeList(List codeTypes, FAC for (FLUXLocation specifiedFluxLocation : faCatches.getSpecifiedFLUXLocations()) { if (specifiedFluxLocation.getTypeCode() != null) { CodeType codeType = mapToCodeType(specifiedFluxLocation.getTypeCode()); - if (codeType != null){ + if (codeType != null) { codeTypes.add(codeType); } } @@ -3084,7 +3111,7 @@ public void setTransportMeans(List transportMeans) { this.transportMeans = transportMeans; } - public List getTransportMeansDtos(){ + public List getTransportMeansDtos() { return transportMeans; } diff --git a/service/src/main/resources/templates/FaFlapDocument.drt b/service/src/main/resources/templates/FaFlapDocument.drt new file mode 100644 index 000000000..0872adfe6 --- /dev/null +++ b/service/src/main/resources/templates/FaFlapDocument.drt @@ -0,0 +1,35 @@ +template header + +tname +expression +brid +rulemsg +type +level +propertyNames +context + +package eu.europa.ec.fisheries.uvms.rules.service.business.activity; + +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.FlapDocumentFact; + + +global eu.europa.ec.fisheries.uvms.rules.service.business.helper.RuleApplicabilityChecker appliChecker; +global eu.europa.ec.fisheries.uvms.rules.service.MDRCacheRuleService mdrService; + + + +template "@{tname}" + +rule "FA Flap Document @{tname} - @{brid} - Context : @{context}" + +when + + $fact : FlapDocumentFact((appliChecker.isApplicable("@{brid}", "@{context}", getMessageDataFlow(), getCreationDateOfMessage(), mdrService)) && (@{expression})) + +then + $fact.setOk(false); + $fact.addWarningOrError(mdrService.getErrorTypeStrForForBrIAndDFAndValidity("@{brid}", "@{context}", $fact.getCreationJavaDateOfMessage()), mdrService.getErrorMessageForBrIAndDFAndValidity("@{brid}", "@{context}", $fact.getCreationJavaDateOfMessage()), "@{brid}", "@{level}", "@{propertyNames}"); +end + +end template diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java index b5034c9c3..82ee7a788 100644 --- a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/ActivityFactMapperTest.java @@ -949,4 +949,26 @@ public void testFaAppliedAAPProcessFacts() { assertEquals(BigDecimal.TEN, fact.getConversionFactorNumeric().getValue()); assertEquals(FORMAT, fact.getConversionFactorNumeric().getFormat()); } + + @Test + public void testFaFlapDocumentFacts() { + + final FLAPDocument flapDocument = new FLAPDocument(); + IDType idType = new IDType(); + idType.setValue("SVN-2018/AUT/123"); + idType.setSchemeID("ICCAT_AUTHORIZATION"); + flapDocument.setID(idType); + + FishingActivity faActivity = new FishingActivity(); + faActivity.setSpecifiedFLAPDocuments(Lists.newArrayList(flapDocument)); + faActivity.setRelatedFLUXLocations(specifiedFluxLocation); + + List facts = activityMapper.generateFactsForFlapDocuments(Lists.newArrayList(flapDocument)); + + List flapDocumentFacts = facts.stream().filter(FlapDocumentFact.class::isInstance).map(FlapDocumentFact.class::cast).collect(Collectors.toList()); + assertEquals(1, flapDocumentFacts.size()); + FlapDocumentFact fact = flapDocumentFacts.get(0); + assertEquals("SVN-2018/AUT/123", fact.getId().getValue()); + assertEquals("ICCAT_AUTHORIZATION", fact.getId().getSchemeId()); + } } From 51e20bea4500c42f133d24ec2275ec02603d52cb Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Tue, 6 Oct 2020 17:10:10 +0300 Subject: [PATCH 28/61] [UNIONVMS-4804] rules for IMO calc of last digit in case of UVI id --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4804.xml | 51 +++++++++++++++++++ .../service/business/fact/IdTypeFact.java | 29 +++++++++++ 3 files changed, 81 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 9f5b61f16..645988cf4 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -71,5 +71,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml new file mode 100644 index 000000000..e63189407 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java index 4b067d40c..c2c671b81 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java @@ -4,6 +4,8 @@ import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; import lombok.Data; +import java.util.Arrays; + @Data public class IdTypeFact extends AbstractFact { @@ -19,6 +21,33 @@ public IdTypeFact(IdType id) { setFactType(); } + /** + * Method to validate the last digit of the schemeId Value if schemeId type is UVI + * + * @param schemeIdValue the value of the schemeId + * @return true if the validation fails and false if succeeds + * Extract the digits from the String SchemeIdValue + * iterate through them to calculate the sum of each one being + * successively (individually) multiplied by 7,6,5,4,3,2. + * Last digit of the calculated sum is the 7th digit. + * see(14.5. Validation of the IMO number format (UVI) v2.5) + */ + public boolean isLastCheckBitInvalidInUVISchemeId(String schemeIdValue) { + int[] digits = Arrays.stream(schemeIdValue.split("")).mapToInt(Integer::parseInt).toArray(); + if (digits.length == 7) { + int lastDigit = digits[digits.length - 1]; + int sum = 0; + for (int i = 1; i < digits.length; i++) { + sum += (digits.length + 1 - i) * digits[i - 1]; + } + int lastDigitOfSum = Math.abs(sum) % 10; + + return lastDigitOfSum != lastDigit; + } + return true; + } + + @Override public void setFactType() { this.factType = FactType.SIMPLE_ID_TYPE_FACT; From d00de270d0e157fde74e2b4dcacbd7c6f53925aa Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Mon, 5 Oct 2020 16:05:25 +0300 Subject: [PATCH 29/61] [UNIONVMS-4805] changes in rules for ApplicableGearCharacteristics ANNEX 14.1 v2.5 --- .../fisheries/uvms/rules/dto/GearMatrix.java | 96 ++++++++++++++----- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java index 1de4ba834..f4fea5823 100644 --- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java +++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java @@ -225,17 +225,38 @@ private void fillNEAFCGearMetrix() { private void fillGearMetrix() { // Trawl nets + matrix.put("TBB", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false), + new Condition("GN", false)) + ); matrix.put("OTB", Arrays.asList( new Condition("ME", false), new Condition("GM", true), new Condition("MT", true)) ); - matrix.put("TBN", Arrays.asList( + matrix.put("OT", Arrays.asList( new Condition("ME", false), new Condition("GM", true), new Condition("MT", true)) ); - matrix.put("TBS", Arrays.asList( + matrix.put("OTT", Arrays.asList( + new Condition("ME", false), + new Condition("GM", true), + new Condition("GN", false), + new Condition("MT", true)) + ); + matrix.put("OTP", Arrays.asList( + new Condition("ME", false), + new Condition("GM", true), + new Condition("MT", true)) + ); + matrix.put("PTB", Arrays.asList( + new Condition("ME", false), + new Condition("GM", true), + new Condition("MT", true)) + ); + matrix.put("PT", Arrays.asList( new Condition("ME", false), new Condition("GM", true), new Condition("MT", true)) @@ -245,18 +266,22 @@ private void fillGearMetrix() { new Condition("GM", true), new Condition("MT", true)) ); - matrix.put("TBB", Arrays.asList( + matrix.put("TBN", Arrays.asList( new Condition("ME", false), - new Condition("GM", false), - new Condition("GN", false)) + new Condition("GM", true), + new Condition("MT", true)) ); - matrix.put("OTT", Arrays.asList( + matrix.put("TBS", Arrays.asList( new Condition("ME", false), new Condition("GM", true), - new Condition("GN", false), new Condition("MT", true)) ); - matrix.put("PTB", Arrays.asList( + matrix.put("PUK", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false), + new Condition("GN", false)) + ); + matrix.put("PUL", Arrays.asList( new Condition("ME", false), new Condition("GM", true), new Condition("MT", true)) @@ -269,6 +294,21 @@ private void fillGearMetrix() { new Condition("ME", false), new Condition("MT", false)) ); + matrix.put("TM", Arrays.asList( + new Condition("ME", false), + new Condition("MT", false)) + ); + matrix.put("TMS", Arrays.asList( + new Condition("ME", false), + new Condition("MT", false)) + ); + matrix.put("TSP", Arrays.asList( + new Condition("ME", false), + new Condition("MT", false)) + ); + matrix.put("TX", Arrays.asList( + new Condition("ME", false)) + ); // Seine nets matrix.put("SDN", Arrays.asList( @@ -291,6 +331,10 @@ private void fillGearMetrix() { new Condition("ME", false), new Condition("GM", false)) ); + matrix.put("SB", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false)) + ); // Surrounding nets matrix.put("PS", Arrays.asList( @@ -313,6 +357,11 @@ private void fillGearMetrix() { new Condition("GM", false), new Condition("HE", false)) ); + matrix.put("SUX", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false), + new Condition("HE", false)) + ); // Dredges matrix.put("DRB", Arrays.asList( @@ -369,12 +418,27 @@ private void fillGearMetrix() { new Condition("NN", false), new Condition("QG", true)) ); + matrix.put("GNF", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false), + new Condition("HE", false), + new Condition("NL", false), + new Condition("NN", false), + new Condition("QG", true)) + ); + matrix.put("GEN", Arrays.asList( + new Condition("ME", false), + new Condition("GM", false), + new Condition("HE", false), + new Condition("NL", false), + new Condition("NN", false), + new Condition("QG", true)) + ); // Traps matrix.put("FPO", Collections.singletonList(new Condition("GN", false)) ); - matrix.put("FIX", Collections.emptyList()); // Hooks & Lines matrix.put("LHP", Arrays.asList( @@ -397,20 +461,6 @@ private void fillGearMetrix() { new Condition("GN", false), new Condition("NI", false)) ); - matrix.put("LTL", Collections.emptyList()); - matrix.put("LX", Collections.emptyList()); - - // Harvesting machines - matrix.put("HMD", Collections.emptyList()); - - // Miscellaneous gear - matrix.put("MIS", Collections.emptyList()); - - // Recreational gear - matrix.put("RG", Collections.emptyList()); - - // Gear not known or not specified - matrix.put("NK", Collections.emptyList()); } @Data From 87efa1792e35b0e48b0fce433695102c9cd1fae0 Mon Sep 17 00:00:00 2001 From: kwstaspgr Date: Wed, 7 Oct 2020 12:15:39 +0300 Subject: [PATCH 30/61] [UNIONVMS-4806] Add Rule Rule FA-L03-00-0650 add liquibase script for rule add implementation for rule add check in RulesFaQueryServiceBean for concurrent access --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4806.xml | 39 +++++++++++++++++++ .../activity/RulesFaQueryServiceBean.java | 3 ++ .../rules/service/business/AbstractFact.java | 11 ++++++ .../service/business/fact/FaQueryFact.java | 11 ++++++ .../generator/ActivityQueryFactGenerator.java | 23 +++++++++++ .../mapper/fact/ActivityFactMapper.java | 12 ++++++ 7 files changed, 100 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 645988cf4..b547ac773 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -72,5 +72,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml new file mode 100644 index 000000000..7bc6bdf0a --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java index 7c621fbbb..88ebc84f6 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java @@ -116,12 +116,15 @@ public void evaluateIncomingFAQuery(SetFaQueryMessageRequest request) { log.info("Evaluate FAQuery with ID {}", faQueryGUID); boolean needToSendToExchange = true; Set idsFromIncomingMessage = fluxMessageHelper.mapQueryToFADocumentID(faQueryMessage); + rulesDaoBean.takeNoteOfDocumentIds(idsFromIncomingMessage); + rulesDaoBean.lockDocumentIds(idsFromIncomingMessage); List faQueryIdsFromDb = rulesDaoBean.loadFADocumentIDByIdsByIds(idsFromIncomingMessage); Map extraValues = new EnumMap<>(ExtraValueType.class); extraValues.put(SENDER_RECEIVER, request.getSenderOrReceiver()); extraValues.put(XML, requestStr); extraValues.put(DATA_FLOW, dataFlow); + extraValues.put(FA_QUERY_AND_REPORT_IDS, faQueryIdsFromDb); Collection faQueryFacts = rulesEngine.evaluate(RECEIVING_FA_QUERY_MSG, faQueryMessage, extraValues, String.valueOf(faQueryMessage.getFAQuery().getID())); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java index 344bafdbc..94cb8963e 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java @@ -371,6 +371,17 @@ public boolean validateFormat(CodeType codeType) { return isInvalid; } + /** + * Returns true if the object is found in the collection. + * + */ + public boolean containsObject(Object obj, Collection col) { + if (CollectionUtils.isEmpty(col)){ + col = new ArrayList(); + } + return CollectionUtils.exists(col, o -> o.equals(obj)); + } + /** * Returns true if at least one element is in both collections. * diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java index 68960bce3..d9c73a4eb 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java @@ -36,6 +36,8 @@ public class FaQueryFact extends AbstractFact { private List submittedFLUXPartyIds; + private List nonUniqueIdsList; + private DelimitedPeriod specifiedDelimitedPeriod; private String sdpStartDateTimeString; @@ -124,4 +126,13 @@ public List getSimpleFAQueryParameterTypeCodes() { public void setSimpleFAQueryParameterTypeCodes(List simpleFAQueryParameterTypeCodes) { this.simpleFAQueryParameterTypeCodes = simpleFAQueryParameterTypeCodes; } + + public List getNonUniqueIdsList() { + return nonUniqueIdsList; + } + + public void setNonUniqueIdsList(List nonUniqueIdsList) { + this.nonUniqueIdsList = nonUniqueIdsList; + } + } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java index 011e0241c..b7cbf4ab4 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java @@ -15,8 +15,13 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import eu.europa.ec.fisheries.uvms.rules.entity.FADocumentID; import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType; +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType; import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException; import eu.europa.ec.fisheries.uvms.rules.service.mapper.fact.ActivityFactMapper; import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper; @@ -25,6 +30,7 @@ import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FAQuery; import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.FA_QUERY_AND_REPORT_IDS; import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER; import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FA_QUERY; import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FLUXFA_QUERY_MESSAGE; @@ -61,6 +67,7 @@ public List generateAllFacts() { if (fluxfaQueryMessage != null) { FAQuery faQuery = fluxfaQueryMessage.getFAQuery(); if (faQuery != null) { + activityFactMapper.getNonUniqueIdsList().addAll(extractNonUniqueIds()); xPathUtil.append(FLUXFA_QUERY_MESSAGE).append(FA_QUERY); factList.add(activityFactMapper.generateFactsForFaQuery(faQuery)); @@ -75,6 +82,22 @@ public List generateAllFacts() { return factList; } + private List extractNonUniqueIds() { + @SuppressWarnings("unchecked") + List faDocumentIDS = Optional.ofNullable((List) extraValueMap.get(FA_QUERY_AND_REPORT_IDS)).orElse(new ArrayList<>()); + return (faDocumentIDS) + .stream() + .map(this::toIdType) + .collect(Collectors.toList()); + } + + private IdType toIdType(FADocumentID d) { + IdType idType = new IdType(); + idType.setValue(d.getUuid()); + Optional.ofNullable(d.getType()).ifPresent(fId -> idType.setSchemeId(fId.name())); + return idType; + } + private void populateCreationDateTime(List factList) { if (fluxfaQueryMessage != null && fluxfaQueryMessage.getFAQuery() != null) { DateTime dateTimeOfCreationOfMessage = activityFactMapper.mapToJodaDateTime(fluxfaQueryMessage.getFAQuery().getSubmittedDateTime()); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 1aab8bc7e..13cd6a22a 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -54,6 +54,7 @@ public class ActivityFactMapper { private XPathStringWrapper xPathUtil; private List faReportMessageIds = new ArrayList<>(); private List faRelatedReportIds = new ArrayList<>(); + private List nonUniqueIdsList = new ArrayList<>(); private List faQueryIds = new ArrayList<>(); private List faResponseIds = new ArrayList<>(); private String senderReceiver = null; @@ -2083,6 +2084,9 @@ public FaQueryFact generateFactsForFaQuery(FAQuery faQuery) { faQueryFact.setSimpleFAQueryParameterTypeCodes(codeTypes); } + faQueryFact.setNonUniqueIdsList(nonUniqueIdsList); + xPathUtil.appendWithoutWrapping(partialXpath).append(FLUXFA_QUERY_MESSAGE, ID).storeInRepo(faQueryFact, "nonUniqueIdsList"); + return faQueryFact; } @@ -3119,4 +3123,12 @@ public void setFaRelatedReportIds(List faRelatedReportIds) { this.faRelatedReportIds = faRelatedReportIds; } + public List getNonUniqueIdsList() { + return nonUniqueIdsList; + } + + public void setNonUniqueIdsList(List nonUniqueIdsList) { + this.nonUniqueIdsList = nonUniqueIdsList; + } + } From b870e0dc9682b0164c01d11785f2cfea08869658 Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Thu, 1 Oct 2020 12:42:37 +0300 Subject: [PATCH 31/61] [UNIONVMS-4807] Missing rules for FA queries --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4807.xml | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index b547ac773..fe0346d32 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -73,5 +73,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml new file mode 100644 index 000000000..d971ff137 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + From ec55ee07e2bd87a3b5ceacc0163ac7e4d4359993 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 15 Oct 2020 10:58:36 +0300 Subject: [PATCH 32/61] Correction --- .../uvms/rules/service/mapper/fact/ActivityFactMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 13cd6a22a..c70fc00ff 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -541,7 +541,7 @@ public List generateFactForVesselTransportMeansForPare int index = 1; String strToAppend = xPathUtil.getValue(); for (VesselTransportMeans vesselTransportMean : vesselTransportMeans) { - VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, fishActType); + VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, fishActType, false); vesselTransportMeansFact.setIsFromParentFishingActivity(true); xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "RoleCode"); list.add(vesselTransportMeansFact); From 9a73beb1ec2e51779cf4f4c06e00c6a34d87f2ab Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Thu, 15 Oct 2020 17:48:48 +0300 Subject: [PATCH 33/61] Corrections --- .../changelog/v3.4/db-changelog-UNIONVMS-4793.xml | 12 ++++++------ .../rules/service/business/fact/FaCatchFact.java | 15 ++++++++++++++- .../service/mapper/fact/ActivityFactMapper.java | 11 +++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml index e79cf0d93..b8095b611 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml @@ -31,7 +31,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -125,7 +125,7 @@ - + @@ -148,7 +148,7 @@ - + @@ -171,7 +171,7 @@ - + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index 70f3682ef..03a5f9151 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -76,7 +76,12 @@ public boolean containsAtMostXTypesOfLocation(List locations,Strin int i =0; for(FLUXLocation location:locations){ - if(type.equals(location.getTypeCode().getValue())){ + + if(location.getID() == null){ + continue; + } + + if(type.equals(location.getID().getSchemeID())){ i ++; } @@ -98,6 +103,10 @@ public boolean hasDuplicateLocationType(List locations){ for(FLUXLocation location:locations){ + if(location.getTypeCode() == null){ + continue; + } + if(map.get(location.getTypeCode().getValue()) == null){ map.put(location.getTypeCode().getValue(),1); } else { @@ -117,6 +126,10 @@ public boolean fluxCharacteristicContainsType(List fluxChara for(FLUXCharacteristic fluxCharacteristic:fluxCharacteristics){ + if(fluxCharacteristic.getTypeCode() == null) { + continue; + } + if(value.equals(fluxCharacteristic.getTypeCode().getValue())){ return true; } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index c70fc00ff..c04494e66 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -544,6 +544,9 @@ public List generateFactForVesselTransportMeansForPare VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, fishActType, false); vesselTransportMeansFact.setIsFromParentFishingActivity(true); xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "RoleCode"); + xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).append(ID).storeInRepo(vesselTransportMeansFact, "relatedIds"); + xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).append(REGISTRATION_VESSEL_COUNTRY).append(ID).storeInRepo(vesselTransportMeansFact, "relatedVesselCountryId"); + xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "relatedVesselTransportMeans"); list.add(vesselTransportMeansFact); index++; } @@ -986,12 +989,12 @@ public List generateFactsForFaCatch(FishingActivity activity, bool if(CollectionUtils.isNotEmpty(faCatch.getSpecifiedFLUXLocations())){ faCatchFact.setFaCatchSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations()); - xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); + xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); List fluxCharacteristics = faCatch.getSpecifiedFLUXLocations().stream() .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics); - xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); + xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,index).append(APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); } faCatchFact.setUsedFishingGears(faCatch.getUsedFishingGears()); @@ -1005,12 +1008,12 @@ public List generateFactsForFaCatch(FishingActivity activity, bool if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)) { faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); + xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); List fluxCharacteristics = fishActRelatedFluxLocations.stream() .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); - xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION,APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); + xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,index).append(APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); } xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds"); From 375fd4b1b04b668ae962c99c3b43c2dbe38769c2 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:53:17 +0300 Subject: [PATCH 34/61] [Rules-Fixes] minor fix for 4798 updated xpath for ApplicableFLUXCharacteristic/TypeCode --- .../mapper/fact/ActivityFactMapper.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index c04494e66..db18a0fa8 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -990,11 +990,10 @@ public List generateFactsForFaCatch(FishingActivity activity, bool if(CollectionUtils.isNotEmpty(faCatch.getSpecifiedFLUXLocations())){ faCatchFact.setFaCatchSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations()); xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); - List fluxCharacteristics = faCatch.getSpecifiedFLUXLocations().stream() - .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) - .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); + List fluxCharacteristics = getFluxCharacteristics(faCatch.getSpecifiedFLUXLocations()); faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics); - xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,index).append(APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); + Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(faCatch.getSpecifiedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,typeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); } faCatchFact.setUsedFishingGears(faCatch.getUsedFishingGears()); @@ -1009,11 +1008,10 @@ public List generateFactsForFaCatch(FishingActivity activity, bool faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); - List fluxCharacteristics = fishActRelatedFluxLocations.stream() - .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) - .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); + List fluxCharacteristics = getFluxCharacteristics(fishActRelatedFluxLocations); faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); - xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,index).append(APPLICABLE_FLUX_CHARACTERISTIC, TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); + Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishActRelatedFluxLocations); + xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,typeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); } xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds"); @@ -1043,6 +1041,26 @@ public List generateFactsForFaCatch(FishingActivity activity, bool return facts; } + private List getFluxCharacteristics(List fishActRelatedFluxLocations){ + return fishActRelatedFluxLocations.stream() + .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) + .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); + } + + private Integer getIndexForFluxCharacteristicsWithTypeCode(List fishActRelatedFluxLocations){ + + Integer index = 1; + for(FLUXLocation location:fishActRelatedFluxLocations){ + if(location.getApplicableFLUXCharacteristics() != null && !location.getApplicableFLUXCharacteristics().isEmpty() && location.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null){ + + return index; + } + + index++; + } + return 1; + } + private void addFactsForAAPStock(List relatedAAPStocks, List facts) { if (CollectionUtils.isEmpty(relatedAAPStocks)) { xPathUtil.clear(); From 74ecb1c370359d94f7972e614a47784162446aca Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Fri, 16 Oct 2020 23:18:26 +0300 Subject: [PATCH 35/61] FIX 4793 --- .../v3.4/db-changelog-UNIONVMS-4793.xml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml index b8095b611..3f2dfb21a 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml @@ -65,9 +65,9 @@ + && !containsAtLeastOneCorrectIdOfTheRelated("CFR") + && (!hasValueForVesselTransports(relatedVesselTransportMeans,"EXT_MARKING") + || !hasValueForVesselTransports(relatedVesselTransportMeans,"IRCS"))"/> @@ -112,8 +112,8 @@ + && (!hasValueForVesselTransports(specifiedVesselTransportMeans,"EXT_MARKING") + || !hasValueForVesselTransports(specifiedVesselTransportMeans,"IRCS"))"/> @@ -135,8 +135,8 @@ + && !(hasValueForVesselTransports(relatedVesselTransportMeans,"EXT_MARKING") + && hasValueForVesselTransports(relatedVesselTransportMeans,"IRCS"))"/> @@ -157,9 +157,9 @@ + value="!isEmpty(ids) && !schemeIdContainsAll(ids, "IRCS", "EXT_MARKING") + && (transportMeans == null + || transportMeans.asset == null)"/> From c15de0fdb75373eea92060f0e86158a8f8bae031 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:56:33 +0300 Subject: [PATCH 36/61] [UNIONVMS-4798] fixed multiple errors for FA-L02-00-0656 to FA-L02-00-0660 --- .../uvms/rules/service/mapper/fact/ActivityFactMapper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index db18a0fa8..c0c922a82 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -989,7 +989,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool if(CollectionUtils.isNotEmpty(faCatch.getSpecifiedFLUXLocations())){ faCatchFact.setFaCatchSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations()); - xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); + xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); List fluxCharacteristics = getFluxCharacteristics(faCatch.getSpecifiedFLUXLocations()); faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics); Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(faCatch.getSpecifiedFLUXLocations()); @@ -1004,10 +1004,11 @@ public List generateFactsForFaCatch(FishingActivity activity, bool } xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "faCatchFluxLocationId"); - if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)) { + //there is only one matching activity to examine for a list of catches. We only have to run the validation rules once. + if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations) && index == 1) { faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,index).append(ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); + xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); List fluxCharacteristics = getFluxCharacteristics(fishActRelatedFluxLocations); faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishActRelatedFluxLocations); From bc6b25a34a7c93946d921a951cb62ff117f6bb82 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:59:42 +0300 Subject: [PATCH 37/61] [UNIONVMS-4798] hasDuplicateLocationType for 659-660-665-666 rules checked typeCode instead of schemaID --- .../uvms/rules/service/business/fact/FaCatchFact.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index 03a5f9151..d623c57a0 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -103,12 +103,12 @@ public boolean hasDuplicateLocationType(List locations){ for(FLUXLocation location:locations){ - if(location.getTypeCode() == null){ + if(location.getID() == null){ continue; } - if(map.get(location.getTypeCode().getValue()) == null){ - map.put(location.getTypeCode().getValue(),1); + if(map.get(location.getID().getSchemeID()) == null){ + map.put(location.getID().getSchemeID(),1); } else { return true; } From ab23b302da9608eb1beeeee1792b2d7e5b7a0847 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Sun, 18 Oct 2020 04:54:53 +0300 Subject: [PATCH 38/61] [UNIONVMS-4798] added fixes for 659/660/665/666 ApplicableFLUXCharacteristic --- .../v3.4/db-changelog-UNIONVMS-4798.xml | 12 ++--- .../service/business/fact/FaCatchFact.java | 45 ++++++++++++++++--- .../mapper/fact/ActivityFactMapper.java | 29 ++++++++++-- 3 files changed, 69 insertions(+), 17 deletions(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml index f9617d0db..b3e1184d3 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml @@ -85,7 +85,7 @@ + value="!isEmpty(fishingActivityRelatedFLUXLocations) && hasDuplicateLocationType(fishingActivityRelatedFLUXLocations) && !fluxLocationContainsApplicableFLUXCharacteristic(fishingActivityRelatedFLUXLocations)"/> @@ -98,7 +98,7 @@ - + @@ -107,7 +107,7 @@ + value="!isEmpty(fishingActivityRelatedFLUXLocations) && hasDuplicateLocationType(fishingActivityRelatedFLUXLocations) && !fluxCharacteristicContainsType(fishingActivityRelatedFLUXLocations,"MAIN_AREA")"/> @@ -199,7 +199,7 @@ + value="!isEmpty(faCatchSpecifiedFLUXLocations) && hasDuplicateLocationType(faCatchSpecifiedFLUXLocations) && !fluxLocationContainsApplicableFLUXCharacteristic(faCatchSpecifiedFLUXLocations)"/> @@ -213,7 +213,7 @@ - + @@ -222,7 +222,7 @@ + value="!isEmpty(faCatchSpecifiedFLUXLocations) && hasDuplicateLocationType(faCatchSpecifiedFLUXLocations) && !fluxCharacteristicContainsType(faCatchSpecifiedFLUXLocations,"MAIN_AREA")"/> diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index d623c57a0..d1819dbea 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; @@ -118,24 +119,54 @@ public boolean hasDuplicateLocationType(List locations){ return false; } - public boolean fluxCharacteristicContainsType(List fluxCharacteristics,String value){ + public boolean fluxCharacteristicContainsType(List locations,String type){ + Map map = new HashMap<>(); + + if(CollectionUtils.isEmpty(locations)){ + return true; + } - if(CollectionUtils.isEmpty(fluxCharacteristics)){ + if(!fluxLocationContainsApplicableFLUXCharacteristic(locations)){ return true; } - for(FLUXCharacteristic fluxCharacteristic:fluxCharacteristics){ + mapLocationsBySchemeID(locations, map); - if(fluxCharacteristic.getTypeCode() == null) { + // each location should have an ApplicableFLUXCharacteristic with specific type + // as long as its schemeID is used two or more times + return locations.stream().filter(t -> t.getID() != null) + .filter(t -> map.get(t.getID().getSchemeID()) > 1) + .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty() + && t.getApplicableFLUXCharacteristics().get(0)!= null && t.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null + && t.getApplicableFLUXCharacteristics().get(0).getTypeCode().getValue().equals(type)); + } + + private void mapLocationsBySchemeID(List locations, Map map) { + for(FLUXLocation location:locations){ + if(location.getID() == null){ continue; } - if(value.equals(fluxCharacteristic.getTypeCode().getValue())){ - return true; + if(map.get(location.getID().getSchemeID()) == null){ + map.put(location.getID().getSchemeID(),1); + } else { + map.put(location.getID().getSchemeID(),map.get(location.getID().getSchemeID()) + 1); } } + } - return false; + public boolean fluxLocationContainsApplicableFLUXCharacteristic(List locations){ + Map map = new HashMap<>(); + + if(CollectionUtils.isEmpty(locations)){ + return true; + } + + mapLocationsBySchemeID(locations, map); + //each location shouold have an ApplicableFLUXCharacteristic as long as its schemeID is used two or more times + return locations.stream().filter(t -> t.getID() != null) + .filter(t -> map.get(t.getID().getSchemeID()) > 1) + .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()); } public boolean containsAtLeastOneGfcmGsaWithValidValue(List ids){ diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index c0c922a82..e9f7e72ba 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -992,8 +992,10 @@ public List generateFactsForFaCatch(FishingActivity activity, bool xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations"); List fluxCharacteristics = getFluxCharacteristics(faCatch.getSpecifiedFLUXLocations()); faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics); - Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(faCatch.getSpecifiedFLUXLocations()); - xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,typeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); + Integer catchCharacteristicsIndex = getIndexForFluxCharacteristics(faCatch.getSpecifiedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,catchCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(faCatchFact, "faCatchFluxCharacteristic"); + Integer catchCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(faCatch.getSpecifiedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,catchCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristicTypeCode"); } faCatchFact.setUsedFishingGears(faCatch.getUsedFishingGears()); @@ -1011,8 +1013,10 @@ public List generateFactsForFaCatch(FishingActivity activity, bool xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); List fluxCharacteristics = getFluxCharacteristics(fishActRelatedFluxLocations); faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); - Integer typeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,typeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); + Integer actCharacteristicsIndex = getIndexForFluxCharacteristics(fishActRelatedFluxLocations); + xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); + Integer actCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishActRelatedFluxLocations); + xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristicTypeCode"); } xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds"); @@ -1048,6 +1052,23 @@ private List getFluxCharacteristics(List fishA .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList()); } + private Integer getIndexForFluxCharacteristics(List fishActRelatedFluxLocations){ + + Integer index = 1; + for(FLUXLocation location:fishActRelatedFluxLocations){ + if(location.getApplicableFLUXCharacteristics() != null && !location.getApplicableFLUXCharacteristics().isEmpty()){ + + index++; + } + + } + if(index >= fishActRelatedFluxLocations.size()){ + return 1; + } + + return index; + } + private Integer getIndexForFluxCharacteristicsWithTypeCode(List fishActRelatedFluxLocations){ Integer index = 1; From 8f8cc2ef876e875d4ab54cc45c98375c5d075f33 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Sun, 18 Oct 2020 23:59:59 +0300 Subject: [PATCH 39/61] [UNIONVMS-4798] Corrections for FA-L02-00-0660 and FA-L02-00-0666 --- .../v3.4/db-changelog-UNIONVMS-4798.xml | 4 +-- .../service/business/fact/FaCatchFact.java | 36 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml index b3e1184d3..3a4644845 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml @@ -107,7 +107,7 @@ + value="!isEmpty(fishingActivityRelatedFLUXLocations) && hasDuplicateLocationType(fishingActivityRelatedFLUXLocations) && fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(fishingActivityRelatedFLUXLocations,"MAIN_AREA")"/> @@ -222,7 +222,7 @@ + value="!isEmpty(faCatchSpecifiedFLUXLocations) && hasDuplicateLocationType(faCatchSpecifiedFLUXLocations) && fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(faCatchSpecifiedFLUXLocations,"MAIN_AREA")"/> diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index d1819dbea..9f2decfa0 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -17,6 +17,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Collectors; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; @@ -30,6 +33,7 @@ import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXCharacteristic; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXLocation; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingGear; +import un.unece.uncefact.data.standard.unqualifieddatatype._20.IDType; @Data @EqualsAndHashCode(callSuper = false) @@ -119,26 +123,20 @@ public boolean hasDuplicateLocationType(List locations){ return false; } - public boolean fluxCharacteristicContainsType(List locations,String type){ - Map map = new HashMap<>(); - - if(CollectionUtils.isEmpty(locations)){ - return true; - } - - if(!fluxLocationContainsApplicableFLUXCharacteristic(locations)){ - return true; - } - - mapLocationsBySchemeID(locations, map); + public boolean fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(List locations, String type) { + return locations.stream().collect(Collectors.groupingBy( + loc -> Optional.ofNullable(loc.getID()).map(IDType::getSchemeID).orElse(null) + )).values().stream() + .filter(locationsWithSameSchemeId -> locationsWithSameSchemeId.size() > 1) + .anyMatch(locationsWithSameSchemeId -> locationsWithSameSchemeId.stream().allMatch(noCharacteristicWithType(type))); + } - // each location should have an ApplicableFLUXCharacteristic with specific type - // as long as its schemeID is used two or more times - return locations.stream().filter(t -> t.getID() != null) - .filter(t -> map.get(t.getID().getSchemeID()) > 1) - .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty() - && t.getApplicableFLUXCharacteristics().get(0)!= null && t.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null - && t.getApplicableFLUXCharacteristics().get(0).getTypeCode().getValue().equals(type)); + private Predicate noCharacteristicWithType(String type) { + return loc -> loc.getApplicableFLUXCharacteristics() == null || loc.getApplicableFLUXCharacteristics().stream() + .map(FLUXCharacteristic::getTypeCode) + .filter(Objects::nonNull) + .map(typeCode -> typeCode.getValue()) + .noneMatch(type::equals); } private void mapLocationsBySchemeID(List locations, Map map) { From 16cdfc490fcb7226f844e2665b6d1033c7c67bef Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:23:29 +0300 Subject: [PATCH 40/61] [UNIONVMS-4798] added fix for template and checks for 660/666 --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4798-patch_V1.0.xml | 89 ++++++++++++++++ .../rules/service/business/AbstractFact.java | 100 ++++++++++++++++++ .../service/business/fact/FaCatchFact.java | 100 ------------------ .../business/fact/FishingActivityFact.java | 2 + .../mapper/fact/ActivityFactMapper.java | 24 +++-- 6 files changed, 206 insertions(+), 110 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index fe0346d32..8d4ef6829 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -74,5 +74,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml new file mode 100644 index 000000000..20fe20da6 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml @@ -0,0 +1,89 @@ + + + + + + + + br_id = 'FA-L02-00-0656' + + + + + br_id = 'FA-L02-00-0657' + + + + + + br_id = 'FA-L02-00-0658' + + + + + + br_id = 'FA-L02-00-0659' + + + + + br_id = 'FA-L02-00-0660' + + + + + + id = '660' + + + + + id = '666' + + + + + + + + + br_id = 'FA-L02-00-0656' + + + + + br_id = 'FA-L02-00-0657' + + + + + + br_id = 'FA-L02-00-0658' + + + + + + br_id = 'FA-L02-00-0659' + + + + + br_id = 'FA-L02-00-0660' + + + + + + id = '660' + + + + + id = '666' + + + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java index 94cb8963e..ff5d4ea1b 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java @@ -80,6 +80,106 @@ public AbstractFact() { setFactType(); } + public boolean containsAtMostXTypesOfLocation(List locations,String type,int times){ + + if(CollectionUtils.isEmpty(locations)){ + return true; + } + + int i =0; + + for(FLUXLocation location:locations){ + + if(location.getID() == null){ + continue; + } + + if(type.equals(location.getID().getSchemeID())){ + i ++; + } + + if (i > times){ + return false; + } + } + + return true; + } + + + public boolean hasDuplicateLocationType(List locations){ + Map map = new HashMap<>(); + + if(CollectionUtils.isEmpty(locations)){ + return false; + } + + for(FLUXLocation location:locations){ + + if(location.getID() == null){ + continue; + } + + if(map.get(location.getID().getSchemeID()) == null){ + map.put(location.getID().getSchemeID(),1); + } else { + return true; + } + + } + + return false; + } + + public boolean fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(List locations, String type,String locationType) { + Map map = new HashMap<>(); + + List locationsWhichMatchType = locations.stream().filter(r -> r.getTypeCode() != null && locationType.equals(r.getTypeCode().getValue())).collect(Collectors.toList()); + mapLocationsBySchemeID(locationsWhichMatchType, map); + + // each location should have an ApplicableFLUXCharacteristic with specific type + // as long as its schemeID is used two or more times + List filteredLocations = locationsWhichMatchType.stream().filter(t -> t.getID() != null) + .filter(t -> map.get(t.getID().getSchemeID()) > 1) + .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()) + .collect(Collectors.toList()); + + if(filteredLocations.isEmpty()){ + return false; + } else { + return !filteredLocations.stream().allMatch(t -> + t.getApplicableFLUXCharacteristics().get(0) != null && t.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null + && t.getApplicableFLUXCharacteristics().get(0).getTypeCode().getValue().equals(type)); + } + } + private void mapLocationsBySchemeID(List locations, Map map) { + for(FLUXLocation location:locations){ + if(location.getID() == null){ + continue; + } + + if(map.get(location.getID().getSchemeID()) == null){ + map.put(location.getID().getSchemeID(),1); + } else { + map.put(location.getID().getSchemeID(),map.get(location.getID().getSchemeID()) + 1); + } + } + } + + public boolean fluxLocationContainsApplicableFLUXCharacteristic(List locations){ + Map map = new HashMap<>(); + + if(CollectionUtils.isEmpty(locations)){ + return true; + } + + mapLocationsBySchemeID(locations, map); + //each location should have an ApplicableFLUXCharacteristic as long as its schemeID is used two or more times + return locations.stream().filter(t -> t.getID() != null) + .filter(t -> map.get(t.getID().getSchemeID()) > 1) + .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()); + } + public static int getNumOfInstances() { return counter; } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java index 9f2decfa0..baf99f7f0 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java @@ -17,9 +17,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Predicate; import java.util.stream.Collectors; import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; @@ -33,7 +30,6 @@ import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXCharacteristic; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXLocation; import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingGear; -import un.unece.uncefact.data.standard.unqualifieddatatype._20.IDType; @Data @EqualsAndHashCode(callSuper = false) @@ -60,112 +56,16 @@ public class FaCatchFact extends AbstractFact { private CodeType categoryCode; private List appliedAAPProcessConversionFactorNumber; private List specifiedFLUXLocations; - private List fishingActivityRelatedFLUXLocations; private List faCatchSpecifiedFLUXLocations; private List specifiedFluxLocationRFMOCodeList; private List appliedAAPProcess; private List destinationFLUXLocations; private List faCatchFluxLocationId; private List fishActRelatedFluxLocationIds; - private List fishingActivityFluxCharacteristic; private List faCatchFluxCharacteristic; private List usedFishingGears; private boolean isSubActivity = false; - public boolean containsAtMostXTypesOfLocation(List locations,String type,int times){ - - if(CollectionUtils.isEmpty(locations)){ - return true; - } - - int i =0; - - for(FLUXLocation location:locations){ - - if(location.getID() == null){ - continue; - } - - if(type.equals(location.getID().getSchemeID())){ - i ++; - } - - if (i > times){ - return false; - } - } - - return true; - } - - - public boolean hasDuplicateLocationType(List locations){ - Map map = new HashMap<>(); - - if(CollectionUtils.isEmpty(locations)){ - return false; - } - - for(FLUXLocation location:locations){ - - if(location.getID() == null){ - continue; - } - - if(map.get(location.getID().getSchemeID()) == null){ - map.put(location.getID().getSchemeID(),1); - } else { - return true; - } - - } - - return false; - } - - public boolean fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(List locations, String type) { - return locations.stream().collect(Collectors.groupingBy( - loc -> Optional.ofNullable(loc.getID()).map(IDType::getSchemeID).orElse(null) - )).values().stream() - .filter(locationsWithSameSchemeId -> locationsWithSameSchemeId.size() > 1) - .anyMatch(locationsWithSameSchemeId -> locationsWithSameSchemeId.stream().allMatch(noCharacteristicWithType(type))); - } - - private Predicate noCharacteristicWithType(String type) { - return loc -> loc.getApplicableFLUXCharacteristics() == null || loc.getApplicableFLUXCharacteristics().stream() - .map(FLUXCharacteristic::getTypeCode) - .filter(Objects::nonNull) - .map(typeCode -> typeCode.getValue()) - .noneMatch(type::equals); - } - - private void mapLocationsBySchemeID(List locations, Map map) { - for(FLUXLocation location:locations){ - if(location.getID() == null){ - continue; - } - - if(map.get(location.getID().getSchemeID()) == null){ - map.put(location.getID().getSchemeID(),1); - } else { - map.put(location.getID().getSchemeID(),map.get(location.getID().getSchemeID()) + 1); - } - } - } - - public boolean fluxLocationContainsApplicableFLUXCharacteristic(List locations){ - Map map = new HashMap<>(); - - if(CollectionUtils.isEmpty(locations)){ - return true; - } - - mapLocationsBySchemeID(locations, map); - //each location shouold have an ApplicableFLUXCharacteristic as long as its schemeID is used two or more times - return locations.stream().filter(t -> t.getID() != null) - .filter(t -> map.get(t.getID().getSchemeID()) > 1) - .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty()); - } public boolean containsAtLeastOneGfcmGsaWithValidValue(List ids){ if(CollectionUtils.isEmpty(ids)){ diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java index 0fe551d76..f613060f8 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java @@ -60,6 +60,8 @@ public class FishingActivityFact extends AbstractFact { private List relatedVesselTransportMeansRoleCodes; private List relFishActRelatedVesselTransportMeansRoleCodes; private List faRepDockSpecifiedVesselTransportMeansRoleCodes; + private List fishingActivityFluxCharacteristic; + private List fishingActivityRelatedFLUXLocations; private FishingActivity thisFishingActivity; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index e9f7e72ba..0cc7c620e 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -396,6 +396,19 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc fishingActivityFact.setSpecifiedFishingGears(fishingActivity.getSpecifiedFishingGears()); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FISHING_GEAR).storeInRepo(fishingActivityFact, "specifiedFishingGears"); + + //there is only one matching activity to examine for a list of catches. We only have to run the validation rules once. + if (CollectionUtils.isNotEmpty(fishingActivityFact.getRelatedFLUXLocations()) && !isSubActivity) { + fishingActivityFact.setFishingActivityRelatedFLUXLocations(fishingActivityFact.getRelatedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FLUX_LOCATION,ID).storeInRepo(fishingActivityFact, "fishingActivityRelatedFLUXLocations"); + List fluxCharacteristics = getFluxCharacteristics(fishingActivityFact.getRelatedFLUXLocations()); + fishingActivityFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); + Integer actCharacteristicsIndex = getIndexForFluxCharacteristics(fishingActivityFact.getRelatedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXpath).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(fishingActivityFact, "fishingActivityFluxCharacteristic"); + Integer actCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishingActivityFact.getRelatedFLUXLocations()); + xPathUtil.appendWithoutWrapping(partialXpath).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(fishingActivityFact, "fishingActivityFluxCharacteristicTypeCode"); + } + return fishingActivityFact; } @@ -1006,17 +1019,8 @@ public List generateFactsForFaCatch(FishingActivity activity, bool } xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "faCatchFluxLocationId"); - //there is only one matching activity to examine for a list of catches. We only have to run the validation rules once. - if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations) && index == 1) { + if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)) { faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations)); - faCatchFact.setFishingActivityRelatedFLUXLocations(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "fishingActivityRelatedFLUXLocations"); - List fluxCharacteristics = getFluxCharacteristics(fishActRelatedFluxLocations); - faCatchFact.setFishingActivityFluxCharacteristic(fluxCharacteristics); - Integer actCharacteristicsIndex = getIndexForFluxCharacteristics(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristic"); - Integer actCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishActRelatedFluxLocations); - xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "fishingActivityFluxCharacteristicTypeCode"); } xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds"); From 0a45138cd427ca5bda5b2b038695c2b1d93113f8 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Fri, 23 Oct 2020 20:51:37 +0300 Subject: [PATCH 41/61] [UNIONVMS-4795] fixes for given rules --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4795-patch_V1.0.xml | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 8d4ef6829..c53a7cd4b 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -75,5 +75,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml new file mode 100644 index 000000000..634e78c26 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml @@ -0,0 +1,36 @@ + + + + + + br_id = 'FA-L00-00-0621' + + + + + id = '620' + + + + + id = '621' + + + + + + br_id = 'FA-L00-00-0621' + + + + + id = '620' + + + + + id = '621' + + + + From 3f638788839f7fc44d0d250e9ac4e86f89d2636e Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Fri, 23 Oct 2020 22:34:39 +0300 Subject: [PATCH 42/61] [UNIONVMS-4798] fixes for rule 659 --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4798-patch_V1.1.xml | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index c53a7cd4b..c13c691d0 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -76,5 +76,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml new file mode 100644 index 000000000..fb02d68fd --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml @@ -0,0 +1,26 @@ + + + + + + br_id = 'FA-L02-00-0659' + + + + + id = '659' + + + + + + br_id = 'FA-L02-00-0659' + + + + + id = '659' + + + + From 3f3ae598dcea9a04533e470280c081be6b1d508b Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 26 Oct 2020 19:00:58 +0200 Subject: [PATCH 43/61] [UNIONVMS-4798] fixes for rule 660 --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4798-patch_V1.2.xml | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index c13c691d0..795af5283 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -77,5 +77,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml new file mode 100644 index 000000000..13d40a2f1 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml @@ -0,0 +1,26 @@ + + + + + + br_id = 'FA-L02-00-0660' + + + + + id = '660' + + + + + + br_id = 'FA-L02-00-0660' + + + + + id = '660' + + + + From fbd73a8070831db2f93dc6bbe1d35e74b65897f7 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Mon, 26 Oct 2020 21:43:08 +0200 Subject: [PATCH 44/61] [UNIONVMS-4793] fixed EXT_MARK and logic for rules --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4793-patch_V1.0.xml | 63 +++++++++++++++++++ .../fact/VesselTransportMeansFact.java | 25 ++++++++ .../mapper/fact/ActivityFactMapper.java | 1 - 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 795af5283..352a14511 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -78,5 +78,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml new file mode 100644 index 000000000..ecd1556b0 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml @@ -0,0 +1,63 @@ + + + + + + + id = '632' + + + + + id = '634' + + + + + id = '635' + + + + + id = '637' + + + + + + + id = '632' + + + + + id = '634' + + + + + id = '635' + + + + + id = '637' + + + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java index a1547e284..ab42a55b3 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java @@ -90,6 +90,31 @@ public boolean containsAtLeastOneCorrectIdOfTheRelated(String schemeId){ return containsValidSchemeId; } + + public boolean hasValueForVesselTransports(VesselTransportMeans relatedVesselTransportMeans,String value1,String value2){ + if(relatedVesselTransportMeans == null ){ + return true; + } + boolean containsValue1 = false,containsValue2 = false; + + for(IDType id :relatedVesselTransportMeans.getIDS()){ + if(id == null || id.getSchemeID() == null){ + continue; + } + + if(value1.equals(id.getSchemeID())){ + containsValue1 = true; + } + + if(value2.equals(id.getSchemeID())){ + containsValue2 = true; + } + + } + + return containsValue1 && containsValue2; + } + public boolean hasValueForVesselTransports(VesselTransportMeans relatedVesselTransportMeans,String value){ if(relatedVesselTransportMeans == null ){ return true; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 0cc7c620e..875075d73 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -397,7 +397,6 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc fishingActivityFact.setSpecifiedFishingGears(fishingActivity.getSpecifiedFishingGears()); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FISHING_GEAR).storeInRepo(fishingActivityFact, "specifiedFishingGears"); - //there is only one matching activity to examine for a list of catches. We only have to run the validation rules once. if (CollectionUtils.isNotEmpty(fishingActivityFact.getRelatedFLUXLocations()) && !isSubActivity) { fishingActivityFact.setFishingActivityRelatedFLUXLocations(fishingActivityFact.getRelatedFLUXLocations()); xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FLUX_LOCATION,ID).storeInRepo(fishingActivityFact, "fishingActivityRelatedFLUXLocations"); From 0184adaccd250f45140e106cb4adfdf7af7f5cfb Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:39:04 +0200 Subject: [PATCH 45/61] [UNIONVMS-4798] removed subactivity check --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4798-patch_V1.3.xml | 141 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 352a14511..0e32b8caf 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -79,5 +79,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml new file mode 100644 index 000000000..b2fd3b55d --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml @@ -0,0 +1,141 @@ + + + + + + + + + br_id = 'FA-L02-00-0656' + + + + + br_id = 'FA-L02-00-0657' + + + + + br_id = 'FA-L02-00-0658' + + + + + br_id = 'FA-L02-00-0662' + + + + + br_id = 'FA-L02-00-0663' + + + + + br_id = 'FA-L02-00-0664' + + + + + + + + + id = '656' + + + + + id = '657' + + + + + id = '658' + + + + + id = '662' + + + + + id = '663' + + + + + id = '664' + + + + + + + + + + + br_id = 'FA-L02-00-0656' + + + + + br_id = 'FA-L02-00-0657' + + + + + br_id = 'FA-L02-00-0658' + + + + + br_id = 'FA-L02-00-0662' + + + + + br_id = 'FA-L02-00-0663' + + + + + br_id = 'FA-L02-00-0664' + + + + + + + + id = '656' + + + + + id = '657' + + + + + id = '658' + + + + + id = '662' + + + + + id = '663' + + + + + id = '664' + + + + \ No newline at end of file From 882e7330b8c7da8c70dde8e856a559e9fd6af0ef Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Tue, 3 Nov 2020 17:18:53 +0200 Subject: [PATCH 46/61] [UNIONVMS-4802]- patching rules to add FISHING_OPERATION and DECLARATION checks --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4802-patch_V1.0.xml | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 0e32b8caf..9e2dff4db 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -80,5 +80,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml new file mode 100644 index 000000000..61aa1726d --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml @@ -0,0 +1,57 @@ + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + \ No newline at end of file From 20177006dc72b419c0dcdce0496a6c7cdd6e8c8a Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 4 Nov 2020 01:27:44 +0200 Subject: [PATCH 47/61] [UNIONVMS-4636] fixed AppliedAAPProcess for 171,219 --- LIQUIBASE/changelog/db-changelog-master.xml | 2 + .../v3.4/db-changelog-UNIONVMS-4636.xml | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 9e2dff4db..6ec174965 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -81,5 +81,7 @@ + + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml new file mode 100644 index 000000000..487847185 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml @@ -0,0 +1,43 @@ + + + + + + + id = '171' + + + + + id = '219' + + + + + + + + id = '171' + + + + + id = '219' + + + + + + \ No newline at end of file From 0e2c3a756426ab9bcee19d1e2621dfb7185bd658 Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Wed, 4 Nov 2020 13:56:04 +0200 Subject: [PATCH 48/61] [UNIONVMS-4799] adding NPE checks in typeCode and typeCode.value --- LIQUIBASE/changelog/db-changelog-master.xml | 2 +- .../db-changelog-UNIONVMS-4799-patch_V1.0.xml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 6ec174965..fb6f1b767 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -82,6 +82,6 @@ - + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml new file mode 100644 index 000000000..1b3d475d7 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml @@ -0,0 +1,16 @@ + + + + + + + id = '642' + + + + + id = '642' + + + + \ No newline at end of file From d0c0555197062b801882f37469ab7c459fc91862 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 5 Nov 2020 13:06:31 +0200 Subject: [PATCH 49/61] [UNIONVMS-4792] Reverted the deletion after request from DG Mare; Rule deletions are handled by the MDR end date --- LIQUIBASE/changelog/db-changelog-master.xml | 2 +- .../db-changelog-UNIONVMS-4792-revert.xml | 142 ++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index fb6f1b767..8daf35c50 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -83,5 +83,5 @@ + - diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml new file mode 100644 index 000000000..678559725 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + rule_id=:value + + + + + + br_id=:value + + + + + + + From cbd8392b2e5e71bd8daa1f6e39f38a8067df9532 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Fri, 6 Nov 2020 00:34:41 +0200 Subject: [PATCH 50/61] [UNIONVMS-4795] fix for 620 FAReportDocument/SpecifiedVesselTransportMeans --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../db-changelog-UNIONVMS-4795-patch_V1.1.xml | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 8daf35c50..9ce0dab4f 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -76,6 +76,7 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml new file mode 100644 index 000000000..4c761b48b --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml @@ -0,0 +1,17 @@ + + + + + + + id = '620' + + + + + + id = '620' + + + + From dd3d03e195d834b0157c3a8a7505b6d800a47f03 Mon Sep 17 00:00:00 2001 From: Ioannis Mitrolios Date: Fri, 6 Nov 2020 10:25:46 +0200 Subject: [PATCH 51/61] [UNIONVMS-4802] patching rules so that when 649 fires 548 and 549 do not fire --- LIQUIBASE/changelog/db-changelog-master.xml | 2 + .../db-changelog-UNIONVMS-4802-patch_V1.1.xml | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 9ce0dab4f..fbc4e40d0 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -85,4 +85,6 @@ + + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml new file mode 100644 index 000000000..13d10da2b --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml @@ -0,0 +1,40 @@ + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + \ No newline at end of file From 91877898a0286cac6f15aa4c5555f8740b467b13 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Tue, 10 Nov 2020 23:07:26 +0200 Subject: [PATCH 52/61] [UNIONVMS-4792] Correction of the undeleted rules (FA-L03-00-0061, FA-L03-00-0066, FA-L02-00-0339, FA-L02-00-0340) --- LIQUIBASE/changelog/db-changelog-master.xml | 2 +- .../db-changelog-UNIONVMS-4792-correction.xml | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index fbc4e40d0..8e4cf19af 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -86,5 +86,5 @@ + - diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml new file mode 100644 index 000000000..30b9b928b --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml @@ -0,0 +1,47 @@ + + + + + + + rule_id=61 + + + + + rule_id=66 + + + + + rule_id=339 + + + + rule_id=339 + + + + + rule_id=340 + + + + rule_id=340 + + + + + + + From 4384be04bc73b5e622591258be12590343f23265 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 18 Nov 2020 16:49:11 +0200 Subject: [PATCH 53/61] [UNIONVMS-incorrect-triggered-rules] fixed existing rules which triggered for invalid cases --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + ...log-UNIONVMS-incorrect-triggered-rules.xml | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 8e4cf19af..0e9b53ffa 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -87,4 +87,5 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml new file mode 100644 index 000000000..9dd2e8ca0 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml @@ -0,0 +1,111 @@ + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + + + id=:value + + + + + + + \ No newline at end of file From a2a1477f5f1d7ee374fbb6fd2d2d2f38cf0b6eb4 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 14 Oct 2020 15:30:27 +0300 Subject: [PATCH 54/61] [UNIONVMS-4477] fixed failing conditions --- LIQUIBASE/changelog/db-changelog-master.xml | 2 ++ .../v3.4/db-changelog-UNIONVMS-4477.xml | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index 0e9b53ffa..fbce5aac9 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -88,4 +88,6 @@ + + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml new file mode 100644 index 000000000..cae3338c1 --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml @@ -0,0 +1,22 @@ + + + + + + + rule_id = '395' + + + + + + + rule_id = '395' + + + + + + \ No newline at end of file From a9638fec9896c146ed9c55384d7275c0d2b49b58 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:52:44 +0200 Subject: [PATCH 55/61] [UNIONVMS-4685] rule FA-L01-00-0146 triggered for invalid MDR element --- LIQUIBASE/changelog/db-changelog-master.xml | 1 + .../v3.4/db-changelog-UNIONVMS-4685.xml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index fbce5aac9..c7536353b 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -89,5 +89,6 @@ + diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml new file mode 100644 index 000000000..e020a6c1d --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml @@ -0,0 +1,18 @@ + + + + + + + id = '146' + + + + + + id = '146' + + + + + \ No newline at end of file From 5c2d143241d8ce28c675cb89ab0f35780997b83e Mon Sep 17 00:00:00 2001 From: PROTOPAPAS Thanasis Date: Thu, 19 Nov 2020 12:14:35 +0200 Subject: [PATCH 56/61] [UNIONVMS-4501] no XPATH returned for FA-L02-00-0296 - --- .../uvms/rules/service/mapper/fact/ActivityFactMapper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java index 875075d73..7cf9128be 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java @@ -1872,7 +1872,10 @@ public FaNotificationOfArrivalFact generateFactsForPriorNotificationOfArrival(Fi } faNotificationOfArrivalFact.setSpecifiedFACatchTypeCodes(codeTypeList); xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FA_CATCH, TYPE_CODE).storeInRepo(faNotificationOfArrivalFact, "specifiedFACatchTypeCodes"); + } else { + xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(faNotificationOfArrivalFact, SPECIFIED_FA_CATCHES); } + faNotificationOfArrivalFact.setReasonCode(mapToCodeType(fishingActivity.getReasonCode())); xPathUtil.appendWithoutWrapping(partialXpath).append(REASON_CODE).storeInRepo(faNotificationOfArrivalFact, REASON_CODE_PROP); From e6bd2b4c1a438d7439230decd471441218d8dfe5 Mon Sep 17 00:00:00 2001 From: kwstaspgr Date: Mon, 23 Nov 2020 13:50:46 +0200 Subject: [PATCH 57/61] [UNIONVMS-4921] updated rules to send module version along with ping" --- service/pom.xml | 6 ++++++ .../uvms/rules/service/bean/PropertiesBean.java | 5 +++++ .../rules/service/bean/RulesConfigHelper.java | 15 +++++++++++++-- service/src/main/resources/app-version.properties | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 service/src/main/resources/app-version.properties diff --git a/service/pom.xml b/service/pom.xml index 9fa94f728..a3e344837 100755 --- a/service/pom.xml +++ b/service/pom.xml @@ -270,6 +270,12 @@ + + + true + src/main/resources + + diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java index 925af43b4..5f9781245 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java @@ -34,6 +34,11 @@ public void startup() { InputStream propsStream = PropertiesBean.class.getResourceAsStream("/logging.properties"); props = new Properties(); props.load(propsStream); + propsStream.close(); + + InputStream propsStream2 = PropertiesBean.class.getResourceAsStream("/app-version.properties"); + props.load(propsStream2); + propsStream2.close(); } catch (IOException e) { throw new EJBException("PropertiesBean initialization error", e); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java index 1e633180f..2d78f14e8 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java @@ -15,6 +15,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.config.ParameterKey; import javax.ejb.Stateless; +import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import java.util.ArrayList; @@ -23,6 +24,11 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The @Stateless public class RulesConfigHelper implements ConfigHelper { + public static final String MODULE_VERSION_PROPERTIES_KEY = "uvms.module.version"; + + @Inject + private PropertiesBean propertiesBean; + @PersistenceContext(unitName = "rules") protected EntityManager em; @@ -39,8 +45,13 @@ public List getAllParameterKeys() { public String getModuleName() { return "rules"; } - - @Override + + @Override + public String getModuleVersion() { + return propertiesBean.getProperty(MODULE_VERSION_PROPERTIES_KEY); + } + + @Override public EntityManager getEntityManager() { return em; } diff --git a/service/src/main/resources/app-version.properties b/service/src/main/resources/app-version.properties new file mode 100644 index 000000000..e90139f2f --- /dev/null +++ b/service/src/main/resources/app-version.properties @@ -0,0 +1 @@ +uvms.module.version=${uvms.rules.module.version} \ No newline at end of file From 3aaf882ab9e78dfbbcb48b77c49cad0e47a64353 Mon Sep 17 00:00:00 2001 From: kwstaspgr Date: Mon, 5 Oct 2020 16:20:01 +0300 Subject: [PATCH 58/61] [UNIONVMS-4843] remove-java-melody --- message/pom.xml | 5 --- pom.xml | 6 --- rest/pom.xml | 5 --- rest/src/main/webapp/WEB-INF/web.xml | 35 --------------- service/pom.xml | 5 --- .../src/main/resources/META-INF/ejb-jar.xml | 44 ------------------- 6 files changed, 100 deletions(-) diff --git a/message/pom.xml b/message/pom.xml index 315b3b849..6c745c5d1 100755 --- a/message/pom.xml +++ b/message/pom.xml @@ -13,11 +13,6 @@ - - fish.focus.uvms.maven - uvms-pom-monitoring-deps - pom - eu.europa.ec.fisheries.uvms.rules rules-model diff --git a/pom.xml b/pom.xml index 927bf9955..a0f6e7f26 100644 --- a/pom.xml +++ b/pom.xml @@ -110,12 +110,6 @@ hibernate-entitymanager ${hibernate.version} - - fish.focus.uvms.maven - uvms-pom-monitoring-deps - 1.21 - pom - fish.focus.uvms.maven uvms-pom-test-deps diff --git a/rest/pom.xml b/rest/pom.xml index 9df014394..edd039a8d 100755 --- a/rest/pom.xml +++ b/rest/pom.xml @@ -55,11 +55,6 @@ - - fish.focus.uvms.maven - uvms-pom-monitoring-deps - pom - eu.europa.ec.fisheries.uvms.commons uvms-commons-notification diff --git a/rest/src/main/webapp/WEB-INF/web.xml b/rest/src/main/webapp/WEB-INF/web.xml index 0c4f76442..581122cb5 100755 --- a/rest/src/main/webapp/WEB-INF/web.xml +++ b/rest/src/main/webapp/WEB-INF/web.xml @@ -7,41 +7,6 @@ Rules - - javamelody.datasources - java:/jdbc/uvms_rules - - - net.bull.javamelody.SessionListener - - - javamelody - net.bull.javamelody.MonitoringFilter - true - - displayed-counters - http,sql,ejb,error,log - - - system-actions-enabled - true - - - storage-directory - javamelody-rules - - - datasources - java:/jdbc/uvms_rules - - - - javamelody - /* - REQUEST - ASYNC - - AuthenticationFilter eu.europa.ec.fisheries.uvms.rest.security.AuthenticationFilter diff --git a/service/pom.xml b/service/pom.xml index a3e344837..aedf78de6 100755 --- a/service/pom.xml +++ b/service/pom.xml @@ -40,11 +40,6 @@ - - fish.focus.uvms.maven - uvms-pom-monitoring-deps - pom - eu.europa.ec.fisheries.uvms.rules rules-model diff --git a/service/src/main/resources/META-INF/ejb-jar.xml b/service/src/main/resources/META-INF/ejb-jar.xml index 63dc1cc82..6eb1a51b3 100644 --- a/service/src/main/resources/META-INF/ejb-jar.xml +++ b/service/src/main/resources/META-INF/ejb-jar.xml @@ -3,48 +3,4 @@ version = "3.1" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"> - - - net.bull.javamelody.MonitoringInterceptor - - - - - - MessageServiceBean - net.bull.javamelody.MonitoringInterceptor - - - RuleAssetsBean - net.bull.javamelody.MonitoringInterceptor - - - RulesFishingGearBean - net.bull.javamelody.MonitoringInterceptor - - - RulePostProcessBean - net.bull.javamelody.MonitoringInterceptor - - - RulesActivityServiceBean - net.bull.javamelody.MonitoringInterceptor - - - RulesEngineBean - net.bull.javamelody.MonitoringInterceptor - - - RulesPreProcessBean - net.bull.javamelody.MonitoringInterceptor - - - RulesServiceBean - net.bull.javamelody.MonitoringInterceptor - - - ValidationServiceBean - net.bull.javamelody.MonitoringInterceptor - - \ No newline at end of file From 6ffe6242ec0e6b6bd4b9c19b686de8a75ca087d4 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Thu, 25 Jun 2020 13:01:42 +0300 Subject: [PATCH 59/61] [UNIONVMS-4660] WIP: activating rules for movement messages --- .../service/bean/movement/MovementsRulesValidator.java | 2 +- .../bean/movement/RulesMovementProcessorBean.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java index ea19f6ec3..96faef16a 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java @@ -188,7 +188,7 @@ public void evaluate(List factList, boolean justToAvoidErasure) { @Lock(LockType.READ) public void evaluate(List facts) { KieSession ksession = getKieSession(); - ksession.setGlobal(LOGGER_STR, log); +// ksession.setGlobal(LOGGER_STR, log); for (RawMovementFact fact : facts) { ksession.insert(fact); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index ca5dd1abd..32e98b6e8 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -248,8 +248,9 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri return; } // Decomment this one and comment the other when validation is working! Still work needs to be done after this! - // processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid()); - enrichAndSenMovementsAsBatch(movementReportsList, userName, request.getLogGuid()); + EnrichedMovementWrapper enrichedWrapper = processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid()); +// enrichAndSenMovementsAsBatch(enrichedWrapper, movementReportsList, userName, request.getLogGuid()); +// enrichAndSenMovementsAsBatch(null, movementReportsList, userName, request.getLogGuid()); // Send some response to Movement, if it originated from there (manual movement) if (MovementSourceType.MANUAL.equals(movementReportsList.get(0).getSource())) {// A person has created a position ProcessedMovementAck response = MovementModuleResponseMapper.mapProcessedMovementAck(eu.europa.ec.fisheries.schema.movement.common.v1.AcknowledgeTypeType.OK, @@ -271,7 +272,7 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri * @param exchangeLogGuid * @throws RulesServiceException */ - private void enrichAndSenMovementsAsBatch(List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException { + private void enrichAndSenMovementsAsBatch(EnrichedMovementWrapper enrichedWrapper1, List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException { try { // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists. EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements); @@ -290,7 +291,7 @@ private void enrichAndSenMovementsAsBatch(List rawMovements, St } } - private void processReceivedMovementsAsBatch(List rawMovements, String pluginType, String username, String exchangeLogGuid) throws RulesServiceException { + private EnrichedMovementWrapper processReceivedMovementsAsBatch(List rawMovements, String pluginType, String username, String exchangeLogGuid) throws RulesServiceException { try { // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists. EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements); @@ -317,6 +318,7 @@ private void processReceivedMovementsAsBatch(List rawMovements, updateRequestMessageStatusInExchange(exchangeLogGuid, ExchangeLogStatusTypeType.FAILED); sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.ALARM, username); } + return enrichedWrapper; } catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException e) { throw new RulesServiceException(e.getMessage()); } From fcf562e37473f2f860b6c018433a5d1d59b27878 Mon Sep 17 00:00:00 2001 From: nomikosi <42890529+nomikosi@users.noreply.github.com> Date: Wed, 1 Jul 2020 16:15:42 +0300 Subject: [PATCH 60/61] [UNIONVMS-4660] added creationDate rules for movements --- LIQUIBASE/changelog/db-changelog-master.xml | 2 +- .../v3.4/db-changelog-UNIONVMS-4660.xml | 103 ++++++++++++++++++ .../src/main/resources/contract/Template.xsd | 2 + .../rules/service/bean/ContainerType.java | 5 +- .../rules/service/bean/RulesEngineBean.java | 37 ++++++- .../bean/RulesKieContainerInitializer.java | 18 +++ .../movement/MovementsRulesValidator.java | 7 +- .../movement/RulesMovementProcessorBean.java | 75 ++++++++++--- .../fact/MovementReportDocumentFact.java | 31 ++++++ .../generator/MovementFactGenerator.java | 72 ++++++++++++ .../business/helper/DrtPathHelper.java | 1 + .../service/config/BusinessObjectType.java | 3 +- .../service/constants/XPathConstants.java | 1 + .../MovementReportDocumentFactMapper.java | 102 +++++++++++++++++ .../templates/MovementReportDocument.drt | 34 ++++++ .../generator/MovementFactGeneratorTest.java | 29 +++++ .../MovementReportDocumentFactMapperTest.java | 50 +++++++++ 17 files changed, 549 insertions(+), 23 deletions(-) create mode 100644 LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java create mode 100644 service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapper.java create mode 100644 service/src/main/resources/templates/MovementReportDocument.drt create mode 100644 service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGeneratorTest.java create mode 100644 service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapperTest.java diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml index c7536353b..35897bb8f 100644 --- a/LIQUIBASE/changelog/db-changelog-master.xml +++ b/LIQUIBASE/changelog/db-changelog-master.xml @@ -90,5 +90,5 @@ + - diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml new file mode 100644 index 000000000..f1ec73fcc --- /dev/null +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + template_id = 36 + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id = 700 + + + br_id = 'MO-R01-00-0001' + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id = 701 + + + br_id = 'MO-R01-00-0002' + + + + + + + + + + + + + + + + + + + + + + + + + + rule_id = 702 + + + br_id = 'MO-R01-00-0003' + + + + diff --git a/model/src/main/resources/contract/Template.xsd b/model/src/main/resources/contract/Template.xsd index 61604e8d6..e99548f72 100755 --- a/model/src/main/resources/contract/Template.xsd +++ b/model/src/main/resources/contract/Template.xsd @@ -86,6 +86,8 @@ + + \ No newline at end of file diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java index 38b2da827..84fa3c640 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java @@ -45,7 +45,10 @@ public enum ContainerType { FactType.SALES_FISHING_TRIP, FactType.SALES_FLUX_LOCATION, FactType.SALES_FLUX_GEOGRAPHICAL_COORDINATE, FactType.SALES_STRUCTURED_ADDRESS, FactType.SALES_QUERY, FactType.SALES_FLUX_RESPONSE_DOCUMENT, FactType.SALES_VALIDATION_RESULT_DOCUMENT, FactType.SALES_VALIDATION_QUALITY_ANALYSIS,FactType.SALES_REPORT_WRAPPER, - FactType.SALES_AUCTION_SALE, FactType.SALES_FLUX_SALES_QUERY_MESSAGE, FactType.SALES_QUERY_PARAMETER, FactType.SALES_FLUX_SALES_RESPONSE_MESSAGE); + FactType.SALES_AUCTION_SALE, FactType.SALES_FLUX_SALES_QUERY_MESSAGE, FactType.SALES_QUERY_PARAMETER, FactType.SALES_FLUX_SALES_RESPONSE_MESSAGE), + + MOVEMENTS("movement","ec.europa.eu.movement", FactType.MOVEMENT_REPORT_DOCUMENT + ); private final String packageName; private final String containerName; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java index ea9d3ba8a..1470c24e4 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java @@ -17,7 +17,14 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType; import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType; -import eu.europa.ec.fisheries.uvms.rules.service.business.generator.*; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.AbstractGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityFaReportFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityQueryFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityResponseFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.MovementFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesQueryFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesReportFactGenerator; +import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesResponseFactGenerator; import eu.europa.ec.fisheries.uvms.rules.service.business.helper.RuleApplicabilityChecker; import eu.europa.ec.fisheries.uvms.rules.service.config.BusinessObjectType; import eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType; @@ -36,12 +43,19 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import javax.ejb.EJB; import javax.ejb.LocalBean; import javax.ejb.Stateless; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import static eu.europa.ec.fisheries.uvms.rules.service.business.MessageType.PULL; import static eu.europa.ec.fisheries.uvms.rules.service.business.MessageType.PUSH; -import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.*; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.RESPONSE_IDS; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.XML; @Stateless @Slf4j @@ -67,6 +81,7 @@ public class RulesEngineBean { private SalesResponseFactGenerator salesResponseFactGenerator; + private FaResponseFactMapper faResponseFactMapper; @EJB @@ -181,6 +196,22 @@ public Collection evaluate(BusinessObjectType businessObjectType, return validateFacts(facts, initializer.getContainerByType(ContainerType.SALES), globals, extraValues); } + else if (businessObjectType == BusinessObjectType.RECEIVING_MOVEMENT_MSG){ + StopWatch stopWatch = StopWatch.createStarted(); + AbstractGenerator generator = new MovementFactGenerator(PUSH); + generator.setBusinessObjectMessage(businessObject); + generator.setExtraValueMap(extraValues); + + List facts = generator.generateAllFacts(); + log.info("Flow Report, Generating the facts took: {} ms", stopWatch.getTime()); + stopWatch.reset(); + stopWatch.start(); + + Map globals = new HashMap<>(); + globals.put("mdrService", mdrCacheRuleService); + globals.put("appliChecker", appliChecker); + return validateFacts(facts, initializer.getContainerByType(ContainerType.MOVEMENTS), globals, extraValues); + } log.info(String.format("It took %s to evaluate the message.", stopwatch)); log.debug(String.format("%s fact instances holding in memory.", AbstractFact.getNumOfInstances())); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java index 5dae11646..eef73df83 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java @@ -60,6 +60,7 @@ public void init() { List faTemplatesAndRules = getFaMessageRules(allTemplates); List salesTemplatesAndRules = getSalesRules(allTemplates); List faQueryTemplatesAndRules = getFaQueryRules(allTemplates); + List movementTemplatesAndRules = getMovementRules(allTemplates); log.info("Initializing templates and rules for FA-Report facts. Nr. of Rules : {}", countRuleExpressions(faTemplatesAndRules)); KieContainer faReportContainer = createContainer(faTemplatesAndRules); @@ -73,11 +74,16 @@ public void init() { log.info("Initializing templates and rules for Sales facts. Nr. of Rules : {}", countRuleExpressions(salesTemplatesAndRules)); KieContainer salesContainer = createContainer(salesTemplatesAndRules); + log.info("Initializing templates and rules for Movement facts. Nr. of Rules : {}", countRuleExpressions(movementTemplatesAndRules)); + KieContainer movementContainer = createContainer(movementTemplatesAndRules); + + containers = new EnumMap<>(ContainerType.class); containers.put(ContainerType.FA_REPORT, faReportContainer); containers.put(ContainerType.FA_RESPONSE, faRespContainer); containers.put(ContainerType.FA_QUERY, faQueryContainer); containers.put(ContainerType.SALES, salesContainer); + containers.put(ContainerType.MOVEMENTS, movementContainer); // To make sure that we have deployed all the templates! if (!allTemplates.isEmpty()) { @@ -214,6 +220,18 @@ private List getFaQueryRules(List allTem return faQueryTemplates; } + private List getMovementRules(List allTemplates) { + List movementTemplates = new ArrayList<>(); + List factTypesList = ContainerType.MOVEMENTS.getFactTypesList(); + for (TemplateRuleMapDto actualTemplate : allTemplates) { + if (factTypesList.contains(actualTemplate.getTemplateType().getType())) { + movementTemplates.add(actualTemplate); + } + } + allTemplates.removeAll(movementTemplates); + return movementTemplates; + } + public KieContainer getContainerByType(ContainerType containerType) { return containers.get(containerType); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java index 96faef16a..9b1d45089 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java @@ -23,6 +23,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The import eu.europa.ec.fisheries.uvms.rules.service.business.CustomRuleDto; import eu.europa.ec.fisheries.uvms.rules.service.business.MovementFact; import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact; +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact; import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; import eu.europa.ec.fisheries.uvms.rules.service.mapper.CustomRuleParser; import org.drools.template.parser.DefaultTemplateContainer; @@ -172,7 +173,7 @@ public void evaluate(MovementFact fact) { } @Lock(LockType.READ) - public void evaluate(List factList, boolean justToAvoidErasure) { + public void evaluate(List factList) { log.info("Verifying user defined rules"); KieSession ksession = getKieSession(); // TODO : decomment as soon as the "Unexpected global [validationService]" is resolved @@ -186,9 +187,9 @@ public void evaluate(List factList, boolean justToAvoidErasure) { @Lock(LockType.READ) - public void evaluate(List facts) { + public void evaluateRawList(List facts) { KieSession ksession = getKieSession(); -// ksession.setGlobal(LOGGER_STR, log); + ksession.setGlobal(LOGGER_STR, log); for (RawMovementFact fact : facts) { ksession.insert(fact); } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index 32e98b6e8..be0601792 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -48,6 +48,7 @@ import eu.europa.ec.fisheries.schema.rules.movement.v1.MovementSourceType; import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType; import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType; +import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType; import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmListCriteria; import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery; import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmSearchKey; @@ -78,6 +79,7 @@ import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException; import eu.europa.ec.fisheries.uvms.movement.model.mapper.MovementModuleRequestMapper; import eu.europa.ec.fisheries.uvms.movement.model.mapper.MovementModuleResponseMapper; +import eu.europa.ec.fisheries.uvms.rules.dao.RulesDao; import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer; import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.*; import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditObjectTypeEnum; @@ -89,11 +91,18 @@ import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMapperException; import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException; import eu.europa.ec.fisheries.uvms.rules.model.mapper.JAXBMarshaller; +import eu.europa.ec.fisheries.uvms.rules.service.bean.RulePostProcessBean; +import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesConfigurationCache; +import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesEngineBean; +import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesExchangeServiceBean; import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MDRCache; +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; import eu.europa.ec.fisheries.uvms.rules.service.business.MovementFact; import eu.europa.ec.fisheries.uvms.rules.service.business.PreviousReportFact; import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact; import eu.europa.ec.fisheries.uvms.rules.service.business.RulesUtil; +import eu.europa.ec.fisheries.uvms.rules.service.business.ValidationResult; +import eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType; import eu.europa.ec.fisheries.uvms.rules.service.constants.MDRAcronymType; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent; import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent; @@ -101,6 +110,7 @@ import eu.europa.ec.fisheries.uvms.rules.service.event.TicketUpdateEvent; import eu.europa.ec.fisheries.uvms.rules.service.exception.InputArgumentException; import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException; import eu.europa.ec.fisheries.uvms.rules.service.mapper.*; import eu.europa.ec.fisheries.uvms.user.model.mapper.UserModuleRequestMapper; import eu.europa.ec.fisheries.wsdl.asset.group.AssetGroup; @@ -116,6 +126,7 @@ import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation; +import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.LocalBean; import javax.ejb.Stateless; @@ -130,6 +141,10 @@ import java.util.stream.Collectors; import static eu.europa.ec.fisheries.uvms.movement.model.exception.ErrorCode.MOVEMENT_DUPLICATE_ERROR; +import static eu.europa.ec.fisheries.uvms.rules.service.config.BusinessObjectType.RECEIVING_MOVEMENT_MSG; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER; +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.XML; @Stateless @@ -176,6 +191,20 @@ public class RulesMovementProcessorBean { @EJB private RulesAuditProducerBean auditProducer; + @EJB + private RulesEngineBean rulesEngine; + + @EJB + private RulePostProcessBean rulePostProcessBean; + + @EJB + private RulesExchangeServiceBean exchangeServiceBean; + + @EJB + private RulesConfigurationCache ruleModuleCache; + + private RulesFLUXMessageHelper fluxMessageHelper; + @Inject @TicketUpdateEvent private Event ticketUpdateEvent; @@ -232,6 +261,11 @@ public void sendMovementReport(SendFLUXMovementReportRequest request, String mes } } + @PostConstruct + public void init() { + fluxMessageHelper = new RulesFLUXMessageHelper(ruleModuleCache); + } + public void setMovementReportReceived(SetFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException { FLUXVesselPositionMessage fluxVesselPositionMessage; String pluginType = request.getType().name(); @@ -247,9 +281,23 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri sendBatchBackToExchange(request.getLogGuid(), movementReportsList, MovementRefTypeType.ALARM, userName); return; } + + Map extraValues = new EnumMap<>(ExtraValueType.class); + extraValues.put(SENDER_RECEIVER, request.getSenderOrReceiver()); + extraValues.put(XML, request.getRequest()); + extraValues.put(DATA_FLOW, request.getFluxDataFlow()); + Collection factsResults = rulesEngine.evaluate(RECEIVING_MOVEMENT_MSG,fluxVesselPositionMessage,extraValues,null); + + ValidationResult validationResult = rulePostProcessBean.checkAndUpdateValidationResult(factsResults, request.getRequest(), String.valueOf(fluxVesselPositionMessage.getFLUXReportDocument().getIDS()), RawMsgType.MOVEMENT); + + if(validationResult.isError()){ + exchangeServiceBean.updateExchangeMessage(request.getLogGuid(), fluxMessageHelper.calculateMessageValidationStatus(validationResult)); + return; + } // Decomment this one and comment the other when validation is working! Still work needs to be done after this! - EnrichedMovementWrapper enrichedWrapper = processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid()); -// enrichAndSenMovementsAsBatch(enrichedWrapper, movementReportsList, userName, request.getLogGuid()); +// MovementReportDocumentFact movementReportDocumentFact = MovementReportDocumentFactMapper.mapToMovementReportDocumentFact(fluxVesselPositionMessage); +// EnrichedMovementWrapper enrichedWrapper = processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid()); + enrichAndSendMovementsAsBatch(validationResult, movementReportsList, userName, request.getLogGuid()); // enrichAndSenMovementsAsBatch(null, movementReportsList, userName, request.getLogGuid()); // Send some response to Movement, if it originated from there (manual movement) if (MovementSourceType.MANUAL.equals(movementReportsList.get(0).getSource())) {// A person has created a position @@ -257,7 +305,7 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri messageGuid, "Movement successfully processed"); movOutQueueProducer.sendMessageWithSpecificIds(JAXBMarshaller.marshallJaxBObjectToString(response), movOutQueueProducer.getDestination(), null, messageGuid, messageGuid); } - } catch (JAXBException | RulesModelMarshallException | MessageException e) { + } catch (JAXBException | MessageException | RulesValidationException | RulesModelMarshallException e) { log.error("Error while processing received movement", e); } } @@ -272,15 +320,15 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri * @param exchangeLogGuid * @throws RulesServiceException */ - private void enrichAndSenMovementsAsBatch(EnrichedMovementWrapper enrichedWrapper1, List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException { + private void enrichAndSendMovementsAsBatch(ValidationResult validationResult,List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException { try { // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists. EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements); CreateMovementBatchResponse movementBatchResponse = sendBatchToMovement(enrichedWrapper.getAssetList(), rawMovements, username); ExchangeLogStatusTypeType status; if (movementBatchResponse != null && SimpleResponse.OK.equals(movementBatchResponse.getResponse())) { - // Here when ready needs to happen the validation with the list returned from movements! movementBatchResponse.getMovements(); - status = ExchangeLogStatusTypeType.SUCCESSFUL; + status = ExchangeLogStatusTypeType.fromValue(fluxMessageHelper.calculateMessageValidationStatus(validationResult).value()); + sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); } else { status = ExchangeLogStatusTypeType.FAILED; } @@ -291,18 +339,18 @@ private void enrichAndSenMovementsAsBatch(EnrichedMovementWrapper enrichedWrappe } } - private EnrichedMovementWrapper processReceivedMovementsAsBatch(List rawMovements, String pluginType, String username, String exchangeLogGuid) throws RulesServiceException { + private void processReceivedMovementsAsBatch(List rawMovements, String pluginType, String username, String exchangeLogGuid) throws RulesServiceException { try { // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists. EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements); List rawMovementFactList = RawMovementFactMapper.mapRawMovementFacts(rawMovements, enrichedWrapper.getMobileTerminalList(), enrichedWrapper.getAssetList(), pluginType); - movementValidator.evaluate(rawMovementFactList); + movementValidator.evaluateRawList(rawMovementFactList); if (allFactsAreOk(rawMovementFactList)) { // For now it is always OK // The collectMovementData actually is the method that sends the movements list to Movements module to be saved! List movementFactList = collectBatchMovementData(enrichedWrapper.getMobileTerminalList(), enrichedWrapper.getAssetList(), rawMovements, username); log.info(" Validating movement from Movement Module"); - movementValidator.evaluate(movementFactList, true); + movementValidator.evaluate(movementFactList); // Tell Exchange that a movement Batch was persisted in Movement ExchangeLogStatusTypeType status; if (CollectionUtils.isNotEmpty(movementFactList)) { @@ -318,7 +366,6 @@ private EnrichedMovementWrapper processReceivedMovementsAsBatch(List collectConnectIds(List mobileTerminals) } private boolean allFactsAreOk(List rawMovementFactList) { - boolean areAllOk = true; + for (RawMovementFact movementFact : rawMovementFactList) { if (movementFact == null || !movementFact.isOk()) { - areAllOk = false; - break; + return false; } } - return areAllOk; + + return true; } private List getMobileTerminalByRawMovementsBatch(List rawMovements) throws MessageException, MobileTerminalModelMapperException, MobileTerminalUnmarshallException, JMSException { diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java new file mode 100644 index 000000000..4c4d8fab9 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java @@ -0,0 +1,31 @@ +/* +Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it +and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of +the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + +*/ + +package eu.europa.ec.fisheries.uvms.rules.service.business.fact; + +import eu.europa.ec.fisheries.schema.rules.template.v1.FactType; +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import lombok.Data; + +import java.util.Date; + +@Data +public class MovementReportDocumentFact extends AbstractFact { + + private boolean ok = true; + private Date creationDateTime; + private String creationDateTimeString; + + @Override + public void setFactType() { + this.factType = FactType.MOVEMENT_REPORT_DOCUMENT; + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java new file mode 100644 index 000000000..80d22f9d6 --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java @@ -0,0 +1,72 @@ +/* +Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it +and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of +the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + +*/ + +package eu.europa.ec.fisheries.uvms.rules.service.business.generator; + +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException; +import eu.europa.ec.fisheries.uvms.rules.service.mapper.fact.MovementReportDocumentFactMapper; +import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType; + +import java.util.ArrayList; +import java.util.List; + +import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW; +import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.MOVEMENT_REPORT_DOCUMENT; + +public class MovementFactGenerator extends AbstractGenerator { + + private MovementReportDocumentFactMapper movementReportDocumentFactMapper; + private XPathStringWrapper xPathUtil; + private FLUXVesselPositionMessage vesselPositionMessage; + + public MovementFactGenerator(MessageType messageType) { + super(messageType); + xPathUtil = new XPathStringWrapper(); + movementReportDocumentFactMapper = new MovementReportDocumentFactMapper(xPathUtil); + } + + public MovementFactGenerator(MessageType messageType,XPathStringWrapper xPathUtil, MovementReportDocumentFactMapper movementReportDocumentFactMapper) { + super(messageType); + this.xPathUtil = xPathUtil; + this.movementReportDocumentFactMapper = movementReportDocumentFactMapper; + } + + public MovementFactGenerator() { + super(MessageType.PUSH); + } + + @Override + public List generateAllFacts() { + List facts = new ArrayList<>(); + FLUXReportDocumentType fluxReportDocument = vesselPositionMessage.getFLUXReportDocument(); + + if (fluxReportDocument != null) { + facts.add(movementReportDocumentFactMapper.generateFactForMovementReportDocument(vesselPositionMessage)); + } + + String df = (String) extraValueMap.get(DATA_FLOW); + facts.forEach(fact -> fact.setMessageDataFlow(df)); + return facts; + } + + @Override + public void setBusinessObjectMessage(Object businessObject) throws RulesValidationException { + + if (!(businessObject instanceof FLUXVesselPositionMessage)) { + throw new RulesValidationException("Business object does not match required type"); + } + this.vesselPositionMessage = (FLUXVesselPositionMessage) businessObject; + } +} diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java index 4c9697add..b8da4fea9 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java @@ -34,6 +34,7 @@ public enum DrtPathHelper { FISHING_ACTIVITY("/templates/FishingActivity.drt"), FA_QUERY("/templates/FaQuery.drt"), FA_QUERY_PARAMETER("/templates/FaQueryParameter.drt"), + MOVEMENT_REPORT_DOCUMENT("/templates/MovementReportDocument.drt"), FA_RELOCATION("/templates/FaRelocation.drt"), FA_RESPONSE("/templates/FaResponse.drt"), FA_TRANSHIPMENT("/templates/FaTranshipment.drt"), diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java index 3aba6f994..e87807e7f 100755 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java @@ -26,5 +26,6 @@ public enum BusinessObjectType { RECEIVING_FA_RESPONSE_MSG, FLUX_SALES_REPORT_MSG, FLUX_SALES_RESPONSE_MSG, - FLUX_SALES_QUERY_MSG + FLUX_SALES_QUERY_MSG, + RECEIVING_MOVEMENT_MSG } diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java index e614b8c36..c7f972fb1 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java @@ -21,6 +21,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The public class XPathConstants { public static final String FLUXFA_REPORT_MESSAGE = "FLUXFAReportMessage"; + public static final String MOVEMENT_REPORT_DOCUMENT = "FLUXVesselPositionMessage"; public static final String FLUXFA_QUERY_MESSAGE = "FLUXFAQueryMessage"; public static final String FA_REPORT_DOCUMENT = "FAReportDocument"; public static final String SPECIFIED_FISHING_ACTIVITY = "SpecifiedFishingActivity"; diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapper.java new file mode 100644 index 000000000..e42e8987b --- /dev/null +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapper.java @@ -0,0 +1,102 @@ +/* +Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016. + +This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it +and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of +the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see . + +*/ + +package eu.europa.ec.fisheries.uvms.rules.service.mapper.fact; + +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact; +import eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants; +import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper; +import lombok.extern.slf4j.Slf4j; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.unqualifieddatatype._18.DateTimeType; + +import java.util.Date; + +import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.CREATION_DATE_TIME; +import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FLUX_REPORT_DOCUMENT; +import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.MOVEMENT_REPORT_DOCUMENT; + +@Slf4j +public class MovementReportDocumentFactMapper { + + private XPathStringWrapper xPathUtil; + + public MovementReportDocumentFactMapper() { + xPathUtil = new XPathStringWrapper(); + } + public MovementReportDocumentFactMapper(XPathStringWrapper strUtil1) { + this.xPathUtil = strUtil1; + } + + public AbstractFact generateFactForMovementReportDocument(FLUXVesselPositionMessage vesselPositionMessage){ + + if(vesselPositionMessage == null){ + return null; + } + + MovementReportDocumentFact fact = new MovementReportDocumentFact(); + String partialXpath = xPathUtil.append(MOVEMENT_REPORT_DOCUMENT).getValue(); + + DateTimeType creationDateTime = vesselPositionMessage.getFLUXReportDocument().getCreationDateTime(); + fact.setCreationDateTimeString(dateTimeAsString(creationDateTime)); + fact.setCreationDateTime(getDate(creationDateTime)); + xPathUtil.appendWithoutWrapping(partialXpath).append(FLUX_REPORT_DOCUMENT, XPathConstants.CREATION_DATE_TIME).storeInRepo(fact, CREATION_DATE_TIME); + + return fact; + } + + public static MovementReportDocumentFact mapToMovementReportDocumentFact(FLUXVesselPositionMessage vesselPositionMessage){ + + if(vesselPositionMessage == null || vesselPositionMessage.getFLUXReportDocument() == null){ + throw new IllegalArgumentException("FLUXVesselPositionMessage and FLUXReportDocument cannot be null"); + } + + MovementReportDocumentFact fact = new MovementReportDocumentFact(); + DateTimeType creationDateTime = vesselPositionMessage.getFLUXReportDocument().getCreationDateTime(); + fact.setCreationDateTime(getDate(creationDateTime)); + fact.setCreationDateTimeString(dateTimeAsString(creationDateTime)); + return fact; + } + + private static String dateTimeAsString(DateTimeType dateTimeType) { + String dateAsString = null; + + if (dateTimeType != null) { + try { + if (dateTimeType.getDateTime() != null) { + dateAsString = dateTimeType.getDateTime().toString(); + } + } catch (Exception e) { + log.debug("Error while trying to parse dateTimeType", e); + } + } + return dateAsString; + } + + private static Date getDate(DateTimeType dateTimeType) { + Date date = null; + if (dateTimeType != null) { + try { + if (dateTimeType.getDateTime() != null) { + date = dateTimeType.getDateTime().toGregorianCalendar().getTime(); + } + } catch (Exception e) { + log.debug("Error while trying to parse dateTimeType", e); + } + } + + return date; + } + + + +} diff --git a/service/src/main/resources/templates/MovementReportDocument.drt b/service/src/main/resources/templates/MovementReportDocument.drt new file mode 100644 index 000000000..fe104b816 --- /dev/null +++ b/service/src/main/resources/templates/MovementReportDocument.drt @@ -0,0 +1,34 @@ +template header + +tname +expression +brid +rulemsg +type +level +propertyNames +context + +package eu.europa.ec.fisheries.uvms.rules.service.business.activity; + +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact; +import java.util.Arrays; +global eu.europa.ec.fisheries.uvms.rules.service.business.helper.RuleApplicabilityChecker appliChecker; +global eu.europa.ec.fisheries.uvms.rules.service.MDRCacheRuleService mdrService; + + +template "@{tname}" + +rule "Movement Report Document @{tname} - @{brid} - Context : @{context}" + +when + + $fact : MovementReportDocumentFact((appliChecker.isApplicable("@{brid}", "@{context}", getMessageDataFlow(), getCreationDateOfMessage(), mdrService)) && (@{expression})) + +then + $fact.setOk(false); + $fact.addWarningOrError(mdrService.getErrorTypeStrForForBrIAndDFAndValidity("@{brid}", "@{context}", $fact.getCreationJavaDateOfMessage()), mdrService.getErrorMessageForBrIAndDFAndValidity("@{brid}", "@{context}", $fact.getCreationJavaDateOfMessage()), "@{brid}", "@{level}", "@{propertyNames}"); + +end + +end template \ No newline at end of file diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGeneratorTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGeneratorTest.java new file mode 100644 index 000000000..e9848a9de --- /dev/null +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGeneratorTest.java @@ -0,0 +1,29 @@ +package eu.europa.ec.fisheries.uvms.rules.service.business.generator; + +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import eu.europa.ec.fisheries.uvms.rules.service.config.BusinessObjectType; +import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException; +import org.junit.Test; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType; + +import java.util.HashMap; +import java.util.List; + +import static eu.europa.ec.fisheries.uvms.rules.service.business.MessageType.PUSH; +import static org.junit.Assert.*; + +public class MovementFactGeneratorTest { + + @Test + public void testGenerateAllFacts() throws RulesValidationException { + + MovementFactGenerator generator = new MovementFactGenerator(PUSH); + FLUXVesselPositionMessage vesselPositionMessage = new FLUXVesselPositionMessage(); + vesselPositionMessage.setFLUXReportDocument(new FLUXReportDocumentType()); + generator.setBusinessObjectMessage(vesselPositionMessage); + generator.setExtraValueMap(new HashMap<>()); + List abstractFacts = generator.generateAllFacts(); + assertEquals(abstractFacts.isEmpty(),false); + } +} \ No newline at end of file diff --git a/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapperTest.java b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapperTest.java new file mode 100644 index 000000000..0208f9a8d --- /dev/null +++ b/service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapperTest.java @@ -0,0 +1,50 @@ +package eu.europa.ec.fisheries.uvms.rules.service.mapper.fact; + +import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact; +import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact; +import org.joda.time.DateTime; +import org.junit.Test; +import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType; +import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType; +import un.unece.uncefact.data.standard.unqualifieddatatype._18.DateTimeType; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; + +import java.util.Date; +import java.util.GregorianCalendar; + +import static org.junit.Assert.*; + +public class MovementReportDocumentFactMapperTest { + + @Test + public void testGenerateFactForMovementReportDocumentNULLDates() { + + MovementReportDocumentFactMapper factMapper = new MovementReportDocumentFactMapper(); + FLUXVesselPositionMessage vesselPositionMessage =new FLUXVesselPositionMessage(); + vesselPositionMessage.setVesselTransportMeans(new VesselTransportMeansType()); + vesselPositionMessage.setFLUXReportDocument(new FLUXReportDocumentType()); + AbstractFact movementReportDocumentFact = factMapper.generateFactForMovementReportDocument(vesselPositionMessage); + } + + @Test + public void testGenerateFactForMovementReportDocumentNormalDates() throws DatatypeConfigurationException { + + MovementReportDocumentFactMapper factMapper = new MovementReportDocumentFactMapper(); + FLUXVesselPositionMessage vesselPositionMessage =new FLUXVesselPositionMessage(); + vesselPositionMessage.setVesselTransportMeans(new VesselTransportMeansType()); + FLUXReportDocumentType reportDocumentType = new FLUXReportDocumentType(); + GregorianCalendar calendar = new GregorianCalendar(); + Date d = new Date(); + calendar.setTime(d); + DateTimeType dateTimeType = new DateTimeType(); + dateTimeType.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar)); + reportDocumentType.setCreationDateTime(dateTimeType); + vesselPositionMessage.setFLUXReportDocument(reportDocumentType); + MovementReportDocumentFact abstractFact = (MovementReportDocumentFact)factMapper.generateFactForMovementReportDocument(vesselPositionMessage); + Date creationDateOfMessage = abstractFact.getCreationDateTime(); + assertEquals(d,creationDateOfMessage); + } +} \ No newline at end of file From 3e244666a7ee01ec4ef67c77ba426003446b3474 Mon Sep 17 00:00:00 2001 From: Nikos Paraskevopoulos Date: Wed, 16 Sep 2020 22:27:36 +0300 Subject: [PATCH 61/61] PATCHES FOR MOVEMENT RULES --- .../v3.4/db-changelog-UNIONVMS-4660.xml | 34 +++++++++---------- .../movement/RulesMovementProcessorBean.java | 10 ++++-- .../helper/RuleApplicabilityChecker.java | 3 ++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml index f1ec73fcc..7a8724037 100644 --- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml +++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml @@ -2,40 +2,40 @@ - + - template_id = 36 + template_id = 2000 - + - + - - + + - rule_id = 700 + rule_id = 20001 br_id = 'MO-R01-00-0001' @@ -45,26 +45,26 @@ - + - + - - + + - rule_id = 701 + rule_id = 20002 br_id = 'MO-R01-00-0002' @@ -74,26 +74,26 @@ - + - + - - + + - rule_id = 702 + rule_id = 20003 br_id = 'MO-R01-00-0003' diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java index be0601792..7277d41b8 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java @@ -125,6 +125,7 @@ import org.apache.commons.lang3.StringUtils; import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage; import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation; +import un.unece.uncefact.data.standard.unqualifieddatatype._18.IDType; import javax.annotation.PostConstruct; import javax.ejb.EJB; @@ -288,7 +289,12 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri extraValues.put(DATA_FLOW, request.getFluxDataFlow()); Collection factsResults = rulesEngine.evaluate(RECEIVING_MOVEMENT_MSG,fluxVesselPositionMessage,extraValues,null); - ValidationResult validationResult = rulePostProcessBean.checkAndUpdateValidationResult(factsResults, request.getRequest(), String.valueOf(fluxVesselPositionMessage.getFLUXReportDocument().getIDS()), RawMsgType.MOVEMENT); + final String reportId = fluxVesselPositionMessage.getFLUXReportDocument().getIDS().stream() + .filter(id -> "UUID".equals(id.getSchemeID())) + .map(IDType::getValue) + .findFirst() + .get(); + ValidationResult validationResult = rulePostProcessBean.checkAndUpdateValidationResult(factsResults, request.getRequest(), reportId, RawMsgType.MOVEMENT); if(validationResult.isError()){ exchangeServiceBean.updateExchangeMessage(request.getLogGuid(), fluxMessageHelper.calculateMessageValidationStatus(validationResult)); @@ -331,8 +337,8 @@ private void enrichAndSendMovementsAsBatch(ValidationResult validationResult,Lis sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); } else { status = ExchangeLogStatusTypeType.FAILED; + sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); } - sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username); updateRequestMessageStatusInExchange(exchangeLogGuid, status); } catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException e) { throw new RulesServiceException(e.getMessage(), e); diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java index 000afefe1..35afec083 100644 --- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java +++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java @@ -76,6 +76,9 @@ && isDateInRange(messageCreationDate, faBrForBrIdAndContext.getStartDate(), faBr * @return */ public boolean isApplicable(String thisRulesBrId, String ruleContext, String messageDataFlow, DateTime messageCreationDate, MDRCacheRuleService mdrService) { + if (thisRulesBrId != null && thisRulesBrId.startsWith("MO-")) { + return true; + } String msgContext = mdrService.findContextForDf(messageDataFlow); if (StringUtils.isEmpty(msgContext)) { return false;