rsanchez
2014-10-27 7f5a20aa40c00fea42c68211f311b6b24ad64c9e
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -337,14 +337,19 @@
337337 public Response delete(@PathParam("packId") String packId) {
338338 LOG.info("Deleting pack with id: {}", packId);
339339 EntityManager em = emProvider.get();
340
- Pack org = em.find(Pack.class, Integer.parseInt(packId));
341
- if (org == null) {
340
+ Pack pack = em.find(Pack.class, Integer.parseInt(packId));
341
+ if (pack == null) {
342342 LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId);
343343 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId)
344344 .build();
345345 }
346
+ if (pack.getMetadata() != null) {
347
+ for (PackMetadata md : pack.getMetadata()) {
348
+ em.remove(md);
349
+ }
350
+ }
346351
347
- em.remove(org);
352
+ em.remove(pack);
348353 return Response.ok(Utils.createMap("success", true, "id", packId)).build();
349354 }
350355