| .. | .. |
|---|
| 337 | 337 | public Response delete(@PathParam("packId") String packId) { |
|---|
| 338 | 338 | LOG.info("Deleting pack with id: {}", packId); |
|---|
| 339 | 339 | 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) { |
|---|
| 342 | 342 | LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId); |
|---|
| 343 | 343 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId) |
|---|
| 344 | 344 | .build(); |
|---|
| 345 | 345 | } |
|---|
| 346 | + if (pack.getMetadata() != null) { |
|---|
| 347 | + for (PackMetadata md : pack.getMetadata()) { |
|---|
| 348 | + em.remove(md); |
|---|
| 349 | + } |
|---|
| 350 | + } |
|---|
| 346 | 351 | |
|---|
| 347 | | - em.remove(org); |
|---|
| 352 | + em.remove(pack); |
|---|
| 348 | 353 | return Response.ok(Utils.createMap("success", true, "id", packId)).build(); |
|---|
| 349 | 354 | } |
|---|
| 350 | 355 | |
|---|