Search in sources :

Example 41 with RecordFilter

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

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

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

Example 44 with RecordFilter

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

the class CollectRDBPublisher method insertData.

private void insertData(final CollectSurvey survey, String rootEntityName, final Step step, Connection targetConn, RelationalSchema relationalSchema, ProgressListener progressListener) throws IOException {
    // Insert data
    RecordFilter recordFilter = new RecordFilter(survey);
    recordFilter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    recordFilter.setStepGreaterOrEqual(step);
    final int total = recordManager.countRecords(recordFilter);
    if (LOG.isInfoEnabled()) {
        LOG.info("Total records: " + total);
    }
    final DatabaseExporter databaseExporter = createDatabaseExporter(relationalSchema, targetConn);
    ProcessProgressListener totalProgressListener = new ProcessProgressListener(2);
    databaseExporter.insertReferenceData(new ProcessStepProgressListener(totalProgressListener, progressListener));
    final ProcessStepProgressListener insertRecordsProgressListener = new ProcessStepProgressListener(totalProgressListener, progressListener);
    final AtomicInteger count = new AtomicInteger();
    recordManager.visitSummaries(recordFilter, null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            try {
                CollectRecord record = recordManager.load(survey, summary.getId(), step, false);
                databaseExporter.insertRecordData(record, ProgressListener.NULL_PROGRESS_LISTENER);
            } catch (CollectRdbException e) {
                LOG.error(e.getMessage(), e);
            }
            insertRecordsProgressListener.progressMade(new Progress(count.addAndGet(1), total));
        }
    });
    databaseExporter.close();
    if (LOG.isInfoEnabled()) {
        LOG.info("All records exported");
        LOG.info("Adding constraints and indexes...");
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Progress(org.openforis.concurrency.Progress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JooqDatabaseExporter(org.openforis.collect.relational.jooq.JooqDatabaseExporter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ProcessStepProgressListener(org.openforis.concurrency.ProcessStepProgressListener) ProcessProgressListener(org.openforis.concurrency.ProcessProgressListener) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 45 with RecordFilter

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

the class RecordController method startBackupDataExportJob.

@RequestMapping(value = "survey/{surveyId}/data/records/startbackupexport", method = POST)
@ResponseBody
public JobView startBackupDataExportJob(@PathVariable("surveyId") int surveyId, @RequestBody BackupDataExportParameters parameters) throws IOException {
    User user = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.getById(surveyId);
    RecordFilter filter = createRecordFilter(survey, user, userGroupManager, null, parameters.onlyOwnedRecords);
    fullBackupJob = jobManager.createJob(SurveyBackupJob.class);
    fullBackupJob.setRecordFilter(filter);
    fullBackupJob.setSurvey(survey);
    fullBackupJob.setIncludeData(true);
    fullBackupJob.setIncludeRecordFiles(parameters.isIncludeRecordFiles());
    jobManager.start(fullBackupJob);
    return getFullBackupJobView();
}
Also used : User(org.openforis.collect.model.User) SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3