Search in sources :

Example 1 with RecordUpdater

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

the class DataCleansingChainIntegrationTest method init.

@Before
public void init() throws SurveyImportException, IdmlParseException, SurveyValidationException {
    updater = new RecordUpdater();
    survey = importModel();
    user = userManager.loadAdminUser();
    initRecords();
}
Also used : RecordUpdater(org.openforis.collect.model.RecordUpdater) Before(org.junit.Before)

Example 2 with RecordUpdater

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

the class CSVDataImportProcess method init.

@Override
public void init() {
    super.init();
    validateParameters();
    adminUser = userManager.loadAdminUser();
    recordUpdater = new RecordUpdater();
    recordUpdater.setValidateAfterUpdate(settings.isRecordValidationEnabled());
}
Also used : RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 3 with RecordUpdater

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

the class RecordManagerIntegrationTest method testNewRecordInsert.

@Test
public void testNewRecordInsert() {
    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.setCreationDate(new Date());
    record.setModifiedBy(user);
    record.setModifiedDate(new Date());
    recordManager.save(record);
    CollectRecord reloaded = recordManager.load(survey, record.getId());
    assertEquals(record, reloaded);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(java.util.Date) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 4 with RecordUpdater

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

the class RecordManagerIntegrationTest method testUpdateCurrentStepDoesntAffectPreviousStep.

@Test
public void testUpdateCurrentStepDoesntAffectPreviousStep() throws MissingRecordKeyException, RecordPromoteException {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    RecordUpdater recordUpdater = new RecordUpdater();
    recordUpdater.initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    recordManager.save(record);
    recordManager.promote(record, user, true);
    CollectRecord cleansingRecord = recordManager.load(survey, record.getId());
    Attribute<?, Code> district = cleansingRecord.findNodeByPath("/cluster/district");
    Code newDistrictValue = new Code("001");
    recordUpdater.updateAttribute(district, newDistrictValue);
    recordManager.save(cleansingRecord);
    CollectRecord entryRecord = recordManager.load(survey, record.getId(), Step.ENTRY);
    assertEquals(2, (int) entryRecord.getWorkflowSequenceNumber());
    assertEquals(1, (int) entryRecord.getDataWorkflowSequenceNumber());
    Attribute<?, Code> entryDistrict = entryRecord.findNodeByPath("/cluster/district");
    assertEquals(new Code("003"), entryDistrict.getValue());
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUpdater(org.openforis.collect.model.RecordUpdater) Code(org.openforis.idm.model.Code) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 5 with RecordUpdater

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

the class DataMarshallerTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey) throws RecordPersistenceException {
    RecordBuilder recordBuilder = record(attribute("id", "123_456"), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "XXX"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), attribute("remarks", "Remarks with UTF-8 character: Í"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
    CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    record.setStep(Step.ENTRY);
    record.updateSummaryFields();
    RecordUpdater recordUpdater = new RecordUpdater();
    recordUpdater.initializeRecord(record);
    Entity cluster = record.getRootEntity();
    recordUpdater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
    recordUpdater.approveMissingValue(cluster, "accessibility");
    NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
    recordUpdater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
    recordUpdater.updateRemarks(boleHeight.getNumberField(), "No value specified");
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) NumberAttribute(org.openforis.idm.model.NumberAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(org.openforis.idm.model.Date)

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