@Test(expected = WebCertServiceException.class) public void testReplacementCopyFailIfOriginalNotSigned() { final String reference = "ref"; WebCertUser user = new WebCertUser(); user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true)); try { setupMockForGettingUtlatande(); copyService.createReplacementCopy(buildReplacementCopyRequest()); fail("An exception should have been thrown."); } catch (Exception e) { throw e; } }
@Override @Transactional public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) { String originalIntygId = replacementRequest.getOriginalIntygId(); WebCertUser user = userService.getUser(); LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(replacementRequest.getOriginalIntygId(), replacementRequest.getOriginalIntygTyp(), replacementRequest.isCoherentJournaling(), false); certificateAccessServiceHelper.validateAccessToReplaceIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(replacementRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) { LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked"); } verifyNotReplaced(originalIntygId, "create replacement"); verifyNotComplementedWithSigned(originalIntygId, "create replacement"); verifySigned(utlatande, "create replacement"); UtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId); if (replacementRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.ERSATTER, originalIntygId); monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId); return new CreateReplacementCopyResponse(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 @Transactional public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) { String originalIntygId = replacementRequest.getOriginalIntygId(); WebCertUser user = userService.getUser(); LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(replacementRequest.getOriginalIntygId(), replacementRequest.getOriginalIntygTyp(), replacementRequest.isCoherentJournaling(), false); certificateAccessServiceHelper.validateAccessToReplaceIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(replacementRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) { LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked"); } verifyNotReplaced(originalIntygId, "create replacement"); verifyNotComplementedWithSigned(originalIntygId, "create replacement"); verifySigned(utlatande, "create replacement"); UtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId); if (replacementRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.ERSATTER, originalIntygId); monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId); return new CreateReplacementCopyResponse(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 @Transactional public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) { String originalIntygId = replacementRequest.getOriginalIntygId(); WebCertUser user = userService.getUser(); LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(replacementRequest.getOriginalIntygId(), replacementRequest.getOriginalIntygTyp(), replacementRequest.isCoherentJournaling(), false); certificateAccessServiceHelper.validateAccessToReplaceIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(replacementRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) { LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked"); } verifyNotReplaced(originalIntygId, "create replacement"); verifyNotComplementedWithSigned(originalIntygId, "create replacement"); verifySigned(utlatande, "create replacement"); UtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId); if (replacementRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.ERSATTER, originalIntygId); monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId); return new CreateReplacementCopyResponse(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 @Transactional public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) { String originalIntygId = replacementRequest.getOriginalIntygId(); WebCertUser user = userService.getUser(); LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(replacementRequest.getOriginalIntygId(), replacementRequest.getOriginalIntygTyp(), replacementRequest.isCoherentJournaling(), false); certificateAccessServiceHelper.validateAccessToReplaceIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(replacementRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) { LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked"); } verifyNotReplaced(originalIntygId, "create replacement"); verifyNotComplementedWithSigned(originalIntygId, "create replacement"); verifySigned(utlatande, "create replacement"); UtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId); if (replacementRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.ERSATTER, originalIntygId); monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId); return new CreateReplacementCopyResponse(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 @Transactional public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) { String originalIntygId = replacementRequest.getOriginalIntygId(); WebCertUser user = userService.getUser(); LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId); try { final Utlatande utlatande = utkastServiceHelper.getUtlatande(replacementRequest.getOriginalIntygId(), replacementRequest.getOriginalIntygTyp(), replacementRequest.isCoherentJournaling(), false); certificateAccessServiceHelper.validateAccessToReplaceIntyg(utlatande); addTestIntygFlagIfNecessaryToCopyRequest(replacementRequest, utlatande.getGrundData().isTestIntyg()); if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) { LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked"); } verifyNotReplaced(originalIntygId, "create replacement"); verifyNotComplementedWithSigned(originalIntygId, "create replacement"); verifySigned(utlatande, "create replacement"); UtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId); if (replacementRequest.isDjupintegrerad()) { checkIntegreradEnhet(builderResponse); } Utkast savedUtkast = saveAndNotify(builderResponse, user, EventCode.ERSATTER, originalIntygId); monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId); return new CreateReplacementCopyResponse(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);  }