Skip to content

Commit 25fc987

Browse files
committed
[UNIONVMS-MOVEMENT-RULES] added rule 007
1 parent 2df507c commit 25fc987

8 files changed

Lines changed: 77 additions & 12 deletions

File tree

LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@
8585
<insert tableName="rule">
8686
<column name="template_id" value="2001" />
8787
<column name="property_names" value="id" />
88-
<column name="note" value="A threshold to compensate for incorrect clock synchronization of the exchanging systems must be taken into account." />
88+
<column name="note" value="Check Format of the value. Must be according to the specified schemeID." />
8989
<column name="level" value="L01" />
90-
<column name="error_type" value="WARNING" />
90+
<column name="error_type" value="ERROR" />
9191
<column name="disabled" value="false" />
9292
<column name="br_id" value="VP-L01-00-0003" />
9393
<column name="rule_id" value="20003"/>
9494
</insert >
9595
<insert tableName="context_expression">
9696
<column name="expression" value="id != null &amp;&amp; !uuidValidateRegex(id)"/>
97-
<column name="failure_message" value="Message creation date/time not in the past."/>
97+
<column name="failure_message" value="Check Format of the value. Must be according to the specified schemeID."/>
9898
<column name="context" value="EU"/>
9999
<column name="rule_id" value="20003"/>
100100
<column name="id" value="20003"/>
@@ -109,4 +109,34 @@
109109
</delete>
110110
</rollback>
111111
</changeSet>
112+
113+
114+
<changeSet id="UNIONVMS-4660-update-VP-L03-00-0007" author="nomikosi">
115+
<insert tableName="rule">
116+
<column name="template_id" value="2000" />
117+
<column name="property_names" value="CreationDateTime" />
118+
<column name="note" value="A threshold to compensate for incorrect clock synchronization of the exchanging systems must be taken into account." />
119+
<column name="level" value="L03" />
120+
<column name="error_type" value="WARNING" />
121+
<column name="disabled" value="false" />
122+
<column name="br_id" value="VP-L03-00-0007" />
123+
<column name="rule_id" value="20007"/>
124+
</insert >
125+
<insert tableName="context_expression">
126+
<column name="expression" value="creationDateTime != null &amp;&amp; !isDateInThePast(creationDateTime)"/>
127+
<column name="failure_message" value="Message creation date/time not in the past."/>
128+
<column name="context" value="EU"/>
129+
<column name="rule_id" value="20007"/>
130+
<column name="id" value="20007"/>
131+
</insert >
132+
133+
<rollback>
134+
<delete tableName="context_expression">
135+
<where>rule_id = 20007</where>
136+
</delete>
137+
<delete tableName="rule">
138+
<where>br_id = 'VP-L01-00-0007'</where>
139+
</delete>
140+
</rollback>
141+
</changeSet>
112142
</databaseChangeLog>

model/src/main/resources/contract/Template.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
<!-- Movements -->
9090
<xsd:enumeration value="MOVEMENT_REPORT_DOCUMENT"/>
9191
<xsd:enumeration value="MOVEMENT_REPORT_DOCUMENT_ID"/>
92-
9392
</xsd:restriction>
9493
</xsd:simpleType>
9594
</xsd:schema>

service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public enum ContainerType {
4747
FactType.SALES_VALIDATION_RESULT_DOCUMENT, FactType.SALES_VALIDATION_QUALITY_ANALYSIS,FactType.SALES_REPORT_WRAPPER,
4848
FactType.SALES_AUCTION_SALE, FactType.SALES_FLUX_SALES_QUERY_MESSAGE, FactType.SALES_QUERY_PARAMETER, FactType.SALES_FLUX_SALES_RESPONSE_MESSAGE),
4949

50-
MOVEMENTS("movement","ec.europa.eu.movement", FactType.MOVEMENT_REPORT_DOCUMENT, FactType.MOVEMENT_REPORT_DOCUMENT_ID
51-
52-
);
50+
MOVEMENTS("movement","ec.europa.eu.movement", FactType.MOVEMENT_REPORT_DOCUMENT, FactType.MOVEMENT_REPORT_DOCUMENT_ID);
5351

5452
private final String packageName;
5553
private final String containerName;

service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,15 +878,19 @@ public List<String> call() {
878878
}
879879

880880
// Todo ; When possible remove loop!
881-
private List<MovementFact> collectBatchMovementData(List<MobileTerminalType> mobileTerminal, List<Asset> asset, List<RawMovementType> rawMovement, String username) {
881+
private List<MovementFact> collectBatchMovementData(List<MobileTerminalType> mobileTerminal, List<Asset> asset, List<RawMovementType> rawMovement, String username) throws MessageException {
882882
List<MovementFact> movFactList = new ArrayList<>();
883883
int index = 0;
884884
for (RawMovementType rawMovementType : rawMovement) {
885885
try {
886886
movFactList.add(collectMovementData(mobileTerminal.get(index), asset.get(index), rawMovementType, username));
887-
} catch (ExecutionException | InterruptedException | RulesServiceException e) {
888-
movFactList.add(null);
887+
}
888+
catch (InterruptedException e) {
889889
Thread.currentThread().interrupt();
890+
throw new MessageException("Thread interrupted...",e);
891+
}
892+
catch (ExecutionException | RulesServiceException e) {
893+
movFactList.add(null);
890894
}
891895
}
892896
return movFactList;

service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
1616
import lombok.Data;
1717
import un.unece.uncefact.data.standard.unqualifieddatatype._18.IDType;
1818

19+
import java.util.Calendar;
1920
import java.util.Date;
2021
import java.util.List;
2122

@@ -41,6 +42,16 @@ public boolean containsTypesOfIdXTimes(List<IDType> ids,String schemaType,int co
4142
return counter == count;
4243
}
4344

45+
public boolean isDateInThePast(Date creationDateTime){
46+
47+
Calendar serverDate = Calendar.getInstance();
48+
long t= serverDate.getTimeInMillis();
49+
Date startDate = new Date(t - 10 * 60000);
50+
new Date();
51+
52+
return creationDateTime.after(startDate) && creationDateTime.before(serverDate.getTime());
53+
}
54+
4455
@Override
4556
public void setFactType() {
4657
this.factType = FactType.MOVEMENT_REPORT_DOCUMENT;

service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
2323
import java.util.List;
2424

2525
import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW;
26+
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.MOVEMENT_REPORT_DOCUMENT;
2627

2728
public class MovementFactGenerator extends AbstractGenerator {
2829

service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/MovementReportDocumentFactMapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
2525
import java.util.Date;
2626
import java.util.List;
2727

28+
import java.util.Date;
29+
2830
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.CREATION_DATE_TIME;
2931
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FLUX_REPORT_DOCUMENT;
3032
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.MOVEMENT_REPORT_DOCUMENT;
@@ -33,17 +35,17 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
3335
public class MovementReportDocumentFactMapper {
3436

3537
private XPathStringWrapper xPathUtil;
36-
3738
public static final String ID = "id";
3839

40+
3941
public MovementReportDocumentFactMapper() {
4042
xPathUtil = new XPathStringWrapper();
4143
}
4244
public MovementReportDocumentFactMapper(XPathStringWrapper strUtil1) {
4345
this.xPathUtil = strUtil1;
4446
}
4547

46-
public AbstractFact generateFactForMovementReportDocument(FLUXVesselPositionMessage vesselPositionMessage){
48+
public MovementReportDocumentFact generateFactForMovementReportDocument(FLUXVesselPositionMessage vesselPositionMessage){
4749

4850
if(vesselPositionMessage == null){
4951
xPathUtil.clear();

service/src/test/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBeanTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
2222
import eu.europa.ec.fisheries.schema.rules.exchange.v1.PluginType;
2323
import eu.europa.ec.fisheries.schema.rules.module.v1.SetFLUXMovementReportRequest;
2424
import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType;
25+
import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
2526
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery;
2627
import eu.europa.ec.fisheries.schema.rules.search.v1.TicketQuery;
2728
import eu.europa.ec.fisheries.schema.rules.source.v1.GetAlarmListByQueryResponse;
@@ -42,8 +43,11 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
4243
import eu.europa.ec.fisheries.uvms.rules.model.dto.TicketListResponseDto;
4344
import eu.europa.ec.fisheries.uvms.rules.model.mapper.RulesDataSourceRequestMapper;
4445
import eu.europa.ec.fisheries.uvms.rules.model.mapper.RulesDataSourceResponseMapper;
46+
import eu.europa.ec.fisheries.uvms.rules.service.bean.RulePostProcessBean;
47+
import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesEngineBean;
4548
import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MDRCache;
4649
import eu.europa.ec.fisheries.uvms.rules.service.business.PreviousReportFact;
50+
import eu.europa.ec.fisheries.uvms.rules.service.business.ValidationResult;
4751
import eu.europa.ec.fisheries.uvms.rules.service.constants.MDRAcronymType;
4852
import eu.europa.ec.fisheries.uvms.rules.service.constants.ServiceConstants;
4953
import org.junit.Before;
@@ -60,9 +64,11 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
6064
import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage;
6165
import un.unece.uncefact.data.standard.mdr.communication.ColumnDataType;
6266
import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation;
67+
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType;
6368
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselPositionEventType;
6469
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType;
6570
import un.unece.uncefact.data.standard.unqualifieddatatype._18.CodeType;
71+
import un.unece.uncefact.data.standard.unqualifieddatatype._18.IDType;
6672

6773
import javax.enterprise.event.Event;
6874
import javax.jms.JMSException;
@@ -89,6 +95,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
8995
public class RulesMovementProcessorBeanTest {
9096

9197
private static final String USERNAME = "USERNAME";
98+
private static final String FLUX_REPORT_DOC_UUID = UUID.randomUUID().toString();
9299

93100
@Mock
94101
RulesMessageProducer mockProducer;
@@ -112,6 +119,10 @@ public class RulesMovementProcessorBeanTest {
112119
MDRCache mdrCache;
113120
@Mock
114121
RulesExchangeProducerBean exchangeProducer;
122+
@Mock
123+
RulesEngineBean rulesEngine;
124+
@Mock
125+
RulePostProcessBean rulePostProcessBean;
115126

116127
@InjectMocks
117128
RulesMovementProcessorBean rulesMovementProcessorBean;
@@ -546,6 +557,9 @@ public void testSetMovementReportReceived() throws Exception {
546557
setupMobileTerminalConversation();
547558
setupMovementModuleConversation();
548559
String messageGuid = UUID.randomUUID().toString();
560+
ValidationResult validationResult = new ValidationResult();
561+
validationResult.setError(false);
562+
when(rulePostProcessBean.checkAndUpdateValidationResult(any(), anyString(), anyString(), eq(RawMsgType.MOVEMENT))).thenReturn(validationResult);
549563

550564
rulesMovementProcessorBean.setMovementReportReceived(request, messageGuid);
551565

@@ -577,6 +591,12 @@ private void setupFluxVesselPositionMessage(SetFLUXMovementReportRequest request
577591
vesselPositionEvent.setTypeCode(new CodeType());
578592
vesselPositionEvent.getTypeCode().setValue("MANUAL");
579593
vesselTransportMeans.getSpecifiedVesselPositionEvents().add(vesselPositionEvent);
594+
FLUXReportDocumentType fluxReportDoc = new FLUXReportDocumentType();
595+
final IDType id = new IDType();
596+
id.setSchemeID("UUID");
597+
id.setValue(FLUX_REPORT_DOC_UUID);
598+
fluxReportDoc.getIDS().add(id);
599+
fluxVesselPositionMessage.setFLUXReportDocument(fluxReportDoc);
580600
request.setRequest(JAXBUtils.marshallJaxBObjectToString(fluxVesselPositionMessage, "UTF-8", true));
581601
}
582602

0 commit comments

Comments
 (0)