Search in sources :

Example 21 with SurveySummary

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

the class SurveyManager method createTemporarySurveyFromPublished.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey createTemporarySurveyFromPublished(String uri, boolean markCopyAsPublished, boolean preserveReferenceToPublishedSurvey, User activeUser) {
    try {
        SurveySummary existingTemporarySurvey = surveyDao.loadSurveySummaryByUri(uri, true);
        if (existingTemporarySurvey != null) {
            throw new IllegalArgumentException("Temporary survey with uri " + uri + " already existing");
        }
        CollectSurvey publishedSurvey = surveyDao.loadByUri(uri, false);
        int publishedSurveyId = publishedSurvey.getId();
        // the published survey object should be cloned...
        CollectSurvey temporarySurvey = publishedSurvey;
        temporarySurvey.setId(null);
        temporarySurvey.setPublished(markCopyAsPublished);
        temporarySurvey.setTemporary(true);
        temporarySurvey.setAvailability(UNPUBLISHED);
        temporarySurvey.setPublishedId(preserveReferenceToPublishedSurvey ? publishedSurveyId : null);
        if (temporarySurvey.getSamplingDesignCodeList() == null) {
            temporarySurvey.addSamplingDesignCodeList();
        }
        surveyDao.insert(temporarySurvey);
        publishedSurvey = getByUri(uri);
        copyReferencedMetadata(publishedSurvey, temporarySurvey, activeUser);
        return temporarySurvey;
    } catch (SurveyImportException e) {
        // it should never enter here, we are duplicating an already existing survey
        throw new RuntimeException(e);
    }
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with SurveySummary

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

the class SurveyManager method updateTemporaryModel.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey updateTemporaryModel(File surveyFile, boolean validate, UserGroup userGroup) throws SurveyValidationException, SurveyStoreException {
    CollectSurvey parsedSurvey;
    try {
        parsedSurvey = unmarshalSurvey(surveyFile, validate, false);
    } catch (IdmlParseException e) {
        throw new SurveyImportException(e);
    }
    String uri = parsedSurvey.getUri();
    SurveySummary oldTemporarySurvey = loadTemporarySummaryByUri(uri);
    if (oldTemporarySurvey == null) {
        throw new IllegalArgumentException("Survey to update not found: " + uri);
    } else {
        int oldSurveyId = oldTemporarySurvey.getId();
        parsedSurvey.setId(oldSurveyId);
        parsedSurvey.setName(oldTemporarySurvey.getName());
        parsedSurvey.setPublishedId(oldTemporarySurvey.getPublishedId());
        parsedSurvey.setTemporary(true);
        parsedSurvey.setUserGroup(userGroup);
        // clean code list items
        for (CodeList codeList : parsedSurvey.getCodeLists()) {
            codeList.removeAllItems();
        }
        codeListManager.deleteAllItemsBySurvey(oldSurveyId, true);
        save(parsedSurvey);
        // import code list items
        try {
            codeListManager.importCodeLists(parsedSurvey, surveyFile);
        } catch (CodeListImportException e) {
            throw new SurveyImportException(e);
        }
    }
    return parsedSurvey;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListImportException(org.openforis.collect.io.exception.CodeListImportException) SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with SurveySummary

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

the class SurveyManager method loadTemporarySummaries.

public List<SurveySummary> loadTemporarySummaries(String labelLang, boolean includeDetails, Set<Integer> groupIds) {
    List<SurveySummary> summaries = surveyDao.loadTemporarySummaries();
    List<SurveySummary> filteredSummaries = filterSummariesUserGroups(summaries, groupIds);
    fillSummariesReferencedItems(filteredSummaries);
    if (includeDetails) {
        for (SurveySummary summary : filteredSummaries) {
            CollectSurvey survey = surveyDao.loadById(summary.getId());
            String projectName = survey.getProjectName(labelLang);
            if (labelLang == null) {
                projectName = survey.getProjectName();
            } else {
                projectName = survey.getProjectName(labelLang, true);
            }
            summary.setProjectName(projectName);
            summary.setDefaultLanguage(survey.getDefaultLanguage());
            summary.setLanguages(survey.getLanguages());
        }
    }
    return filteredSummaries;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 24 with SurveySummary

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

the class SurveyManager method unpublish.

/**
 * If no temporary survey is associated to the published one with the specified id,
 * it duplicates the published survey into a temporary one, then removes the published one.
 * @param activeUser
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey unpublish(int surveyId, User activeUser) throws SurveyStoreException {
    CollectSurvey publishedSurvey = getById(surveyId);
    String uri = publishedSurvey.getUri();
    SurveySummary temporarySurveySummary = surveyDao.loadSurveySummaryByUri(uri, true);
    CollectSurvey temporarySurvey;
    if (temporarySurveySummary == null) {
        temporarySurvey = createTemporarySurveyFromPublished(uri, false, false, activeUser);
    } else {
        temporarySurvey = loadSurvey(temporarySurveySummary.getId());
        temporarySurvey.setPublished(false);
        temporarySurvey.setPublishedId(null);
        save(temporarySurvey);
        if (dataCleansingManager != null) {
            // overwrite temporary cleansing metadata with published one
            dataCleansingManager.moveMetadata(publishedSurvey, temporarySurvey, activeUser);
        }
    }
    // delete published survey
    deleteSurvey(surveyId);
    return temporarySurvey;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with SurveySummary

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

the class SurveyManager method getSurveySummaries.

public List<SurveySummary> getSurveySummaries(String lang, Set<Integer> userGroupIds) {
    List<SurveySummary> summaries = new ArrayList<SurveySummary>();
    for (CollectSurvey survey : getPublishedSurveyCache().surveys) {
        if (userGroupIds == null || userGroupIds.contains(survey.getUserGroupId())) {
            SurveySummary summary = SurveySummary.createFromSurvey(survey, lang);
            if (summary.isPublished()) {
                int publishedSurveyId = summary.isTemporary() ? summary.getPublishedId() : summary.getId();
                summary.setRecordValidationProcessStatus(getRecordValidationProcessStatus(publishedSurveyId));
            }
            summaries.add(summary);
        }
    }
    sortSummaries(summaries);
    return summaries;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey)

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