Roberto Sánchez
2014-01-10 3d0c6e4865d4a0ddd764da533a327faf76e0cb32
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -119,7 +119,7 @@
119119 users = new ArrayList<>();
120120 for (String username : usersIds) {
121121 User user = em.find(User.class, username);
122
- if (parentOrg == null) {
122
+ if (user == null) {
123123 log.error("Organization user with id {} not found in DB", username);
124124 return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's user not found with ID: " + username).build();
125125 }
....@@ -191,13 +191,17 @@
191191 public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
192192 log.info("Deleting app with id: {}", orgid);
193193 EntityManager em = emProvider.get();
194
- Organization app = em.find(Organization.class, Integer.parseInt(orgid));
195
- if (app == null) {
194
+ Organization org = em.find(Organization.class, Integer.parseInt(orgid));
195
+ if (org == null) {
196196 log.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
197
- return Response.status(Status.NOT_FOUND).build();
197
+ return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization was not found, ID: " + orgid).build();
198
+ }
199
+ if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) {
200
+ log.error("Organization has children and can not be deleted, ID: " + orgid);
201
+ return Response.status(Status.FORBIDDEN).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization has children and can not be deleted, ID: " + orgid).build();
198202 }
199203
200
- em.remove(app);
204
+ em.remove(org);
201205 return Response.ok(Utils.createMap("success", true, "id", orgid)).build();
202206 }
203207