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;
}
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);
}
}
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;
}
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;
}
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());
}
}
}
Aggregations