Search in sources :

Example 6 with SurveySummary

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

the class SurveyWorkDao method loadSurveySummary.

@Transactional
public SurveySummary loadSurveySummary(int id) {
    Record record = dsl().select().from(OFC_SURVEY_WORK).where(OFC_SURVEY_WORK.ID.equal(id)).fetchOne();
    SurveySummary result = processSurveySummaryRow(record);
    return result;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) Record(org.jooq.Record) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with SurveySummary

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

the class SurveyWorkDao method processSurveySummaryRow.

@Override
protected SurveySummary processSurveySummaryRow(Record row) {
    if (row == null) {
        return null;
    }
    Integer id = row.getValue(OFC_SURVEY_WORK.ID);
    String name = row.getValue(OFC_SURVEY_WORK.NAME);
    String uri = row.getValue(OFC_SURVEY.URI);
    SurveySummary survey = new SurveySummary(id, name, uri, null);
    survey.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
    survey.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
    survey.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
    survey.setWork(true);
    survey.setPublished(false);
    return survey;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Example 8 with SurveySummary

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

the class SurveyWorkDao method loadSurveySummaryByUri.

@Transactional
public SurveySummary loadSurveySummaryByUri(String uri) {
    Record record = dsl().select().from(OFC_SURVEY_WORK).where(OFC_SURVEY_WORK.URI.equal(uri)).fetchOne();
    SurveySummary result = processSurveySummaryRow(record);
    return result;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) Record(org.jooq.Record) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with SurveySummary

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

the class SurveyNameValidator method validateNameUniqueness.

private boolean validateNameUniqueness(ValidationContext ctx) {
    String name = getValue(ctx, surveyNameField);
    SurveySummary existingSurveySummary = loadExistingSurveySummaryByName(ctx, name);
    if (existingSurveySummary == null) {
        return true;
    } else {
        this.addInvalidMessage(ctx, surveyNameField, Labels.getLabel(DUPLICATE_NAME_MESSAGE_KEY));
        return false;
    }
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Example 10 with SurveySummary

use of org.openforis.collect.model.SurveySummary 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

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