use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdater method addEntity.
public NodeChangeSet addEntity(Entity parentEntity, EntityDefinition entityDef) {
Entity entity = performEntityAdd(parentEntity, entityDef, null);
setMissingValueApproved(parentEntity, entityDef.getName(), false);
NodeChangeMap changeMap = initializeEntity(entity, true);
return changeMap;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
if (enumeratingCodeDefn != null) {
CodeList list = enumeratingCodeDefn.getList();
Survey survey = record.getSurvey();
CodeListService codeListService = survey.getContext().getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(list);
int i = 0;
for (CodeListItem item : items) {
if (version == null || version.isApplicable(item)) {
String code = item.getCode();
Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
if (enumeratedEntity == null) {
Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
addEmptyNodes(addedEntity);
// set the value of the key CodeAttribute
CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
addedCode.setValue(new Code(code));
addedCode.updateSummaryInfo();
} else if (enumeratedEntity.getIndex() != i) {
parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
}
i++;
}
}
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdater method moveNode.
public void moveNode(CollectRecord record, int nodeId, int index) {
Node<?> node = record.getNodeByInternalId(nodeId);
Entity parent = node.getParent();
List<Node<?>> siblings = parent.getChildren(node.getDefinition());
int oldIndex = siblings.indexOf(node);
parent.move(node.getDefinition(), oldIndex, index);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordValidationCache method getTotalMissingCount.
protected int getTotalMissingCount(Map<Integer, Set<NodeDefinition>> nodeDefsByEntityId) {
int result = 0;
Set<Integer> keySet = nodeDefsByEntityId.keySet();
for (Integer id : keySet) {
Entity entity = (Entity) record.getNodeByInternalId(id);
Set<NodeDefinition> nodeDefs = nodeDefsByEntityId.get(id);
for (NodeDefinition childDef : nodeDefs) {
int missingCount = entity.getMissingCount(childDef);
result += missingCount;
}
}
return result;
}
use of org.openforis.idm.model.Entity 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;
}
Aggregations