Search in sources :

Example 1 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class RecordDao method loadFullSummaries.

public List<CollectRecordSummary> loadFullSummaries(RecordFilter filter, List<RecordSummarySortField> sortFields) {
    List<CollectRecordSummary> recordSummaries = loadSummaries(filter, sortFields);
    for (CollectRecordSummary recordSummary : recordSummaries) {
        recordSummary.clearStepSummaries();
        Map<Step, StepSummary> summaryByStep = loadLatestStepSummaries(filter.getSurvey(), recordSummary.getId());
        for (Step step : Step.values()) {
            StepSummary stepSummary = summaryByStep.get(step);
            if (stepSummary != null) {
                recordSummary.addStepSummary(stepSummary);
            }
        }
    }
    return recordSummaries;
}
Also used : StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step)

Example 2 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary 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 3 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class DataCleansingChainExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.chain.getSurvey();
    RecordFilter filter = createRecordsFilter();
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    datasetSize = recordSummaries.size();
    lastRecordModifiedDate = null;
    // Delete records in bulk if needed
    Set<Integer> recordIdsToBeDeleted = new TreeSet<Integer>();
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        udpateLastRecordModifiedDate(recordSummary);
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        boolean recordCleansed = false;
        for (DataCleansingStep step : input.chain.getSteps()) {
            DataCleansingStepExecutionResult stepExecutionResult = executeStep(record, step);
            if (stepExecutionResult != null) {
                recordCleansed = true;
                if (stepExecutionResult == DataCleansingStepExecutionResult.RECORD_TO_BE_DELETED) {
                    recordIdsToBeDeleted.add(record.getId());
                    break;
                }
            }
        }
        if (recordCleansed) {
            cleansedRecords++;
        }
        incrementProcessedItems();
    }
    recordManager.deleteByIds(recordIdsToBeDeleted);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) TreeSet(java.util.TreeSet) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary 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)

Example 5 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class DataBackupTask method countTotalItems.

@Override
protected long countTotalItems() {
    int count = 0;
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(recordFilter);
    if (CollectionUtils.isNotEmpty(recordSummaries) && steps != null && steps.length > 0) {
        for (CollectRecordSummary summary : recordSummaries) {
            for (Step step : steps) {
                if (step.getStepNumber() <= summary.getStep().getStepNumber()) {
                    count++;
                }
            }
        }
    }
    return count;
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step)

Aggregations

CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)55 RecordFilter (org.openforis.collect.model.RecordFilter)33 CollectRecord (org.openforis.collect.model.CollectRecord)25 Step (org.openforis.collect.model.CollectRecord.Step)21 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 IOException (java.io.IOException)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 User (org.openforis.collect.model.User)5 Transactional (org.springframework.transaction.annotation.Transactional)5 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)4 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)4 StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)4 Schema (org.openforis.idm.metamodel.Schema)4 List (java.util.List)3 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2