Search in sources :

Example 61 with CollectSurvey

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

the class SamplingPointsController method exportWorkSamplingDesign.

@RequestMapping(value = "api/survey/{surveyId}/sampling_point_data.csv", method = GET)
@ResponseBody
public String exportWorkSamplingDesign(HttpServletResponse response, @PathVariable("surveyId") Integer surveyId) throws IOException {
    SamplingDesignExportProcess process = new SamplingDesignExportProcess(samplingDesignManager);
    ServletOutputStream out = response.getOutputStream();
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    Controllers.setOutputContent(response, SAMPLING_DESIGN_CSV_FILE_NAME, CSV_CONTENT_TYPE);
    process.exportToCSV(out, survey);
    return "ok";
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignExportProcess(org.openforis.collect.manager.dataexport.samplingdesign.SamplingDesignExportProcess) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with CollectSurvey

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

the class SessionController method setActiveSurvey.

@RequestMapping(value = "survey", method = POST)
@ResponseBody
public Response setActiveSurvey(@RequestParam int surveyId) {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    sessionManager.setActiveSurvey(survey);
    return new Response();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.openforis.commons.web.Response) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with CollectSurvey

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

the class SessionController method getActiveSurvey.

@RequestMapping(value = "survey", method = GET)
@ResponseBody
public SurveyView getActiveSurvey(HttpServletResponse response) {
    CollectSurvey survey = getUpdatedActiveSurvey();
    if (survey == null) {
        HttpResponses.setNoContentStatus(response);
        return null;
    } else {
        Locale locale = sessionManager.getSessionState().getLocale();
        if (locale == null) {
            locale = Locale.ENGLISH;
        }
        SurveyViewGenerator viewGenerator = new SurveyViewGenerator(locale.getLanguage());
        SurveyView view = viewGenerator.generateView(survey);
        return view;
    }
}
Also used : Locale(java.util.Locale) SurveyViewGenerator(org.openforis.collect.metamodel.view.SurveyViewGenerator) SurveyView(org.openforis.collect.metamodel.view.SurveyView) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 64 with CollectSurvey

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

the class SessionController method getUpdatedActiveSurvey.

private CollectSurvey getUpdatedActiveSurvey() {
    CollectSurvey sessionSurvey = sessionManager.getActiveSurvey();
    if (sessionSurvey == null) {
        return null;
    }
    CollectSurvey storedSurvey;
    if (sessionSurvey.isTemporary()) {
        storedSurvey = surveyManager.loadSurvey(sessionSurvey.getId());
    } else {
        storedSurvey = surveyManager.getById(sessionSurvey.getId());
    }
    if (storedSurvey == null || storedSurvey.isTemporary() != sessionSurvey.isTemporary()) {
        return null;
    } else if (storedSurvey.getModifiedDate().compareTo(sessionSurvey.getModifiedDate()) > 0) {
        // survey updated
        sessionManager.setActiveSurvey(storedSurvey);
        return storedSurvey;
    } else {
        return sessionSurvey;
    }
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 65 with CollectSurvey

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

the class SurveyController method loadSurveys.

@SuppressWarnings("unchecked")
@RequestMapping(method = GET)
@ResponseBody
public List<?> loadSurveys(@RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "groupId", required = false) Integer groupId, @RequestParam(value = "full", required = false) boolean fullSurveys, @RequestParam(value = "includeCodeListValues", required = false) boolean includeCodeListValues, @RequestParam(value = "includeTemporary", required = false) boolean includeTemporary) throws Exception {
    String languageCode = Locale.ENGLISH.getLanguage();
    if (userId == null) {
        userId = sessionManager.getLoggedUser().getId();
    }
    Set<Integer> groupIds = getAvailableUserGroupIds(userId, groupId);
    List<SurveySummary> summaries = new ArrayList<SurveySummary>(surveyManager.getSurveySummaries(languageCode, groupIds));
    if (includeTemporary) {
        summaries.addAll(surveyManager.loadTemporarySummaries(languageCode, true, groupIds));
    }
    List<Object> views = new ArrayList<Object>();
    for (SurveySummary surveySummary : summaries) {
        if (fullSurveys) {
            CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveySummary.getId());
            views.add(generateView(survey, includeCodeListValues));
        } else {
            views.add(surveySummary);
        }
    }
    views.sort(Collections.reverseOrder(new BeanComparator("modifiedDate")));
    return views;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) 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