Search in sources :

Example 66 with CollectSurvey

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

the class SurveyController method createNewSurveyFromTemplate.

private CollectSurvey createNewSurveyFromTemplate(String name, String langCode, TemplateType templateType) throws IdmlParseException, SurveyValidationException {
    String templateFileName = String.format(IDM_TEMPLATE_FILE_NAME_FORMAT, templateType.name().toLowerCase(Locale.ENGLISH));
    InputStream surveyFileIs = this.getClass().getResourceAsStream(templateFileName);
    CollectSurvey survey = surveyManager.unmarshalSurvey(surveyFileIs, false, true);
    survey.setName(name);
    survey.setTemporary(true);
    survey.setUri(surveyManager.generateSurveyUri(name));
    survey.setDefaultLanguage(langCode);
    SurveyTarget target;
    switch(templateType) {
        case COLLECT_EARTH:
        case COLLECT_EARTH_IPCC:
            target = SurveyTarget.COLLECT_EARTH;
            break;
        default:
            target = SurveyTarget.COLLECT_DESKTOP;
    }
    survey.setTarget(target);
    if (survey.getSamplingDesignCodeList() == null) {
        survey.addSamplingDesignCodeList();
    }
    return survey;
}
Also used : SurveyTarget(org.openforis.collect.metamodel.SurveyTarget) InputStream(java.io.InputStream) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 67 with CollectSurvey

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

the class SurveyController method downloadCsvExportResult.

@RequestMapping(value = "export/{surveyId}/result", method = GET)
public void downloadCsvExportResult(HttpServletResponse response) throws FileNotFoundException, IOException {
    if (surveyBackupJob != null) {
        File outputFile;
        String outputFileExtension;
        CollectSurvey survey;
        String projectName;
        if (surveyBackupJob instanceof CollectEarthSurveyExportJob) {
            CollectEarthSurveyExportJob backupJob = (CollectEarthSurveyExportJob) surveyBackupJob;
            outputFile = backupJob.getOutputFile();
            outputFileExtension = COLLECT_EARTH_PROJECT_FILE_EXTENSION;
            survey = backupJob.getSurvey();
            projectName = survey.getName();
        } else {
            SurveyBackupJob backupJob = (SurveyBackupJob) surveyBackupJob;
            outputFile = backupJob.getOutputFile();
            outputFileExtension = backupJob.getOutputFormat().getOutputFileExtension();
            survey = backupJob.getSurvey();
            projectName = survey.getName();
            if (backupJob.getOutputFormat() == SurveyBackupJob.OutputFormat.MOBILE) {
                projectName += "_" + backupJob.getOutputSurveyDefaultLanguage();
            }
        }
        String fileName = String.format("%s_%s.%s", projectName, Dates.formatCompactDateTime(survey.getModifiedDate()), outputFileExtension);
        Controllers.writeFileToResponse(response, outputFile, fileName, Controllers.ZIP_CONTENT_TYPE);
    }
}
Also used : CollectEarthSurveyExportJob(org.openforis.collect.manager.CollectEarthSurveyExportJob) SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with CollectSurvey

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

the class SurveyController method closeSurvey.

@RequestMapping(value = "close/{id}", method = POST)
@ResponseBody
public SurveyView closeSurvey(@PathVariable int id) throws SurveyImportException {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(id);
    surveyManager.close(survey);
    return generateView(survey, false);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 69 with CollectSurvey

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

the class SurveyController method unpublishSurvey.

@RequestMapping(value = "unpublish/{id}", method = POST)
@ResponseBody
public SurveyView unpublishSurvey(@PathVariable int id) throws SurveyStoreException {
    User activeUser = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.unpublish(id, activeUser);
    return generateView(survey, false);
}
Also used : User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 70 with CollectSurvey

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

the class SurveyController method archiveSurvey.

@RequestMapping(value = "archive/{id}", method = POST)
@ResponseBody
public SurveyView archiveSurvey(@PathVariable int id) throws SurveyImportException {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(id);
    surveyManager.archive(survey);
    return generateView(survey, false);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15