Search in sources :

Example 16 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.

the class RecordGenerator method addSecondLevelEntities.

private void addSecondLevelEntities(CollectRecord record, RecordKey recordKey) {
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    List<String> keyValues = recordKey.getValues(nonMeasurementKeyDefs);
    List<SamplingDesignItem> secondLevelSamplingPointItems = samplingDesignManager.loadChildItems(survey.getId(), keyValues);
    List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = findSamplingPointCodeAttributes(survey);
    if (!secondLevelSamplingPointItems.isEmpty() && samplingPointDataCodeAttributeDefs.size() > 1) {
        int levelIndex = 1;
        for (SamplingDesignItem samplingDesignItem : secondLevelSamplingPointItems) {
            CodeAttributeDefinition levelKeyDef = samplingPointDataCodeAttributeDefs.get(levelIndex);
            EntityDefinition levelEntityDef = levelKeyDef.getParentEntityDefinition();
            Entity parentLevelEntity = record.getRootEntity();
            NodeChangeSet addEntityChangeSet = recordUpdater.addEntity(parentLevelEntity, levelEntityDef);
            Entity entity = getAddedEntity(addEntityChangeSet);
            CodeAttribute keyAttr = entity.getChild(levelKeyDef);
            recordUpdater.updateAttribute(keyAttr, new Code(samplingDesignItem.getLevelCode(levelIndex + 1)));
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Code(org.openforis.idm.model.Code) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 17 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.

the class CodeListManager method isInUse.

public boolean isInUse(final CodeList list) {
    Survey survey = list.getSurvey();
    Schema schema = survey.getSchema();
    NodeDefinition attrDefnUsingCodeList = schema.findNodeDefinition(new NodeDefinitionVerifier() {

        @Override
        public boolean verify(NodeDefinition definition) {
            return definition instanceof CodeAttributeDefinition && ((CodeAttributeDefinition) definition).getList() == list;
        }
    });
    return attrDefnUsingCodeList != null;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVerifier(org.openforis.idm.metamodel.NodeDefinitionVerifier)

Example 18 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.

the class CollectEarthGridTemplateGenerator method getFirstAvailableCodeItem.

private CodeListItem getFirstAvailableCodeItem(AttributeDefinition attrDef) {
    CodeAttributeDefinition codeDefn = (CodeAttributeDefinition) attrDef;
    CodeList list = codeDefn.getList();
    CodeListService codeListService = attrDef.getSurvey().getContext().getCodeListService();
    Integer levelIndex = codeDefn.getListLevelIndex();
    int levelPosition = levelIndex == null ? 1 : levelIndex + 1;
    List<CodeListItem> items;
    if (levelPosition == 1) {
        items = codeListService.loadRootItems(list);
    } else {
        items = codeListService.loadItems(list, levelPosition);
    }
    if (items.isEmpty()) {
        return null;
    } else {
        return items.get(0);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 19 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.

the class CollectEarthGridTemplateGenerator method getDummyValue.

private String getDummyValue(AttributeDefinition attrDef, Integer ord) {
    String attrName = attrDef.getName();
    String value;
    if (attrDef instanceof NumericAttributeDefinition || attrDef instanceof BooleanAttributeDefinition) {
        value = "0";
        if (ord != null) {
            value = ord + "";
        }
    } else if (attrDef instanceof DateAttributeDefinition) {
        value = "1/1/2000";
    } else if (attrDef instanceof CodeAttributeDefinition) {
        CodeListItem firstAvailableItem = getFirstAvailableCodeItem(attrDef);
        value = firstAvailableItem == null ? "0" : firstAvailableItem.getCode();
    } else {
        value = attrName;
        if (ord != null) {
            value += "_" + ord;
        }
    }
    return value;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 20 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.

the class RecordUpdater method addEmptyEnumeratedEntities.

private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
    Record record = parentEntity.getRecord();
    ModelVersion version = record.getVersion();
    CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
    if (enumeratingCodeDefn != null) {
        CodeList list = enumeratingCodeDefn.getList();
        Survey survey = record.getSurvey();
        CodeListService codeListService = survey.getContext().getCodeListService();
        List<CodeListItem> items = codeListService.loadRootItems(list);
        int i = 0;
        for (CodeListItem item : items) {
            if (version == null || version.isApplicable(item)) {
                String code = item.getCode();
                Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
                if (enumeratedEntity == null) {
                    Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
                    addEmptyNodes(addedEntity);
                    // set the value of the key CodeAttribute
                    CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
                    addedCode.setValue(new Code(code));
                    addedCode.updateSummaryInfo();
                } else if (enumeratedEntity.getIndex() != i) {
                    parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
                }
                i++;
            }
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) CodeListService(org.openforis.idm.metamodel.CodeListService) Code(org.openforis.idm.model.Code) CodeList(org.openforis.idm.metamodel.CodeList) Survey(org.openforis.idm.metamodel.Survey) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)48 CodeList (org.openforis.idm.metamodel.CodeList)21 CodeListItem (org.openforis.idm.metamodel.CodeListItem)19 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)13 ArrayList (java.util.ArrayList)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)8 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)8 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)7 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)7 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)6 ModelVersion (org.openforis.idm.metamodel.ModelVersion)6 Code (org.openforis.idm.model.Code)6 Entity (org.openforis.idm.model.Entity)6 DataTable (org.openforis.collect.relational.model.DataTable)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeTable (org.openforis.collect.relational.model.CodeTable)4 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)4