@Test public void testCreateCompletion() throws Exception { final String reference = "ref"; WebCertUser user = new WebCertUser(); user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", true, false, false, true)); when(userService.getUser()).thenReturn(user); when(mockUtkastRepository.existsById(INTYG_ID)).thenReturn(Boolean.TRUE); UtkastBuilderResponse resp = createCopyUtkastBuilderResponse(); when(copyCompletionUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateCompletionCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class))).thenReturn(resp); CreateCompletionCopyRequest copyReq = buildCompletionRequest(); setupMockForGettingUtlatande(); CreateCompletionCopyResponse copyResp = copyService.createCompletion(copyReq); assertNotNull(copyResp); assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId()); assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType()); assertEquals(INTYG_ID, copyResp.getOriginalIntygId()); verify(mockPUService).getPerson(PATIENT_SSN); verify(copyCompletionUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateCompletionCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class)); 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.KOMPLETTERAR, INTYG_ID); verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false); }
@Override public CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating completion to intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); try { boolean coherentJournaling = isCoherentJournaling(user); final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToComplementIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) { LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } UtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.KOMPLETTERAR, originalIntygId); monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId); return new CreateCompletionCopyResponse(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 CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating completion to intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); try { boolean coherentJournaling = isCoherentJournaling(user); final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToComplementIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) { LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } UtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.KOMPLETTERAR, originalIntygId); monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId); return new CreateCompletionCopyResponse(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 CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating completion to intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); try { boolean coherentJournaling = isCoherentJournaling(user); final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToComplementIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) { LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } UtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.KOMPLETTERAR, originalIntygId); monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId); return new CreateCompletionCopyResponse(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 CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating completion to intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); try { boolean coherentJournaling = isCoherentJournaling(user); final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToComplementIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) { LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } UtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.KOMPLETTERAR, originalIntygId); monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId); return new CreateCompletionCopyResponse(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 CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) { String originalIntygId = copyRequest.getOriginalIntygId(); LOG.debug("Creating completion to intyg '{}'", originalIntygId); WebCertUser user = userService.getUser(); try { boolean coherentJournaling = isCoherentJournaling(user); final Utlatande utlatande = utkastServiceHelper.getUtlatande(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling, false); certificateAccessServiceHelper.validateAccessToComplementIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(copyRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) { LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked"); } UtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true); if (copyRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.KOMPLETTERAR, originalIntygId); monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId); return new CreateCompletionCopyResponse(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);  }