@Test(expected = WebCertServiceException.class) public void testRenewalCopyFailIfOriginalNotSigned() { final String reference = "ref"; WebCertUser user = new WebCertUser(); user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true)); try { setupMockForGettingUtlatande(); copyService.createRenewalCopy(buildRenewalRequest()); fail("An exception should have been thrown."); } catch (Exception e) { throw e; } }
@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);  }