use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class DatabaseExternalCodeListProvider method getLevelKeyColumnName.
protected String getLevelKeyColumnName(CodeAttribute codeAttribute) {
CodeAttributeDefinition defn = codeAttribute.getDefinition();
CodeList list = defn.getList();
if (list.getHierarchy().isEmpty()) {
return defn.getName();
} else {
int level = defn.getLevelPosition();
return getLevelKeyColumnName(list, level);
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class BaseAttributeUpdateRequestProxy method parseCompositeAttributeValue.
protected Value parseCompositeAttributeValue(CodeListManager codeListManager, Entity parentEntity, String attributeName, Object value) {
EntityDefinition parentEntityDefn = parentEntity.getDefinition();
AttributeDefinition defn = (AttributeDefinition) parentEntityDefn.getChildDefinition(attributeName);
if (defn instanceof CodeAttributeDefinition) {
if (value instanceof String) {
String stringVal = (String) value;
Value result = parseCode(codeListManager, parentEntity, (CodeAttributeDefinition) defn, stringVal);
return result;
} else {
throw new IllegalArgumentException("Invalid value type: expected String");
}
} else if (defn instanceof RangeAttributeDefinition) {
if (value instanceof String) {
String stringVal = (String) value;
RangeAttributeDefinition rangeDef = (RangeAttributeDefinition) defn;
RangeAttributeDefinition.Type type = rangeDef.getType();
NumericRange<?> range = null;
// todo check if unit is required here or is set later by the client
Unit unit = null;
switch(type) {
case INTEGER:
range = IntegerRange.parseIntegerRange(stringVal, unit);
break;
case REAL:
range = RealRange.parseRealRange(stringVal, unit);
break;
}
return range;
} else {
throw new IllegalArgumentException("Invalid value type: expected String");
}
} else {
throw new IllegalArgumentException("Invalid AttributeDefinition: expected CodeAttributeDefinition or RangeAttributeDefinition");
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class SurveyViewGenerator method generateView.
public SurveyView generateView(final CollectSurvey survey) {
final SurveyView surveyView = new SurveyView(survey);
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList codeList : codeLists) {
CodeListView codeListView = new CodeListView();
codeListView.setId(codeList.getId());
codeListView.setName(codeList.getName());
codeListView.setLabel(codeList.getLabel(CodeListLabel.Type.ITEM, languageCode));
if (includeCodeListValues && !codeList.isExternal()) {
CodeListService service = survey.getContext().getCodeListService();
List<CodeListItem> items = service.loadRootItems(codeList);
for (CodeListItem item : items) {
codeListView.addItem(createCodeListItemView(item));
}
}
surveyView.addCodeList(codeListView);
}
final Map<Integer, NodeDefView> viewById = new HashMap<Integer, NodeDefView>();
survey.getSchema().traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
int id = def.getId();
String name = def.getName();
String label = getLabel(def);
NodeDefView view;
if (def instanceof EntityDefinition) {
view = new EntityDefView(((EntityDefinition) def).isRoot(), id, name, label, def.isMultiple());
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition attrDef = (CodeAttributeDefinition) def;
int codeListId = attrDef.getList() == null ? -1 : attrDef.getList().getId();
view = new CodeAttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef), codeListId);
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
view = new AttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef));
}
NodeDefinition parentDef = def.getParentDefinition();
if (parentDef == null) {
surveyView.getSchema().addRootEntity((EntityDefView) view);
} else {
EntityDefView parentView = (EntityDefView) viewById.get(parentDef.getId());
parentView.addChild(view);
}
viewById.put(id, view);
}
});
return surveyView;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeParentValidator method isExternalCodeList.
private boolean isExternalCodeList(CodeAttribute node) {
CodeAttributeDefinition definition = node.getDefinition();
CodeList codeList = definition.getList();
return codeList.isExternal();
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeValueFKColumnValueExtractor method extractValue.
@Override
public Object extractValue(Node<?> context) {
CodeAttributeDefinition defn = (CodeAttributeDefinition) column.getNodeDefinition();
Node<?> valNode = super.extractValueNode(context);
if (valNode != null && valNode instanceof CodeAttribute) {
return extractValue((CodeAttribute) valNode);
} else if (column.getDefaultCodeValue() != null) {
ModelVersion version = context.getRecord().getVersion();
return getDefaultCodeItemId(((CodeAttributeDefinition) defn).getList(), version);
} else {
return null;
}
}
Aggregations