Search in sources :

Example 1 with AttributeDefinition

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

the class ValidationMessageBuilder method getMessageArgs.

protected String[] getMessageArgs(Attribute<?, ?> attribute, ValidationResult validationResult, Locale locale) {
    ValidationRule<?> validator = validationResult.getValidator();
    if (validator instanceof ComparisonCheck) {
        ComparisonCheck check = (ComparisonCheck) validator;
        ArrayList<String> args = new ArrayList<String>();
        String labelText = getPrettyLabelText(attribute.getDefinition(), locale);
        args.add(labelText);
        Map<String, String> expressions = new HashMap<String, String>();
        expressions.put("lt", check.getLessThanExpression());
        expressions.put("lte", check.getLessThanOrEqualsExpression());
        expressions.put("gt", check.getGreaterThanExpression());
        expressions.put("gte", check.getGreaterThanOrEqualsExpression());
        for (String key : expressions.keySet()) {
            String expression = expressions.get(key);
            if (expression != null) {
                String argPart1 = key;
                String argPart2 = getComparisonCheckMessageArg(attribute, expression, locale);
                String arg = StringUtils.join(argPart1, MULTIPLE_MESSAGE_ARGS_SEPARATOR, argPart2);
                args.add(arg);
            }
        }
        return args.toArray(new String[args.size()]);
    } else if (validator instanceof EntityKeyValidator) {
        EntityDefinition parentDefn = attribute.getDefinition().getParentEntityDefinition();
        String parentLabel = getPrettyLabelText(parentDefn, locale.getLanguage());
        List<AttributeDefinition> keyDefns = parentDefn.getKeyAttributeDefinitions();
        List<String> keyDefnLabels = new ArrayList<String>(keyDefns.size());
        for (AttributeDefinition keyDefn : keyDefns) {
            keyDefnLabels.add(getPrettyLabelText(keyDefn, locale.getLanguage()));
        }
        // TODO localize separator
        return new String[] { parentLabel, StringUtils.join(keyDefnLabels, ", ") };
    } else {
        return null;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) HashMap(java.util.HashMap) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) EntityKeyValidator(org.openforis.idm.metamodel.validation.EntityKeyValidator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with AttributeDefinition

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

the class ValidationMessageBuilder method getKeyText.

public String getKeyText(Entity entity, Locale locale) {
    EntityDefinition defn = entity.getDefinition();
    List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
    if (!keyDefns.isEmpty()) {
        List<String> shortKeyParts = new ArrayList<String>();
        List<String> fullKeyParts = new ArrayList<String>();
        for (AttributeDefinition keyDefn : keyDefns) {
            Attribute<?, ?> keyAttr = (Attribute<?, ?>) entity.getChild(keyDefn, 0);
            if (keyAttr != null) {
                Object keyValue = getKeyLabelPart(keyAttr);
                if (keyValue != null && StringUtils.isNotBlank(keyValue.toString())) {
                    shortKeyParts.add(keyValue.toString());
                    String label = getPrettyLabelText(keyDefn, locale);
                    String fullKeyPart = label + " " + keyValue;
                    fullKeyParts.add(fullKeyPart);
                }
            }
        }
        return StringUtils.join(shortKeyParts, RECORD_KEYS_LABEL_SEPARATOR);
    } else if (entity.getParent() != null) {
        return "" + (entity.getIndex() + 1);
    } else {
        return null;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Attribute(org.openforis.idm.model.Attribute) TaxonAttribute(org.openforis.idm.model.TaxonAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 3 with AttributeDefinition

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

the class CollectValidator method isRootEntityKey.

private boolean isRootEntityKey(Attribute<?, ?> attribute) {
    AttributeDefinition attrDef = attribute.getDefinition();
    if (attrDef.isKey()) {
        Record record = attribute.getRecord();
        Entity rootEntity = record.getRootEntity();
        EntityDefinition rootEntityDef = rootEntity.getDefinition();
        List<AttributeDefinition> keyAttributeDefs = rootEntityDef.getKeyAttributeDefinitions();
        for (AttributeDefinition keyDef : keyAttributeDefs) {
            if (keyDef.getId() == attrDef.getId()) {
                return true;
            }
        }
    }
    return false;
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Record(org.openforis.idm.model.Record) CollectRecord(org.openforis.collect.model.CollectRecord)

Example 4 with AttributeDefinition

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

the class CollectValidator method isReasonBlankAlwaysSpecified.

static boolean isReasonBlankAlwaysSpecified(Attribute<?, ?> attribute) {
    int fieldCount = 0;
    // ignore unit for numeric attributes
    if (attribute instanceof NumberAttribute || attribute instanceof CodeAttribute) {
        fieldCount = 1;
    } else if (attribute instanceof NumericRangeAttribute) {
        fieldCount = 2;
    } else {
        fieldCount = attribute.getFieldCount();
    }
    AttributeDefinition defn = attribute.getDefinition();
    CollectSurvey survey = (CollectSurvey) defn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    for (int i = 0; i < fieldCount; i++) {
        Field<?> field = attribute.getField(i);
        boolean visible = uiOptions.isVisibleField(defn, field.getName());
        if (visible) {
            FieldSymbol symbol = FieldSymbol.valueOf(field.getSymbol());
            if (symbol == null || !symbol.isReasonBlank()) {
                return false;
            }
        }
    }
    return true;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) FieldSymbol(org.openforis.collect.model.FieldSymbol) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NumberAttribute(org.openforis.idm.model.NumberAttribute) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 5 with AttributeDefinition

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

the class Mondrian4SchemaGenerator method createCube.

private Cube createCube(DataTable dataTable) {
    NodeDefinition nodeDef = dataTable.getNodeDefinition();
    Cube cube = new Cube();
    cube.name = nodeDef.getName();
    MeasureGroups measureGroups = new MondrianDef.MeasureGroups();
    MeasureGroup measureGroup = new MeasureGroup();
    measureGroup.name = cube.name;
    Measures measures = new Measures();
    List<Measure> measureList = createMeasures(dataTable);
    measures.list().addAll(measureList);
    measureGroup.children.add(measures);
    measureGroup.table = dataTable.getName();
    DimensionLinks dimensionLinks = new DimensionLinks();
    measureGroup.children.add(dimensionLinks);
    measureGroups.list().add(measureGroup);
    cube.children.add(measureGroups);
    if (nodeDef instanceof EntityDefinition) {
        Dimensions dimensions = new Dimensions();
        Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
        queue.addAll(((EntityDefinition) nodeDef).getChildDefinitions());
        while (!queue.isEmpty()) {
            NodeDefinition def = queue.poll();
            if (def instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                Dimension dimension = createDimension(dataTable, attrDef);
                if (dimension != null) {
                    dimensions.list().add(dimension);
                    // add dimension link
                    DimensionLink dimensionLink = createDimensionLink(dimension, attrDef);
                    dimensionLinks.list().add(dimensionLink);
                }
            } else if (!def.isMultiple()) {
                queue.addAll(((EntityDefinition) def).getChildDefinitions());
            }
        }
        cube.children.add(dimensions);
    }
    return cube;
}
Also used : MeasureGroup(mondrian.olap.MondrianDef.MeasureGroup) DimensionLinks(mondrian.olap.MondrianDef.DimensionLinks) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Dimensions(mondrian.olap.MondrianDef.Dimensions) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Dimension(mondrian.olap.MondrianDef.Dimension) LinkedList(java.util.LinkedList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Measures(mondrian.olap.MondrianDef.Measures) Cube(mondrian.olap.MondrianDef.Cube) Measure(mondrian.olap.MondrianDef.Measure) MeasureGroups(mondrian.olap.MondrianDef.MeasureGroups) DimensionLink(mondrian.olap.MondrianDef.DimensionLink)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8