use of org.openforis.idm.metamodel.xml.IdmlParseException 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.idm.metamodel.xml.IdmlParseException 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.idm.metamodel.xml.IdmlParseException 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.idm.metamodel.xml.IdmlParseException in project collect by openforis.
the class SurveyDao method processSurveyRow.
protected CollectSurvey processSurveyRow(Record row) {
try {
if (row == null) {
return null;
}
String idml = row.getValue(OFC_SURVEY.IDML);
CollectSurvey s = unmarshalIdml(idml);
s.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
s.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
s.setId(row.getValue(OFC_SURVEY.ID));
s.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
s.setName(row.getValue(OFC_SURVEY.NAME));
s.setPublishedId(row.getValue(OFC_SURVEY.PUBLISHED_ID));
s.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
s.setTemporary(row.getValue(OFC_SURVEY.TEMPORARY));
s.setUri(row.getValue(OFC_SURVEY.URI));
s.setUserGroupId(row.getValue(OFC_SURVEY.USERGROUP_ID));
return s;
} catch (IdmlParseException e) {
throw new RuntimeException("Error deserializing IDML from database", e);
}
}
use of org.openforis.idm.metamodel.xml.IdmlParseException in project collect by openforis.
the class SurveyWorkDao method processSurveyRow.
@Override
protected CollectSurvey processSurveyRow(Record row) {
if (row == null) {
return null;
}
String name = null;
Integer id = null;
try {
id = row.getValue(OFC_SURVEY_WORK.ID);
name = row.getValue(OFC_SURVEY_WORK.NAME);
String idml = row.getValue(OFC_SURVEY_WORK.IDML);
CollectSurvey survey = unmarshalIdml(idml);
survey.setId(id);
survey.setName(name);
survey.setWork(true);
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.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
return survey;
} catch (IdmlParseException e) {
throw new RuntimeException(String.format("Error deserializing temporary survey from database (id=%d, name=%s)", id, name), e);
}
}
Aggregations