Search in sources :

Example 1 with NodeDefinition

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

the class ValidationMessageBuilder method getMaxCountValidationMessage.

public String getMaxCountValidationMessage(Entity parentEntity, String childName, Locale locale) {
    EntityDefinition defn = parentEntity.getDefinition();
    NodeDefinition childDefn = defn.getChildDefinition(childName);
    Integer maxCount = parentEntity.getMaxCount(childDefn);
    Object[] args = new Integer[] { maxCount > 0 ? maxCount : 1 };
    String surveyDefaultLanguage = defn.getSurvey().getDefaultLanguage();
    String message = getMessage(surveyDefaultLanguage, locale, "validation.maxCount", args);
    return message;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 2 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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)

Example 3 with NodeDefinition

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

the class RelationalTransformer method initDataTableTransformations.

/**
 * Recursively init table transformations
 * @param defn
 */
private void initDataTableTransformations(EntityDefinition defn) {
    List<NodeDefinition> children = defn.getChildDefinitions();
    for (NodeDefinition child : children) {
        if (child instanceof EntityDefinition) {
            initDataTableTransformations((EntityDefinition) child);
        }
    }
    if (defn.isMultiple()) {
        Transformation xform = Transformation.createDefaultTransformation(defn);
        Path path = (Path) xform.getRowAxis();
        dataTransforms.put(path, xform);
        System.out.println(path);
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Transformation(org.openforis.idm.transform2.Transformation) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 4 with NodeDefinition

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

the class RelationalSchemaGenerator method addDataObjects.

/**
 * Recursively creates and adds tables and columns
 *
 * @param rs
 * @param parentTable
 * @param defn
 * @throws CollectRdbException
 */
private void addDataObjects(RelationalSchema rs, DataTable table, NodeDefinition defn, Path relativePath) throws CollectRdbException {
    if (defn instanceof EntityDefinition) {
        if (defn.isMultiple()) {
            // Create table for multiple entity
            table = createDataTable(rs, table, defn, relativePath);
            rs.addTable(table);
        } else {
            // just keep a reference
            rs.assignAncestorTable((EntityDefinition) defn);
        }
        // Add child tables and columns
        EntityDefinition entityDefn = (EntityDefinition) defn;
        for (NodeDefinition child : entityDefn.getChildDefinitions()) {
            Path childPath;
            if (defn.isMultiple()) {
                childPath = Path.relative(child.getName());
            } else {
                childPath = relativePath.appendElement(child.getName());
            }
            addDataObjects(rs, table, child, childPath);
        }
    } else if (defn instanceof AttributeDefinition) {
        AttributeDefinition attrDefn = (AttributeDefinition) defn;
        CollectSurvey survey = (CollectSurvey) defn.getSurvey();
        CollectAnnotations annotations = survey.getAnnotations();
        // do not include if it's a calculated attribute and it has not to be included in data export
        if (!attrDefn.isCalculated() || annotations.isIncludedInDataExport(defn)) {
            if (defn.isMultiple()) {
                // Create table for multiple attributes
                table = createDataTable(rs, table, defn, relativePath);
                rs.addTable(table);
                relativePath = Path.relative(".");
            }
            // Add columns for attributes in entity tables or attribute tables
            addDataColumns(rs, table, (AttributeDefinition) defn, relativePath);
        }
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 5 with NodeDefinition

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

the class DataQueryGenerator method generateMissingDataQueries.

public List<DataQuery> generateMissingDataQueries(final CollectSurvey survey, final DataQueryType type) {
    final List<DataQuery> result = new ArrayList<DataQuery>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                if (StringUtils.isNotBlank(def.getMinCountExpression())) {
                    DataQuery query = new DataQuery(survey);
                    query.setTitle(String.format(MISSING_DATA_QUERY_TITLE_FORMAT, def.getName()));
                    query.setAttributeDefinition((AttributeDefinition) def);
                    query.setEntityDefinition(def.getParentEntityDefinition());
                    query.setConditions(String.format(MISSING_DATA_CONDITION_FORMAT, def.getName()));
                    query.setType(type);
                    result.add(query);
                }
            }
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8