use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttribute method getCodeListItem.
/**
* @deprecated Access code list items using manager class.
*
* @return
*/
@Deprecated
public CodeListItem getCodeListItem() {
Code code = getValue();
if (code != null) {
String codeValue = code.getCode();
if (StringUtils.isNotBlank(codeValue)) {
ModelVersion currentVersion = getRecord().getVersion();
CodeAttributeDefinition definition = getDefinition();
String parentExpression = definition.getParentExpression();
if (StringUtils.isBlank(parentExpression)) {
return findCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
} else {
CodeAttribute codeParent = getCodeParent();
if (codeParent != null) {
CodeListItem codeListItemParent = codeParent.getCodeListItem();
if (codeListItemParent != null) {
return findCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
}
}
}
}
}
return null;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeDefinitionPR method onStartDefinition.
@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
super.onStartDefinition();
String parent = getAttribute(PARENT, false);
Boolean strict = getBooleanAttribute(STRICT, false);
String listName = getAttribute(LIST, true);
Boolean allowValuesSorting = getBooleanAttribute(ALLOW_VALUES_SORTING, false);
CodeAttributeDefinition defn = (CodeAttributeDefinition) getDefinition();
defn.setParentExpression(parent);
defn.setAllowUnlisted(strict == null ? false : !strict);
defn.setListName(listName);
defn.setAllowValuesSorting(allowValuesSorting == null ? false : allowValuesSorting.booleanValue());
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeVM method openParentAttributeSelector.
@Command
public void openParentAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
String title = Labels.getLabel("survey.schema.attribute.code.select_parent_for_node", new String[] { editedItem.getName() });
final Collection<CodeAttributeDefinition> assignableParentAttributes = editedItem.getAssignableParentCodeAttributeDefinitions();
if (assignableParentAttributes.isEmpty()) {
MessageUtil.showWarning("survey.schema.attribute.code.no_assignable_parent_available");
} else {
CodeAttributeDefinition parentCodeAttributeDefinition = ((CodeAttributeDefinitionFormObject) formObject).getParentCodeAttributeDefinition();
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return item instanceof UITab || item instanceof EntityDefinition || item instanceof CodeAttributeDefinition && assignableParentAttributes.contains(item);
}
};
Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return !(item instanceof CodeAttributeDefinition);
}
};
final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, parentCodeAttributeDefinition, true);
parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
CodeAttributeDefinition parentAttrDefn = (CodeAttributeDefinition) event.getSelectedItem();
CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) formObject;
fo.setParentCodeAttributeDefinition(parentAttrDefn);
String hierarchicalLevel = getHierarchicalLevelName(parentAttrDefn);
fo.setHierarchicalLevel(hierarchicalLevel);
notifyChange("formObject");
dispatchApplyChangesCommand(binder);
notifyChange("dependentCodePaths");
closePopUp(parentSelectorPopUp);
}
});
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeAttributeVM method getDependentCodePaths.
public String getDependentCodePaths() {
if (newItem) {
return null;
} else {
StringBuilder sb = new StringBuilder();
Collection<CodeAttributeDefinition> dependents = editedItem.getDependentCodeAttributeDefinitions();
Iterator<CodeAttributeDefinition> it = dependents.iterator();
while (it.hasNext()) {
CodeAttributeDefinition dependent = it.next();
sb.append(dependent.getPath());
if (it.hasNext()) {
sb.append(", ");
}
}
return sb.toString();
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeListsVM method getReferences.
protected List<NodeDefinition> getReferences(CodeList 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 CodeAttributeDefinition) {
CodeList list = ((CodeAttributeDefinition) defn).getList();
if (list.equals(item)) {
references.add(defn);
}
}
;
}
return references;
}
Aggregations