| .. | .. |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | import javax.annotation.security.RolesAllowed; |
|---|
| 8 | 8 | import javax.inject.Inject; |
|---|
| 9 | | -import javax.inject.Provider; |
|---|
| 10 | 9 | import javax.persistence.EntityManager; |
|---|
| 11 | 10 | import javax.persistence.TypedQuery; |
|---|
| 12 | 11 | import javax.servlet.http.HttpServletRequest; |
|---|
| 12 | +import javax.transaction.Transactional; |
|---|
| 13 | 13 | import javax.ws.rs.Consumes; |
|---|
| 14 | 14 | import javax.ws.rs.DELETE; |
|---|
| 15 | 15 | import javax.ws.rs.GET; |
|---|
| .. | .. |
|---|
| 39 | 39 | import org.apache.logging.log4j.LogManager; |
|---|
| 40 | 40 | import org.apache.logging.log4j.Logger; |
|---|
| 41 | 41 | |
|---|
| 42 | | -import com.google.inject.persist.Transactional; |
|---|
| 43 | | - |
|---|
| 44 | 42 | /** |
|---|
| 45 | 43 | * Application resource, this service will provide methods to create, modify and |
|---|
| 46 | 44 | * delete applications |
|---|
| .. | .. |
|---|
| 54 | 52 | TokenHelper tokenHelper; |
|---|
| 55 | 53 | |
|---|
| 56 | 54 | @Inject |
|---|
| 57 | | - Provider<EntityManager> emProvider; |
|---|
| 55 | + EntityManager em; |
|---|
| 58 | 56 | |
|---|
| 59 | 57 | private static final Logger LOG = LogManager.getLogger(ApplicationResource.class); |
|---|
| 60 | 58 | |
|---|
| .. | .. |
|---|
| 74 | 72 | public Response index() { |
|---|
| 75 | 73 | LOG.info("Getting applications list "); |
|---|
| 76 | 74 | |
|---|
| 77 | | - EntityManager em = emProvider.get(); |
|---|
| 75 | + // EntityManager em = emProvider.get(); |
|---|
| 78 | 76 | em.clear(); |
|---|
| 79 | 77 | TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class); |
|---|
| 80 | 78 | List<Application> list = q.getResultList(); |
|---|
| .. | .. |
|---|
| 100 | 98 | return Response.status(Status.NOT_FOUND).build(); |
|---|
| 101 | 99 | } |
|---|
| 102 | 100 | |
|---|
| 103 | | - EntityManager em = emProvider.get(); |
|---|
| 101 | + // EntityManager em = emProvider.get(); |
|---|
| 104 | 102 | em.clear(); |
|---|
| 105 | 103 | |
|---|
| 106 | 104 | Application app = null; |
|---|
| .. | .. |
|---|
| 138 | 136 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 139 | 137 | public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| 140 | 138 | LOG.info("Creating new application"); |
|---|
| 141 | | - EntityManager em = emProvider.get(); |
|---|
| 139 | + // EntityManager em = emProvider.get(); |
|---|
| 142 | 140 | app.setCreationTimestamp(new Date()); |
|---|
| 143 | 141 | em.persist(app); |
|---|
| 144 | 142 | LOG.info("App ID: {}", app.getId()); |
|---|
| .. | .. |
|---|
| 167 | 165 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 168 | 166 | public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| 169 | 167 | LOG.info("Modifying application with id: {}", appid); |
|---|
| 170 | | - EntityManager em = emProvider.get(); |
|---|
| 168 | + // EntityManager em = emProvider.get(); |
|---|
| 171 | 169 | Application currentapp = em.find(Application.class, Integer.parseInt(appid)); |
|---|
| 172 | 170 | if (currentapp == null) { |
|---|
| 173 | 171 | LOG.error("Application with id {} not found in DB", appid); |
|---|
| .. | .. |
|---|
| 214 | 212 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 215 | 213 | public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) { |
|---|
| 216 | 214 | LOG.info("Deleting app with id: {}", appid); |
|---|
| 217 | | - EntityManager em = emProvider.get(); |
|---|
| 215 | + // EntityManager em = emProvider.get(); |
|---|
| 218 | 216 | Application app = em.find(Application.class, Integer.parseInt(appid)); |
|---|
| 219 | 217 | if (app == null) { |
|---|
| 220 | 218 | LOG.error("Application with id {} can not be deleted, It was not found in DB", appid); |
|---|