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();
}
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations