| .. | .. |
|---|
| 119 | 119 | users = new ArrayList<>(); |
|---|
| 120 | 120 | for (String username : usersIds) { |
|---|
| 121 | 121 | User user = em.find(User.class, username); |
|---|
| 122 | | - if (parentOrg == null) { |
|---|
| 122 | + if (user == null) { |
|---|
| 123 | 123 | log.error("Organization user with id {} not found in DB", username); |
|---|
| 124 | 124 | return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's user not found with ID: " + username).build(); |
|---|
| 125 | 125 | } |
|---|
| .. | .. |
|---|
| 191 | 191 | public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) { |
|---|
| 192 | 192 | log.info("Deleting app with id: {}", orgid); |
|---|
| 193 | 193 | 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) { |
|---|
| 196 | 196 | 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(); |
|---|
| 198 | 202 | } |
|---|
| 199 | 203 | |
|---|
| 200 | | - em.remove(app); |
|---|
| 204 | + em.remove(org); |
|---|
| 201 | 205 | return Response.ok(Utils.createMap("success", true, "id", orgid)).build(); |
|---|
| 202 | 206 | } |
|---|
| 203 | 207 | |
|---|