rsanchez
2015-01-28 da889d489da5d7fa8c71d9f21f24b1dc2e29d8e1
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -7,9 +7,9 @@
77
88 import javax.annotation.security.RolesAllowed;
99 import javax.inject.Inject;
10
-import javax.inject.Provider;
1110 import javax.persistence.EntityManager;
1211 import javax.persistence.TypedQuery;
12
+import javax.transaction.Transactional;
1313 import javax.ws.rs.Consumes;
1414 import javax.ws.rs.DELETE;
1515 import javax.ws.rs.FormParam;
....@@ -46,8 +46,6 @@
4646 import org.apache.logging.log4j.LogManager;
4747 import org.apache.logging.log4j.Logger;
4848
49
-import com.google.inject.persist.Transactional;
50
-
5149 /**
5250 * Pack resource, this service will provide methods to create, modify and delete
5351 * packs
....@@ -63,7 +61,7 @@
6361 TokenHelper tokenHelper;
6462
6563 @Inject
66
- Provider<EntityManager> emProvider;
64
+ EntityManager em;
6765
6866 @Inject
6967 private LicenseHelper licenseHelper;
....@@ -81,7 +79,7 @@
8179 public Response index(@Context BasicSecurityContext bsc) {
8280 LOG.info("Getting packs list ");
8381
84
- EntityManager em = emProvider.get();
82
+ // EntityManager em = emProvider.get();
8583 em.clear();
8684
8785 TypedQuery<Pack> q;
....@@ -123,7 +121,7 @@
123121 return Response.status(Status.NOT_FOUND).build();
124122 }
125123
126
- EntityManager em = emProvider.get();
124
+ // EntityManager em = emProvider.get();
127125 em.clear();
128126 Pack pack = em.find(Pack.class, packId);
129127 if (pack == null) {
....@@ -148,7 +146,7 @@
148146 @Transactional
149147 public Response create(Pack pack, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
150148 LOG.info("Creating new pack");
151
- EntityManager em = emProvider.get();
149
+ // EntityManager em = emProvider.get();
152150
153151 if (checkIfCodeExists(pack.getCode(), em)) {
154152 throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The pack code is already used in an existing pack");
....@@ -213,7 +211,7 @@
213211 MediaType.TEXT_PLAIN
214212 })
215213 public Response getCodeSuffix(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
216
- EntityManager em = emProvider.get();
214
+ // EntityManager em = emProvider.get();
217215
218216 if (packId == null) {
219217 throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The pack code is mandatory");
....@@ -250,7 +248,7 @@
250248 })
251249 public Response modify(Pack pack, @PathParam("packId") Integer packId) {
252250 LOG.info("Modifying pack with id: {}", packId);
253
- EntityManager em = emProvider.get();
251
+ // EntityManager em = emProvider.get();
254252 Pack currentPack = em.find(Pack.class, packId);
255253
256254 try {
....@@ -305,7 +303,7 @@
305303 })
306304 public Response activate(@PathParam("packId") Integer packId) throws SeCurisServiceException {
307305 LOG.info("Activating pack with id: {}", packId);
308
- EntityManager em = emProvider.get();
306
+ // EntityManager em = emProvider.get();
309307
310308 Pack currentPack = em.find(Pack.class, packId);
311309
....@@ -331,7 +329,7 @@
331329 })
332330 public Response onhold(@PathParam("packId") Integer packId) throws SeCurisServiceException {
333331 LOG.info("Putting On hold pack with id: {}", packId);
334
- EntityManager em = emProvider.get();
332
+ // EntityManager em = emProvider.get();
335333
336334 Pack currentPack = em.find(Pack.class, packId);
337335
....@@ -358,7 +356,7 @@
358356 public Response cancel(@PathParam("packId") Integer packId, @FormParam("reason") String reason, @Context BasicSecurityContext bsc)
359357 throws SeCurisServiceException {
360358 LOG.info("Cancelling pack with id: {}", packId);
361
- EntityManager em = emProvider.get();
359
+ // EntityManager em = emProvider.get();
362360
363361 Pack currentPack = em.find(Pack.class, packId);
364362
....@@ -401,7 +399,7 @@
401399 })
402400 public Response delete(@PathParam("packId") String packId) throws SeCurisServiceException {
403401 LOG.info("Deleting pack with id: {}", packId);
404
- EntityManager em = emProvider.get();
402
+ // EntityManager em = emProvider.get();
405403 Pack pack = em.find(Pack.class, Integer.parseInt(packId));
406404 if (pack == null) {
407405 LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId);