Search in sources :

Example 1 with Survey

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

the class RelationalSchemaGenerator method createCodeListTable.

protected CodeTable createCodeListTable(RelationalSchema rs, CodeList codeList, CodeTable parent, Integer hierarchyIdx) throws CollectRdbException {
    String tableName = CodeListTables.getTableName(config, codeList, hierarchyIdx);
    CodeTable table = new CodeTable(config.getCodeListTablePrefix(), tableName, codeList, parent, config.getDefaultCode(), config.getDefaultCodeLabels());
    if (rs.containsTable(tableName)) {
        throw new CollectRdbException("Duplicate table '" + tableName + "' for CodeList " + codeList.getName());
    }
    // Create PK column
    Column<?> pkColumn = new CodePrimaryKeyColumn(CodeListTables.getIdColumnName(config, table.getName()));
    table.addColumn(pkColumn);
    // Create PK constraint
    addPKConstraint(table, pkColumn);
    // add code column
    CodeListCodeColumn codeColumn = new CodeListCodeColumn(CodeListTables.getCodeColumnName(codeList, hierarchyIdx));
    table.addColumn(codeColumn);
    if (parent != null) {
        // Create Parent FK column
        Column<?> parentIdColumn = new CodeParentKeyColumn(CodeListTables.getIdColumnName(config, parent.getName()));
        addColumn(table, parentIdColumn);
        // Create FK constraint
        String fkConstraintName = config.getFkConstraintPrefix() + table.getBaseName() + "_" + parent.getBaseName();
        PrimaryKeyConstraint parentPkConstraint = parent.getPrimaryKeyConstraint();
        ReferentialConstraint fkConstraint = new ReferentialConstraint(fkConstraintName, table, parentPkConstraint, parentIdColumn);
        table.addConstraint(fkConstraint);
    }
    Survey survey = codeList.getSurvey();
    // add default language label column
    {
        String columnName = CodeListTables.getLabelColumnName(config, codeList, hierarchyIdx);
        CodeLabelColumn col = new CodeLabelColumn(survey.getDefaultLanguage(), columnName);
        addColumn(table, col);
    }
    // add label columns
    for (String langCode : survey.getLanguages()) {
        String colName = CodeListTables.getLabelColumnName(config, codeList, hierarchyIdx, langCode);
        CodeLabelColumn col = new CodeLabelColumn(langCode, colName);
        addColumn(table, col);
    }
    // add default language description column
    {
        String colName = CodeListTables.getDescriptionColumnName(config, codeList, hierarchyIdx);
        CodeListDescriptionColumn col = new CodeListDescriptionColumn(survey.getDefaultLanguage(), colName);
        addColumn(table, col);
    }
    // add description columns
    for (String langCode : survey.getLanguages()) {
        String colName = CodeListTables.getDescriptionColumnName(config, codeList, hierarchyIdx, langCode);
        CodeListDescriptionColumn col = new CodeListDescriptionColumn(langCode, colName);
        table.addColumn(col);
    }
    return table;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectRdbException(org.openforis.collect.relational.CollectRdbException)

Example 2 with Survey

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

the class RelationalSchemaGenerator method addDataTables.

private void addDataTables(RelationalSchema rs) throws CollectRdbException {
    Survey survey = rs.getSurvey();
    Schema schema = survey.getSchema();
    // Recursively create tables, columns and constraints
    List<EntityDefinition> roots = schema.getRootEntityDefinitions();
    for (EntityDefinition root : roots) {
        Path relativePath = Path.relative(root.getName());
        addDataObjects(rs, null, root, relativePath);
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) Schema(org.openforis.idm.metamodel.Schema)

Example 3 with Survey

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

the class DataQueryResultItem method extractNodePath.

public String extractNodePath() {
    Survey survey = record.getSurvey();
    NodeDefinition attrDefn = survey.getSchema().getDefinitionById(query.getAttributeDefinitionId());
    Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
    String path;
    if (attrDefn.isMultiple()) {
        path = String.format("%s/%s[%d]", parentEntity.getPath(), attrDefn.getName(), nodeIndex + 1);
    } else {
        path = String.format("%s/%s", parentEntity.getPath(), attrDefn.getName());
    }
    return path;
}
Also used : Entity(org.openforis.idm.model.Entity) Survey(org.openforis.idm.metamodel.Survey) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 4 with Survey

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

the class CodeTableDataExtractor method getCodeListService.

private CodeListService getCodeListService(CodeList list) {
    Survey survey = list.getSurvey();
    SurveyContext context = survey.getContext();
    CodeListService codeListService = context.getCodeListService();
    return codeListService;
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) CodeListService(org.openforis.idm.metamodel.CodeListService) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 5 with Survey

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

the class CSVDataImportProcess method setSRSIdField.

private void setSRSIdField(Attribute<?, ?> attr, String value, long row, String colName) {
    boolean valid = true;
    if (StringUtils.isNotBlank(value)) {
        // check SRS id validity
        Survey survey = attr.getSurvey();
        SpatialReferenceSystem srs = survey.getSpatialReferenceSystem(value);
        if (srs == null) {
            ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, SRS_NOT_FOUND_MESSAGE_KEY);
            parsingError.setMessageArgs(new String[] { value });
            status.addParsingError(parsingError);
            valid = false;
        }
    }
    if (valid) {
        Field<String> field = ((CoordinateAttribute) attr).getSrsIdField();
        NodeChangeSet changes = recordUpdater.updateField(field, value);
        if (nodeChangeBatchProcessor != null) {
            nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
        }
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Aggregations

Survey (org.openforis.idm.metamodel.Survey)67 Test (org.junit.Test)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)13 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)11 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)10 Schema (org.openforis.idm.metamodel.Schema)10 SurveyContext (org.openforis.idm.metamodel.SurveyContext)8 Entity (org.openforis.idm.model.Entity)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 LookupProvider (org.openforis.idm.metamodel.validation.LookupProvider)3 TestSurveyContext (org.openforis.idm.model.TestSurveyContext)3 IOException (java.io.IOException)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)2 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 CodeList (org.openforis.idm.metamodel.CodeList)2 CodeListService (org.openforis.idm.metamodel.CodeListService)2 ModelVersion (org.openforis.idm.metamodel.ModelVersion)2