use of org.openforis.collect.persistence.SurveyImportException in project collect by openforis.
the class CollectSurveyIdmlBinder method marshal.
public String marshal(Survey survey) throws SurveyImportException {
try {
// Serialize Survey to XML
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshal(survey, os);
return new String(os.toByteArray(), OpenForisIOUtils.UTF_8);
} catch (IOException e) {
throw new SurveyImportException("Error marshalling survey", e);
}
}
use of org.openforis.collect.persistence.SurveyImportException in project collect by openforis.
the class SurveyManager method duplicateSurveyIntoTemporary.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey duplicateSurveyIntoTemporary(String originalSurveyName, boolean originalSurveyIsTemporary, String newName, User activeUser) {
try {
CollectSurvey oldSurvey = loadSurvey(originalSurveyName, originalSurveyIsTemporary);
// TODO : clone it
CollectSurvey newSurvey = oldSurvey;
newSurvey.setId(null);
newSurvey.setPublished(false);
newSurvey.setTemporary(true);
newSurvey.setAvailability(UNPUBLISHED);
newSurvey.setPublishedId(null);
newSurvey.setName(newName);
newSurvey.setUri(generateSurveyUri(newName));
newSurvey.setCreationDate(new Date());
newSurvey.setModifiedDate(new Date());
if (newSurvey.getSamplingDesignCodeList() == null) {
newSurvey.addSamplingDesignCodeList();
}
surveyDao.insert(newSurvey);
// reload old survey, it has been modified previously
oldSurvey = loadSurvey(originalSurveyName, originalSurveyIsTemporary);
copyReferencedMetadata(oldSurvey, newSurvey, activeUser);
return newSurvey;
} catch (SurveyImportException e) {
// it should never enter here, we are duplicating an already existing survey
throw new RuntimeException(e);
}
}
use of org.openforis.collect.persistence.SurveyImportException 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.persistence.SurveyImportException 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.persistence.SurveyImportException 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);
}
}
Aggregations