use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeMapper method addNode.
@Override
CodeAttribute addNode(NodeDefinition defn, Record r, Entity parent) {
String name = defn.getName();
String qualifier = r.getValueAsString(DATA.TEXT2);
CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) defn;
CodeList list = codeAttrDefn.getList();
String code = r.getValueAsString(DATA.TEXT1);
Code value = new Code(code, qualifier);
return parent.addValue(name, value);
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeVM method confirmParentCodeListChange.
private void confirmParentCodeListChange(final Binder binder, final CodeList list) {
ConfirmParams confirmParams = new ConfirmParams(new MessageUtil.CompleteConfirmHandler() {
@Override
public void onOk() {
performListChange(binder, list);
}
@Override
public void onCancel() {
CodeList oldList = editedItem.getList();
setFormFieldValue(binder, "list", oldList);
setTempFormObjectFieldValue("list", oldList);
}
}, "survey.schema.attribute.code.confirm_change_list_on_referenced_node.message");
confirmParams.setOkLabelKey("survey.schema.attribute.code.confirm_change_list_on_referenced_node.ok");
confirmParams.setTitleKey("survey.schema.attribute.code.confirm_change_list_on_referenced_node.title");
List<String> dependentAttributePaths = new ArrayList<String>();
for (CodeAttributeDefinition codeAttributeDefinition : editedItem.getDependentCodeAttributeDefinitions()) {
dependentAttributePaths.add(codeAttributeDefinition.getPath());
}
confirmParams.setMessageArgs(new String[] { StringUtils.join(dependentAttributePaths, ", ") });
MessageUtil.showConfirm(confirmParams);
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeDefinitionFormValidator method validateParentAttributeDefinition.
private void validateParentAttributeDefinition(ValidationContext ctx) {
String parentCodeAttributeDefPath = getValue(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD);
if (parentCodeAttributeDefPath != null) {
CodeAttributeVM vm = getVM(ctx);
CollectSurvey survey = vm.getSurvey();
CodeAttributeDefinition parentDef = (CodeAttributeDefinition) survey.getSchema().getDefinitionByPath(parentCodeAttributeDefPath);
if (parentDef != null) {
CodeList list = getValue(ctx, LIST_FIELD);
if (list.isHierarchical()) {
try {
Integer parentHierarchicalLevelIdx = parentDef.getListLevelIndex();
if (parentHierarchicalLevelIdx + 1 >= list.getHierarchy().size()) {
addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.invalid_parent_attribute_relation"));
}
} catch (Exception e) {
addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.invalid_parent_attribute_relation_in_referenced_parent_attribute"));
}
} else {
addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.parent_attribute_specified_for_a_flat_list"));
}
}
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeListManager method loadPersistedItem.
protected PersistedCodeListItem loadPersistedItem(CodeAttribute attribute) {
Code code = attribute.getValue();
if (code == null || StringUtils.isBlank(code.getCode())) {
return null;
} else {
String codeVal = code.getCode();
CodeAttributeDefinition defn = attribute.getDefinition();
CodeList list = defn.getList();
Record record = attribute.getRecord();
ModelVersion version = record.getVersion();
if (StringUtils.isBlank(defn.getParentExpression())) {
CodeListItem item = codeListItemDao.loadRootItem(list, codeVal, version);
return (PersistedCodeListItem) item;
} else {
PersistedCodeListItem parentItem = (PersistedCodeListItem) loadParentItem(attribute);
if (parentItem == null) {
return null;
} else {
CodeListItem item = codeListItemDao.loadItem(list, parentItem.getSystemId(), codeVal, version);
return (PersistedCodeListItem) item;
}
}
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeListManager method getInternalCodeListItem.
protected CodeListItem getInternalCodeListItem(CodeAttribute attribute) {
Code code = attribute.getValue();
if (code != null) {
String codeValue = code.getCode();
if (StringUtils.isNotBlank(codeValue)) {
ModelVersion currentVersion = attribute.getRecord().getVersion();
CodeAttributeDefinition definition = attribute.getDefinition();
String parentExpression = definition.getParentExpression();
if (StringUtils.isBlank(parentExpression)) {
return getCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
} else {
CodeAttribute codeParent = attribute.getCodeParent();
if (codeParent != null) {
CodeListItem codeListItemParent = loadItemByAttribute(codeParent);
if (codeListItemParent != null) {
return getCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
}
}
}
}
}
return null;
}
Aggregations