Search in sources :

Example 1 with SurveyImportException

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);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SurveyImportException(org.openforis.collect.persistence.SurveyImportException)

Example 2 with SurveyImportException

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

Example 3 with SurveyImportException

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

Example 4 with SurveyImportException

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

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);
    }
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) 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