Search in sources :

Example 26 with SurveySummary

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;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) ArrayList(java.util.ArrayList) Record(org.jooq.Record) OfcSurveyRecord(org.openforis.collect.persistence.jooq.tables.records.OfcSurveyRecord)

Example 27 with SurveySummary

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;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Example 28 with SurveySummary

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;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) ArrayList(java.util.ArrayList) Record(org.jooq.Record) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with SurveySummary

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;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with SurveySummary

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);
    }
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Aggregations

SurveySummary (org.openforis.collect.model.SurveySummary)34 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 Record (org.jooq.Record)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ArrayList (java.util.ArrayList)5 OfcSurveyRecord (org.openforis.collect.persistence.jooq.tables.records.OfcSurveyRecord)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 UserGroup (org.openforis.collect.model.UserGroup)2 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)2 Response (org.openforis.commons.web.Response)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1