Search in sources :

Example 1 with CodeListImportException

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

Example 2 with CodeListImportException

use of org.openforis.collect.io.exception.CodeListImportException 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 3 with CodeListImportException

use of org.openforis.collect.io.exception.CodeListImportException 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 4 with CodeListImportException

use of org.openforis.collect.io.exception.CodeListImportException 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 5 with CodeListImportException

use of org.openforis.collect.io.exception.CodeListImportException 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)

Aggregations

CodeListImportException (org.openforis.collect.io.exception.CodeListImportException)6 Transactional (org.springframework.transaction.annotation.Transactional)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)4 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)4 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 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