use of org.openforis.collect.persistence.SurveyImportException 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.persistence.SurveyImportException in project collect by openforis.
the class SurveyManager method importModel.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey importModel(File surveyFile, String name, boolean validate, boolean includeCodeLists, UserGroup userGroup) throws SurveyImportException, SurveyValidationException {
try {
CollectSurvey survey = unmarshalSurvey(surveyFile, validate, includeCodeLists);
survey.setUserGroup(userGroup);
survey.setName(name);
survey.setPublished(true);
surveyDao.insert(survey);
getPublishedSurveyCache().add(survey);
codeListManager.importCodeLists(survey, surveyFile);
return survey;
} catch (CodeListImportException e) {
throw new SurveyImportException(e);
} catch (IdmlParseException e) {
throw new SurveyImportException(e);
}
}
use of org.openforis.collect.persistence.SurveyImportException in project collect by openforis.
the class SurveyManager method updateModel.
/**
* Updates a published or a temporary survey and overwrites it with the specified one.
* The existing survey will be searched by his URI.
* If a temporary survey with the same URI as the survey in the surveyFile exists,
* than it will be overwritten with the passed one, otherwise the published survey will be overwritten.
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey updateModel(File surveyFile, boolean validate, boolean includeCodeLists) throws SurveyValidationException, SurveyImportException {
CollectSurvey parsedSurvey;
try {
parsedSurvey = unmarshalSurvey(surveyFile, validate, includeCodeLists);
} catch (IdmlParseException e) {
throw new SurveyImportException(e);
}
updateModel(surveyFile, parsedSurvey);
/*
String uri = parsedSurvey.getUri();
SurveySummary oldSurveyWork = loadWorkSummaryByUri(uri);
CollectSurvey oldPublishedSurvey = getByUri(uri);
if ( oldSurveyWork == null && oldPublishedSurvey == null ) {
throw new IllegalArgumentException("Survey to update not found: " + uri);
} else if ( oldSurveyWork != null ) {
updateSurveyWork(surveyFile, parsedSurvey, oldSurveyWork);
} else {
updatePublishedSurvey(surveyFile, parsedSurvey, false);
}
*/
return parsedSurvey;
}
use of org.openforis.collect.persistence.SurveyImportException in project collect by openforis.
the class SurveyManager method updateModel.
/**
* Updates a published survey and overwrites it with the specified one.
* The existing published survey will be searched by his URI.
*
* @param survey
* @throws SurveyImportException
* @deprecated Use {@link #updateModel(File, boolean)} instead.
*/
@Deprecated
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void updateModel(CollectSurvey survey) throws SurveyImportException {
// remove old survey from surveys cache
CollectSurvey oldSurvey = get(survey.getName());
if (oldSurvey != null) {
getPublishedSurveyCache().remove(oldSurvey);
} else {
throw new SurveyImportException("Could not find survey to update");
}
surveyDao.update(survey);
getPublishedSurveyCache().add(survey);
}
Aggregations