use of org.openforis.idm.metamodel.ModelVersion 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;
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class CodeListManager method loadValidItems.
public <T extends CodeListItem> List<T> loadValidItems(Entity parent, CodeAttributeDefinition def) {
List<T> items = null;
CodeList list = def.getList();
if (StringUtils.isEmpty(def.getParentExpression())) {
items = loadRootItems(list);
} else {
CodeAttribute parentCodeAttribute = getCodeParent(parent, def);
if (parentCodeAttribute != null) {
CodeListItem parentCodeListItem = loadItemByAttribute(parentCodeAttribute);
if (parentCodeListItem != null) {
items = loadChildItems(parentCodeListItem);
}
}
}
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
return filterApplicableItems(items, version);
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class CodeListManager method findValidItems.
public List<CodeListItem> findValidItems(Entity parent, CodeAttributeDefinition defn, String... codes) {
List<CodeListItem> result = new ArrayList<CodeListItem>();
List<CodeListItem> assignableItems = loadValidItems(parent, defn);
if (!assignableItems.isEmpty()) {
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
for (String code : codes) {
CodeListItem item = findCodeListItem(assignableItems, code, version);
if (item != null) {
result.add(item);
}
}
}
return result;
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
EntityDefinition parentEntityDefn = parentEntity.getDefinition();
List<NodeDefinition> childDefinitions = parentEntityDefn.getChildDefinitionsInVersion(version);
for (NodeDefinition childDefn : childDefinitions) {
if (childDefn instanceof EntityDefinition) {
EntityDefinition childEntityDefn = (EntityDefinition) childDefn;
if (childEntityDefn.isMultiple() && childEntityDefn.isEnumerable() && childEntityDefn.isEnumerate()) {
addEmptyEnumeratedEntities(parentEntity, childEntityDefn);
}
}
}
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class RecordUpdater method performEntityAdd.
private Entity performEntityAdd(Entity parentEntity, Entity entity, Integer idx) {
if (idx == null) {
parentEntity.add(entity);
} else {
parentEntity.add(entity, idx);
}
ModelVersion version = parentEntity.getRecord().getVersion();
for (NodeDefinition childDef : entity.getDefinition().getChildDefinitionsInVersion(version)) {
entity.setMinCount(childDef, calculateMinCount(entity, childDef));
entity.setMaxCount(childDef, calculateMaxCount(entity, childDef));
}
return entity;
}
Aggregations