Search in sources :

Example 11 with ValidationResultFlag

use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.

the class RecordUpdater method validateCardinality.

private Set<NodePointer> validateCardinality(Record record, Collection<NodePointer> pointers, NodeChangeMap changeMap) {
    Set<NodePointer> updatedPointers = new HashSet<NodePointer>();
    Validator validator = record.getSurveyContext().getValidator();
    for (NodePointer nodePointer : pointers) {
        Entity entity = nodePointer.getEntity();
        NodeDefinition childDef = nodePointer.getChildDefinition();
        ValidationResultFlag minCountResult, maxCountResult;
        if (entity.isRelevant(childDef)) {
            minCountResult = validator.validateMinCount(entity, childDef);
            maxCountResult = validator.validateMaxCount(entity, childDef);
        } else {
            minCountResult = maxCountResult = ValidationResultFlag.OK;
        }
        if (entity.getMinCountValidationResult(childDef) != minCountResult) {
            entity.setMinCountValidationResult(childDef, minCountResult);
            changeMap.addMinCountValidationResultChange(nodePointer, minCountResult);
            updatedPointers.add(nodePointer);
        }
        if (entity.getMaxCountValidationResult(childDef) != maxCountResult) {
            entity.setMaxCountValidationResult(childDef, maxCountResult);
            changeMap.addMaxCountValidationResultChange(nodePointer, maxCountResult);
            updatedPointers.add(nodePointer);
        }
    }
    return updatedPointers;
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodePointer(org.openforis.idm.model.NodePointer) Validator(org.openforis.idm.metamodel.validation.Validator) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with ValidationResultFlag

use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.

the class EntityProxy method getChildrenMaxCountValidation.

@ExternalizedProperty
public List<ValidationResultFlag> getChildrenMaxCountValidation() {
    List<ValidationResultFlag> result = new ArrayList<ValidationResultFlag>(availableChildDefinitions.size());
    for (NodeDefinition childDefinition : availableChildDefinitions) {
        ValidationResultFlag valid = entity.getMaxCountValidationResult(childDefinition);
        result.add(valid);
    }
    return result;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 13 with ValidationResultFlag

use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.

the class EntityProxy method getChildrenMinCountValidation.

@ExternalizedProperty
public List<ValidationResultFlag> getChildrenMinCountValidation() {
    List<ValidationResultFlag> result = new ArrayList<ValidationResultFlag>(availableChildDefinitions.size());
    for (NodeDefinition childDefinition : availableChildDefinitions) {
        ValidationResultFlag valid = entity.getMinCountValidationResult(childDefinition);
        result.add(valid);
    }
    return result;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 14 with ValidationResultFlag

use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.

the class CollectRecordIntegrationTest method testRemoveRequiredEntity.

@Test
public void testRemoveRequiredEntity() throws Exception {
    CollectSurvey survey = loadSurvey();
    CollectRecord record = createTestRecord(survey);
    Entity cluster = record.getRootEntity();
    Entity timeStudy = (Entity) cluster.getChild("time_study", 0);
    NodeChangeSet changeSet = recordUpdater.deleteNode(timeStudy);
    assertEquals(2, changeSet.size());
    {
        NodeChange<?> timeStudyDeleteChange = changeSet.getChange(timeStudy);
        assertTrue(timeStudyDeleteChange instanceof NodeDeleteChange);
        Node<?> deletedNode = timeStudyDeleteChange.getNode();
        assertEquals(timeStudy.getInternalId(), deletedNode.getInternalId());
    }
    {
        NodeChange<?> clusterChange = changeSet.getChange(cluster);
        assertTrue(clusterChange instanceof EntityChange);
        EntityChange clusterEntityChange = (EntityChange) clusterChange;
        Map<String, ValidationResultFlag> childrenMinCountValid = clusterEntityChange.getChildrenMinCountValidation();
        ValidationResultFlag timeStudyMinCountValid = childrenMinCountValid.get("time_study");
        assertEquals(ValidationResultFlag.ERROR, timeStudyMinCountValid);
        Map<String, ValidationResultFlag> childrenMaxCountValid = clusterEntityChange.getChildrenMaxCountValidation();
        ValidationResultFlag timeStudyMaxCountValid = childrenMaxCountValid.get("time_study");
        assertNull(timeStudyMaxCountValid);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) Node(org.openforis.idm.model.Node) HashMap(java.util.HashMap) Map(java.util.Map) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 15 with ValidationResultFlag

use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.

the class RecordValidationReportGenerator method extractAttributeValidationResultItem.

protected List<RecordValidationReportItem> extractAttributeValidationResultItem(Locale locale, Integer attrId, ValidationResultFlag level, boolean includeConfirmedErrors) {
    List<RecordValidationReportItem> items = new ArrayList<RecordValidationReportItem>();
    Attribute<?, ?> attr = (Attribute<?, ?>) record.getNodeByInternalId(attrId);
    ValidationResults validationResults = validationCache.getAttributeValidationResults(attrId);
    List<ValidationResult> failed = validationResults.getFailed();
    if (CollectionUtils.isNotEmpty(failed)) {
        String path = getPath(attr);
        String prettyFormatPath = messageBuilder.getPrettyFormatPath(attr, locale);
        for (ValidationResult validationResult : failed) {
            ValidationResultFlag flag = validationResult.getFlag();
            if (isInLevel(flag, level) || flag == ValidationResultFlag.WARNING && includeConfirmedErrors && record.isErrorConfirmed(attr)) {
                String message = messageBuilder.getValidationMessage(attr, validationResult, locale);
                RecordValidationReportItem recordValidationItem = new RecordValidationReportItem(attrId, path, prettyFormatPath, flag, message);
                items.add(recordValidationItem);
            }
        }
    }
    return items;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Attribute(org.openforis.idm.model.Attribute) ArrayList(java.util.ArrayList) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Aggregations

ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)20 Entity (org.openforis.idm.model.Entity)7 Test (org.junit.Test)6 CollectRecord (org.openforis.collect.model.CollectRecord)5 ArrayList (java.util.ArrayList)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)2 Step (org.openforis.collect.model.CollectRecord.Step)2 FieldSymbol (org.openforis.collect.model.FieldSymbol)2 ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)2 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 NumberValueUnitValidator (org.openforis.idm.metamodel.validation.NumberValueUnitValidator)1 NumericRangeUnitValidator (org.openforis.idm.metamodel.validation.NumericRangeUnitValidator)1 Validator (org.openforis.idm.metamodel.validation.Validator)1 Attribute (org.openforis.idm.model.Attribute)1