@Test public void testCreateUtkastFromTemplate() { final String personnummer = "191212121212"; final String newIntygId = "newIntygId"; final String newCertificateType = "newCertificateType"; CopyIntygRequest copyIntygRequest = new CopyIntygRequest(); copyIntygRequest.setPatientPersonnummer(createPnr(personnummer)); WebCertUser user = new WebCertUser(); addFeatures(user, newCertificateType, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST); addPrivileges(user, newCertificateType, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG); user.setOrigin("NORMAL"); ArgumentCaptor<CreateUtkastFromTemplateRequest> captor = ArgumentCaptor.forClass(CreateUtkastFromTemplateRequest.class); when(copyUtkastService.createUtkastFromSignedTemplate(captor.capture())) .thenReturn(new CreateUtkastFromTemplateResponse(newCertificateType, CERTIFICATE_VERSION, newIntygId, CERTIFICATE_ID)); when(webcertUserService.getUser()).thenReturn(user); Response response = moduleApiController .createUtkastFromSignedTemplate(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID, newCertificateType); verify(copyUtkastService).createUtkastFromSignedTemplate(any()); verifyNoMoreInteractions(copyUtkastService); assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId()); assertEquals(newCertificateType, ((CopyIntygResponse) response.getEntity()).getIntygsTyp()); }
@POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) public Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) { LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId); if (!request.isValid()) { LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload"); } CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request); serviceRequest.setTypVersion(intygTextsService.getLatestVersion(newIntygsTyp)); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromSignedTemplate(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }
IntygModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) public Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) { LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId); if (!request.isValid()) { LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload"); } CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request); serviceRequest.setTypVersion(intygTextsService.getLatestVersion(newIntygsTyp)); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromSignedTemplate(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); } }
IntygModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) public Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) { LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId); if (!request.isValid()) { LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload"); } CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request); serviceRequest.setTypVersion(intygTextsService.getLatestVersion(newIntygsTyp)); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromSignedTemplate(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }  }
IntygModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) public Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) { LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId); if (!request.isValid()) { LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload"); } CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request); serviceRequest.setTypVersion(intygTextsService.getLatestVersion(newIntygsTyp)); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromSignedTemplate(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }  @GET @Path("/{intygsTyp}/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response getIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId); @GET @Path("/{intygsTyp}/{intygsId}/pdf") @Produces("application/pdf") final Response getIntygAsPdf(@PathParam("intygsTyp") String intygsTyp, @PathParam(value = "intygsId") final String intygsId); @GET @Path("/{intygsTyp}/{intygsId}/pdf/arbetsgivarutskrift") @Produces("application/pdf") final Response getIntygAsPdfForEmployer(@PathParam("intygsTyp") String intygsTyp,
        @PathParam(value = "intygsId") final String intygsId); @POST @Path("/{intygsTyp}/{intygsId}/skicka") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response sendSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        SendSignedIntygParameter param); @POST @Path("/{intygsTyp}/{intygsId}/aterkalla") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response revokeSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        RevokeSignedIntygParameter param); @POST @Path("/{intygsTyp}/{intygsId}/komplettera") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createCompletion(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId); @POST @Path("/{intygsTyp}/{intygsId}/fornya") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId); @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp,
        @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp); @POST @Path("/{intygsTyp}/{intygsId}/ersatt") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createReplacement(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId); }
IntygModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) public Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) { LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId); if (!request.isValid()) { LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload"); } CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request); serviceRequest.setTypVersion(intygTextsService.getLatestVersion(newIntygsTyp)); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromSignedTemplate(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }  @GET @Path("/{intygsTyp}/{intygsId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response getIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId); @GET @Path("/{intygsTyp}/{intygsId}/pdf") @Produces("application/pdf") final Response getIntygAsPdf(@PathParam("intygsTyp") String intygsTyp, @PathParam(value = "intygsId") final String intygsId); @GET @Path("/{intygsTyp}/{intygsId}/pdf/arbetsgivarutskrift") @Produces("application/pdf") final Response getIntygAsPdfForEmployer(@PathParam("intygsTyp") String intygsTyp,
        @PathParam(value = "intygsId") final String intygsId); @POST @Path("/{intygsTyp}/{intygsId}/skicka") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response sendSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        SendSignedIntygParameter param); @POST @Path("/{intygsTyp}/{intygsId}/aterkalla") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response revokeSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        RevokeSignedIntygParameter param); @POST @Path("/{intygsTyp}/{intygsId}/komplettera") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createCompletion(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId); @POST @Path("/{intygsTyp}/{intygsId}/fornya") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId); @POST @Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createUtkastFromSignedTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp,
        @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp); @POST @Path("/{intygsTyp}/{intygsId}/ersatt") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) Response createReplacement(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String orgIntygsId);  }