Search in sources :

Example 6 with CollectSurvey

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;
}
Also used : ArrayList(java.util.ArrayList) Record(org.jooq.Record) OfcSurveyRecord(org.openforis.collect.persistence.jooq.tables.records.OfcSurveyRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 7 with CollectSurvey

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;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) FieldSymbol(org.openforis.collect.model.FieldSymbol) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NumberAttribute(org.openforis.idm.model.NumberAttribute) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 8 with CollectSurvey

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);
        }
    }
}
Also used : UIOptionsMigrator(org.openforis.collect.metamodel.ui.UIOptionsMigrator) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey) IOException(java.io.IOException) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) UIOptionsMigrationException(org.openforis.collect.metamodel.ui.UIOptionsMigrator.UIOptionsMigrationException) UIOptionsMigrationException(org.openforis.collect.metamodel.ui.UIOptionsMigrator.UIOptionsMigrationException)

Example 9 with CollectSurvey

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);
        }
    }
}
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 10 with CollectSurvey

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15