use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CollectRelationalTest method createTestRecord.
protected static CollectRecord createTestRecord(CollectSurvey survey, String id) {
CollectRecord record = new CollectRecord(survey, "2.0");
Entity cluster = record.createRootEntity("cluster");
record.setCreationDate(new GregorianCalendar(2011, 12, 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;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RelationalDataConverterTest method testGenerator.
@Test
public void testGenerator() throws Exception {
RelationalSchemaGenerator rsg = new RelationalSchemaGenerator();
RelationalSchema rs = rsg.generateSchema(survey, "archenland1");
List<Table<?>> tables = rs.getTables();
CollectRecord record = createTestRecord(survey, "123_456");
Dataset data = rs.createDataset(record);
data.print(System.out);
// TODO proper integration test
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataPersister method persist.
public void persist(Node<? extends NodeDefinition> node, int idx) {
CollectRecord record = (CollectRecord) node.getRecord();
// Get database ID of parent
Integer internalId = node.getInternalId();
Integer parentDataId = null;
if (node.getParent() != null) {
Integer parentId = node.getParent().getInternalId();
if (parentId == null) {
throw new NullPointerException("Parent id not set ");
}
parentDataId = dataIds.get(parentId);
}
int dataId = insertRow(record, node, parentDataId, idx);
dataIds.put(internalId, dataId);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordController method exportRecord.
@RequestMapping(value = "survey/{survey_id}/data/records/{record_id}/steps/{step}/csv_content.zip", method = GET, produces = MediaTypes.ZIP_CONTENT_TYPE)
public void exportRecord(@PathVariable(value = "survey_id") int surveyId, @PathVariable(value = "record_id") int recordId, @PathVariable(value = "step") int stepNumber, HttpServletResponse response) throws RecordPersistenceException, IOException {
CollectSurvey survey = surveyManager.getById(surveyId);
CollectRecord record = recordManager.load(survey, recordId);
RecordAccessControlManager accessControlManager = new RecordAccessControlManager();
if (accessControlManager.canEdit(sessionManager.getLoggedUser(), record)) {
CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
CSVDataExportParameters parameters = new CSVDataExportParameters();
RecordFilter recordFilter = createRecordFilter(survey, sessionManager.getLoggedUser(), userGroupManager, null, false);
recordFilter.setRecordId(recordId);
recordFilter.setStepGreaterOrEqual(Step.valueOf(stepNumber));
parameters.setRecordFilter(recordFilter);
parameters.setAlwaysGenerateZipFile(true);
job.setParameters(parameters);
File outputFile = File.createTempFile("record_export", ".zip");
job.setOutputFile(outputFile);
jobManager.startSurveyJob(job);
if (job.isCompleted()) {
String fileName = String.format("record_data_%s.zip", Dates.formatDate(new Date()));
Controllers.writeFileToResponse(response, outputFile, fileName, MediaTypes.ZIP_CONTENT_TYPE);
}
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordFileController method download.
@RequestMapping(value = "/downloadRecordFile.htm", method = RequestMethod.POST)
public void download(HttpServletRequest request, HttpServletResponse response, @RequestParam("nodeId") Integer nodeId) throws Exception {
SessionState sessionState = getSessionState(request);
CollectRecord record = sessionState.getActiveRecord();
File file = fileManager.getFile(record, nodeId);
if (file != null && file.exists()) {
Controllers.writeFileToResponse(response, file);
} else {
Integer recordId = record == null ? null : record.getId();
String fileName = file == null ? null : file.getName();
Exception e = new Exception("File not found: " + fileName + " record id: " + recordId + " node id: " + nodeId);
LOG.error(e);
throw e;
}
}
Aggregations