use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class RecordIndexManager method index.
protected void index(final IndexWriter indexWriter, CollectRecord record) throws RecordIndexException {
try {
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition defn = node.getDefinition();
if (defn instanceof AttributeDefinition) {
index(indexWriter, (Attribute<?, ?>) node);
}
}
});
} catch (Exception e) {
throw new RecordIndexException(e);
}
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class SurveyValidator method validateSchemaNodes.
/**
* Checks for the existence of empty entities
*
* @param survey
* @return
*/
protected List<SurveyValidationResult> validateSchemaNodes(CollectSurvey survey) {
final List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
Schema schema = survey.getSchema();
schema.traverse(new NodeDefinitionVisitor() {
@Override
public void visit(NodeDefinition def) {
results.addAll(validateSchemaNode(def));
}
});
return results;
}
use of org.openforis.idm.metamodel.NodeDefinition 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;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class RecordUpdater method getDescendantNodePointers.
private List<NodePointer> getDescendantNodePointers(Entity entity) {
ModelVersion version = entity.getRecord().getVersion();
List<NodePointer> pointers = new ArrayList<NodePointer>();
EntityDefinition definition = entity.getDefinition();
for (NodeDefinition childDef : definition.getChildDefinitionsInVersion(version)) {
pointers.add(new NodePointer(entity, childDef));
if (childDef instanceof EntityDefinition) {
for (Node<?> childEntity : entity.getChildren(childDef)) {
pointers.addAll(getDescendantNodePointers((Entity) childEntity));
}
}
}
return pointers;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class RecordUpdater method addEmptyNodes.
private void addEmptyNodes(Entity entity) {
Record record = entity.getRecord();
ModelVersion version = record.getVersion();
addEmptyEnumeratedEntities(entity);
EntityDefinition entityDefn = entity.getDefinition();
List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitionsInVersion(version);
for (NodeDefinition childDefn : childDefinitions) {
if (entity.getCount(childDefn) == 0) {
if (addEmptyMultipleEntitiesWhenAddingNewEntities || !(childDefn instanceof EntityDefinition && childDefn.isMultiple())) {
int toBeInserted = entity.getMinCount(childDefn);
if (toBeInserted <= 0 && childDefn instanceof AttributeDefinition || !childDefn.isMultiple()) {
// insert at least one node
toBeInserted = 1;
}
addEmptyChildren(entity, childDefn, toBeInserted);
}
} else {
entity.visitChildren(childDefn, new NodeVisitor() {
public void visit(Node<? extends NodeDefinition> child, int idx) {
if (child instanceof Entity) {
addEmptyNodes((Entity) child);
}
}
});
}
}
}
Aggregations