Search in sources :

Example 51 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class NodeDefinitionProxy method fromList.

static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
    List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
    if (list != null) {
        for (NodeDefinition n : list) {
            NodeDefinitionProxy p = null;
            CollectSurvey survey = (CollectSurvey) n.getSurvey();
            UIOptions uiOptions = survey.getUIOptions();
            boolean hidden = uiOptions.isHidden(n);
            if (!hidden) {
                if (n instanceof AttributeDefinition) {
                    if (n instanceof BooleanAttributeDefinition) {
                        p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
                    } else if (n instanceof CodeAttributeDefinition) {
                        p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
                    } else if (n instanceof CoordinateAttributeDefinition) {
                        p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
                    } else if (n instanceof DateAttributeDefinition) {
                        p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
                    } else if (n instanceof FileAttributeDefinition) {
                        p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
                    } else if (n instanceof NumberAttributeDefinition) {
                        p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
                    } else if (n instanceof RangeAttributeDefinition) {
                        p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
                    } else if (n instanceof TaxonAttributeDefinition) {
                        p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
                    } else if (n instanceof TextAttributeDefinition) {
                        p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
                    } else if (n instanceof TimeAttributeDefinition) {
                        p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
                    } else {
                        throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
                    }
                } else if (n instanceof EntityDefinition) {
                    p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
                }
                if (p != null) {
                    proxies.add(p);
                }
            }
        }
    }
    return proxies;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Example 52 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class UIFieldView method getAttributeType.

public String getAttributeType() {
    AttributeDefinition attrDef = uiObject.getAttributeDefinition();
    AttributeType attrType = AttributeType.valueOf(attrDef);
    return attrType.name();
}
Also used : AttributeType(org.openforis.collect.designer.metamodel.AttributeType) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 53 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class SchemaProxy method getKeyAttributeDefinitionIdsByRootEntityId.

@ExternalizedProperty
public Map<Integer, List<Integer>> getKeyAttributeDefinitionIdsByRootEntityId() {
    Map<Integer, List<Integer>> result = new HashMap<Integer, List<Integer>>();
    List<EntityDefinition> rootEntityDefinitions = schema.getRootEntityDefinitions();
    for (EntityDefinition rootEntity : rootEntityDefinitions) {
        List<Integer> keyDefnIds = new ArrayList<Integer>();
        List<AttributeDefinition> keyDefns = rootEntity.getKeyAttributeDefinitions();
        for (AttributeDefinition keyDefn : keyDefns) {
            keyDefnIds.add(keyDefn.getId());
        }
        result.put(rootEntity.getId(), keyDefnIds);
    }
    return result;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) List(java.util.List) ArrayList(java.util.ArrayList) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 54 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition 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);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) FieldValueKey(org.openforis.collect.io.data.DataLine.FieldValueKey) Schema(org.openforis.idm.metamodel.Schema) Node(org.openforis.idm.model.Node) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entry(java.util.Map.Entry)

Example 55 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class DataCSVReader method getKeyAttributeColumnNames.

protected static String[] getKeyAttributeColumnNames(EntityDefinition parentEntityDefinition, List<AttributeDefinition> ancestorKeyAttrDefns) {
    List<String> result = new ArrayList<String>(ancestorKeyAttrDefns.size());
    for (int i = 0; i < ancestorKeyAttrDefns.size(); i++) {
        AttributeDefinition attrDefn = ancestorKeyAttrDefns.get(i);
        result.addAll(getKeyAttributeColumnNames(parentEntityDefinition, attrDefn));
    }
    return result.toArray(new String[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8