use of org.openforis.collect.io.exception.CodeListImportException in project collect by openforis.
the class CodeListManager method importCodeLists.
@Transactional
public void importCodeLists(CollectSurvey survey, InputStream is) throws CodeListImportException {
int nextSystemId = codeListItemDao.nextSystemId();
CollectCodeListService service = new CollectCodeListService();
service.setCodeListManager(this);
CodeListImporter binder = new CodeListImporter(service, nextSystemId);
try {
binder.importCodeLists(survey, is);
} catch (IdmlParseException e) {
throw new CodeListImportException(e);
}
}
use of org.openforis.collect.io.exception.CodeListImportException in project collect by openforis.
the class SurveyManager method updateModel.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey updateModel(File surveyFile, CollectSurvey packagedSurvey) throws SurveyValidationException, SurveyImportException {
String uri = packagedSurvey.getUri();
CollectSurvey oldPublishedSurvey = getByUri(uri);
if (oldPublishedSurvey == null) {
throw new IllegalArgumentException("Survey to update not found: " + uri);
}
Integer id = oldPublishedSurvey.getId();
packagedSurvey.setId(id);
packagedSurvey.setName(oldPublishedSurvey.getName());
// ---- WARNING --- cannot check survey compatibility: code lists in packaged survey are empty
// if ( validate ) {
// surveyValidator.checkCompatibility(oldPublishedSurvey1, packagedSurvey);
// }
codeListManager.deleteAllItemsBySurvey(id, false);
getPublishedSurveyCache().remove(oldPublishedSurvey);
surveyDao.update(packagedSurvey);
getPublishedSurveyCache().add(packagedSurvey);
try {
codeListManager.importCodeLists(packagedSurvey, surveyFile);
} catch (CodeListImportException e) {
throw new SurveyImportException(e);
}
return packagedSurvey;
}
use of org.openforis.collect.io.exception.CodeListImportException in project collect by openforis.
the class SurveyManager method importTemporaryModel.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey importTemporaryModel(File surveyFile, String name, boolean validate, UserGroup userGroup) throws SurveyImportException, SurveyValidationException {
try {
CollectSurvey survey = unmarshalSurvey(surveyFile, validate, false);
survey.setUserGroup(userGroup != null ? userGroup : userGroupManager == null ? null : userGroupManager.getDefaultPublicUserGroup());
survey.setName(name);
survey.setTemporary(true);
surveyDao.insert(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.io.exception.CodeListImportException 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.io.exception.CodeListImportException 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);
}
}
Aggregations