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