use of org.openforis.idm.model.Entity in project collect by openforis.
the class EventProducerTest method testEntityCollectionAddedEvent.
@Test
public void testEntityCollectionAddedEvent() {
record(rootEntityDef(entityDef("plot", entityDef("tree", attributeDef("tree_count")).multiple()).multiple()));
assertEventTypes(updater.addEntity(record.getRootEntity(), "plot"), EntityCreatedEvent.class, EntityCollectionCreatedEvent.class);
Entity plot = entityByPath("/root/plot[1]");
assertEventTypes(updater.addEntity(plot, "tree"), EntityCreatedEvent.class, TextAttributeUpdatedEvent.class);
}
use of org.openforis.idm.model.Entity 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.model.Entity in project collect by openforis.
the class SingleFieldAttributeColumnProvider method getParentEntity.
/**
* Attribute definition can be inside nested single entities inside the axis.
* This method will look for the nearest parent entity for attributes to extract value for.
*/
private Entity getParentEntity(Entity axis) {
EntityDefinition entityDef = axis.getDefinition();
List<EntityDefinition> ancestorEntityDefinitions = attributeDefinition.getAncestorEntityDefinitionsInReverseOrder();
int indexOfAxis = ancestorEntityDefinitions.indexOf(entityDef);
Entity nearestParentEntity = axis;
if (indexOfAxis + 1 < ancestorEntityDefinitions.size()) {
List<EntityDefinition> relativeSingleEntityDefs = ancestorEntityDefinitions.subList(indexOfAxis + 1, ancestorEntityDefinitions.size());
for (EntityDefinition parentSingleEntityDef : relativeSingleEntityDefs) {
nearestParentEntity = (Entity) nearestParentEntity.getChild(parentSingleEntityDef);
}
}
return nearestParentEntity;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class SpeciesManager method extractQualifierValues.
protected String[] extractQualifierValues(TaxonAttribute attr) {
TaxonAttributeDefinition defn = attr.getDefinition();
List<String> qualifiers = defn.getQualifiers();
String[] qualifierValues = null;
if (qualifiers != null && !qualifiers.isEmpty()) {
qualifierValues = new String[qualifiers.size()];
Entity parent = attr.getParent();
for (int i = 0; i < qualifiers.size(); i++) {
String qualifierExpr = qualifiers.get(i);
try {
ModelPathExpression expression = expressionFactory.createModelPathExpression(qualifierExpr);
CodeAttribute code = (CodeAttribute) expression.evaluate(parent, null);
String qualifierValue = code.getValue().getCode();
qualifierValues[i] = qualifierValue;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Error evaluating taxon qualifiers: ", e);
}
break;
}
}
}
return qualifierValues;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordConverter method convertToLatestUnitStorage.
/**
* This is a workaround: it avoids to refer to the old unit field to get data
*
* TODO remove this conversion or apply only for records stored using version prior to 3.0 Alpha 5
*
* @param survey
* @param rootEntity
*/
protected void convertToLatestUnitStorage(CollectRecord record) {
final CollectSurvey survey = (CollectSurvey) record.getSurvey();
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
if (node instanceof NumberAttribute<?, ?> || node instanceof NumericRangeAttribute<?, ?>) {
Field<String> unitNameField;
Field<Integer> unitField;
if (node instanceof NumberAttribute<?, ?>) {
unitNameField = ((NumberAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumberAttribute<?, ?>) node).getUnitField();
} else {
unitNameField = ((NumericRangeAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumericRangeAttribute<?, ?>) node).getUnitField();
}
if (unitNameField.hasData()) {
moveDataToNewUnitField(survey, unitNameField, unitField);
}
}
}
});
}
Aggregations