Search in sources :

Example 11 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromOrignalUtkast.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromOrignalUtkast(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public CopyUtkastBuilderResponse populateCopyUtkastFromOrignalUtkast(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    Utkast orgUtkast = utkastRepository.findOne(orignalIntygsId);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(copyRequest.getOriginalIntygTyp());
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(orgUtkast.getModel());
    } catch (IOException e) {
        throw new ModuleException("Could not convert original certificate to Utlatande", e);
    }
    // Perform enhets auth if coherent journaling is not active.
    if (!coherentJournaling || enforceEnhet) {
        verifyEnhetsAuth(orgUtkast.getVardgivarId(), orgUtkast.getEnhetsId(), true);
    } else {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(orgUtkast, coherentJournaling);
        logService.logReadIntyg(logRequest);
    }
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(orgUtkast.getEnhetsId());
    builderResponse.setOrginalEnhetsNamn(orgUtkast.getEnhetsNamn());
    builderResponse.setOrginalVardgivarId(orgUtkast.getVardgivarId());
    builderResponse.setOrginalVardgivarNamn(orgUtkast.getVardgivarNamn());
    LOG.debug("Populating copy with details from Utkast '{}'", orignalIntygsId);
    ModuleApi moduleApi = moduleRegistry.getModuleApi(copyRequest.getTyp());
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, copyRequest.getTyp(), addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        populatePatientDetailsFromUtkast(utkast, orgUtkast);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Relation(se.inera.intyg.common.support.model.common.internal.Relation) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class UtkastModelToXmlConverterServiceImpl method utkastToJAXBObject.

private Intyg utkastToJAXBObject(String intygsTyp, String json) {
    try {
        ModuleApi moduleApi = intygModuleRegistry.getModuleApi(intygsTyp);
        Utlatande utlatandeFromJson = moduleApi.getUtlatandeFromJson(json);
        return moduleApi.getIntygFromUtlatande(utlatandeFromJson);
    } catch (ModuleNotFoundException | IOException | ModuleException e) {
        LOG.error("Error building Intyg JAXB object from Utkast. Message: {}", e.getMessage());
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Example 13 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class UtkastBootstrapBean method init.

@PostConstruct
public void init() throws IOException {
    for (Resource resource : getResourceListing("classpath*:module-bootstrap-certificate/*.xml")) {
        try {
            String moduleName = resource.getFilename().split("__")[0];
            LOG.info("Bootstrapping certificate '{}' from module ", resource.getFilename(), moduleName);
            Utlatande utlatande = buildUtlatande(resource, moduleName);
            if (utkastRepo.findOne(utlatande.getId()) == null) {
                utkastRepo.save(createUtkast(utlatande));
                switch(utlatande.getTyp()) {
                    case Fk7263EntryPoint.MODULE_ID:
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, true, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.WEBCERT, false, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, true));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, false));
                        break;
                    case TsBasEntryPoint.MODULE_ID:
                    case TsDiabetesEntryPoint.MODULE_ID:
                        // These certificates does not support arende or fragaSvar
                        break;
                    default:
                        // SIT certificates
                        setupArende(utlatande, true, true, FrageStallare.FORSAKRINGSKASSAN);
                        setupArende(utlatande, false, false, FrageStallare.WEBCERT);
                        setupArende(utlatande, false, false, FrageStallare.FORSAKRINGSKASSAN);
                        break;
                }
            }
        } catch (ModuleException | ModuleNotFoundException | IOException e) {
            LOG.error("Could not bootstrap {}", resource.getFilename(), e);
        }
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) PostConstruct(javax.annotation.PostConstruct)

Example 14 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class IntygModuleFacadeTest method testGetRevokeCertificateRequestModuleException.

@Test(expected = ModuleException.class)
public void testGetRevokeCertificateRequestModuleException() throws Exception {
    when(moduleApi.createRevokeRequest(isNull(), isNull(), anyString())).thenThrow(new ModuleException());
    moduleFacade.getRevokeCertificateRequest(CERTIFICATE_TYPE, null, null, "message");
}
Also used : ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Test(org.junit.Test)

Example 15 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class IntygServiceImpl method revokeIntyg.

/*
     * (non-Javadoc)
     *
     * @see se.inera.intyg.webcert.web.service.intyg.IntygService#revokeIntyg(java.lang.String, java.lang.String)
     */
@Override
public IntygServiceResult revokeIntyg(String intygsId, String intygsTyp, String revokeMessage, String reason) {
    LOG.debug("Attempting to revoke intyg {}", intygsId);
    IntygContentHolder intyg = getIntygData(intygsId, intygsTyp, false);
    verifyEnhetsAuth(intyg.getUtlatande(), true);
    verifyIsSigned(intyg.getStatuses());
    if (intyg.isRevoked()) {
        LOG.debug("Certificate with id '{}' is already revoked", intygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificate is already revoked");
    }
    try {
        certificateSenderService.revokeCertificate(intygsId, modelFacade.getRevokeCertificateRequest(intygsTyp, intyg.getUtlatande(), IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null), revokeMessage), intygsTyp);
        whenSuccessfulRevoke(intyg.getUtlatande(), reason);
        return IntygServiceResult.OK;
    } catch (CertificateSenderException | ModuleException | IntygModuleFacadeException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, e.getMessage());
    }
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Aggregations

ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)27 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)16 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)14 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)13 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 IOException (java.io.IOException)9 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 Test (org.junit.Test)6 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)6 Transactional (org.springframework.transaction.annotation.Transactional)4 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 WebServiceException (javax.xml.ws.WebServiceException)2 Status (se.inera.intyg.common.support.model.Status)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2