Search in sources :

Example 1 with StepSummary

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

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

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

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

the class DataRestoreSummaryTask method execute.

@Override
protected void execute() throws Throwable {
    if (fullSummary || dataSummaryFile == null) {
        List<Integer> idsToImport = extractEntryIdsToImport();
        for (Integer entryId : idsToImport) {
            if (!isRunning()) {
                break;
            }
            for (Step step : Step.values()) {
                if (!isRunning()) {
                    break;
                }
                createSummaryForEntry(entryId, step);
            }
        }
    } else {
        CsvReader dataSummaryCSVReader = null;
        try {
            dataSummaryCSVReader = new CsvReader(dataSummaryFile);
            dataSummaryCSVReader.readHeaders();
            CsvLine line = dataSummaryCSVReader.readNextLine();
            while (line != null) {
                Integer entryId = line.getValue("entry_id", Integer.class);
                String stepVal = line.getValue("step", String.class);
                Step step = Step.valueOf(stepVal);
                CollectRecordSummary recordSummary = new CollectRecordSummary();
                recordSummary.setStep(step);
                Integer rootEntityDefId = line.getValue("root_entity_id", Integer.class);
                recordSummary.setRootEntityDefinitionId(rootEntityDefId);
                Date creationDate = Dates.parseDateTime(line.getValue("created_on", String.class));
                Date modifiedDate = Dates.parseDateTime(line.getValue("last_modified", String.class));
                recordSummary.setCreationDate(creationDate);
                recordSummary.setModifiedDate(modifiedDate);
                StepSummary stepSummary = new StepSummary(step);
                List<String> rootEntityKeyValues = Arrays.asList(line.getValue("key1", String.class), line.getValue("key2", String.class), line.getValue("key3", String.class));
                stepSummary.setRootEntityKeyValues(rootEntityKeyValues);
                stepSummary.setCreationDate(creationDate);
                stepSummary.setModifiedDate(modifiedDate);
                recordSummary.addStepSummary(stepSummary);
                recordSummaryByEntryId.put(entryId, recordSummary);
                for (Step s : Step.values()) {
                    if (s.beforeEqual(step)) {
                        addStepPerEntry(entryId, s);
                        incrementTotalPerStep(step);
                        incrementProcessedItems();
                    }
                }
                CollectRecordSummary oldRecord = findAlreadyExistingRecordSummary(entryId, step, rootEntityDefId, rootEntityKeyValues);
                if (oldRecord != null) {
                    conflictingRecordByEntryId.put(entryId, oldRecord);
                }
                line = dataSummaryCSVReader.readNextLine();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(dataSummaryCSVReader);
        }
    }
}
Also used : CsvReader(org.openforis.commons.io.csv.CsvReader) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) CsvLine(org.openforis.commons.io.csv.CsvLine) Date(java.util.Date) IOException(java.io.IOException)

Example 5 with StepSummary

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

the class RecordStatsGenerator method generate.

public RecordsStats generate(int surveyId, Date[] period) {
    final RecordsStats stats = new RecordsStats(period);
    CollectSurvey survey = surveyManager.getById(surveyId);
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary s) {
            for (Entry<Step, StepSummary> entry : s.getStepSummaries().entrySet()) {
                Step step = entry.getKey();
                StepSummary stepSummary = entry.getValue();
                if (stepSummary.getCreationDate() != null) {
                    PointStats pointStats = stats.getOrCreateDailyStats(stepSummary.getCreationDate());
                    switch(step) {
                        case ENTRY:
                            pointStats.incrementCreated();
                            break;
                        case CLEANSING:
                            pointStats.incrementEntered();
                            break;
                        case ANALYSIS:
                            pointStats.incrementCleansed();
                            break;
                    }
                }
            }
            if (s.getModifiedDate() != null) {
                PointStats pointStats = stats.getOrCreateDailyStats(s.getModifiedDate());
                pointStats.incrementModified();
            }
        }
    }, true);
    stats.finalize();
    return stats;
}
Also used : Entry(java.util.Map.Entry) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)8 Step (org.openforis.collect.model.CollectRecord.Step)7 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Record (org.jooq.Record)1 TableField (org.jooq.TableField)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 OfcRecordDataRecord (org.openforis.collect.persistence.jooq.tables.records.OfcRecordDataRecord)1 OfcRecordRecord (org.openforis.collect.persistence.jooq.tables.records.OfcRecordRecord)1 CsvLine (org.openforis.commons.io.csv.CsvLine)1 CsvReader (org.openforis.commons.io.csv.CsvReader)1 ModelVersion (org.openforis.idm.metamodel.ModelVersion)1