Search in sources :

Example 1 with IntygModuleFacadeException

use of se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygDataWithRelationNotFoundInIT.

@Test
public void testFetchIntygDataWithRelationNotFoundInIT() throws Exception {
    when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenThrow(new IntygModuleFacadeException(""));
    when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(getIntyg(CERTIFICATE_ID, null, null));
    IntygContentHolder res = intygService.fetchIntygDataWithRelations(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertNotNull(res);
    assertNotNull(res.getRelations());
    verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(utkastRepository).findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(logservice).logReadIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logIntygRead(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(certificateRelationService).getRelations(eq(CERTIFICATE_ID));
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) Test(org.junit.Test)

Example 2 with IntygModuleFacadeException

use of se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygWithFailingIntygstjanst.

@Test(expected = WebCertServiceException.class)
public void testFetchIntygWithFailingIntygstjanst() throws IntygModuleFacadeException {
    when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenThrow(new IntygModuleFacadeException(""));
    intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) Test(org.junit.Test)

Example 3 with IntygModuleFacadeException

use of se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException 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)

Example 4 with IntygModuleFacadeException

use of se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException in project webcert by sklintyg.

the class IntygServiceImpl method fetchIntygAsPdf.

@Override
public IntygPdf fetchIntygAsPdf(String intygsId, String intygsTyp, boolean isEmployer) {
    try {
        LOG.debug("Fetching intyg '{}' as PDF", intygsId);
        IntygContentHolder intyg = getIntygDataPreferWebcert(intygsId, intygsTyp);
        // 
        verifyPuServiceAvailable(intyg);
        boolean coherentJournaling = userIsDjupintegreradWithSjf();
        if (!coherentJournaling) {
            verifyEnhetsAuth(intyg.getUtlatande(), true);
        }
        IntygPdf intygPdf = modelFacade.convertFromInternalToPdfDocument(intygsTyp, intyg.getContents(), intyg.getStatuses(), isEmployer);
        // Log print as PDF to PDL log
        logPdfPrinting(intyg, coherentJournaling);
        return intygPdf;
    } catch (IntygModuleFacadeException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 5 with IntygModuleFacadeException

use of se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException in project webcert by sklintyg.

the class IntygServiceImpl method getIntygData.

/**
 * Builds a IntygContentHolder by first trying to get the Intyg from intygstjansten. If
 * not found or the Intygstjanst couldn't be reached, the local Utkast - if available -
 * will be used instead.
 * <p>
 * Note that even when found, we check if we need to decorate the response with data from the utkast in order
 * to mitigate async send states. (E.g. a send may be in resend due to 3rd party issues, in that case decorate with
 * data about sent state from the Utkast)
 *
 * @param relations
 */
private IntygContentHolder getIntygData(String intygId, String typ, boolean relations) {
    try {
        CertificateResponse certificate = modelFacade.getCertificate(intygId, typ);
        String internalIntygJsonModel = certificate.getInternalModel();
        final Personnummer personId = certificate.getUtlatande().getGrundData().getPatient().getPersonId();
        // INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
        // Since an FK-intyg never will have anything other than personId, try to fetch all using ruleset
        Patient newPatientData = patientDetailsResolver.resolvePatient(personId, typ);
        Utlatande utlatande = null;
        boolean patientNameChanged = false;
        boolean patientAddressChanged = false;
        try {
            utlatande = moduleRegistry.getModuleApi(typ).getUtlatandeFromJson(internalIntygJsonModel);
            patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
            patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
        } catch (IOException e) {
            LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygId);
        }
        // parameters were available.
        if (newPatientData != null) {
            // Get the module api and use the "updateBeforeSave" to update the outbound "model" with the
            // Patient object.
            ModuleApi moduleApi = moduleRegistry.getModuleApi(typ);
            // INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
            if (!completeAddressProvided(newPatientData)) {
                // Use the old address data.
                Patient oldPatientData = utlatande.getGrundData().getPatient();
                copyOldAddressToNewPatientData(oldPatientData, newPatientData);
            }
            internalIntygJsonModel = moduleApi.updateBeforeSave(internalIntygJsonModel, newPatientData);
        }
        utkastIntygDecorator.decorateWithUtkastStatus(certificate);
        Relations certificateRelations = intygRelationHelper.getRelationsForIntyg(intygId);
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personId);
        if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
        }
        final boolean sekretessmarkering = SekretessStatus.TRUE.equals(sekretessStatus);
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        final LocalDateTime created = utkast != null ? utkast.getSkapad() : null;
        return IntygContentHolder.builder().setContents(internalIntygJsonModel).setUtlatande(certificate.getUtlatande()).setStatuses(certificate.getMetaData().getStatus()).setRevoked(certificate.isRevoked()).setRelations(certificateRelations).setCreated(created).setDeceased(isDeceased(personId)).setSekretessmarkering(sekretessmarkering).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
    } catch (IntygModuleFacadeException me) {
        // It's possible the Intygstjanst hasn't received the Intyg yet, look for it locally before rethrowing
        // exception
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (WebServiceException wse) {
        // Something went wrong communication-wise, try to find a matching Utkast instead.
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Cannot get intyg. Intygstjansten was not reachable and the Utkast could " + "not be found, perhaps it was issued by a non-webcert system?");
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (ModuleNotFoundException | ModuleException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebServiceException(javax.xml.ws.WebServiceException) CertificateResponse(se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IOException(java.io.IOException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Aggregations

IntygModuleFacadeException (se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException)6 Test (org.junit.Test)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)3 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 IOException (java.io.IOException)1 LocalDateTime (java.time.LocalDateTime)1 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)1 WebServiceException (javax.xml.ws.WebServiceException)1 Patient (se.inera.intyg.common.support.model.common.internal.Patient)1 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)1 CertificateResponse (se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse)1 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)1 CertificateSenderException (se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)1 IntygPdf (se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf)1