use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class UIModelObject method getNodeDefinition.
protected NodeDefinition getNodeDefinition(int id) {
UIConfiguration uiConfiguration = getUIConfiguration();
if (uiConfiguration == null || uiConfiguration.getSurvey() == null) {
throw new IllegalStateException("UIConfiguration not initialized correctly");
}
CollectSurvey survey = uiConfiguration.getSurvey();
Schema schema = survey.getSchema();
NodeDefinition result = schema.getDefinitionById(id);
return result;
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class UIOptions method getRootEntityDefinition.
public EntityDefinition getRootEntityDefinition(UITabSet tabSet) {
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntityDefinitions = schema.getRootEntityDefinitions();
for (EntityDefinition defn : rootEntityDefinitions) {
UITabSet entityTabSet = getAssignedRootTabSet(defn);
if (entityTabSet != null && entityTabSet.equals(tabSet)) {
return defn;
}
}
return null;
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class UIOptionsMigrator method findAssociatedRootEntity.
protected EntityDefinition findAssociatedRootEntity(UITabSet tabSet) {
UIOptions uiOptions = tabSet.getUIOptions();
CollectSurvey survey = uiOptions.getSurvey();
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntityDefinitions = schema.getRootEntityDefinitions();
for (EntityDefinition rootEntityDefn : rootEntityDefinitions) {
UITabSet assignedRootTabSet = uiOptions.getAssignedRootTabSet(rootEntityDefn);
if (ObjectUtils.equals(assignedRootTabSet, tabSet)) {
return rootEntityDefn;
}
}
return null;
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class CSVDataExportProcess method getEntitiesToExport.
private Collection<EntityDefinition> getEntitiesToExport() {
final Collection<EntityDefinition> result = new ArrayList<EntityDefinition>();
Schema schema = recordFilter.getSurvey().getSchema();
if (entityId == null) {
EntityDefinition rootEntity = schema.getRootEntityDefinition(recordFilter.getRootEntityId());
rootEntity.traverse(new NodeDefinitionVisitor() {
@Override
public void visit(NodeDefinition node) {
if (node instanceof EntityDefinition && node.isMultiple()) {
result.add((EntityDefinition) node);
}
}
});
} else {
EntityDefinition entity = (EntityDefinition) schema.getDefinitionById(entityId);
result.add(entity);
}
return result;
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class CSVDataImportProcess method setValuesInAttributes.
private void setValuesInAttributes(Entity ancestorEntity, Map<FieldValueKey, String> fieldValues, Map<FieldValueKey, String> colNameByField, long row) {
Set<Entry<FieldValueKey, String>> entrySet = fieldValues.entrySet();
// delete all multiple attributes
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
if (attrDefn.isMultiple()) {
List<Node<?>> attributes = parentEntity.getChildren(attrDefn);
int tot = attributes.size();
for (int i = 0; i < tot; i++) {
Node<?> node = attributes.get(0);
NodeChangeSet changes = recordUpdater.deleteNode(node);
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
}
}
}
// set values
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
String strValue = entry.getValue();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
String fieldName = fieldValueKey.getFieldName();
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
String colName = colNameByField.get(fieldValueKey);
int attrPos = fieldValueKey.getAttributePosition();
setValueInField(parentEntity, attrDefn, attrPos - 1, fieldName, strValue, colName, row);
}
}
Aggregations