Search in sources :

Example 6 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException 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);
    }
}
Also used : CodeListImportException(org.openforis.collect.io.exception.CodeListImportException) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException 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;
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)6 Transactional (org.springframework.transaction.annotation.Transactional)5 CodeListImportException (org.openforis.collect.io.exception.CodeListImportException)4 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)4 Version (org.openforis.commons.versioning.Version)2 SurveySummary (org.openforis.collect.model.SurveySummary)1 CollectCodeListService (org.openforis.collect.service.CollectCodeListService)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListImporter (org.openforis.idm.metamodel.xml.CodeListImporter)1