use of org.openforis.idm.model.Entity in project collect by openforis.
the class EntityKeyValidator method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> keyAttribute) {
Entity multipleEntity = keyAttribute.getNearestMultipleEntityAncestor();
EntityDefinition multipleEntityDef = multipleEntity.getDefinition();
if (multipleEntityDef.isRoot()) {
return ValidationResultFlag.OK;
}
Value[] keyValues = multipleEntity.getKeyAttributeValues();
if (keyValues == null) {
return null;
}
List<Entity> entities = multipleEntity.getParent().findChildEntitiesByKeys(multipleEntityDef, keyValues);
if (entities.size() > 1) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testCardinalityRevalidatedOnAttributeUpdate.
@Test
public void testCardinalityRevalidatedOnAttributeUpdate() {
record(rootEntityDef(attributeDef("min_time_study"), entityDef("time_study", attributeDef("start_time")).multiple().minCount("min_time_study")), attribute("min_time_study", "2"), entity("time_study", attribute("start_time", "2011")), entity("time_study", attribute("start_time", "2012")));
Entity rootEntity = record.getRootEntity();
assertEquals(ValidationResultFlag.OK, rootEntity.getMinCountValidationResult("time_study"));
Attribute<?, ?> minTimeStudy = record.findNodeByPath("/root/min_time_study");
NodeChangeSet nodeChangeSet = update(minTimeStudy, "3");
assertNotNull(nodeChangeSet.getChange(rootEntity));
assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("time_study"));
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testRemoveEntityWithCalculatedAttribute.
@Test
public void testRemoveEntityWithCalculatedAttribute() {
record(rootEntityDef(entityDef("plot_details", attributeDef("dbh_sum").calculated("sum(parent()/tree/dbh)"), attributeDef("tree_health").relevant("dbh_sum > 0").required()), entityDef("tree", attributeDef("dbh")).multiple()), entity("plot_details", attribute("dbh_sum"), attribute("tree_health")), entity("tree", attribute("dbh", "1")));
Entity plotDetails = entityByPath("/root/plot_details");
Entity tree1 = entityByPath("/root/tree[1]");
NodeChangeSet changeSet = updater.deleteNode(tree1);
Attribute<?, ?> dbhSum = (Attribute<?, ?>) plotDetails.getChild("dbh_sum");
assertEquals(new TextValue("0.0"), dbhSum.getValue());
NodeChange<?> dbhSumChange = changeSet.getChange(dbhSum);
assertNotNull(dbhSumChange);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testCardinalityRevalidatedOnRequiredAttributeUpdate.
@Test
public void testCardinalityRevalidatedOnRequiredAttributeUpdate() {
record(rootEntityDef(attributeDef("source"), attributeDef("dependent").required("source = 1")), attribute("source", "2"), attribute("dependent", null));
Entity rootEntity = record.getRootEntity();
assertEquals(ValidationResultFlag.OK, rootEntity.getMinCountValidationResult("dependent"));
Attribute<?, ?> source = record.findNodeByPath("/root/source");
NodeChangeSet nodeChangeSet = update(source, "1");
EntityChange rootEntityChange = (EntityChange) nodeChangeSet.getChange(rootEntity);
assertNotNull(rootEntityChange);
ValidationResultFlag dependentValidationResult = rootEntityChange.getChildrenMinCountValidation().get("dependent");
assertEquals(ValidationResultFlag.ERROR, dependentValidationResult);
assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("dependent"));
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testMinCountValidationInitializedOnNestedEntity.
@Test
public void testMinCountValidationInitializedOnNestedEntity() {
record(rootEntityDef(entityDef("time_study", attributeDef("start_time").required()).minCount("1")));
Entity timeStudy = entityByPath("/root/time_study");
assertEquals(ValidationResultFlag.ERROR, timeStudy.getMinCountValidationResult("start_time"));
}
Aggregations