Search in sources :

Example 36 with CollectRecord

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

the class RecordDaoTest method testLoadRecordSummariesOrderedByPlotCount.

// @Test
public void testLoadRecordSummariesOrderedByPlotCount() throws IOException, SurveyImportException, DataInconsistencyException, InvalidIdmlException, NonexistentIdException {
    EntityDefinition rootEntity = survey.getSchema().getRootEntityDefinitions().get(0);
    String rootEntityName = rootEntity.getName();
    // load record summaries
    int offset = 0;
    int maxNumberOfRecords = 5;
    String orderByFieldName = "count_plot";
    String filter = null;
    List<CollectRecord> list = this.recordDao.loadSummaries(survey, recordManager, rootEntityName, offset, maxNumberOfRecords, orderByFieldName, filter);
    assertNotNull(list);
    assertEquals(maxNumberOfRecords, list.size());
    // test first record of the page
    {
        CollectRecord sampleRecordSummary = list.get(0);
        List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
        assertEquals(new Integer(1), entityCounts.get(0));
    }
    // test last record of the page
    {
        CollectRecord sampleRecordSummary = list.get(4);
        List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
        assertEquals(new Integer(5), entityCounts.get(0));
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with CollectRecord

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

the class RecordDaoTest method createAndSaveSampleRecords.

/**
 * Creates sample records with different id and different number of plots.
 */
private void createAndSaveSampleRecords() {
    sampleRecords = new ArrayList<CollectRecord>();
    // create and save clusters
    for (int i = 1; i <= numberOfSampleRecords; i++) {
        CollectRecord record = createRecord(survey, i);
        sampleRecords.add(record);
        recordDao.saveOrUpdate(record);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord)

Example 38 with CollectRecord

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

the class RecordDaoTest method createRecord.

private CollectRecord createRecord(CollectSurvey survey, int sequenceNumber) {
    int skippedCount = new Double(Math.ceil((double) (Math.random() * 40))).intValue();
    int missingCount = new Double(Math.ceil((double) (Math.random() * 50))).intValue();
    int errorsCount = new Double(Math.ceil((double) (Math.random() * 10))).intValue();
    int warningsCount = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    int numberOfPlots = new Double(Math.ceil((double) (Math.random() * 20))).intValue();
    int numberOfTrees = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    ;
    CollectRecord record = new CollectRecord(recordManager, survey, "2.0");
    record.setCreationDate(new GregorianCalendar(2011, 0, sequenceNumber, 8, 30).getTime());
    // record.setCreatedBy("ModelDaoIntegrationTest");
    record.setStep(Step.ENTRY);
    record.setModifiedDate(new GregorianCalendar(2011, 1, sequenceNumber, 8, 30).getTime());
    record.setSkipped(skippedCount);
    record.setMissing(missingCount);
    record.setErrors(errorsCount);
    record.setWarnings(warningsCount);
    Entity cluster = record.createRootEntity("cluster");
    String keyId = Integer.toString(sequenceNumber);
    EntityBuilder.addValue(cluster, "id", new Code(keyId));
    EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
    EntityBuilder.addValue(cluster, "region", new Code("001"));
    EntityBuilder.addValue(cluster, "district", new Code("002"));
    EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(432423423l, 4324324l, "srs"));
    EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 14));
        ts.addValue("start_time", new Time(8, 15));
        ts.addValue("end_time", new Time(15, 29));
    }
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 15));
        ts.addValue("start_time", new Time(8, 32));
        ts.addValue("end_time", new Time(11, 20));
    }
    for (int i = 0; i < numberOfPlots; i++) {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code(Integer.toString(i + 1)));
        for (int j = 0; j < numberOfTrees; j++) {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            tree.addValue("dbh", 54.2);
            tree.addValue("total_height", 2.0);
            RealAttribute boleHeight = tree.addValue("bole_height", (Double) null);
            boleHeight.getField().setSymbol('*');
            boleHeight.getField().setRemarks("No value specified");
        // .setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
        }
    }
    // set counts
    record.getEntityCounts().add(numberOfPlots);
    // set keys
    record.getRootEntityKeys().add(keyId);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RealAttribute(org.openforis.idm.model.RealAttribute) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 39 with CollectRecord

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

the class RecordDaoSpeedTest method testCRUD.

// @Autowired
// protected SurveyContext recordContext;
// public void testRecordSerialize() throws Exception  {
// CollectSurvey survey = surveyDao.load("naforma1");
// CollectRecord r1 = recordDao.load(survey, new CollectRecordContext(),  2099);
// ModelSerializer ser = new ModelSerializer(10000);
// FileOutputStream fis = new FileOutputStream("src/it/resources/test-record.bin");
// try {
// ser.writeTo(fis, r1.getRootEntity());
// fis.flush();
// } finally {
// fis.close();
// }
// }
// public void testRecordStore() throws Exception {
// CollectSurvey survey = surveyDao.load("naforma1");
// ModelSerializer ser = new ModelSerializer(10000);
// FileInputStream fis = new FileInputStream("src/it/resources/test-record.bin");
// try {
// CollectRecord r1 = new CollectRecord(new CollectRecordContext(), survey, "2.0");
// r1.createRootEntity("cluster");
// r1.setId(2099);
// ser.mergeFrom(fis, r1.getRootEntity());
// recordDao.update(r1);
// } finally {
// fis.close();
// }
// 
// }
@Test
public void testCRUD() throws Exception {
    // try {
    // LOAD MODEL
    CollectSurvey survey = surveyDao.load("naforma1");
    CollectRecord r1;
    {
        long t1 = System.currentTimeMillis();
        r1 = recordDao.load(survey, new CollectRecordContext(), 2099);
        long t = System.currentTimeMillis() - t1;
        System.out.println("load " + t);
    }
    String s1 = r1.toString();
    {
        long t1 = System.currentTimeMillis();
        recordDao.update(r1);
        long t = System.currentTimeMillis() - t1;
        System.out.println("update " + t);
    }
    {
        long t1 = System.currentTimeMillis();
        recordDao.delete(r1);
        long t = System.currentTimeMillis() - t1;
        System.out.println("delete " + t);
    }
    {
        long t1 = System.currentTimeMillis();
        recordDao.insert(r1);
        long t = System.currentTimeMillis() - t1;
        System.out.println("insert " + t);
    }
    CollectRecord r2 = recordDao.load(survey, new CollectRecordContext(), 2099);
    String s2 = r2.toString();
    Assert.assertEquals(s1, s2);
// 
// // SAVE NEW
// CollectRecord record = createTestRecord(survey);
// recordDao.saveOrUpdate(record);
// 
// String saved = record.toString();
// log.debug("Saving record:\n"+saved);
// 
// // RELOAD
// record = recordDao.load(survey, record.getId());
// String reloaded = record.toString();
// log.debug("Reloaded as:\n"+reloaded);
// 
// assertEquals(saved, reloaded);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordContext(org.openforis.collect.model.CollectRecordContext) CollectSurvey(org.openforis.collect.model.CollectSurvey) Test(org.junit.Test)

Example 40 with CollectRecord

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

the class DataHandler method startRecord.

public void startRecord(String localName, Attributes attributes) {
    String versionName = extractVersionName(attributes);
    record = new CollectRecord(currentSurvey, versionName, localName, validationEnabled);
    String stateAttr = attributes.getValue(ATTRIBUTE_STATE);
    State state = State.fromCode(stateAttr);
    record.setState(state);
    Date created = Dates.parseDateTime(attributes.getValue(ATTRIBUTE_DATE_CREATED));
    Date modified = Dates.parseDateTime(attributes.getValue(ATTRIBUTE_DATE_MODIFIED));
    record.setCreationDate(created);
    record.setModifiedDate(modified);
    String createdByUserName = attributes.getValue(ATTRIBUTE_CREATED_BY);
    User createdBy = fetchUser(createdByUserName);
    record.setCreatedBy(createdBy);
    String modifiedByUserName = attributes.getValue(ATTRIBUTE_MODIFIED_BY);
    User modifiedBy = fetchUser(modifiedByUserName);
    record.setModifiedBy(modifiedBy);
    node = record.getRootEntity();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) State(org.openforis.collect.model.CollectRecord.State) Date(java.util.Date)

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