Search in sources :

Example 31 with ModelVersion

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;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code)

Example 32 with ModelVersion

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);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttribute(org.openforis.idm.model.CodeAttribute) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 33 with ModelVersion

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;
}
Also used : ArrayList(java.util.ArrayList) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 34 with ModelVersion

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);
            }
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Example 35 with ModelVersion

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;
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Aggregations

ModelVersion (org.openforis.idm.metamodel.ModelVersion)40 ArrayList (java.util.ArrayList)9 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)9 Record (org.openforis.idm.model.Record)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)7 CodeListItem (org.openforis.idm.metamodel.CodeListItem)7 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 Code (org.openforis.idm.model.Code)4 Entity (org.openforis.idm.model.Entity)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 Survey (org.openforis.idm.metamodel.Survey)2 NodePointer (org.openforis.idm.model.NodePointer)2 Command (org.zkoss.bind.annotation.Command)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2