Search in sources :

Example 41 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) GregorianCalendar(java.util.GregorianCalendar)

Example 42 with CollectRecord

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
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Table(org.openforis.collect.relational.model.Table) RelationalSchemaGenerator(org.openforis.collect.relational.model.RelationalSchemaGenerator) Dataset(org.openforis.collect.relational.model.Dataset) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) Test(org.junit.Test)

Example 43 with CollectRecord

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);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord)

Example 44 with CollectRecord

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);
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with CollectRecord

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;
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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