Search in sources :

Example 21 with RecordFilter

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

the class CSVDataImportProcessIntegrationTest method loadRecord.

private CollectRecord loadRecord(String key) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition("cluster").getId());
    filter.setKeyValues(Arrays.asList(key));
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    assertEquals(1, summaries.size());
    CollectRecordSummary summary = summaries.get(0);
    CollectRecord reloadedRecord = recordManager.load(survey, summary.getId(), summary.getStep());
    return reloadedRecord;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 22 with RecordFilter

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

the class ModelDaoIntegrationTest method testLoadRecordSummaries.

// @Test
public void testLoadRecordSummaries() {
    // get the first root entity
    EntityDefinition rootEntity = survey.getSchema().getFirstRootEntityDefinition();
    String rootEntityName = rootEntity.getName();
    int offset = 0;
    int maxNumberOfRecords = 1;
    RecordSummarySortField sortField = new RecordSummarySortField(Sortable.KEY1);
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    filter.setOffset(offset);
    filter.setMaxNumberOfRecords(maxNumberOfRecords);
    List<CollectRecordSummary> list = this.recordDao.loadSummaries(filter, Arrays.asList(sortField));
    assertNotNull(list);
    assertEquals(1, list.size());
    CollectRecordSummary summary = list.get(0);
    assertEquals(Step.ENTRY, summary.getStep());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) RecordSummarySortField(org.openforis.collect.model.RecordSummarySortField) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 23 with RecordFilter

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

the class SurveyEditVM method exportCeCsvDataImportTemplate.

@Command
public void exportCeCsvDataImportTemplate() throws IOException {
    CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
    job.setOutputFile(File.createTempFile("ce-data-import-template-" + survey.getName(), ".csv"));
    RecordFilter recordFilter = new RecordFilter(survey);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    recordFilter.setRootEntityId(rootEntityDef.getId());
    CSVDataExportParameters parameters = new CSVDataExportParameters();
    parameters.setRecordFilter(recordFilter);
    parameters.setEntityId(rootEntityDef.getId());
    parameters.setAlwaysGenerateZipFile(false);
    parameters.setIncludeEnumeratedEntities(true);
    job.setParameters(parameters);
    jobManager.start(job, false);
    if (job.isCompleted()) {
        File outputFile = job.getOutputFile();
        String dateStr = Dates.formatLocalDateTime(new Date());
        String fileName = String.format(DATA_IMPORT_TEMPLATE_FILE_NAME_PATTERN, survey.getName(), dateStr, "csv");
        String contentType = URLConnection.guessContentTypeFromName(fileName);
        FileInputStream is = new FileInputStream(outputFile);
        Filedownload.save(is, contentType, fileName);
    } else {
        throw new RuntimeException("Error generating the CSV data export template: " + job.getErrorMessage(), job.getLastException());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 24 with RecordFilter

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

the class SurveyExportParametersVM method startRDBSurveyExportJob.

private void startRDBSurveyExportJob(final CollectSurvey survey, final SurveyExportParametersFormObject parameters) {
    rdbExportJob = new RDBPrintJob();
    rdbExportJob.setSurvey(survey);
    rdbExportJob.setTargetSchemaName(survey.getName());
    rdbExportJob.setRecordManager(recordManager);
    RecordFilter recordFilter = new RecordFilter(survey);
    rdbExportJob.setRecordFilter(recordFilter);
    rdbExportJob.setIncludeData(parameters.isIncludeData());
    rdbExportJob.setDialect(parameters.getRdbDialectEnum());
    rdbExportJob.setDateTimeFormat(parameters.getRdbDateTimeFormat());
    rdbExportJob.setTargetSchemaName(parameters.getRdbTargetSchemaName());
    jobManager.start(rdbExportJob, String.valueOf(survey.getId()));
    openSurveyExportStatusPopUp(survey.getName(), rdbExportJob);
}
Also used : RDBPrintJob(org.openforis.collect.relational.print.RDBPrintJob) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 25 with RecordFilter

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

the class RandomRecordGenerator method calculateRecordMeasurementsByKey.

private Map<RecordKey, Integer> calculateRecordMeasurementsByKey(CollectSurvey survey, final User user) {
    final List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    final Map<RecordKey, Integer> measurementsByRecordKey = new HashMap<RecordKey, Integer>();
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            if (summary.getCreatedBy().getId() != user.getId()) {
                List<String> keys = summary.getCurrentStepSummary().getRootEntityKeyValues();
                RecordKey nonMeasurementKey = new RecordKey(nonMeasurementKeyDefs, keys);
                Integer measurements = measurementsByRecordKey.get(nonMeasurementKey);
                if (measurements == null) {
                    measurements = 1;
                } else {
                    measurements += 1;
                }
                measurementsByRecordKey.put(nonMeasurementKey, measurements);
            }
        }
    });
    samplingDesignManager.visitItems(survey.getId(), 1, new Visitor<SamplingDesignItem>() {

        public void visit(SamplingDesignItem item) {
            RecordKey key = new RecordKey(nonMeasurementKeyDefs, item.getLevelCodes());
            Integer measurements = measurementsByRecordKey.get(key);
            if (measurements == null) {
                measurementsByRecordKey.put(key, 0);
            }
        }
    });
    return measurementsByRecordKey;
}
Also used : HashMap(java.util.HashMap) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) RecordFilter(org.openforis.collect.model.RecordFilter) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3