From f94f4b0fb0c4f664620e9b1060b90aa1d66a457a Mon Sep 17 00:00:00 2001 From: Olof Svensson Date: Fri, 18 May 2018 11:09:06 +0200 Subject: [PATCH 1/2] Issue #293 : New web services getAutoProcAttachmentPdf and getAutoProcAttachmentHtml --- .../mx/AutoprocintegrationRestWebService.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java index 4de80758b..adec32c17 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java @@ -404,5 +404,54 @@ public Response getAutoProcAttachment(@PathParam("token") String token, @PathPar } } + @RolesAllowed({ "User", "Manager", "Industrial", "Localcontact" }) + @GET + @Path("{token}/proposal/{proposal}/mx/autoprocintegration/autoprocattachmentid/{autoProcAttachmentId}/getPdf") + @Produces("application/pdf") + public Response getAutoProcAttachmentPdf(@PathParam("token") String token, @PathParam("proposal") String proposal, + @PathParam("autoProcAttachmentId") int autoProcAttachmentId) { + + String methodName = "getAutoProcAttachment"; + long start = this.logInit(methodName, logger, token, proposal); + try { + /** Checking that attachment is linked to the proposal **/ + if (this.checkProposalByAutoProcProgramAttachmentId(this.getProposalId(proposal), autoProcAttachmentId)){ + AutoProcProgramAttachment3VO attachment = this.getAutoProcProgramAttachment3Service().findByPk(autoProcAttachmentId); + File file = new File(attachment.getFilePath() + "/" + attachment.getFileName()); + this.logFinish(methodName, start, logger); + return this.downloadFile(file.getAbsolutePath()); + } + else{ + throw new Exception(NOT_ALLOWED); + } + } catch (Exception e) { + return this.logError(methodName, e, start, logger); + } + } + @RolesAllowed({ "User", "Manager", "Industrial", "Localcontact" }) + @GET + @Path("{token}/proposal/{proposal}/mx/autoprocintegration/autoprocattachmentid/{autoProcAttachmentId}/getHtml") + @Produces("text/html") + public Response getAutoProcAttachmentHtml(@PathParam("token") String token, @PathParam("proposal") String proposal, + @PathParam("autoProcAttachmentId") int autoProcAttachmentId) { + + String methodName = "getAutoProcAttachment"; + long start = this.logInit(methodName, logger, token, proposal); + try { + /** Checking that attachment is linked to the proposal **/ + if (this.checkProposalByAutoProcProgramAttachmentId(this.getProposalId(proposal), autoProcAttachmentId)){ + AutoProcProgramAttachment3VO attachment = this.getAutoProcProgramAttachment3Service().findByPk(autoProcAttachmentId); + File file = new File(attachment.getFilePath() + "/" + attachment.getFileName()); + this.logFinish(methodName, start, logger); + return this.downloadFile(file.getAbsolutePath()); + } + else{ + throw new Exception(NOT_ALLOWED); + } + } catch (Exception e) { + return this.logError(methodName, e, start, logger); + } + } + } From 050de4a75239b30f81a3f52ed56742fb64d2589f Mon Sep 17 00:00:00 2001 From: Olof Svensson Date: Fri, 18 May 2018 14:52:01 +0200 Subject: [PATCH 2/2] Issue #293 : Refactoring of the methods getAutoProcAttachment, getAutoProcAttachmentPdf and getAutoProcAttachmentHtml --- .../mx/AutoprocintegrationRestWebService.java | 43 +++---------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java index adec32c17..c0bfd78b5 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/AutoprocintegrationRestWebService.java @@ -385,23 +385,7 @@ public Response downloadAutoProcAttachment(@PathParam("token") String token, @Pa @Produces("text/plain") public Response getAutoProcAttachment(@PathParam("token") String token, @PathParam("proposal") String proposal, @PathParam("autoProcAttachmentId") int autoProcAttachmentId) { - - String methodName = "getAutoProcAttachment"; - long start = this.logInit(methodName, logger, token, proposal); - try { - /** Checking that attachment is linked to the proposal **/ - if (this.checkProposalByAutoProcProgramAttachmentId(this.getProposalId(proposal), autoProcAttachmentId)){ - AutoProcProgramAttachment3VO attachment = this.getAutoProcProgramAttachment3Service().findByPk(autoProcAttachmentId); - File file = new File(attachment.getFilePath() + "/" + attachment.getFileName()); - this.logFinish(methodName, start, logger); - return this.downloadFile(file.getAbsolutePath()); - } - else{ - throw new Exception(NOT_ALLOWED); - } - } catch (Exception e) { - return this.logError(methodName, e, start, logger); - } + return this.getFile(token, proposal, autoProcAttachmentId); } @RolesAllowed({ "User", "Manager", "Industrial", "Localcontact" }) @@ -410,23 +394,7 @@ public Response getAutoProcAttachment(@PathParam("token") String token, @PathPar @Produces("application/pdf") public Response getAutoProcAttachmentPdf(@PathParam("token") String token, @PathParam("proposal") String proposal, @PathParam("autoProcAttachmentId") int autoProcAttachmentId) { - - String methodName = "getAutoProcAttachment"; - long start = this.logInit(methodName, logger, token, proposal); - try { - /** Checking that attachment is linked to the proposal **/ - if (this.checkProposalByAutoProcProgramAttachmentId(this.getProposalId(proposal), autoProcAttachmentId)){ - AutoProcProgramAttachment3VO attachment = this.getAutoProcProgramAttachment3Service().findByPk(autoProcAttachmentId); - File file = new File(attachment.getFilePath() + "/" + attachment.getFileName()); - this.logFinish(methodName, start, logger); - return this.downloadFile(file.getAbsolutePath()); - } - else{ - throw new Exception(NOT_ALLOWED); - } - } catch (Exception e) { - return this.logError(methodName, e, start, logger); - } + return this.getFile(token, proposal, autoProcAttachmentId); } @RolesAllowed({ "User", "Manager", "Industrial", "Localcontact" }) @@ -435,8 +403,11 @@ public Response getAutoProcAttachmentPdf(@PathParam("token") String token, @Path @Produces("text/html") public Response getAutoProcAttachmentHtml(@PathParam("token") String token, @PathParam("proposal") String proposal, @PathParam("autoProcAttachmentId") int autoProcAttachmentId) { - - String methodName = "getAutoProcAttachment"; + return this.getFile(token, proposal, autoProcAttachmentId); + } + + private Response getFile(String token, String proposal, int autoProcAttachmentId) { + String methodName = "getFile"; long start = this.logInit(methodName, logger, token, proposal); try { /** Checking that attachment is linked to the proposal **/