use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyController method prepareSurveyImport.
@RequestMapping(value = "prepareimport", method = POST, consumes = MULTIPART_FORM_DATA_VALUE)
@ResponseBody
public Response prepareSurveyImport(@RequestParam("file") MultipartFile multipartFile) throws IOException {
String fileName = multipartFile.getOriginalFilename();
File tempFile = Files.writeToTempFile(multipartFile.getInputStream(), multipartFile.getOriginalFilename(), "ofc_csv_data_import");
String extension = FilenameUtils.getExtension(fileName);
this.uploadedSurveyFile = tempFile;
if (surveyBackupInfoExtractorJob != null && surveyBackupInfoExtractorJob.isRunning()) {
surveyBackupInfoExtractorJob.abort();
}
surveyBackupInfoExtractorJob = jobManager.createJob(SurveyBackupInfoExtractorJob.class);
if (COLLECT_EARTH_PROJECT_FILE_EXTENSION.equalsIgnoreCase(extension)) {
File idmFile = extractIdmFromCEPFile(tempFile);
surveyBackupInfoExtractorJob.setFile(idmFile);
} else {
surveyBackupInfoExtractorJob.setFile(tempFile);
}
surveyBackupInfoExtractorJob.setValidate(false);
jobManager.start(surveyBackupInfoExtractorJob, false);
Response response = new Response();
if (surveyBackupInfoExtractorJob.isCompleted()) {
uploadedSurveyInfo = surveyBackupInfoExtractorJob.getInfo();
response.addObject("surveyBackupInfo", uploadedSurveyInfo);
SurveySummary existingSummary = surveyManager.loadSummaryByUri(uploadedSurveyInfo.getSurveyUri());
response.addObject("importingIntoExistingSurvey", existingSummary != null);
response.addObject("existingSurveyUserGroupId", existingSummary == null ? null : existingSummary.getUserGroupId());
return response;
} else {
response.setErrorStatus();
response.setErrorMessage(surveyBackupInfoExtractorJob.getErrorMessage());
return response;
}
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyController method startExport.
@RequestMapping(value = "export/{id}", method = POST)
@ResponseBody
public JobView startExport(@Valid SurveyExportParameters params, BindingResult result) {
this.surveyBackupJob = null;
String uri = params.getSurveyUri();
// boolean skipValidation = params.isSkipValidation();
SurveySummary surveySummary = surveyManager.loadSummaryByUri(uri);
final CollectSurvey loadedSurvey;
if (surveySummary.isTemporary() && params.getSurveyType() == SurveyType.TEMPORARY) {
loadedSurvey = surveyManager.loadSurvey(surveySummary.getId());
} else {
loadedSurvey = surveyManager.getByUri(uri);
}
switch(params.getOutputFormat()) {
case EARTH:
{
// if (skipValidation || collectEarthSurveyValidator.validate(loadedSurvey).isOk()) {
CollectEarthSurveyExportJob job = jobManager.createJob(CollectEarthSurveyExportJob.class);
job.setSurvey(loadedSurvey);
job.setLanguageCode(params.getLanguageCode());
jobManager.start(job, String.valueOf(loadedSurvey.getId()));
this.surveyBackupJob = job;
return new JobView(job);
}
// break;
case MOBILE:
default:
SurveyBackupJob job = jobManager.createJob(SurveyBackupJob.class);
job.setSurvey(loadedSurvey);
// surveyBackupJob.setIncludeData(parameters.isIncludeData());
// surveyBackupJob.setIncludeRecordFiles(parameters.isIncludeUploadedFiles());
job.setOutputFormat(org.openforis.collect.io.SurveyBackupJob.OutputFormat.valueOf(params.getOutputFormat().name()));
job.setOutputSurveyDefaultLanguage(ObjectUtils.defaultIfNull(params.getLanguageCode(), loadedSurvey.getDefaultLanguage()));
jobManager.start(job, String.valueOf(loadedSurvey.getId()));
this.surveyBackupJob = job;
return new JobView(job);
}
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyCreationParametersValidator method validateSurveyNameUniqueness.
private boolean validateSurveyNameUniqueness(SurveyCreationParameters parameters, Errors errors) {
String name = parameters.getName();
SurveySummary existingSummary = surveyManager.loadSummaryByName(name);
if (existingSummary != null) {
errors.rejectValue(NAME_FIELD, NAME_ALREADY_IN_USE_MESSAGE_KEY);
return false;
} else {
return true;
}
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class ModelDaoIntegrationTest method testSurveyNotFoundByName.
@Test
public void testSurveyNotFoundByName() {
SurveySummary survey = surveyManager.loadSummaryByName("!!!!!!");
assertNull(survey);
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyImportVM method updateForm.
protected void updateForm() {
String surveyName = null;
if (uploadedSurveyUri != null) {
SurveySummary surveySummary = surveyManager.loadSummaryByUri(uploadedSurveyUri);
if (surveySummary == null) {
// new survey
updatingExistingSurvey = false;
updatingPublishedSurvey = false;
surveyName = getFormSurveyName();
if (StringUtils.isEmpty(surveyName)) {
surveyName = uploadedSurveyName;
}
if (StringUtils.isEmpty(surveyName)) {
surveyName = suggestSurveyName(uploadedFileName);
}
} else {
// updating existing survey
updatingExistingSurvey = true;
updatingPublishedSurvey = !surveySummary.isTemporary();
surveyName = surveySummary.getName();
}
}
form.put(SURVEY_NAME_FIELD, surveyName);
notifyChange("updatingPublishedSurvey", "updatingExistingSurvey", "form");
}
Aggregations