Search in sources :

Example 1 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException 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 IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException 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 3 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException 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 4 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException in project collect by openforis.

the class SurveyDao method processSurveyRow.

protected CollectSurvey processSurveyRow(Record row) {
    try {
        if (row == null) {
            return null;
        }
        String idml = row.getValue(OFC_SURVEY.IDML);
        CollectSurvey s = unmarshalIdml(idml);
        s.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
        s.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
        s.setId(row.getValue(OFC_SURVEY.ID));
        s.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
        s.setName(row.getValue(OFC_SURVEY.NAME));
        s.setPublishedId(row.getValue(OFC_SURVEY.PUBLISHED_ID));
        s.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
        s.setTemporary(row.getValue(OFC_SURVEY.TEMPORARY));
        s.setUri(row.getValue(OFC_SURVEY.URI));
        s.setUserGroupId(row.getValue(OFC_SURVEY.USERGROUP_ID));
        return s;
    } catch (IdmlParseException e) {
        throw new RuntimeException("Error deserializing IDML from database", e);
    }
}
Also used : Version(org.openforis.commons.versioning.Version) CollectSurvey(org.openforis.collect.model.CollectSurvey) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException)

Example 5 with IdmlParseException

use of org.openforis.idm.metamodel.xml.IdmlParseException in project collect by openforis.

the class SurveyWorkDao method processSurveyRow.

@Override
protected CollectSurvey processSurveyRow(Record row) {
    if (row == null) {
        return null;
    }
    String name = null;
    Integer id = null;
    try {
        id = row.getValue(OFC_SURVEY_WORK.ID);
        name = row.getValue(OFC_SURVEY_WORK.NAME);
        String idml = row.getValue(OFC_SURVEY_WORK.IDML);
        CollectSurvey survey = unmarshalIdml(idml);
        survey.setId(id);
        survey.setName(name);
        survey.setWork(true);
        survey.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
        survey.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
        survey.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
        survey.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
        return survey;
    } catch (IdmlParseException e) {
        throw new RuntimeException(String.format("Error deserializing temporary survey from database (id=%d, name=%s)", id, name), e);
    }
}
Also used : Version(org.openforis.commons.versioning.Version) CollectSurvey(org.openforis.collect.model.CollectSurvey) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException)

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