@Test public void testCopyUtkast() { String intygsId = "intygId"; String intygsTyp = "fk7263"; String intygsTypVersion = INTYG_TYPE_VERSION; String newIntygsId = "newIntygId"; setupUser(intygsTyp, false, UserOriginType.NORMAL.name(), Arrays.asList(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG), Arrays.asList(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST)); Utkast utkast = new Utkast(); utkast.setPatientPersonnummer(Personnummer.createPersonnummer("19121212-1212").get()); when(utkastService.getDraft(eq(intygsId), eq(intygsTyp))).thenReturn(utkast); ArgumentCaptor<CreateUtkastFromTemplateRequest> captor = ArgumentCaptor.forClass(CreateUtkastFromTemplateRequest.class); when(copyUtkastService.createUtkastCopy(captor.capture())) .thenReturn(new CreateUtkastFromTemplateResponse(intygsTyp, intygsTypVersion, newIntygsId, intygsId)); Response response = moduleApiController.copyUtkast(intygsTyp, intygsId); verify(copyUtkastService).createUtkastCopy(any()); verifyNoMoreInteractions(copyUtkastService); assertEquals(newIntygsId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId()); assertEquals(intygsTyp, ((CopyIntygResponse) response.getEntity()).getIntygsTyp()); }
@POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) { LOG.debug("Attempting to create a new certificate from certificate with type {} and id '{}'", intygsTyp, orgIntygsId); Utkast utkast = utkastService.getDraft(orgIntygsId, intygsTyp); lockedDraftAccessServiceHelper.validateAccessToCopyLockedUtkast(utkast); CopyIntygRequest request = new CopyIntygRequest(); request.setPatientPersonnummer(utkast.getPatientPersonnummer()); CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromUtkast(orgIntygsId, intygsTyp, request); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastCopy(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), intygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }
UtkastModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) { LOG.debug("Attempting to create a new certificate from certificate with type {} and id '{}'", intygsTyp, orgIntygsId); Utkast utkast = utkastService.getDraft(orgIntygsId, intygsTyp); lockedDraftAccessServiceHelper.validateAccessToCopyLockedUtkast(utkast); CopyIntygRequest request = new CopyIntygRequest(); request.setPatientPersonnummer(utkast.getPatientPersonnummer()); CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromUtkast(orgIntygsId, intygsTyp, request); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastCopy(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), intygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); } }
UtkastModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) { LOG.debug("Attempting to create a new certificate from certificate with type {} and id '{}'", intygsTyp, orgIntygsId); Utkast utkast = utkastService.getDraft(orgIntygsId, intygsTyp); lockedDraftAccessServiceHelper.validateAccessToCopyLockedUtkast(utkast); CopyIntygRequest request = new CopyIntygRequest(); request.setPatientPersonnummer(utkast.getPatientPersonnummer()); CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromUtkast(orgIntygsId, intygsTyp, request); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastCopy(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), intygsTyp, orgIntygsId); CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), serviceResponse.getNewDraftIntygTypeVersion()); return Response.ok().entity(response).build(); }  }
UtkastModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) { LOG.debug("Attempting to create a new certificate from certificate with type {} and id '{}'", intygsTyp, orgIntygsId); Utkast utkast = utkastService.getDraft(orgIntygsId, intygsTyp); lockedDraftAccessServiceHelper.validateAccessToCopyLockedUtkast(utkast); CopyIntygRequest request = new CopyIntygRequest(); request.setPatientPersonnummer(utkast.getPatientPersonnummer()); CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromUtkast(orgIntygsId, intygsTyp, request); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastCopy(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), intygsTyp, 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) @PrometheusTimeMethod Response getDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @Context HttpServletRequest request); @PUT @Path("/{intygsTyp}/{intygsId}/{version}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response saveDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version,
        @DefaultValue("false") @QueryParam("autoSave") boolean autoSave, byte[] payload, @Context HttpServletRequest request); @POST @Path("/{intygsTyp}/{intygsId}/validate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response validateDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        byte[] payload); @POST @Path("/{intygsTyp}/{intygsId}/copyfromcandidate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response copyFromCandidate(
        @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String intygsId,
        CopyFromCandidateRequest request); @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId); @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version,
        @Context HttpServletRequest request); @POST @Path("/{intygsTyp}/{intygsId}/aterkalla") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response revokeLockedDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        RevokeSignedIntygParameter param); }
UtkastModuleApiController extends AbstractApiController { @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) { LOG.debug("Attempting to create a new certificate from certificate with type {} and id '{}'", intygsTyp, orgIntygsId); Utkast utkast = utkastService.getDraft(orgIntygsId, intygsTyp); lockedDraftAccessServiceHelper.validateAccessToCopyLockedUtkast(utkast); CopyIntygRequest request = new CopyIntygRequest(); request.setPatientPersonnummer(utkast.getPatientPersonnummer()); CreateUtkastFromTemplateRequest serviceRequest = copyUtkastServiceHelper.createUtkastFromUtkast(orgIntygsId, intygsTyp, request); CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastCopy(serviceRequest); LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), intygsTyp, 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) @PrometheusTimeMethod Response getDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @Context HttpServletRequest request); @PUT @Path("/{intygsTyp}/{intygsId}/{version}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response saveDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version,
        @DefaultValue("false") @QueryParam("autoSave") boolean autoSave, byte[] payload, @Context HttpServletRequest request); @POST @Path("/{intygsTyp}/{intygsId}/validate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response validateDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        byte[] payload); @POST @Path("/{intygsTyp}/{intygsId}/copyfromcandidate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response copyFromCandidate(
        @PathParam("intygsTyp") String intygsTyp,
        @PathParam("intygsId") String intygsId,
        CopyFromCandidateRequest request); @POST @Path("/{intygsTyp}/{intygsId}/copy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response copyUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId); @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        @PathParam("version") long version,
        @Context HttpServletRequest request); @POST @Path("/{intygsTyp}/{intygsId}/aterkalla") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response revokeLockedDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId,
        RevokeSignedIntygParameter param); static final String LAST_SAVED_DRAFT; }