Search in sources :

Example 6 with SurveyImportException

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListImportException(org.openforis.collect.io.exception.CodeListImportException) SurveySummary(org.openforis.collect.model.SurveySummary) 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 SurveyImportException

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);
    }
}
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 8 with SurveyImportException

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;
}
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)

Example 9 with SurveyImportException

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

Aggregations

SurveyImportException (org.openforis.collect.persistence.SurveyImportException)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)8 Transactional (org.springframework.transaction.annotation.Transactional)8 CodeListImportException (org.openforis.collect.io.exception.CodeListImportException)4 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)4 SurveySummary (org.openforis.collect.model.SurveySummary)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 CodeList (org.openforis.idm.metamodel.CodeList)1