Search in sources :

Example 96 with CollectRecord

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

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

the class RecordManagerIntegrationTest method testUpdateCurrentStep.

@Test
public void testUpdateCurrentStep() 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 reloadedCleansingRecord = recordManager.load(survey, record.getId());
    Attribute<?, Code> reloadedDistrict = reloadedCleansingRecord.findNodeByPath("/cluster/district");
    assertEquals(newDistrictValue, reloadedDistrict.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 98 with CollectRecord

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

the class DataMarshallerIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey) {
    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");
    User user = userManager.loadByUserName("admin");
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    record.setModifiedDate(new GregorianCalendar(2012, 2, 3, 9, 30).getTime());
    record.setStep(Step.ENTRY);
    record.setState(State.REJECTED);
    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) User(org.openforis.collect.model.User) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) Coordinate(org.openforis.idm.model.Coordinate) NumberAttribute(org.openforis.idm.model.NumberAttribute) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 99 with CollectRecord

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

the class DataMarshallerIntegrationTest method testMarshal.

@Test
public void testMarshal() throws Exception {
    // LOAD MODEL
    CollectSurvey survey = loadSurvey();
    CollectRecord record = createTestRecord(survey);
    StringWriter out = new StringWriter();
    dataMarshaller.write(record, out);
    String xml = out.toString();
    assertNotNull(xml);
    ParseRecordResult parseRecordResult = parseRecord(survey, xml);
    assertNotNull(parseRecordResult);
    CollectRecord record2 = parseRecordResult.getRecord();
    assertNotNull(record2);
    assertEquals(record, record2);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) StringWriter(java.io.StringWriter) CollectSurvey(org.openforis.collect.model.CollectSurvey) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 100 with CollectRecord

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

the class ModelDaoIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey, String id) {
    CollectRecord record = new CollectRecord(survey, "2.0", "cluster");
    Entity cluster = record.getRootEntity();
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    // record.setCreatedBy("ModelDaoIntegrationTest");
    record.setStep(Step.ENTRY);
    addTestValues(cluster, id);
    // set counts
    record.getEntityCounts().add(2);
    // set keys
    record.getRootEntityKeyValues().add(id);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9