Skip to content

Commit

Permalink
Merge pull request #56 from OP-TED/feature/check-business-entity-info
Browse files Browse the repository at this point in the history
Add checks for business entity info
  • Loading branch information
bertrand-lorentz authored May 29, 2024
2 parents a70a019 + 8ddad4c commit 11fcff6
Show file tree
Hide file tree
Showing 29 changed files with 31,110 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/java/eu/europa/ted/eforms/sdk/analysis/FactsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import eu.europa.ted.eforms.sdk.analysis.domain.SvrlReport;
import eu.europa.ted.eforms.sdk.analysis.domain.XmlNotice;
import eu.europa.ted.eforms.sdk.analysis.domain.codelist.Codelist;
import eu.europa.ted.eforms.sdk.analysis.domain.field.BusinessEntity;
import eu.europa.ted.eforms.sdk.analysis.domain.field.Field;
import eu.europa.ted.eforms.sdk.analysis.domain.field.XmlStructureNode;
import eu.europa.ted.eforms.sdk.analysis.domain.label.Label;
import eu.europa.ted.eforms.sdk.analysis.domain.noticetype.DocumentType;
import eu.europa.ted.eforms.sdk.analysis.domain.noticetype.NoticeType;
import eu.europa.ted.eforms.sdk.analysis.domain.view.index.TedefoViewTemplateIndex;
import eu.europa.ted.eforms.sdk.analysis.domain.view.index.TedefoViewTemplatesIndex;
import eu.europa.ted.eforms.sdk.analysis.fact.BusinessEntityFact;
import eu.europa.ted.eforms.sdk.analysis.fact.CodelistFact;
import eu.europa.ted.eforms.sdk.analysis.fact.CodelistsIndexFact;
import eu.europa.ted.eforms.sdk.analysis.fact.DocumentTypeFact;
Expand Down Expand Up @@ -71,6 +73,17 @@ public DataStore<FieldFact> loadFields() throws IOException {
return datastore;
}

public DataStore<BusinessEntityFact> loadBusinessEntities() throws IOException {
logger.debug("Creating facts datastore for business entities");

final DataStore<BusinessEntityFact> datastore = DataSource.createStore();

sdkLoader.getFieldsAndNodes().getBusinessEntities()
.forEach((BusinessEntity entity) -> datastore.add(new BusinessEntityFact(entity)));

return datastore;
}

public DataStore<NodeFact> loadNodes() throws IOException {
logger.debug("Creating facts datastore for nodes");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BusinessEntity {
private boolean repeatable;
private String repeatsWithNodeId;

private BusinessEntityChangeIdentification changeIdentification;
private BusinessEntityChangeIdentification changeIdentification;

private BusinessEntityIdentifier instanceIdentifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.drools.ruleunits.api.DataStore;
import org.kie.api.definition.rule.Rule;

import eu.europa.ted.eforms.sdk.analysis.fact.BusinessEntityFact;
import eu.europa.ted.eforms.sdk.analysis.fact.CodelistFact;
import eu.europa.ted.eforms.sdk.analysis.fact.CodelistsIndexFact;
import eu.europa.ted.eforms.sdk.analysis.fact.DocumentTypeFact;
Expand All @@ -33,6 +34,7 @@ public class SdkUnit implements RuleUnit {
private DataStore<XmlNoticeFact> xmlNotices;
private DataStore<FieldsAndNodesMetadataFact> fieldsAndNodesMetadata;
private DataStore<FieldFact> fields;
private DataStore<BusinessEntityFact> businessEntities;
private DataStore<LabelFact> labels;
private DataStore<NodeFact> nodes;
private DataStore<NoticeTypesIndexFact> noticeTypesIndex;
Expand Down Expand Up @@ -106,6 +108,15 @@ public SdkUnit setFields(DataStore<FieldFact> fields) {
return this;
}

public DataStore<BusinessEntityFact> getBusinessEntities() {
return businessEntities;
}

public SdkUnit setBusinessEntities(DataStore<BusinessEntityFact> businessEntities) {
this.businessEntities = businessEntities;
return this;
}

public DataStore<LabelFact> getLabels() {
return labels;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package eu.europa.ted.eforms.sdk.analysis.fact;

import eu.europa.ted.eforms.sdk.analysis.domain.field.BusinessEntity;

public class BusinessEntityFact implements SdkComponentFact<String> {
private static final long serialVersionUID = -8325643682910825716L;

private BusinessEntity businessEntity;

public BusinessEntityFact(BusinessEntity businessEntity) {
this.businessEntity = businessEntity;
}

public String getLabelId() {
return businessEntity.getLabelId();
}

public String getRepeatsWithNodeId() {
return businessEntity.getRepeatsWithNodeId();
}

public String getIdentifierFieldId() {
if (businessEntity.getInstanceIdentifier() != null) {
return businessEntity.getInstanceIdentifier().getIdentifierFieldId();
} else {
return null;
}
}

public String getCaptionFieldId() {
if (businessEntity.getInstanceIdentifier() != null) {
return businessEntity.getInstanceIdentifier().getCaptionFieldId();
} else {
return null;
}
}

public String getReferencedBusinessEntityId() {
if (businessEntity.getInstanceIdentifier() != null) {
return businessEntity.getInstanceIdentifier().getReferencedBusinessEntityId();
} else {
return null;
}
}

@Override
public String getId() {
return businessEntity.getId();
}

@Override
public String getTypeName() {
return "businessEntity";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public String getPresetValue() {
return field.getPresetValue();
}

public String getBusinessEntityId() {
return field.getBusinessEntityId();
}

/**
* Return a stream of the dynamic properties of the field
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public List<String> getInvalidXpathRelativeSteps() {
return badSteps;
}

public String getBusinessEntityId() {
return node.getBusinessEntityId();
}

@Override
public String getId() {
return node.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Validator validate() throws Exception {
.setDocumentTypes(factsLoader.loadDocumentTypes())
.setFieldsAndNodesMetadata(factsLoader.loadFieldsAndNodesMetadata())
.setFields(factsLoader.loadFields())
.setBusinessEntities(factsLoader.loadBusinessEntities())
.setNodes(factsLoader.loadNodes())
.setNoticeTypes(factsLoader.loadNoticeTypes())
.setNoticeTypesIndex(factsLoader.loadNoticeTypesIndex())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,44 @@ when
/fields[ $f: this, $duplicateNoticeTypes: duplicateNoticeTypes, $duplicateNoticeTypes.size() > 0 ]
then
results.add(new ValidationResult($f, "At least one constraint has duplicate notice types :" + $duplicateNoticeTypes, ValidationStatusEnum.ERROR));
end
end

rule "All fields are part of an existing business entity"
when
/fields[ $f: this, $businessEntityId: businessEntityId ]
not (exists /businessEntities[ id == $businessEntityId ])
then
results.add(new ValidationResult($f, "BusinessEntityId is not indicated or does not exist : " + $businessEntityId, ValidationStatusEnum.ERROR));
end

rule "Business entities have a correct label identifier"
when
/businessEntities[ $b: this, $labelId: labelId ]
not (exists /labels[ id == $labelId ])
then
results.add(new ValidationResult($b, "Referenced label " + $labelId + " does not exist", ValidationStatusEnum.ERROR));
end

rule "Relationships between business entities and nodes are consistent"
when
/businessEntities[ $b: this, $businessEntityId: id, $nodeId: repeatsWithNodeId, repeatsWithNodeId != null ]
not (exists /nodes[ id == $nodeId, businessEntityId == $businessEntityId ])
then
results.add(new ValidationResult($b, "Relationship with node " + $nodeId + " is incorrect", ValidationStatusEnum.ERROR));
end

rule "Relationships between business entities and identifier fields are consistent"
when
/businessEntities[ $b: this, $businessEntityId: id, $fieldId: identifierFieldId, identifierFieldId != null ]
not (exists /fields[ id == $fieldId, businessEntityId == $businessEntityId ])
then
results.add(new ValidationResult($b, "Relationship with identifier field " + $fieldId + " is incorrect", ValidationStatusEnum.ERROR));
end

rule "Relationships between business entities and caption fields are consistent"
when
/businessEntities[ $b: this, $businessEntityId: id, $referencedBusinessEntityId: referencedBusinessEntityId, $fieldId: captionFieldId, captionFieldId != null ]
not (exists /fields[ id == $fieldId, businessEntityId == $businessEntityId || businessEntityId == $referencedBusinessEntityId ])
then
results.add(new ValidationResult($b, "Relationship with caption field " + $fieldId + " is incorrect", ValidationStatusEnum.ERROR));
end
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ then
results.add(new ValidationResult($nt, "Field " + $fieldId + " is missing the privacy field " + $privacyField + " under " + $unpublishGroupId, ValidationStatusEnum.ERROR));
end

rule "Business entity of the group is consistent with the node"
when
$group : /noticeTypes[ $nt: this ]/groups[ $groupId: id, $nodeId: nodeId, $businessEntityId: businessEntityId, businessEntityId != null ]
not (exists /businessEntities[ id == $businessEntityId, repeatsWithNodeId == $nodeId ])
then
results.add(new ValidationResult($nt, "Group " + $groupId + " references business entity " + $businessEntityId + " which does not correspond to the same node", ValidationStatusEnum.ERROR));
end

// TEDEFO-1845: Warning
// For every field in a notice type definition, all its repeatable ancestor should be in this notice type definition
rule "All repeatable ancestors of a field are in the notice type definition"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public void i_load_all_fields() throws IOException {
sdkValidator.getSdkUnit().setFields(new FactsLoader(testsFolder).loadFields());
}

@When("I load all business entities")
public void i_load_all_business_entities() throws IOException {
sdkValidator.getSdkUnit().setBusinessEntities(new FactsLoader(testsFolder).loadBusinessEntities());
}

@When("I load all nodes")
public void i_load_all_nodes() throws IOException {
sdkValidator.getSdkUnit().setNodes(new FactsLoader(testsFolder).loadNodes());
Expand Down
Loading

0 comments on commit 11fcff6

Please sign in to comment.