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