Search in sources :

Example 6 with RecordUpdater

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

the class CalculatedAttributeTest method before.

@Before
public void before() {
    recordUpdater = new RecordUpdater();
    survey = createTestSurvey();
    record = createTestRecord(survey);
}
Also used : RecordUpdater(org.openforis.collect.model.RecordUpdater) Before(org.junit.Before)

Example 7 with RecordUpdater

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

the class RecordManager method load.

public CollectRecord load(CollectSurvey survey, int recordId, Step step, boolean validate) {
    if (survey == null) {
        int surveyId = recordDao.loadSurveyId(recordId);
        survey = surveyManager.getOrLoadSurveyById(surveyId);
    }
    CollectRecord r = recordDao.load(survey, recordId, step, validate);
    if (r == null) {
        throw new NullPointerException(format("Could not load record with id %d in phase %s in survey %s", recordId, step, survey.getName()));
    }
    loadDetachedObjects(r);
    recordConverter.convertToLatestVersion(r);
    RecordUpdater updater = new RecordUpdater();
    updater.setValidateAfterUpdate(validate);
    updater.initializeRecord(r);
    return r;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 8 with RecordUpdater

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

the class XMLParsingRecordProvider method init.

@Override
public void init(ProgressListener progressListener) throws Exception {
    this.backupFileExtractor = new NewBackupFileExtractor(file);
    this.backupFileExtractor.init(progressListener);
    this.dataUnmarshaller = new DataUnmarshaller(existingSurvey == null ? packagedSurvey : existingSurvey, packagedSurvey);
    this.dataUnmarshaller.setRecordValidationEnabled(validateRecords);
    this.dataUnmarshaller.setIgnoreDuplicateRecordKeyValidationErrors(ignoreDuplicateRecordKeyValidationErrors);
    this.dataUnmarshaller.setRecordApplicationVersion(backupFileExtractor.getInfo().getCollectVersion());
    this.recordUpdater = new RecordUpdater();
    this.recordUpdater.setValidateAfterUpdate(validateRecords);
    initializeRecordUserLoader();
}
Also used : DataUnmarshaller(org.openforis.collect.persistence.xml.DataUnmarshaller) NewBackupFileExtractor(org.openforis.collect.io.NewBackupFileExtractor) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 9 with RecordUpdater

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

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

Aggregations

RecordUpdater (org.openforis.collect.model.RecordUpdater)14 CollectRecord (org.openforis.collect.model.CollectRecord)8 User (org.openforis.collect.model.User)6 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 Code (org.openforis.idm.model.Code)4 Before (org.junit.Before)3 Entity (org.openforis.idm.model.Entity)3 GregorianCalendar (java.util.GregorianCalendar)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 RecordFilter (org.openforis.collect.model.RecordFilter)2 Coordinate (org.openforis.idm.model.Coordinate)2 Date (org.openforis.idm.model.Date)2 NumberAttribute (org.openforis.idm.model.NumberAttribute)2 Time (org.openforis.idm.model.Time)2 RecordBuilder (org.openforis.idm.testfixture.RecordBuilder)2 Date (java.util.Date)1 NewBackupFileExtractor (org.openforis.collect.io.NewBackupFileExtractor)1 DataUnmarshaller (org.openforis.collect.persistence.xml.DataUnmarshaller)1