Search in sources :

Example 21 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class CollectRecordIntegrationTest method testMultipleCodeListLevelValidation.

@Test
public void testMultipleCodeListLevelValidation() {
    CollectRecord record = createTestMultipleCodeListLevelRecord();
    assertEquals(Integer.valueOf(0), record.getErrors());
    assertEquals(Integer.valueOf(0), record.getWarnings());
    Entity rootEntity = record.getRootEntity();
    CodeAttribute code1 = (CodeAttribute) rootEntity.getChild("code1", 0);
    CodeAttribute code2 = (CodeAttribute) rootEntity.getChild("code2", 0);
    CodeAttribute code3 = (CodeAttribute) rootEntity.getChild("code3", 0);
    recordUpdater.updateAttribute(code1, new Code("WRONG"));
    assertEquals(Integer.valueOf(1), record.getErrors());
    assertEquals(Integer.valueOf(2), record.getWarnings());
    checkHasError(record, code1.getInternalId(), CodeValidator.class);
    checkHasWarning(record, code2.getInternalId(), CodeParentValidator.class);
    checkHasWarning(record, code3.getInternalId(), CodeParentValidator.class);
    recordUpdater.updateAttribute(code1, new Code("A"));
    assertEquals(Integer.valueOf(0), record.getErrors());
    assertEquals(Integer.valueOf(0), record.getWarnings());
    recordUpdater.updateAttribute(code2, new Code("WRONG"));
    assertEquals(Integer.valueOf(1), record.getErrors());
    assertEquals(Integer.valueOf(1), record.getWarnings());
    checkHasError(record, code2.getInternalId(), CodeValidator.class);
    checkHasWarning(record, code3.getInternalId(), CodeParentValidator.class);
}
Also used : Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 22 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class RequiredExpressionTest method testTrue.

@Test
public void testTrue() throws InvalidExpressionException {
    CodeAttribute region = EntityBuilder.addValue(cluster, "region", new Code("004"));
    String expr = "true()";
    boolean b = evaluateExpression(expr, region);
    Assert.assertTrue(b);
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 23 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class CodeValueFKColumnValueExtractor method extractValue.

@Override
public Object extractValue(Node<?> context) {
    CodeAttributeDefinition defn = (CodeAttributeDefinition) column.getNodeDefinition();
    Node<?> valNode = super.extractValueNode(context);
    if (valNode != null && valNode instanceof CodeAttribute) {
        return extractValue((CodeAttribute) valNode);
    } else if (column.getDefaultCodeValue() != null) {
        ModelVersion version = context.getRecord().getVersion();
        return getDefaultCodeItemId(((CodeAttributeDefinition) defn).getList(), version);
    } else {
        return null;
    }
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Example 24 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute 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 25 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute 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)

Aggregations

CodeAttribute (org.openforis.idm.model.CodeAttribute)28 Code (org.openforis.idm.model.Code)16 Test (org.junit.Test)13 Entity (org.openforis.idm.model.Entity)12 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)5 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeListItem (org.openforis.idm.metamodel.CodeListItem)4 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 AbstractTest (org.openforis.idm.AbstractTest)3 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)3 Node (org.openforis.idm.model.Node)3 List (java.util.List)2 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)2