use of org.openforis.idm.model.NodeVisitor 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);
}
}
});
}
}
}
use of org.openforis.idm.model.NodeVisitor in project collect by openforis.
the class CollectRecord method getFileAttributes.
public List<FileAttribute> getFileAttributes() {
final List<FileAttribute> result = new ArrayList<FileAttribute>();
Entity rootEntity = getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int pos) {
if (node instanceof FileAttribute) {
result.add((FileAttribute) node);
}
}
});
return result;
}
use of org.openforis.idm.model.NodeVisitor in project collect by openforis.
the class RecordValidationReportGenerator method extractCardinalityValidationResultItems.
protected List<RecordValidationReportItem> extractCardinalityValidationResultItems(final Locale locale, final ValidationResultFlag level, final boolean includeConfirmedErrors) {
final List<RecordValidationReportItem> result = new ArrayList<RecordValidationReportItem>();
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
if (node instanceof Entity) {
Entity entity = (Entity) node;
List<RecordValidationReportItem> items = extractCardinalityValidationItems(locale, entity, level, includeConfirmedErrors);
result.addAll(items);
}
}
});
return result;
}
Aggregations