Search in sources :

Example 41 with CollectRecordSummary

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

the class RecordDao method visitSummaries.

public void visitSummaries(RecordFilter filter, List<RecordSummarySortField> sortFields, Visitor<CollectRecordSummary> visitor, boolean includeStepDetails, Predicate<CollectRecordSummary> stopWhenPredicate) {
    SelectQuery<Record> q = createSelectSummariesQuery(filter, sortFields);
    Cursor<Record> cursor = null;
    try {
        cursor = q.fetchLazy();
        while (cursor.hasNext()) {
            Record r = cursor.fetchOne();
            CollectRecordSummary s = fromSummaryQueryRecord(filter.getSurvey(), r);
            if (includeStepDetails) {
                s.clearStepSummaries();
                Map<Step, StepSummary> summaryByStep = loadLatestStepSummaries(filter.getSurvey(), s.getId());
                for (Step step : Step.values()) {
                    StepSummary stepSummary = summaryByStep.get(step);
                    if (stepSummary != null) {
                        s.addStepSummary(stepSummary);
                    }
                }
            }
            visitor.visit(s);
            if (stopWhenPredicate.evaluate(s)) {
                break;
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
Also used : StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) OfcRecordRecord(org.openforis.collect.persistence.jooq.tables.records.OfcRecordRecord) CollectRecord(org.openforis.collect.model.CollectRecord) OfcRecordDataRecord(org.openforis.collect.persistence.jooq.tables.records.OfcRecordDataRecord) Record(org.jooq.Record) Step(org.openforis.collect.model.CollectRecord.Step)

Example 42 with CollectRecordSummary

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

the class CSVDataImportJobIntegrationTest method loadRecord.

private CollectRecord loadRecord(String key) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition("cluster").getId());
    filter.setKeyValues(Arrays.asList(key));
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    assertEquals(1, summaries.size());
    CollectRecordSummary summary = summaries.get(0);
    CollectRecord reloadedRecord = recordManager.load(survey, summary.getId(), summary.getStep());
    return reloadedRecord;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 43 with CollectRecordSummary

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

the class RecordManagerIntegrationTest method testPublish.

@Test
public void testPublish() throws MissingRecordKeyException, RecordPromoteException {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    new RecordUpdater().initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    recordManager.save(record);
    recordManager.promote(record, user, true);
    CollectRecord promotedRecord = recordManager.load(survey, record.getId());
    assertEquals(record, promotedRecord);
    List<CollectRecordSummary> fullSummaries = recordDao.loadFullSummaries(new RecordFilter(survey), null);
    assertEquals(1, fullSummaries.size());
    CollectRecordSummary recordSummary = fullSummaries.get(0);
    assertEquals(2, recordSummary.getStepSummaries().size());
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordUpdater(org.openforis.collect.model.RecordUpdater) RecordFilter(org.openforis.collect.model.RecordFilter) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 44 with CollectRecordSummary

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

the class RecordManagerIntegrationTest method testRecordSummaryUpdatedInCleansedRecord.

@Test
public void testRecordSummaryUpdatedInCleansedRecord() throws MissingRecordKeyException, RecordPromoteException {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_114"), attribute("region", "001"), attribute("district", "002"), entity("plot", attribute("no", "1"), entity("tree", attribute("tree_no", "1"), attribute("dbh", "10")), entity("tree", attribute("tree_no", "2"), attribute("dbh", "20")))).build(survey, "cluster", "2.0");
    RecordUpdater recordUpdater = new RecordUpdater();
    User user = userManager.loadAdminUser();
    recordManager.promote(record, user, true);
    CollectRecord cleansingRecord = recordManager.load(survey, record.getId());
    Entity tree = cleansingRecord.findNodeByPath("/cluster/plot[1]/tree[2]");
    recordUpdater.deleteNode(tree);
    recordManager.save(cleansingRecord);
    CollectRecord reloadedCleansingRecord = recordManager.load(survey, record.getId());
    int cleansingTreesCount = reloadedCleansingRecord.getEntityCounts().get(1);
    assertEquals(1, cleansingTreesCount);
    CollectRecord reloadedEntryRecord = recordManager.load(survey, record.getId(), Step.ENTRY);
    int entryTreesCount = reloadedEntryRecord.getEntityCounts().get(1);
    assertEquals(2, entryTreesCount);
    List<CollectRecordSummary> fullSummaries = recordManager.loadFullSummaries(new RecordFilter(survey));
    CollectRecordSummary recordSummary = fullSummaries.get(0);
    int entryTreesCountInSummary = recordSummary.getSummaryByStep(Step.ENTRY).getEntityCounts().get(1);
    assertEquals(2, entryTreesCountInSummary);
    int cleansingTreesCountInSummary = recordSummary.getSummaryByStep(Step.CLEANSING).getEntityCounts().get(1);
    assertEquals(1, cleansingTreesCountInSummary);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordUpdater(org.openforis.collect.model.RecordUpdater) RecordFilter(org.openforis.collect.model.RecordFilter) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 45 with CollectRecordSummary

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

the class ModelDaoIntegrationTest method testLoadSummariesByKey.

@Test
public void testLoadSummariesByKey() throws Exception {
    // SAVE NEW
    String testKey = "123_456";
    CollectRecord record = createTestRecord(survey, testKey);
    recordDao.insert(record);
    String saved = record.toString();
    log.debug("Saving record:\n" + saved);
    // RELOAD
    RecordFilter filter = new RecordFilter(survey, survey.getSchema().getRootEntityDefinition("cluster").getId());
    filter.setKeyValues(Arrays.asList(testKey));
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    Assert.assertEquals(1, summaries.size());
    CollectRecordSummary record1 = summaries.get(0);
    String key = record1.getRootEntityKeyValues().get(0);
    assertEquals(key, testKey);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

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