diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml
index 0c10a0faf..10cfa780b 100644
--- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml
@@ -359,52 +359,7 @@
-
-
-
-
-
-
-
-
-
-
- template_id = 2003
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- rule_id = 20101
-
-
- br_id = 'VP-L01-00-0101'
-
-
-
-
-
+
@@ -498,4 +453,436 @@
+
+
+
+
+
+
+
+
+
+
+ template_id = 3003
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20101
+
+
+ br_id = 'VP-L01-00-0101'
+
+
+
+
+
+
+
+
+
+
+
+
+
+ template_id = 3004
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30100
+
+
+ br_id = 'VP-L00-00-0100'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20102
+
+
+ br_id = 'VP-L01-00-0102'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20103
+
+
+ br_id = 'VP-L01-00-0103'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20104
+
+
+ br_id = 'VP-L02-00-0104'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20105
+
+
+ br_id = 'VP-L01-00-0105'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30130
+
+
+ br_id = 'VP-L00-00-0130'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30131
+
+
+ br_id = 'VP-L00-00-0131'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30110
+
+
+ br_id = 'VP-L03-00-0110'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30111
+
+
+ br_id = 'VP-L03-00-0111'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30112
+
+
+ br_id = 'VP-L03-00-0112'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30113
+
+
+ br_id = 'VP-L03-00-0113'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 30114
+
+
+ br_id = 'VP-L03-00-0114'
+
+
+
diff --git a/model/src/main/resources/contract/Template.xsd b/model/src/main/resources/contract/Template.xsd
index e07152f21..077376e46 100755
--- a/model/src/main/resources/contract/Template.xsd
+++ b/model/src/main/resources/contract/Template.xsd
@@ -90,6 +90,7 @@
+
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/MDRCacheRuleService.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/MDRCacheRuleService.java
index fcc9724c5..4e155d896 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/MDRCacheRuleService.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/MDRCacheRuleService.java
@@ -91,4 +91,6 @@ boolean combinationExistsInConversionFactorListAndIsGreaterOrEqualToOne(List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType, Map mapToMovementType) {
+ public static List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, MovementVesselMappingContext ctx, String registerClassName, String pluginType, Map mapToMovementType) {
VesselTransportMeansType positionReport = fluxVesselPositionMessage.getVesselTransportMeans();
List rowMovements = new ArrayList<>();
for (VesselPositionEventType col : positionReport.getSpecifiedVesselPositionEvents()) {
@@ -76,8 +77,25 @@ public static List mapToRawMovementTypes(FLUXVesselPositionMess
rawMovement.setPluginName(registerClassName);
rawMovement.setDateRecieved(DateUtils.getNowDateUTC());
rowMovements.add(rawMovement);
+ if(ctx != null) {
+ ctx.put(positionReport, rawMovement);
+ }
}
return rowMovements;
+ }
+
+ public static List mapToRawMovementTypesForEmptyMessage(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType, Map mapToMovementType) {
+ VesselTransportMeansType positionReport = fluxVesselPositionMessage.getVesselTransportMeans();
+ MovementBaseType baseMovement = mapResponseForEmptyMovement(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) {
+ assetId.getAssetIdList().addAll(MovementMapper.mapAssetIdList(baseMovement.getAssetId().getAssetIdList()));
+ }
+ rawMovement.setPluginType(PluginType.FLUX.name());
+ rawMovement.setPluginName(registerClassName);
+ rawMovement.setDateRecieved(DateUtils.getNowDateUTC());
+ return Collections.singletonList(rawMovement);
}
private static MovementBaseType mapResponse(VesselPositionEventType response, VesselTransportMeansType report, String pluginType, Map mapToMovementType) {
@@ -98,6 +116,18 @@ private static MovementBaseType mapResponse(VesselPositionEventType response, Ve
return movement;
}
+ private static MovementBaseType mapResponseForEmptyMovement(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));
+ setFlagState(movement, report.getRegistrationVesselCountry());
+ movement.setComChannelType(MovementComChannelType.FLUX);
+ movement.setSource(MovementSourceType.MANUAL.name().equals(pluginType)? MovementSourceType.MANUAL : MovementSourceType.OTHER);
+ return movement;
+ }
+
private static void setFlagState(MovementBaseType movement, VesselCountryType registrationVesselCountry) {
if (registrationVesselCountry != null && registrationVesselCountry.getID() != null) {
movement.setFlagState(registrationVesselCountry.getID().getValue());
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementVesselMappingContext.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementVesselMappingContext.java
new file mode 100644
index 000000000..14e7b130b
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementVesselMappingContext.java
@@ -0,0 +1,31 @@
+package eu.europa.ec.fisheries.uvms.rules.service.bean.movement;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType;
+import eu.europa.ec.fisheries.wsdl.asset.types.Asset;
+import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType;
+
+public class MovementVesselMappingContext {
+
+ private Map vesselTransportMeansToRawMovement = new HashMap<>();
+
+ private Map rawMovementToAsset = new HashMap<>();
+
+ public void put(VesselTransportMeansType vesselTransportMeansType, RawMovementType rawMovementType) {
+ vesselTransportMeansToRawMovement.put(vesselTransportMeansType, rawMovementType);
+ }
+
+ public void put(RawMovementType rawMovementType, Asset asset) {
+ rawMovementToAsset.put(rawMovementType, asset);
+ }
+
+ public RawMovementType getRawMovement(VesselTransportMeansType vesselTransportMeansType) {
+ return vesselTransportMeansToRawMovement.get(vesselTransportMeansType);
+ }
+
+ public Asset getAsset(RawMovementType rawMovementType) {
+ return rawMovementToAsset.get(rawMovementType);
+ }
+}
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 c343b9b5c..103a5c70c 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
@@ -16,6 +16,7 @@
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.MOVEMENT_VESSEL_MAP;
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;
@@ -270,21 +271,24 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
String pluginType = request.getType().name();
String userName = request.getUsername();
String registeredPluginClassName = request.getRegisteredClassName();
+ MovementVesselMappingContext ctx = new MovementVesselMappingContext();
try {
fluxVesselPositionMessage = JAXBUtils.unMarshallMessage(request.getRequest(), FLUXVesselPositionMessage.class, null);
- List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, registeredPluginClassName,pluginType,mapToMovementType);
+ List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, ctx, 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!");
updateRequestMessageStatusInExchange(request.getLogGuid(), ExchangeLogStatusTypeType.FAILED);
- sendBatchBackToExchange(request.getLogGuid(), movementReportsList, MovementRefTypeType.ALARM, userName);
- return;
+ movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypesForEmptyMessage(fluxVesselPositionMessage, registeredPluginClassName,pluginType,mapToMovementType);
}
+ // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists.
+ EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(movementReportsList, ctx);
+
Map extraValues = new EnumMap<>(ExtraValueType.class);
extraValues.put(SENDER_RECEIVER, request.getSenderOrReceiver());
extraValues.put(XML, request.getRequest());
extraValues.put(DATA_FLOW, request.getFluxDataFlow());
+ extraValues.put(MOVEMENT_VESSEL_MAP, ctx);
Collection factsResults = rulesEngine.evaluate(RECEIVING_MOVEMENT_MSG,fluxVesselPositionMessage,extraValues,null);
final String reportId = fluxVesselPositionMessage.getFLUXReportDocument().getIDS().stream()
@@ -300,14 +304,14 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
}
// 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(validationResult, movementReportsList, userName, request.getLogGuid(), request, request.getLogGuid());
+ enrichAndSenMovementsAsBatch(validationResult, movementReportsList, enrichedWrapper, userName, request.getLogGuid(), request, 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,
messageGuid, "Movement successfully processed");
movOutQueueProducer.sendMessageWithSpecificIds(JAXBMarshaller.marshallJaxBObjectToString(response), movOutQueueProducer.getDestination(), null, messageGuid, messageGuid);
}
- } catch (JAXBException | RulesModelMarshallException | MessageException | RulesValidationException e) {
+ } catch (JAXBException | RulesModelMarshallException | MessageException | RulesValidationException | JMSException | MobileTerminalUnmarshallException | AssetModelMapperException | MobileTerminalModelMapperException e) {
log.error("Error while processing received movement", e);
}
}
@@ -322,10 +326,8 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
* @param exchangeLogGuid
* @throws RulesServiceException
*/
- private void enrichAndSenMovementsAsBatch(ValidationResult validationResult, List rawMovements, String username, String exchangeLogGuid, SetFLUXMovementReportRequest request, String reportId) throws RulesServiceException {
+ private void enrichAndSenMovementsAsBatch(ValidationResult validationResult, List rawMovements, EnrichedMovementWrapper enrichedWrapper, String username, String exchangeLogGuid, SetFLUXMovementReportRequest request, String reportId) 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.getPermitted())) {
@@ -340,7 +342,7 @@ private void enrichAndSenMovementsAsBatch(ValidationResult validationResult, Lis
}
sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username);
updateRequestMessageStatusInExchange(exchangeLogGuid, status);
- } catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException | RulesModelException e) {
+ } catch (MessageException | RulesModelException e) {
throw new RulesServiceException(e.getMessage(), e);
}
}
@@ -348,7 +350,7 @@ private void enrichAndSenMovementsAsBatch(ValidationResult validationResult, Lis
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);
+ EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements, null);
List rawMovementFactList = RawMovementFactMapper.mapRawMovementFacts(rawMovements, enrichedWrapper.getMobileTerminalList(),
enrichedWrapper.getAssetList(), pluginType);
movementValidator.evaluateRawList(rawMovementFactList);
@@ -387,7 +389,7 @@ private void processReceivedMovementsAsBatch(List rawMovements,
* @throws JMSException
* @throws MobileTerminalModelMapperException
*/
- private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets(List rawMovementList) throws AssetModelMapperException, MessageException, MobileTerminalUnmarshallException, JMSException, MobileTerminalModelMapperException {
+ private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets(List rawMovementList, MovementVesselMappingContext ctx) throws AssetModelMapperException, MessageException, MobileTerminalUnmarshallException, JMSException, MobileTerminalModelMapperException {
List assetList = new ArrayList<>();
// Get Mobile Terminal if it exists
List mobileTerminalList;
@@ -403,6 +405,7 @@ private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets(List ids;
+ private DateTime creationDateTime;
+ private VesselCountryType registrationVesselCountry;
+ private List specifiedVesselPositionEvents;
+ private Asset asset;
+
+ public boolean hasAtLeastTimesXNonEmptyIds(List ids, int count) {
+ return ids.stream().filter(id -> id.getValue() != null && !id.getValue().isEmpty()).count() >= count;
+ }
+
+ public boolean hasAtLeastOneOfTheSchemeIds(List ids, String... schemeIds) {
+ List schemeIdsAsList = Arrays.asList(schemeIds);
+ return ids.stream().anyMatch(id -> schemeIdsAsList.contains(id.getSchemeID()));
+ }
+
+ public boolean hasBothSchemeIdsOrNone(List ids, String schemeId1, String schemeId2) {
+ return ids.stream().anyMatch(id -> schemeId1.equals(id.getSchemeID())) == ids.stream().anyMatch(id -> schemeId2.equals(id.getSchemeID()));
+ }
+
+ public boolean hasAtLeastTimesXSpecifiedVesselPositionEvents(List specifiedVesselPositionEvents, int count) {
+ return specifiedVesselPositionEvents.size() >= count;
+ }
+
+ public boolean hasSchemeId(List ids, String schemeID){
+ return ids.stream().anyMatch(id -> schemeID.equals(id.getSchemeID()));
+ }
+
+ public boolean hasExistingAsset(Asset asset) {
+ return asset != null && asset.getAssetId() != null && AssetIdType.GUID.equals(asset.getAssetId().getType());
+ }
+ @Override
+ public void setFactType() {
+ this.factType = FactType.MOVEMENT_VESSEL_TRANSPORT_MEANS;
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementVesselTransportMeansIdFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementVesselTransportMeansIdFact.java
index d3dbd1c23..40a5bf245 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementVesselTransportMeansIdFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementVesselTransportMeansIdFact.java
@@ -12,6 +12,17 @@ public class MovementVesselTransportMeansIdFact extends AbstractFact {
private IDType id;
private DateTime creationDateTime;
+ public boolean hasValidUvi(IDType id) {
+ int[] multipliers = {7,6,5,4,3,2};
+ String value = id.getValue();
+ int sum = 0;
+ for(int i = 0; i < 6; i++) {
+ sum += Integer.parseInt(value.substring(i, i + 1)) * multipliers[i];
+ }
+ return String.valueOf(value.charAt(6)).equals(String.valueOf(sum % 10));
+ }
+
+
@Override
public void setFactType() {
this.factType = FactType.MOVEMENT_VESSEL_TRANSPORT_MEANS_ID;
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
index 29e8c48ab..db41d7ab2 100644
--- 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
@@ -11,6 +11,13 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
package eu.europa.ec.fisheries.uvms.rules.service.business.generator;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.MOVEMENT_VESSEL_MAP;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.MovementVesselMappingContext;
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;
@@ -18,14 +25,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
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 un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType;
-import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.VesselTransportMeans;
-
-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 {
@@ -51,6 +50,7 @@ public MovementFactGenerator() {
@Override
public List generateAllFacts() {
+ movementReportDocumentFactMapper.setMovementVesselMappingContext((MovementVesselMappingContext) extraValueMap.get(MOVEMENT_VESSEL_MAP));
List facts = new ArrayList<>();
FLUXReportDocumentType fluxReportDocument = vesselPositionMessage.getFLUXReportDocument();
@@ -59,6 +59,7 @@ public List generateAllFacts() {
facts.addAll(movementReportDocumentFactMapper.generateFactForMovementReportDocumentId(vesselPositionMessage));
facts.addAll(movementReportDocumentFactMapper.generateFactForMovementReportDocOwnerFluxPartyId(vesselPositionMessage));
facts.addAll(movementReportDocumentFactMapper.generateFactForMovementVesselTransportMeansId(vesselPositionMessage));
+ facts.add(movementReportDocumentFactMapper.generateFactForMovementVesselTransportMeans(vesselPositionMessage));
}
String df = (String) extraValueMap.get(DATA_FLOW);
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 fbb8663d2..7eaf99183 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
@@ -37,6 +37,7 @@ public enum DrtPathHelper {
MOVEMENT_REPORT_DOCUMENT("/templates/MovementReportDocument.drt"),
MOVEMENT_REPORT_DOCUMENT_ID("/templates/MovementReportDocumentId.drt"),
MOVEMENT_REPORT_DOC_OWNER_FLUX_PARTY_ID("/templates/MovementReportDocOwnerFluxPartyId.drt"),
+ MOVEMENT_VESSEL_TRANSPORT_MEANS("/templates/MovementVesselTransportMeans.drt"),
MOVEMENT_VESSEL_TRANSPORT_MEANS_ID("/templates/MovementVesselTransportMeansId.drt"),
FA_RELOCATION("/templates/FaRelocation.drt"),
FA_RESPONSE("/templates/FaResponse.drt"),
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/ExtraValueType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/ExtraValueType.java
index 036a95740..677f348ab 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/ExtraValueType.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/ExtraValueType.java
@@ -22,5 +22,6 @@ public enum ExtraValueType {
CREATION_DATE_OF_MESSAGE,
RESPONSE_IDS,
XML,
- DATA_FLOW
+ DATA_FLOW,
+ MOVEMENT_VESSEL_MAP
}
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 a65bb751b..e8dd021c1 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
@@ -32,6 +32,7 @@ public class XPathConstants {
public static final String OWNER_FLUX_PARTY = "OwnerFLUXParty";
public static final String PURPOSE_CODE = "PurposeCode";
public static final String REGISTRATION_VESSEL_COUNTRY = "RegistrationVesselCountry";
+ public static final String REGISTRATION_VESSEL_COUNTRY_ID = "RegistrationVesselCountryId";
public static final String SPECIFIED_CONTACT_PARTY = "SpecifiedContactParty";
public static final String SPECIFIED_CONTACT_PERSON = "SpecifiedContactPerson";
public static final String ROLE_CODE = "RoleCode";
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
index e9cf509d7..3b0c1eb1a 100644
--- 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
@@ -17,6 +17,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.OWNER_FLUX_PARTY;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.PURPOSE_CODE;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.REGISTRATION_VESSEL_COUNTRY;
+import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.REGISTRATION_VESSEL_COUNTRY_ID;
+import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.SPECIFIED_VESSELPOSITION_EVENT;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.VESSEL_TRANSPORT_MEANS;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.VESSEL_TRANSPORT_MEANS_ID;
@@ -25,9 +27,12 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import java.util.List;
import java.util.Optional;
+import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.MovementVesselMappingContext;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocOwnerFluxPartyIdFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentIdFact;
+import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementVesselTransportMeansFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementVesselTransportMeansIdFact;
import eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants;
import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper;
@@ -43,6 +48,7 @@ public class MovementReportDocumentFactMapper {
private XPathStringWrapper xPathUtil;
public static final String ID = "id";
+ private MovementVesselMappingContext movementVesselMappingContext;
public MovementReportDocumentFactMapper() {
@@ -51,6 +57,10 @@ public MovementReportDocumentFactMapper() {
public MovementReportDocumentFactMapper(XPathStringWrapper strUtil1) {
this.xPathUtil = strUtil1;
}
+
+ public void setMovementVesselMappingContext(MovementVesselMappingContext movementVesselMappingContext) {
+ this.movementVesselMappingContext = movementVesselMappingContext;
+ }
public MovementReportDocumentFact generateFactForMovementReportDocument(FLUXVesselPositionMessage vesselPositionMessage){
@@ -133,15 +143,15 @@ public List generateFactForMovementReport
}
return factList;
}
-
+
public List generateFactForMovementVesselTransportMeansId(FLUXVesselPositionMessage vesselPositionMessage) {
List factList = new ArrayList<>();
-
+
if(vesselPositionMessage == null || vesselPositionMessage.getVesselTransportMeans() == null || vesselPositionMessage.getVesselTransportMeans().getIDS().isEmpty()){
xPathUtil.clear();
return null;
}
-
+
String partialXpath = xPathUtil.append(MOVEMENT_REPORT_DOCUMENT).append(VESSEL_TRANSPORT_MEANS).getValue();
List ids = vesselPositionMessage.getVesselTransportMeans().getIDS();
Date creationDate = getDate(vesselPositionMessage.getFLUXReportDocument().getCreationDateTime());
@@ -156,6 +166,30 @@ public List generateFactForMovementVesselTra
}
return factList;
}
+
+ public MovementVesselTransportMeansFact generateFactForMovementVesselTransportMeans(FLUXVesselPositionMessage vesselPositionMessage) {
+ if(vesselPositionMessage == null || vesselPositionMessage.getVesselTransportMeans() == null || vesselPositionMessage.getVesselTransportMeans().getIDS() == null){
+ xPathUtil.clear();
+ return null;
+ }
+ MovementVesselTransportMeansFact fact = new MovementVesselTransportMeansFact();
+ Date creationDate = getDate(vesselPositionMessage.getFLUXReportDocument().getCreationDateTime());
+ fact.setCreationDateTime(new DateTime(creationDate));
+ String partialXpath = xPathUtil.append(MOVEMENT_REPORT_DOCUMENT).append(VESSEL_TRANSPORT_MEANS).getValue();
+ fact.setIds(vesselPositionMessage.getVesselTransportMeans().getIDS());
+ xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(fact, VESSEL_TRANSPORT_MEANS);
+ fact.setRegistrationVesselCountry(vesselPositionMessage.getVesselTransportMeans().getRegistrationVesselCountry());
+ xPathUtil.appendWithoutWrapping(partialXpath).append(REGISTRATION_VESSEL_COUNTRY).storeInRepo(fact, REGISTRATION_VESSEL_COUNTRY);
+ fact.setSpecifiedVesselPositionEvents(vesselPositionMessage.getVesselTransportMeans().getSpecifiedVesselPositionEvents());
+ xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_VESSELPOSITION_EVENT).storeInRepo(fact, SPECIFIED_VESSELPOSITION_EVENT);
+
+ RawMovementType rawMovement = movementVesselMappingContext.getRawMovement(vesselPositionMessage.getVesselTransportMeans());
+ if(rawMovement != null) {
+ fact.setAsset(movementVesselMappingContext.getAsset(rawMovement));
+ }
+ xPathUtil.appendWithoutWrapping(partialXpath).append(REGISTRATION_VESSEL_COUNTRY, ID).storeInRepo(fact, REGISTRATION_VESSEL_COUNTRY_ID);
+ return fact;
+ }
public static MovementReportDocumentFact mapToMovementReportDocumentFact(FLUXVesselPositionMessage vesselPositionMessage){
diff --git a/service/src/main/resources/templates/MovementVesselTransportMeans.drt b/service/src/main/resources/templates/MovementVesselTransportMeans.drt
new file mode 100644
index 000000000..e78063fce
--- /dev/null
+++ b/service/src/main/resources/templates/MovementVesselTransportMeans.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.MovementVesselTransportMeansFact;
+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 Vessel Transport Means @{tname} - @{brid} - Context : @{context}"
+
+when
+
+ $fact : MovementVesselTransportMeansFact((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