Search in sources :

Example 1 with ModuleApi

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

the class NotificationTransformerTest method testSchemaVersion2Transformation.

@Test
public void testSchemaVersion2Transformation() throws Exception {
    NotificationMessage notificationMessage = new NotificationMessage(INTYGS_ID, LUSE, LocalDateTime.now(), HandelsekodEnum.SKAPAT, LOGISK_ADRESS, "{ }", null, ArendeCount.getEmpty(), ArendeCount.getEmpty(), SchemaVersion.VERSION_3, "ref");
    Message message = spy(new DefaultMessage());
    message.setBody(notificationMessage);
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(moduleRegistry.getModuleApi(eq(LUSE))).thenReturn(moduleApi);
    Intyg intyg = new Intyg();
    IntygId intygsId = new IntygId();
    intygsId.setExtension(INTYGS_ID);
    intyg.setIntygsId(intygsId);
    HosPersonal hosPersonal = new HosPersonal();
    Enhet enhet = new Enhet();
    enhet.setArbetsplatskod(new ArbetsplatsKod());
    enhet.setVardgivare(new Vardgivare());
    hosPersonal.setEnhet(enhet);
    intyg.setSkapadAv(hosPersonal);
    when(moduleApi.getIntygFromUtlatande(any())).thenReturn(intyg);
    transformer.process(message);
    assertEquals(INTYGS_ID, ((se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType) message.getBody()).getIntyg().getIntygsId().getExtension());
    assertEquals(HandelsekodEnum.SKAPAT.value(), message.getHeader(NotificationRouteHeaders.HANDELSE));
    assertEquals(INTYGS_ID, message.getHeader(NotificationRouteHeaders.INTYGS_ID));
    assertEquals(LOGISK_ADRESS, message.getHeader(NotificationRouteHeaders.LOGISK_ADRESS));
    assertEquals(SchemaVersion.VERSION_3.name(), message.getHeader(NotificationRouteHeaders.VERSION));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.LOGISK_ADRESS), eq(LOGISK_ADRESS));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.INTYGS_ID), eq(INTYGS_ID));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.HANDELSE), eq(HandelsekodEnum.SKAPAT.value()));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.VERSION), eq(SchemaVersion.VERSION_3.name()));
    verify(moduleRegistry, times(1)).getModuleApi(eq(LUSE));
    verify(moduleApi, times(1)).getUtlatandeFromJson(any());
    verify(moduleApi, times(1)).getIntygFromUtlatande(any());
    verify(notificationPatientEnricher, times(1)).enrichWithPatient(any());
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) HosPersonal(se.riv.clinicalprocess.healthcond.certificate.v3.HosPersonal) ArbetsplatsKod(se.riv.clinicalprocess.healthcond.certificate.types.v3.ArbetsplatsKod) Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) DefaultMessage(org.apache.camel.impl.DefaultMessage) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) Vardgivare(se.riv.clinicalprocess.healthcond.certificate.v3.Vardgivare) IntygId(se.riv.clinicalprocess.healthcond.certificate.types.v3.IntygId) Enhet(se.riv.clinicalprocess.healthcond.certificate.v3.Enhet) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Test(org.junit.Test)

Example 2 with ModuleApi

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

the class CertificateRevokeProcessorTest method testRevokeCertificateWhenWebServiceExceptionIsThrown.

@Test(expected = TemporaryException.class)
public void testRevokeCertificateWhenWebServiceExceptionIsThrown() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    doThrow(new WebServiceException()).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Example 3 with ModuleApi

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

the class CertificateRevokeProcessorTest method testRevokeCertificateOnTransformationErrorResponse.

@Test(expected = PermanentException.class)
public void testRevokeCertificateOnTransformationErrorResponse() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.TRANSFORMATION_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException) Test(org.junit.Test)

Example 4 with ModuleApi

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

the class CertificateRevokeProcessorTest method testRevokeCertificateOnValidationErrorResponse.

@Test(expected = PermanentException.class)
public void testRevokeCertificateOnValidationErrorResponse() throws Exception {
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
    doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.VALIDATION_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
    certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ExternalServiceCallException(se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException) Test(org.junit.Test)

Example 5 with ModuleApi

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

the class UtkastServiceImpl method saveDraft.

@Override
@Transactional("jpaTransactionManager")
public SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent) {
    LOG.debug("Saving and validating utkast '{}'", intygId);
    Utkast utkast = utkastRepository.findOne(intygId);
    if (utkast == null) {
        LOG.warn("Utkast '{}' was not found", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The utkast could not be found");
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != version) {
        LOG.debug("Utkast '{}' was concurrently modified", intygId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    // check that the draft is still a draft
    if (!isTheDraftStillADraft(utkast.getStatus())) {
        LOG.error("Utkast '{}' can not be updated since it is no longer in draft mode", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "This utkast can not be updated since it is no longer in draft mode");
    }
    String intygType = utkast.getIntygsTyp();
    // Keep persisted json for comparsion
    String persistedJson = utkast.getModel();
    // Update draft with user information
    updateUtkastModel(utkast, draftAsJson);
    // Is draft valid?
    DraftValidation draftValidation = validateDraft(intygId, intygType, draftAsJson);
    UtkastStatus utkastStatus = draftValidation.isDraftValid() ? UtkastStatus.DRAFT_COMPLETE : UtkastStatus.DRAFT_INCOMPLETE;
    utkast.setStatus(utkastStatus);
    // Save the updated draft
    utkast = saveDraft(utkast);
    LOG.debug("Utkast '{}' updated", utkast.getIntygsId());
    if (createPdlLogEvent) {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
        logService.logUpdateIntyg(logRequest);
        monitoringService.logUtkastEdited(utkast.getIntygsId(), utkast.getIntygsTyp());
    }
    // Notify stakeholders when a draft has been changed/updated
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        if (moduleApi.shouldNotify(persistedJson, draftAsJson)) {
            LOG.debug("*** Detected changes in model, sending notification! ***");
            sendNotification(utkast, Event.CHANGED);
        }
    } catch (ModuleException | ModuleNotFoundException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
    // Flush JPA changes, to make sure the version attribute is updated
    utkastRepository.flush();
    return new SaveDraftResponse(utkast.getVersion(), utkastStatus);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)27 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)13 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 Test (org.junit.Test)10 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)7 Patient (se.inera.intyg.common.support.model.common.internal.Patient)6 ExternalServiceCallException (se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArrayList (java.util.ArrayList)3 WebServiceException (javax.xml.ws.WebServiceException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)2