Search in sources :

Example 36 with CollectSurvey

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

the class AbstractSurveyRestoreJob method onTaskCompleted.

@Override
protected void onTaskCompleted(Worker task) {
    super.onTaskCompleted(task);
    if (task instanceof IdmlUnmarshallTask) {
        CollectSurvey s = ((IdmlUnmarshallTask) task).getSurvey();
        this.surveyUri = s.getUri();
    } else if (task instanceof IdmlImportTask) {
        IdmlImportTask t = (IdmlImportTask) task;
        // get output survey and set it into job instance instance variable
        this.survey = t.getSurvey();
    }
}
Also used : IdmlUnmarshallTask(org.openforis.collect.io.metadata.IdmlUnmarshallTask) CollectSurvey(org.openforis.collect.model.CollectSurvey) IdmlImportTask(org.openforis.collect.io.metadata.IdmlImportTask)

Example 37 with CollectSurvey

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

the class DeleteRecordHandler method execute.

@Override
public RecordEvent execute(DeleteRecordCommand command) {
    try {
        CollectSurvey survey = surveyManager.getById(command.getSurveyId());
        recordManager.delete(command.getRecordId());
        return new RecordDeletedEvent(survey.getName(), command.getRecordId(), new Date(), command.getUsername());
    } catch (RecordPersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : RecordDeletedEvent(org.openforis.collect.event.RecordDeletedEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) Date(java.util.Date)

Example 38 with CollectSurvey

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

the class NodeCommandHandler method findRecord.

protected CollectRecord findRecord(NodeCommand command) {
    CollectSurvey survey = surveyManager.getById(command.getSurveyId());
    CollectRecord record = recordProvider.provide(survey, command.getRecordId());
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 39 with CollectSurvey

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

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

the class CollectRDBPublisher method export.

public void export(String surveyName, String rootEntityName, Step step, String targetSchemaName, Connection targetConn, RelationalSchemaConfig config, ProgressListener progressListener) throws CollectRdbException {
    try {
        targetConn.setAutoCommit(false);
    } catch (SQLException e) {
    }
    try {
        CollectSurvey survey = surveyManager.get(surveyName);
        // Generate relational model
        RelationalSchemaGenerator schemaGenerator = new RelationalSchemaGenerator(config);
        RelationalSchema relationalSchema = schemaGenerator.generateSchema(survey, targetSchemaName);
        RelationalSchemaCreator relationalSchemaCreator = createRelationalSchemaCreator();
        relationalSchemaCreator.createRelationalSchema(relationalSchema, targetConn);
        relationalSchemaCreator.addConstraints(relationalSchema, targetConn);
        relationalSchemaCreator.addIndexes(relationalSchema, targetConn);
        insertData(survey, rootEntityName, step, targetConn, relationalSchema, progressListener);
        targetConn.commit();
        if (LOG.isInfoEnabled()) {
            LOG.info("RDB generation completed");
        }
    } catch (Exception e) {
        try {
            targetConn.rollback();
        } catch (SQLException e1) {
        }
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) RelationalSchemaGenerator(org.openforis.collect.relational.model.RelationalSchemaGenerator) JooqRelationalSchemaCreator(org.openforis.collect.relational.jooq.JooqRelationalSchemaCreator) CollectSurvey(org.openforis.collect.model.CollectSurvey) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15