Search in sources :

Example 1 with CreateRenewalCopyResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse in project webcert by sklintyg.

the class CopyUtkastServiceImpl method createRenewalCopy.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastService#createCopy(se.inera.intyg.webcert.web.service.utkast.
     * dto.
     * CreateRenewalCopyRequest)
     */
@Override
public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating renewal for intyg '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
            LOG.debug("Cannot renew certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        verifyNotComplementedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        CopyUtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 2 with CreateRenewalCopyResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testRenewalCopyFailIfSignedReplacementExists.

@Test(expected = WebCertServiceException.class)
public void testRenewalCopyFailIfSignedReplacementExists() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.SIGNED))).thenReturn(Optional.of(ersattRelation));
    CreateRenewalCopyRequest renewalCopyRequest = buildRenewalRequest();
    try {
        CreateRenewalCopyResponse copyResp = copyService.createRenewalCopy(renewalCopyRequest);
        fail("An exception should have been thrown.");
    } catch (Exception e) {
        verifyZeroInteractions(mockUtkastRepository);
        verifyZeroInteractions(mockNotificationService);
        verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
        // Assert no pdl logging
        verifyZeroInteractions(logService);
        throw e;
    }
}
Also used : IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 3 with CreateRenewalCopyResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateRenewalWhenIntegratedAndSjfTrue.

@Test
public void testCreateRenewalWhenIntegratedAndSjfTrue() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setOrigin(DJUPINTEGRATION.name());
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", true, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.TRUE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), isNull(), any(boolean.class), eq(true), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    copyReq.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalResponse);
    assertEquals(INTYG_COPY_ID, renewalResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalResponse.getNewDraftIntygType());
    assertEquals(INTYG_ID, renewalResponse.getOriginalIntygId());
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), isNull(), any(boolean.class), eq(true), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, true);
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 4 with CreateRenewalCopyResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateRenewal.

@Test
public void testCreateRenewal() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.TRUE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(false))).thenReturn(resp);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.SIGNED))).thenReturn(Optional.empty());
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    CreateRenewalCopyResponse renewalResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalResponse);
    assertEquals(INTYG_COPY_ID, renewalResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalResponse.getNewDraftIntygType());
    assertEquals(INTYG_ID, renewalResponse.getOriginalIntygId());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 5 with CreateRenewalCopyResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateRenewalWhenIntegrated.

@Test
public void testCreateRenewalWhenIntegrated() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest renewRequest = buildRenewalRequest();
    renewRequest.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalCopyResponse = copyService.createRenewalCopy(renewRequest);
    assertNotNull(renewalCopyResponse);
    assertEquals(INTYG_COPY_ID, renewalCopyResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalCopyResponse.getNewDraftIntygType());
    verifyZeroInteractions(mockPUService);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
    // Assert pdl log
    verify(logService).logCreateIntyg(any(LogRequest.class));
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)9 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)9 Test (org.junit.Test)8 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)8 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)5 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)5 Response (javax.ws.rs.core.Response)3 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)3 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)3 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)3 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)3 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)3 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)3 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)2 Person (se.inera.intyg.infra.integration.pu.model.Person)1