@Test public void testDiscardDraft() { String intygsTyp = "fk7263"; String intygsId = "intyg1"; setupUser(intygsTyp, false, UserOriginType.NORMAL.name(), Arrays.asList(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG), Arrays.asList(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST)); doReturn(buildUtkast("intygtyp", "intygsid")).when(utkastService).getDraft(anyString(), anyString(), anyBoolean()); Response response = moduleApiController.discardDraft(intygsTyp, intygsId, UTKAST_VERSION, request); verify(utkastService).deleteUnsignedDraft(intygsId, UTKAST_VERSION); assertEquals(OK.getStatusCode(), response.getStatus()); }
@DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) { Utkast utkast = utkastService.getDraft(intygsId, intygsTyp, false); draftAccessServiceHelper.validateAllowToDeleteUtkast(utkast); LOG.debug("Deleting draft with id {}", intygsId); try { utkastService.deleteUnsignedDraft(intygsId, version); } catch (OptimisticLockException | OptimisticLockingFailureException e) { monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage()); } request.getSession(true).removeAttribute(LAST_SAVED_DRAFT); return Response.ok().build(); }
UtkastModuleApiController extends AbstractApiController { @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) { Utkast utkast = utkastService.getDraft(intygsId, intygsTyp, false); draftAccessServiceHelper.validateAllowToDeleteUtkast(utkast); LOG.debug("Deleting draft with id {}", intygsId); try { utkastService.deleteUnsignedDraft(intygsId, version); } catch (OptimisticLockException | OptimisticLockingFailureException e) { monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage()); } request.getSession(true).removeAttribute(LAST_SAVED_DRAFT); return Response.ok().build(); } }
UtkastModuleApiController extends AbstractApiController { @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) { Utkast utkast = utkastService.getDraft(intygsId, intygsTyp, false); draftAccessServiceHelper.validateAllowToDeleteUtkast(utkast); LOG.debug("Deleting draft with id {}", intygsId); try { utkastService.deleteUnsignedDraft(intygsId, version); } catch (OptimisticLockException | OptimisticLockingFailureException e) { monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage()); } request.getSession(true).removeAttribute(LAST_SAVED_DRAFT); return Response.ok().build(); }  }
UtkastModuleApiController extends AbstractApiController { @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) { Utkast utkast = utkastService.getDraft(intygsId, intygsTyp, false); draftAccessServiceHelper.validateAllowToDeleteUtkast(utkast); LOG.debug("Deleting draft with id {}", intygsId); try { utkastService.deleteUnsignedDraft(intygsId, version); } catch (OptimisticLockException | OptimisticLockingFailureException e) { monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage()); } request.getSession(true).removeAttribute(LAST_SAVED_DRAFT); return Response.ok().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 { @DELETE @Path("/{intygsTyp}/{intygsId}/{version}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) { Utkast utkast = utkastService.getDraft(intygsId, intygsTyp, false); draftAccessServiceHelper.validateAllowToDeleteUtkast(utkast); LOG.debug("Deleting draft with id {}", intygsId); try { utkastService.deleteUnsignedDraft(intygsId, version); } catch (OptimisticLockException | OptimisticLockingFailureException e) { monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp); throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage()); } request.getSession(true).removeAttribute(LAST_SAVED_DRAFT); return Response.ok().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; }