Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LIQUIBASE/changelog/db-changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@
<include file="changelog/v3.4/db-changelog-UNIONVMS-4884.xml" />
<include file="changelog/v3.4/db-changelog-UNIONVMS-4477.xml" />
<include file="changelog/v3.4/db-changelog-UNIONVMS-4685.xml" />
<include file="changelog/v3.4/db-changelog-UNIONVMS-4660.xml" />
</databaseChangeLog>

501 changes: 501 additions & 0 deletions LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.schema.rules.customrule.v1.*;
import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMessageType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.RuleType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.ValidationMessageType;
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery;
Expand Down Expand Up @@ -125,6 +126,15 @@ public void updateValidationMessagesWithPermission(ValidationMessageType validat
}
}

@Override
public void createOrUpdateValidationMessagesWithPermission(ValidationMessageType validationMessage, String rawMsgGuid, String rawMessage, RawMsgType type) throws RulesModelException {
try {
rulesDao.createOrUpdateValidationMessagesWithPermission(rawMsgGuid, rawMessage, type, RawMessageMapper.INSTANCE.mapToValidationMessageEntity(validationMessage));
} catch (DaoException e) {
throw new RulesModelException(e.getMessage(), e);
}
}

@Override
public CustomRuleType createCustomRule(CustomRuleType customRule) throws RulesModelException {
LOG.debug("Create in Rules");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import java.util.List;
import java.util.Set;

import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
import eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException;
import eu.europa.ec.fisheries.uvms.rules.entity.AlarmReport;
import eu.europa.ec.fisheries.uvms.rules.entity.CustomRule;
Expand Down Expand Up @@ -160,6 +161,8 @@ List<Ticket> getTicketListPaginated(Integer page, Integer listSize, String sql,

void updateValidationMessagesWith(String rawMessageGuid, String type, ValidationMessage validationMessage) throws DaoException;

void createOrUpdateValidationMessagesWithPermission(String rawMessageGuid, String rawMessage, RawMsgType type, ValidationMessage validationMessage) throws DaoException;

List<ValidationMessage> getValidationMessagesById(List<String> ids) throws DaoException;

List<ValidationMessage> getValidationMessagesByRawMsgGuid(String rawMsgGuid, String type) throws DaoException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import javax.persistence.TransactionRequiredException;
import javax.persistence.TypedQuery;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
import eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException;
import eu.europa.ec.fisheries.uvms.rules.constant.UvmsConstants;
import eu.europa.ec.fisheries.uvms.rules.dao.FADocumentIDDAO;
Expand Down Expand Up @@ -559,7 +561,7 @@ public void saveValidationMessages(List<RawMessage> rawMessages) throws DaoExcep
@Override
public void updateValidationMessagesWith(String rawMessageGuid, String type, ValidationMessage validationMessage) throws DaoException {
try {
List<RawMessage> rawMessageByGuid = rawMessageDao.getRawMessageByGuid(rawMessageGuid, type);
List<RawMessage> rawMessageByGuid = rawMessageDao.getRawMessageByGuid(rawMessageGuid, type);
rawMessageByGuid.forEach(r -> {
r.getValidationMessages().add(validationMessage);
validationMessage.setRawMessage(r);
Expand All @@ -569,6 +571,29 @@ public void updateValidationMessagesWith(String rawMessageGuid, String type, Val
}
}

@Override
public void createOrUpdateValidationMessagesWithPermission(String rawMessageGuid, String rawMessageContent, RawMsgType type, ValidationMessage validationMessage) throws DaoException {
try {
List<RawMessage> rawMessageByGuid = rawMessageDao.getRawMessageByGuid(rawMessageGuid, type.value());
if (rawMessageByGuid.isEmpty()) {
RawMessage rawMessage = new RawMessage();
rawMessage.setGuid(rawMessageGuid);
rawMessage.setRawMessage(rawMessageContent);
rawMessage.setRawMsgType(type);
validationMessage.setRawMessage(rawMessage);
rawMessage.setValidationMessages(Collections.singleton(validationMessage));
rawMessageDao.saveRawMessages(Collections.singletonList(rawMessage));
} else {
rawMessageByGuid.forEach(r -> {
r.getValidationMessages().add(validationMessage);
validationMessage.setRawMessage(r);
});
}
} catch (ServiceException e) {
throw new DaoException(e.getMessage(), e);
}
}

@Override
public List<ValidationMessage> getValidationMessagesById(List<String> ids) throws DaoException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.schema.rules.customrule.v1.UpdateSubscriptionType;
import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMessageType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
import eu.europa.ec.fisheries.schema.rules.rule.v1.ValidationMessageType;
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery;
import eu.europa.ec.fisheries.schema.rules.search.v1.CustomRuleQuery;
Expand Down Expand Up @@ -115,4 +116,6 @@ public interface RulesDomainModel {
List<ValidationMessageType> getValidationMessagesByRawMsgGuid(String rawMsgGuid, String type) throws RulesModelException;

void updateValidationMessagesWithPermission(ValidationMessageType validationMessage, String rawMsgGuid, String type) throws RulesModelException;
}

void createOrUpdateValidationMessagesWithPermission(ValidationMessageType validationMessage, String rawMsgGuid, String rawMessage, RawMsgType type) throws RulesModelException;
}
5 changes: 5 additions & 0 deletions model/src/main/resources/contract/Template.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<xsd:enumeration value="SALES_QUERY_PARAMETER"/>
<xsd:enumeration value="SALES_FLUX_SALES_RESPONSE_MESSAGE"/>

<!-- Movements -->
<xsd:enumeration value="MOVEMENT_REPORT_DOCUMENT"/>
<xsd:enumeration value="MOVEMENT_REPORT_DOCUMENT_ID"/>
<xsd:enumeration value="MOVEMENT_REPORT_DOC_OWNER_FLUX_PARTY_ID"/>
<xsd:enumeration value="MOVEMENT_VESSEL_TRANSPORT_MEANS_ID"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -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, FactType.MOVEMENT_REPORT_DOCUMENT_ID,
FactType.MOVEMENT_REPORT_DOC_OWNER_FLUX_PARTY_ID, FactType.MOVEMENT_VESSEL_TRANSPORT_MEANS_ID);

private final String packageName;
private final String containerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ private void saveValidationResult(List<ValidationMessageType> validationMessageT
}
}

public void createOrUpdateValidationResult(String rawMsgGuid, String rawMessage, RawMsgType type, RuleError ruleError) throws RulesModelException {
final ValidationMessageType validationMessage = createValidationMessageFromParams(ruleError.getRuleId(), ErrorType.ERROR, ruleError.getMessage(), ruleError.getLevel(), Collections.emptyList(), ruleError.getXpaths(), new Date());
rulesDomainModel.createOrUpdateValidationMessagesWithPermission(validationMessage, rawMsgGuid, rawMessage, type);
}

private void updateValidationResult(String rawMsgGuid, String type, ValidationMessageType validationMessage) throws RulesModelException {
rulesDomainModel.updateValidationMessagesWithPermission(validationMessage, rawMsgGuid, type);

}

private ValidationResult createValidationResultDtoFromParams(boolean isError, boolean isWarning, boolean isOk, List<ValidationMessageType> validationMessages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -67,6 +81,7 @@ public class RulesEngineBean {
private SalesResponseFactGenerator salesResponseFactGenerator;



private FaResponseFactMapper faResponseFactMapper;

@EJB
Expand Down Expand Up @@ -181,6 +196,22 @@ public Collection<AbstractFact> 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<AbstractFact> facts = generator.generateAllFacts();
log.info("Flow Report, Generating the facts took: {} ms", stopWatch.getTime());
stopWatch.reset();
stopWatch.start();

Map<String, Object> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void init() {
List<TemplateRuleMapDto> faTemplatesAndRules = getFaMessageRules(allTemplates);
List<TemplateRuleMapDto> salesTemplatesAndRules = getSalesRules(allTemplates);
List<TemplateRuleMapDto> faQueryTemplatesAndRules = getFaQueryRules(allTemplates);
List<TemplateRuleMapDto> movementTemplatesAndRules = getMovementRules(allTemplates);

log.info("Initializing templates and rules for FA-Report facts. Nr. of Rules : {}", countRuleExpressions(faTemplatesAndRules));
KieContainer faReportContainer = createContainer(faTemplatesAndRules);
Expand All @@ -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()) {
Expand Down Expand Up @@ -214,6 +220,18 @@ private List<TemplateRuleMapDto> getFaQueryRules(List<TemplateRuleMapDto> allTem
return faQueryTemplates;
}

private List<TemplateRuleMapDto> getMovementRules(List<TemplateRuleMapDto> allTemplates) {
List<TemplateRuleMapDto> movementTemplates = new ArrayList<>();
List<FactType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,18 @@ private void overrideBRMessages() {
final List<ObjectRepresentation> objRapprList = new ArrayList<>();
List<ObjectRepresentation> brDef = getEntry(MDRAcronymType.FA_BR);
List<ObjectRepresentation> saleBrDef = getEntry(MDRAcronymType.SALE_BR);
List<ObjectRepresentation> movementDef = getEntry(MDRAcronymType.VP_BR);
// For start up non reachable MDR purposes :)
if (CollectionUtils.isNotEmpty(brDef)) {
objRapprList.addAll(brDef);
}
if (CollectionUtils.isNotEmpty(saleBrDef)) {
objRapprList.addAll(saleBrDef);
}
if (CollectionUtils.isNotEmpty(movementDef)) {
objRapprList.addAll(movementDef);
}

objRapprList.removeAll(Collections.singleton(null));
if (CollectionUtils.isEmpty(objRapprList)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,7 +173,7 @@ public void evaluate(MovementFact fact) {
}

@Lock(LockType.READ)
public void evaluate(List<MovementFact> factList, boolean justToAvoidErasure) {
public void evaluate(List<MovementFact> factList) {
log.info("Verifying user defined rules");
KieSession ksession = getKieSession();
// TODO : decomment as soon as the "Unexpected global [validationService]" is resolved
Expand All @@ -186,7 +187,7 @@ public void evaluate(List<MovementFact> factList, boolean justToAvoidErasure) {


@Lock(LockType.READ)
public void evaluate(List<RawMovementFact> facts) {
public void evaluateRawList(List<RawMovementFact> facts) {
KieSession ksession = getKieSession();
ksession.setGlobal(LOGGER_STR, log);
for (RawMovementFact fact : facts) {
Expand Down
Loading