Add new method to delete a work report from the web service

FEA: ItEr77S06AllowDeleteWorkReports
This commit is contained in:
Manuel Rego Casasnovas 2012-08-27 11:42:10 +02:00
parent 8bde7df447
commit 8509515e75
4 changed files with 60 additions and 1 deletions

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -39,4 +39,6 @@ public interface IWorkReportService {
public Response getWorkReport(String code);
Response removeWorkReport(String code);
}

View file

@ -22,12 +22,14 @@
package org.libreplan.ws.workreports.impl;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
@ -122,4 +124,22 @@ public class WorkReportServiceREST extends
public Response getWorkReport(@PathParam("code") String code) {
return getDTOByCode(code);
}
@Override
@DELETE
@Path("/{code}/")
@Transactional
public Response removeWorkReport(@PathParam("code") String code) {
try {
WorkReport workReport = workReportDAO.findByCode(code);
sumChargedEffortDAO
.updateRelatedSumChargedEffortWithDeletedWorkReportLineSet(workReport
.getWorkReportLines());
workReportDAO.remove(workReport.getId());
return Response.ok().build();
} catch (InstanceNotFoundException e) {
return Response.status(Status.NOT_FOUND).build();
}
}
}

View file

@ -25,6 +25,9 @@
<intercept-url pattern="/ws/rest/**"
access="ROLE_WS_WRITER"
method="POST" />
<intercept-url pattern="/ws/rest/**"
access="ROLE_WS_WRITER"
method="DELETE" />
<!-- Web application -->
<intercept-url pattern="/common/img/**"

View file

@ -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/$code`
if hash tidy &> /dev/null; then
echo $result | tidy -xml -i -q -utf8
else
echo $result
fi