use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CollectEarthBalloonGenerator method createComponent.
private CEComponent createComponent(NodeDefinition def, int entityPosition) {
String label = def.getLabel(Type.INSTANCE, language);
if (label == null && !isDefaultLanguage()) {
label = def.getLabel(Type.INSTANCE);
}
if (label == null) {
label = def.getName();
}
boolean multiple = def.isMultiple();
UIOptions uiOptions = survey.getUIOptions();
boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
CEComponent comp;
if (def instanceof EntityDefinition) {
if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
comp = createEnumeratedEntityComponent((EntityDefinition) def);
} else {
String tooltip = def.getDescription(language);
CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
fieldSet.addChild(createComponent(child));
}
}
comp = fieldSet;
}
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
String htmlParameterName;
boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
if (insideEnumeratedEntity) {
htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
} else {
htmlParameterName = getHtmlParameterName(def);
}
String tooltip = attrDef.getDescription(language);
CEFieldType type = getFieldType(def);
boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
if (insideEnumeratedEntity && key) {
comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
CodeList list = codeAttrDef.getList();
Integer listLevelIndex = codeAttrDef.getListLevelIndex();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
} else {
comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
}
CollectAnnotations annotations = survey.getAnnotations();
if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
((CEField) comp).setReadOnly(true);
}
}
comp.hideWhenNotRelevant = hideWhenNotRelevant;
componentByName.put(comp.getName(), comp);
return comp;
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class UnitsVM method getReferences.
protected List<NodeDefinition> getReferences(Unit item) {
List<NodeDefinition> references = new ArrayList<NodeDefinition>();
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
Stack<NodeDefinition> stack = new Stack<NodeDefinition>();
stack.addAll(rootEntities);
while (!stack.isEmpty()) {
NodeDefinition defn = stack.pop();
if (defn instanceof EntityDefinition) {
stack.addAll(((EntityDefinition) defn).getChildDefinitions());
} else if (defn instanceof NumericAttributeDefinition) {
List<Unit> units = ((NumericAttributeDefinition) defn).getUnits();
if (units.contains(item)) {
references.add(defn);
}
}
}
return references;
}
use of org.openforis.idm.metamodel.EntityDefinition 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.EntityDefinition in project collect by openforis.
the class RecordGenerator method createRecord.
private CollectRecord createRecord(CollectSurvey survey, User user, RecordKey recordKey) {
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
String rootEntityName = rootEntityDef.getName();
CollectRecord record = recordManager.create(survey, rootEntityName, user, null);
if (recordKey.isNotEmpty()) {
setRecordKeyValues(record, recordKey);
}
return record;
}
use of org.openforis.idm.metamodel.EntityDefinition 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;
}
Aggregations