Search in sources :

Example 6 with TaxonAttributeDefinition

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

the class TaxonAttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    TaxonAttributeDefinition defn = (TaxonAttributeDefinition) getDefinition();
    String taxonomy = getAttribute(TAXONOMY, false);
    String highestRankName = getAttribute(HIGHEST_RANK, false);
    String qualifiers = getAttribute(QUALIFIERS, false);
    defn.setTaxonomy(taxonomy);
    defn.setHighestTaxonRank(TaxonRank.fromName(highestRankName, true));
    defn.setQualifiers(qualifiers);
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition)

Example 7 with TaxonAttributeDefinition

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

the class SpeciesService method getTaxonAttributeDefinitionsForDesignerSurvey.

protected List<TaxonAttributeDefinition> getTaxonAttributeDefinitionsForDesignerSurvey(String oldName) {
    CollectSurvey survey = sessionManager.getActiveDesignerSurvey();
    Schema schema = survey.getSchema();
    List<TaxonAttributeDefinition> defns = schema.getTaxonAttributeDefinitions(oldName);
    return defns;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 8 with TaxonAttributeDefinition

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

the class SpeciesService method isTaxonomyInUse.

@Secured("ROLE_ADMIN")
public boolean isTaxonomyInUse(String taxonomyName) {
    CollectSurvey survey = sessionManager.getActiveDesignerSurvey();
    Schema schema = survey.getSchema();
    List<TaxonAttributeDefinition> defns = schema.getTaxonAttributeDefinitions(taxonomyName);
    return !defns.isEmpty();
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 9 with TaxonAttributeDefinition

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

the class CollectTaxonVernacularLanguageValidator method evaluate.

/**
 * Returns:
 * - OK if vernacular name, language code and language variety are all blank or all specified or
 * 		vernacular name is specified and language code and language variety are not visible in the UI
 * - ERROR if vernacular name is specified but language code not
 * - WARNING if vernacular name is specified and reason blank for language code is specified too
 */
@Override
public ValidationResultFlag evaluate(TaxonAttribute attribute) {
    TaxonAttributeDefinition defn = attribute.getDefinition();
    CollectSurvey survey = (CollectSurvey) defn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    boolean vernacularNameBlank = StringUtils.isBlank(attribute.getVernacularName());
    boolean langCodeBlank = StringUtils.isBlank(attribute.getLanguageCode());
    boolean langCodeVisible = uiOptions.isVisibleField(defn, TaxonAttributeDefinition.LANGUAGE_CODE_FIELD_NAME);
    boolean langVarietyBlank = StringUtils.isBlank(attribute.getLanguageVariety());
    if ((vernacularNameBlank && langCodeBlank && langVarietyBlank) || (!vernacularNameBlank && !(langCodeVisible && langCodeBlank))) {
        return ValidationResultFlag.OK;
    } else {
        CollectRecord record = (CollectRecord) attribute.getRecord();
        Step step = record.getStep();
        if (step == Step.ENTRY && langCodeBlank && FieldSymbol.isReasonBlankSpecified(attribute.getLanguageCodeField())) {
            return ValidationResultFlag.WARNING;
        } else {
            return ValidationResultFlag.ERROR;
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 10 with TaxonAttributeDefinition

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

the class NewMondrianSchemaGenerator method generateDimension.

private Dimension generateDimension(Cube cube, AttributeDefinition attrDef) {
    Dimension dimension = new Dimension(determineDimensionName(attrDef));
    EntityDefinition ancestorMultipleEntity = attrDef.getNearestAncestorMultipleEntity();
    if (ancestorMultipleEntity.isRoot()) {
        dimension.caption = extractLabel(attrDef);
    } else {
        dimension.caption = String.format("%s %s", extractLabel(ancestorMultipleEntity), extractLabel(attrDef));
    }
    Hierarchy hierarchy = dimension.hierarchy;
    hierarchy.table = new Table(dbSchemaName, cube.tables.get(0).name);
    if (attrDef instanceof CodeAttributeDefinition) {
        CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) attrDef;
        if (!codeAttrDef.getList().isExternal()) {
            if (attrDef.isMultiple()) {
                DataTable dataTable = rdbSchema.getDataTable(attrDef);
                String parentEntityPKColumnName = getEntityPKColumnName(ancestorMultipleEntity);
                dimension.foreignKey = parentEntityPKColumnName;
                hierarchy.table = null;
                hierarchy.primaryKey = parentEntityPKColumnName;
                hierarchy.primaryKeyTable = dataTable.getName();
                Join join = new Join(null);
                String codeListTableName = CodeListTables.getTableName(rdbConfig, codeAttrDef);
                join.leftKey = dataTable.getForeignKeyCodeColumn(codeAttrDef).getName();
                join.rightKey = CodeListTables.getIdColumnName(rdbConfig, codeListTableName);
                join.tables = Arrays.asList(new Table(dbSchemaName, dataTable.getName()), new Table(dbSchemaName, codeListTableName));
                hierarchy.join = join;
            } else {
                String codeListTableName = CodeListTables.getTableName(rdbConfig, codeAttrDef);
                hierarchy.table = new Table(dbSchemaName, codeListTableName);
                DataTable dataTable = rdbSchema.getDataTable(attrDef.getParentEntityDefinition());
                CodeValueFKColumn foreignKeyCodeColumn = dataTable.getForeignKeyCodeColumn(codeAttrDef);
                dimension.foreignKey = foreignKeyCodeColumn.getName();
            }
        }
        hierarchy.levels.add(generateLevel(attrDef));
    } else if (attrDef instanceof CoordinateAttributeDefinition) {
        dimension.type = "";
        hierarchy.type = "StandardDimension";
        {
            String fieldName = CoordinateAttributeDefinition.Y_FIELD_NAME;
            Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Latitude");
            level.column = attrDef.getName() + "_" + fieldName;
            hierarchy.levels.add(level);
        }
        {
            String fieldName = CoordinateAttributeDefinition.X_FIELD_NAME;
            Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Longitude");
            level.column = attrDef.getName() + "_" + fieldName;
            hierarchy.levels.add(level);
        }
    } else if (attrDef instanceof DateAttributeDefinition) {
        dimension.type = "";
        hierarchy.type = "TimeDimension";
        hierarchy.allMemberName = "attrLabel";
        String[] fieldNames = new String[] { DateAttributeDefinition.YEAR_FIELD_NAME, DateAttributeDefinition.MONTH_FIELD_NAME, DateAttributeDefinition.DAY_FIELD_NAME };
        for (String fieldName : fieldNames) {
            String fieldLabel = StringUtils.capitalize(fieldName);
            Level level = new Level(dimension.name + "_" + fieldName, determineLevelCaption(attrDef, fieldLabel));
            level.column = attrDef.getName() + "_" + fieldName.toLowerCase(Locale.ENGLISH);
            level.levelType = String.format("Time%ss", fieldLabel);
            level.type = NUMERIC_DATATYPE;
            hierarchy.levels.add(level);
        }
    } else if (attrDef instanceof TaxonAttributeDefinition) {
        {
            String fieldName = TaxonAttributeDefinition.CODE_FIELD_NAME;
            Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Code");
            level.column = attrDef.getName() + "_" + fieldName;
            hierarchy.levels.add(level);
        }
        {
            String fieldName = TaxonAttributeDefinition.SCIENTIFIC_NAME_FIELD_NAME;
            Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Scientific name");
            level.column = attrDef.getName() + "_" + fieldName;
            hierarchy.levels.add(level);
        }
    } else if (attrDef instanceof TimeAttributeDefinition) {
        dimension.type = "";
        hierarchy.type = "TimeDimension";
        hierarchy.allMemberName = "attrLabel";
        String[] fieldNames = new String[] { TimeAttributeDefinition.HOUR_FIELD, TimeAttributeDefinition.MINUTE_FIELD };
        for (String fieldName : fieldNames) {
            String fieldLabel = StringUtils.capitalize(fieldName);
            Level level = new Level(dimension.name + "_" + fieldName, determineLevelCaption(attrDef, fieldLabel));
            level.column = attrDef.getName() + "_" + fieldName.toLowerCase(Locale.ENGLISH);
            level.levelType = String.format("Time%ss", fieldLabel);
            level.type = NUMERIC_DATATYPE;
            hierarchy.levels.add(level);
        }
    } else {
        hierarchy.levels.add(generateLevel(attrDef));
    }
    return dimension;
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CodeValueFKColumn(org.openforis.collect.relational.model.CodeValueFKColumn) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Aggregations

TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)10 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 CodeTable (org.openforis.collect.relational.model.CodeTable)2 DataTable (org.openforis.collect.relational.model.DataTable)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1