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);
}
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;
}
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);
}
}
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)));
}
}
}
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;
}
Aggregations