diff --git a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointLocalV2.java b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointLocalV2.java index ed93495b..600e5d7b 100644 --- a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointLocalV2.java +++ b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointLocalV2.java @@ -686,4 +686,6 @@ public interface ContactsEndpointLocalV2 { Response updateContact(RestfulContactV2 contact); + Response deleteContact(String id); + } diff --git a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointV2.java b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointV2.java index c1a659dc..d1daee87 100644 --- a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointV2.java +++ b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v2/ContactsEndpointV2.java @@ -672,6 +672,7 @@ You should also get your employer (if you work as a programmer) or school, import javax.ejb.Stateless; import javax.naming.InitialContext; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -881,6 +882,41 @@ public Response createContact(RestfulContactV2 contact) { } } + + /** + * Creates a new contact + * + * @param id contact id + * @response 401 User not authorized + * @response 403 User not authenticated + * @response 404 Contact not found + */ + @Override + @DELETE + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") + @Path("/{id}/delete") + @RolesAllowed({"createAddressRole"}) + public Response deleteContact(@PathParam("id") String id) { + try { + + InitialContext ic = new InitialContext(); + AddressServiceLocal addresses = (AddressServiceLocal) ic.lookup("java:global/j-lawyer-server/j-lawyer-server-ejb/AddressService!com.jdimension.jlawyer.services.AddressServiceLocal"); + + AddressBean a=addresses.getAddress(id); + if(a==null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + + addresses.removeAddress(id); + Response res = Response.ok().build(); + return res; + } catch (Exception ex) { + log.error("can not delete address " + id, ex); + Response res = Response.serverError().build(); + return res; + } + + } /** * Updates an existing contact based on its ID. The external ID of the diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressServiceLocal.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressServiceLocal.java index 0b47127c..722c2e9f 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressServiceLocal.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressServiceLocal.java @@ -693,6 +693,7 @@ public interface AddressServiceLocal { ArrayList getAllAddressIds(); public void updateAddress(AddressBean dto); + public void removeAddress(String id); Collection getTags(String addressId);