From 1a973577e3dc48138fcf66cdfb003a5cf23c5ce0 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Mon, 27 Aug 2012 12:15:45 +0200 Subject: [PATCH] Add method to remove a work report line from the web service FEA: ItEr77S06AllowDeleteWorkReports --- .../workreports/api/IWorkReportService.java | 2 ++ .../impl/WorkReportServiceREST.java | 25 ++++++++++++++ .../rest-clients/remove-work-report-line.sh | 34 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100755 scripts/rest-clients/remove-work-report-line.sh diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/api/IWorkReportService.java b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/api/IWorkReportService.java index ffd63a90f..b35204866 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/api/IWorkReportService.java +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/api/IWorkReportService.java @@ -41,4 +41,6 @@ public interface IWorkReportService { Response removeWorkReport(String code); + Response removeWorkReportLine(String code); + } \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportServiceREST.java b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportServiceREST.java index 2338ba65b..585d71257 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportServiceREST.java +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/workreports/impl/WorkReportServiceREST.java @@ -21,6 +21,9 @@ package org.libreplan.ws.workreports.impl; +import java.util.Arrays; +import java.util.HashSet; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -37,7 +40,9 @@ import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.orders.daos.IOrderElementDAO; import org.libreplan.business.orders.daos.ISumChargedEffortDAO; import org.libreplan.business.workreports.daos.IWorkReportDAO; +import org.libreplan.business.workreports.daos.IWorkReportLineDAO; import org.libreplan.business.workreports.entities.WorkReport; +import org.libreplan.business.workreports.entities.WorkReportLine; import org.libreplan.ws.common.api.InstanceConstraintViolationsListDTO; import org.libreplan.ws.common.impl.GenericRESTService; import org.libreplan.ws.workreports.api.IWorkReportService; @@ -62,6 +67,9 @@ public class WorkReportServiceREST extends @Autowired private IWorkReportDAO workReportDAO; + @Autowired + private IWorkReportLineDAO workReportLineDAO; + @Autowired private IOrderElementDAO orderElementDAO; @@ -142,4 +150,21 @@ public class WorkReportServiceREST extends } } + @Override + @DELETE + @Path("/line/{code}/") + @Transactional + public Response removeWorkReportLine(@PathParam("code") String code) { + try { + WorkReportLine workReportLine = workReportLineDAO.findByCode(code); + sumChargedEffortDAO + .updateRelatedSumChargedEffortWithDeletedWorkReportLineSet(new HashSet( + Arrays.asList(workReportLine))); + workReportLineDAO.remove(workReportLine.getId()); + return Response.ok().build(); + } catch (InstanceNotFoundException e) { + return Response.status(Status.NOT_FOUND).build(); + } + } + } \ No newline at end of file diff --git a/scripts/rest-clients/remove-work-report-line.sh b/scripts/rest-clients/remove-work-report-line.sh new file mode 100755 index 000000000..14e01c87d --- /dev/null +++ b/scripts/rest-clients/remove-work-report-line.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +. ./rest-common-env.sh + +printf "Username: " +read loginName +printf "Password: " +read password + +code=$1 + +if [ "$1" = "--prod" ]; then + baseServiceURL=$PRODUCTION_BASE_SERVICE_URL + certificate=$PRODUCTION_CERTIFICATE + code=$2 +elif [ "$1" = "--dev" ]; then + baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL + certificate=$DEVELOPMENT_CERTIFICATE + code=$2 +else + baseServiceURL=$DEMO_BASE_SERVICE_URL + certificate=$DEMO_CERTIFICATE +fi + +authorization=`echo -n "$loginName:$password" | base64` + +result=`curl -sv -X DELETE $certificate --header "Authorization: Basic $authorization" \ + $baseServiceURL/workreports/line/$code` + +if hash tidy &> /dev/null; then + echo $result | tidy -xml -i -q -utf8 +else + echo $result +fi