use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyDao method loadTemporarySummaries.
public List<SurveySummary> loadTemporarySummaries() {
List<SurveySummary> surveys = new ArrayList<SurveySummary>();
Result<Record> results = dsl().select().from(OFC_SURVEY).where(OFC_SURVEY.TEMPORARY.equal(true)).fetch();
for (Record row : results) {
SurveySummary survey = processSurveySummaryRow(row);
if (survey != null) {
surveys.add(survey);
}
}
return surveys;
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyDao method processSurveySummaryRow.
protected SurveySummary processSurveySummaryRow(Record row) {
if (row == null) {
return null;
}
Integer id = row.getValue(OFC_SURVEY.ID);
String name = row.getValue(OFC_SURVEY.NAME);
String uri = row.getValue(OFC_SURVEY.URI);
SurveySummary s = new SurveySummary(id, name, uri);
s.setTemporary(row.getValue(OFC_SURVEY.TEMPORARY));
s.setPublishedId(row.getValue(OFC_SURVEY.PUBLISHED_ID));
s.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
s.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
s.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
s.setUserGroupId(row.getValue(OFC_SURVEY.USERGROUP_ID));
s.setAvailability(s.isTemporary() ? UNPUBLISHED : PUBLISHED);
return s;
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyWorkDao method loadSummaries.
@Transactional
public List<SurveySummary> loadSummaries() {
List<SurveySummary> surveys = new ArrayList<SurveySummary>();
Result<Record> results = dsl().select().from(OFC_SURVEY_WORK).fetch();
for (Record row : results) {
SurveySummary survey = processSurveySummaryRow(row);
if (survey != null) {
surveys.add(survey);
}
}
return surveys;
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyController method createSurvey.
@Transactional
@RequestMapping(method = POST)
@ResponseBody
public Response createSurvey(@Valid SurveyCreationParameters params, BindingResult bindingResult) throws Exception {
if (bindingResult.hasErrors()) {
Response res = new Response();
res.setErrorStatus();
res.addObject("errors", bindingResult.getFieldErrors());
return res;
}
CollectSurvey survey;
switch(params.getTemplateType()) {
case BLANK:
survey = createEmptySurvey(params.getName(), params.getDefaultLanguageCode());
break;
default:
survey = createNewSurveyFromTemplate(params.getName(), params.getDefaultLanguageCode(), params.getTemplateType());
}
UserGroup userGroup = userGroupManager.loadById(params.getUserGroupId());
survey.setUserGroupId(userGroup.getId());
surveyManager.save(survey);
SurveySummary surveySummary = SurveySummary.createFromSurvey(survey);
Response res = new Response();
res.setObject(surveySummary);
return res;
}
use of org.openforis.collect.model.SurveySummary in project collect by openforis.
the class SurveyCloneParametersValidator method validateOriginalSurveyExists.
private void validateOriginalSurveyExists(SurveyCloneParameters parameters, Errors errors) {
ErrorsHelper helper = new ErrorsHelper(errors);
String originalSurveyName = helper.getStringValue(ORIGINAL_SURVEY_NAME_FIELD);
SurveySummary summary = surveyManager.loadSummaryByName(originalSurveyName);
if (summary == null) {
errors.rejectValue(ORIGINAL_SURVEY_NAME_FIELD, ORIGINAL_SURVEY_NOT_FOUND_MESSAGE_KEY, new String[] { originalSurveyName }, null);
}
}
Aggregations