@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.existsById(INTYG_ID)).thenReturn(Boolean.TRUE); UtkastBuilderResponse resp = createCopyUtkastBuilderResponse(); when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class))).thenReturn(resp); when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Collections.singletonList(UtkastStatus.SIGNED))) .thenReturn(Optional.empty()); CreateRenewalCopyRequest copyReq = buildRenewalRequest(); setupMockForGettingUtlatande(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(mockPUService).getPerson(PATIENT_SSN); verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), eq(false)); verify(mockUtkastRepository).save(any(Utkast.class)); verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference)); verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class)); verify(certificateEventService) .createCertificateEventFromCopyUtkast(resp.getUtkast(), user.getHsaId(), EventCode.FORLANGER, INTYG_ID); verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false); }
@Override public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating renewal for intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToRenewIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); 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"); verifySigned(utlatande, "create renewal"); UtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.FORLANGER, originalIntygId); monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId); return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), 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); } }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating renewal for intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToRenewIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); 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"); verifySigned(utlatande, "create renewal"); UtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.FORLANGER, originalIntygId); monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId); return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), 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); } } }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating renewal for intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToRenewIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); 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"); verifySigned(utlatande, "create renewal"); UtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.FORLANGER, originalIntygId); monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId); return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), 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); } }  }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating renewal for intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToRenewIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); 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"); verifySigned(utlatande, "create renewal"); UtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.FORLANGER, originalIntygId); monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId); return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), 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); } }  @Override CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest); @Override CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest); @Override @Transactional CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest); @Override CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest); @Override CreateUtkastFromTemplateResponse createUtkastCopy(CreateUtkastFromTemplateRequest copyRequest); }
CopyUtkastServiceImpl implements CopyUtkastService { @Override public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating renewal for intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); boolean coherentJournaling = isCoherentJournaling(user); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToRenewIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); 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"); verifySigned(utlatande, "create renewal"); UtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.FORLANGER, originalIntygId); monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId); return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygTypeVersion(), 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); } }  @Override CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest); @Override CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest); @Override @Transactional CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest); @Override CreateUtkastFromTemplateResponse createUtkastFromSignedTemplate(CreateUtkastFromTemplateRequest templateRequest); @Override CreateUtkastFromTemplateResponse createUtkastCopy(CreateUtkastFromTemplateRequest copyRequest);  }