use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyDao method loadAllPublished.
public List<CollectSurvey> loadAllPublished() {
List<CollectSurvey> surveys = new ArrayList<CollectSurvey>();
Result<Record> results = dsl().select().from(OFC_SURVEY).where(OFC_SURVEY.TEMPORARY.equal(false)).fetch();
for (Record row : results) {
CollectSurvey survey = processSurveyRow(row);
survey.setAvailability(PUBLISHED);
surveys.add(survey);
}
return surveys;
}
use of org.openforis.collect.model.CollectSurvey 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;
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class CollectSurveyIdmlBinder method onUnmarshallingComplete.
@Override
protected void onUnmarshallingComplete(Survey survey) {
super.onUnmarshallingComplete(survey);
CollectSurvey collectSurvey = (CollectSurvey) survey;
CollectAnnotations annotations = collectSurvey.getAnnotations();
collectSurvey.setTarget(annotations.getSurveyTarget());
collectSurvey.setCollectVersion(annotations.getCollectVersion());
if (collectSurvey.getUIOptions() != null) {
try {
UIConfiguration uiConfiguration = new UIOptionsMigrator().migrateToUIConfiguration(collectSurvey.getUIOptions());
collectSurvey.setUIConfiguration(uiConfiguration);
} catch (UIOptionsMigrationException e) {
log.error("Error generating UI model for survey " + collectSurvey.getUri() + ": " + e.getMessage());
} catch (Exception e) {
log.error("Error generating UI model for survey " + collectSurvey.getUri() + ": " + e.getMessage(), e);
}
}
}
use of org.openforis.collect.model.CollectSurvey 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);
}
}
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class DataQueryExectutorTask method createRecordsFilter.
private RecordFilter createRecordsFilter(boolean limitResults) {
CollectSurvey survey = input.query.getSurvey();
EntityDefinition entityDef = (EntityDefinition) survey.getSchema().getDefinitionById(input.query.getEntityDefinitionId());
EntityDefinition rootEntityDef = entityDef.getRootEntity();
Integer rootEntityId = rootEntityDef.getId();
RecordFilter filter = new RecordFilter(survey);
filter.setStep(input.step);
filter.setRootEntityId(rootEntityId);
if (limitResults) {
filter.setOffset(0);
filter.setMaxNumberOfRecords(input.maxRecords);
}
return filter;
}
Aggregations