Search in sources :

Example 36 with AttributeDefinition

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

the class RecordGenerator method generate.

@Transactional
public CollectRecord generate(int surveyId, NewRecordParameters parameters, List<String> recordKeyValues) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    List<AttributeDefinition> keyDefs = getKeyAttributeDefs(survey);
    RecordKey recordKey = new RecordKey(keyDefs, recordKeyValues);
    return generate(surveyId, parameters, recordKey);
}
Also used : AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with AttributeDefinition

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

the class RecordGenerator method getMeasurementKeyDefs.

protected List<AttributeDefinition> getMeasurementKeyDefs(CollectSurvey survey) {
    List<AttributeDefinition> keyAttrDefs = getKeyAttributeDefs(survey);
    List<AttributeDefinition> measurementKeyAttrDefs = new ArrayList<AttributeDefinition>();
    for (AttributeDefinition keyAttrDef : keyAttrDefs) {
        if (survey.getAnnotations().isMeasurementAttribute(keyAttrDef)) {
            measurementKeyAttrDefs.add(keyAttrDef);
        }
    }
    return measurementKeyAttrDefs;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 38 with AttributeDefinition

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

the class RecordGenerator method setRecordKeyValues.

private void setRecordKeyValues(CollectRecord record, RecordKey recordKey) {
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    List<AttributeDefinition> keyAttributeDefs = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
    for (AttributeDefinition keyAttrDef : keyAttributeDefs) {
        String keyPart = recordKey.getValue(keyAttrDef.getPath());
        Attribute<?, Value> keyAttribute = record.findNodeByPath(keyAttrDef.getPath());
        Value value = keyAttrDef.createValue(keyPart);
        recordUpdater.updateAttribute(keyAttribute, value);
    }
}
Also used : Value(org.openforis.idm.model.Value) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 39 with AttributeDefinition

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

the class RecordGenerator method addSecondLevelEntities.

private void addSecondLevelEntities(CollectRecord record, RecordKey recordKey) {
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    List<String> keyValues = recordKey.getValues(nonMeasurementKeyDefs);
    List<SamplingDesignItem> secondLevelSamplingPointItems = samplingDesignManager.loadChildItems(survey.getId(), keyValues);
    List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = findSamplingPointCodeAttributes(survey);
    if (!secondLevelSamplingPointItems.isEmpty() && samplingPointDataCodeAttributeDefs.size() > 1) {
        int levelIndex = 1;
        for (SamplingDesignItem samplingDesignItem : secondLevelSamplingPointItems) {
            CodeAttributeDefinition levelKeyDef = samplingPointDataCodeAttributeDefs.get(levelIndex);
            EntityDefinition levelEntityDef = levelKeyDef.getParentEntityDefinition();
            Entity parentLevelEntity = record.getRootEntity();
            NodeChangeSet addEntityChangeSet = recordUpdater.addEntity(parentLevelEntity, levelEntityDef);
            Entity entity = getAddedEntity(addEntityChangeSet);
            CodeAttribute keyAttr = entity.getChild(levelKeyDef);
            recordUpdater.updateAttribute(keyAttr, new Code(samplingDesignItem.getLevelCode(levelIndex + 1)));
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Code(org.openforis.idm.model.Code) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 40 with AttributeDefinition

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

the class CollectEarthGridTemplateGenerator method getAttributesPerRow.

private List<AttributeDefinition> getAttributesPerRow(CollectSurvey survey) {
    List<AttributeDefinition> expectedColumns = new ArrayList<AttributeDefinition>();
    List<AttributeDefinition> keyAttributeDefinitions = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
    expectedColumns.addAll(keyAttributeDefinitions);
    NumberAttributeDefinition latAttribute = survey.getSchema().createNumberAttributeDefinition();
    latAttribute.setType(Type.REAL);
    latAttribute.setName(LAT_COORDINATE);
    latAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Latitude");
    expectedColumns.add(latAttribute);
    NumberAttributeDefinition longAttribute = survey.getSchema().createNumberAttributeDefinition();
    longAttribute.setType(Type.REAL);
    longAttribute.setName(LONG_COORDINATE);
    longAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Longitude");
    expectedColumns.add(longAttribute);
    List<AttributeDefinition> fromCsvAttributes = survey.getExtendedDataFields();
    expectedColumns.addAll(fromCsvAttributes);
    return expectedColumns;
}
Also used : ArrayList(java.util.ArrayList) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

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