Search in sources :

Example 1 with Schema

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

the class RecordDao method fromSummaryQueryRecord.

public CollectRecordSummary fromSummaryQueryRecord(CollectSurvey survey, Record r) {
    int rootEntityDefId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    String versionName = r.getValue(OFC_RECORD.MODEL_VERSION);
    ModelVersion modelVersion = versionName == null ? null : survey.getVersion(versionName);
    CollectRecordSummary s = new CollectRecordSummary();
    s.setSurvey(survey);
    s.setVersion(modelVersion);
    s.setRootEntityDefinitionId(rootEntityDefId);
    s.setId(r.getValue(OFC_RECORD.ID));
    s.setOwner(createDetachedUser(r.getValue(OFC_RECORD.OWNER_ID)));
    Step step = Step.valueOf(r.getValue(OFC_RECORD.STEP));
    s.setStep(step);
    s.setWorkflowSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    s.setCreationDate(r.getValue(OFC_RECORD.DATE_CREATED));
    s.setModifiedDate(r.getValue(OFC_RECORD.DATE_MODIFIED));
    s.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD.CREATED_BY_ID)));
    s.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD.MODIFIED_BY_ID)));
    StepSummary stepSummary = new StepSummary(step);
    stepSummary.setSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    stepSummary.setErrors(r.getValue(OFC_RECORD.ERRORS));
    stepSummary.setWarnings(r.getValue(OFC_RECORD.WARNINGS));
    stepSummary.setSkipped(r.getValue(OFC_RECORD.SKIPPED));
    stepSummary.setMissing(r.getValue(OFC_RECORD.MISSING));
    int totalErrors = step == Step.ENTRY ? Numbers.sum(stepSummary.getErrors(), stepSummary.getSkipped()) : Numbers.sum(stepSummary.getErrors(), stepSummary.getMissingErrors());
    stepSummary.setTotalErrors(totalErrors);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.getRootEntityDefinition(rootEntityDefId);
    stepSummary.setRootEntityKeyValues(getFieldValues(r, rootEntityDef.getKeyAttributeDefinitions(), RECORD_KEY_FIELDS, String.class));
    stepSummary.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDef), RECORD_COUNT_FIELDS, Integer.class));
    stepSummary.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDef), RECORD_QUALIFIER_FIELDS, String.class));
    stepSummary.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDef), RECORD_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD.STATE);
    stepSummary.setState(state == null ? null : State.fromCode(state));
    s.addStepSummary(stepSummary);
    return s;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Schema(org.openforis.idm.metamodel.Schema) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Step(org.openforis.collect.model.CollectRecord.Step)

Example 2 with Schema

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

the class RecordDao method fromDataSummaryQueryRecord.

@SuppressWarnings("unchecked")
public StepSummary fromDataSummaryQueryRecord(Record r, CollectSurvey survey) {
    Step step = Step.valueOf(r.getValue(OFC_RECORD_DATA.STEP));
    StepSummary s = new StepSummary(step);
    s.setSequenceNumber(r.getValue(OFC_RECORD_DATA.SEQ_NUM));
    s.setCreationDate(r.getValue(OFC_RECORD_DATA.DATE_CREATED));
    s.setModifiedDate(r.getValue(OFC_RECORD_DATA.DATE_MODIFIED));
    s.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.CREATED_BY)));
    s.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.MODIFIED_BY)));
    s.setErrors(r.getValue(OFC_RECORD_DATA.ERRORS));
    s.setWarnings(r.getValue(OFC_RECORD_DATA.WARNINGS));
    s.setSkipped(r.getValue(OFC_RECORD_DATA.SKIPPED));
    s.setMissing(r.getValue(OFC_RECORD_DATA.MISSING));
    // create list of entity counts
    List<Integer> counts = new ArrayList<Integer>(RECORD_DATA_COUNT_FIELDS.length);
    for (TableField tableField : RECORD_DATA_COUNT_FIELDS) {
        counts.add((Integer) r.getValue(tableField));
    }
    s.setEntityCounts(counts);
    int rootEntityDefId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.getRootEntityDefinition(rootEntityDefId);
    s.setRootEntityKeyValues(getFieldValues(r, rootEntityDef.getKeyAttributeDefinitions(), RECORD_DATA_KEY_FIELDS, String.class));
    s.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDef), RECORD_DATA_COUNT_FIELDS, Integer.class));
    s.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDef), RECORD_DATA_QUALIFIER_FIELDS, String.class));
    s.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDef), RECORD_DATA_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD_DATA.STATE);
    s.setState(state == null ? null : State.fromCode(state));
    return s;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) Step(org.openforis.collect.model.CollectRecord.Step) TableField(org.jooq.TableField)

Example 3 with Schema

use of org.openforis.idm.metamodel.Schema 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 4 with Schema

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

the class DataExportService method export.

@Transactional
public Proxy export(String rootEntityName, int stepNumber, Integer entityId, boolean includeAllAncestorAttributes, boolean includeEnumeratedEntities, boolean includeCompositeAttributeMergedColumn, boolean codeAttributeExpanded, boolean onlyOwnedRecords, String[] rootEntityKeyValues, boolean includeKMLColumnForCoordinates, boolean includeCodeItemLabelColumn, String headingSource, String languageCode, boolean includeGroupingLabels) throws IOException {
    if (dataExportProcess == null || !dataExportProcess.getStatus().isRunning()) {
        resetJobs();
        SessionState sessionState = sessionManager.getSessionState();
        CollectSurvey survey = sessionState.getActiveSurvey();
        File outputFile = File.createTempFile("collect_data_export_" + survey.getName(), ".zip");
        Step step = Step.valueOf(stepNumber);
        // prepare record filter
        Schema schema = survey.getSchema();
        EntityDefinition rootEntityDefn = schema.getRootEntityDefinition(rootEntityName);
        RecordFilter recordFilter = createRecordFilter(survey, rootEntityDefn.getId(), onlyOwnedRecords, rootEntityKeyValues);
        // filter by record step
        recordFilter.setStepGreaterOrEqual(step);
        // instantiate process
        CSVDataExportProcess process = appContext.getBean(CSVDataExportProcess.class);
        process.setOutputFile(outputFile);
        process.setRecordFilter(recordFilter);
        process.setEntityId(entityId);
        process.setAlwaysGenerateZipFile(true);
        CSVDataExportParameters config = new CSVDataExportParameters();
        config.setIncludeAllAncestorAttributes(includeAllAncestorAttributes);
        config.setIncludeEnumeratedEntities(includeEnumeratedEntities);
        config.setIncludeCompositeAttributeMergedColumn(includeCompositeAttributeMergedColumn);
        config.setIncludeKMLColumnForCoordinates(includeKMLColumnForCoordinates);
        config.setCodeAttributeExpanded(codeAttributeExpanded);
        config.setIncludeCodeItemLabelColumn(includeCodeItemLabelColumn);
        config.setHeadingSource(HeadingSource.valueOf(headingSource));
        config.setLanguageCode(languageCode);
        config.setIncludeGroupingLabels(includeGroupingLabels);
        process.setConfiguration(config);
        process.init();
        // start process
        dataExportProcess = process;
        ExecutorServiceUtil.executeInCachedPool(process);
    }
    return getCurrentJob();
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportProcess(org.openforis.collect.io.data.CSVDataExportProcess) Schema(org.openforis.idm.metamodel.Schema) Step(org.openforis.collect.model.CollectRecord.Step) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Schema

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

the class DataService method loadRecordSummaries.

/**
 * @param rootEntityName
 * @param offset
 * @param toIndex
 * @param orderByFieldName
 * @param filter
 *
 * @return map with "count" and "records" items
 */
@Secured(USER)
public Map<String, Object> loadRecordSummaries(String rootEntityName, int offset, int maxNumberOfRows, List<RecordSummarySortField> sortFields, String[] keyValues) {
    Map<String, Object> result = new HashMap<String, Object>();
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    Schema schema = activeSurvey.getSchema();
    EntityDefinition rootEntityDefinition = schema.getRootEntityDefinition(rootEntityName);
    RecordFilter filter = new RecordFilter(activeSurvey, rootEntityDefinition.getId());
    filter.setKeyValues(keyValues);
    filter.setOffset(offset);
    filter.setMaxNumberOfRecords(maxNumberOfRows);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, getProxyContext());
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) HashMap(java.util.HashMap) Schema(org.openforis.idm.metamodel.Schema) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

Schema (org.openforis.idm.metamodel.Schema)65 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)46 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)23 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 ArrayList (java.util.ArrayList)10 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)10 Survey (org.openforis.idm.metamodel.Survey)10 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)6 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)5 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)5 Test (org.junit.Test)4 UITab (org.openforis.collect.metamodel.ui.UITab)4 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)4 Step (org.openforis.collect.model.CollectRecord.Step)4 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)4 RecordFilter (org.openforis.collect.model.RecordFilter)4 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)4 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)4 Entity (org.openforis.idm.model.Entity)4 List (java.util.List)3