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