rsanchez
2014-12-12 4c13c7324a920f5cca9601154e5224e5d7484fa9
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -26,10 +26,14 @@
2626
2727 import net.curisit.integrity.commons.Utils;
2828 import net.curisit.securis.DefaultExceptionHandler;
29
+import net.curisit.securis.SeCurisException;
2930 import net.curisit.securis.db.Application;
3031 import net.curisit.securis.db.ApplicationMetadata;
3132 import net.curisit.securis.security.BasicSecurityContext;
3233 import net.curisit.securis.security.Securable;
34
+import net.curisit.securis.services.exception.SeCurisServiceException;
35
+import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
36
+import net.curisit.securis.utils.JsonUtils;
3337 import net.curisit.securis.utils.TokenHelper;
3438
3539 import org.apache.logging.log4j.LogManager;
....@@ -71,6 +75,7 @@
7175 LOG.info("Getting applications list ");
7276
7377 EntityManager em = emProvider.get();
78
+ em.clear();
7479 TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
7580 List<Application> list = q.getResultList();
7681
....@@ -80,6 +85,7 @@
8085 /**
8186 *
8287 * @return the server version in format majorVersion.minorVersion
88
+ * @throws SeCurisServiceException
8389 */
8490 @GET
8591 @Path("/{appid}")
....@@ -87,7 +93,7 @@
8793 MediaType.APPLICATION_JSON
8894 })
8995 @Securable
90
- public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PĂ€RAM) String token) {
96
+ public Response get(@PathParam("appid") String appid) throws SeCurisServiceException {
9197 LOG.info("Getting application data for id: {}: ", appid);
9298 if (appid == null || "".equals(appid)) {
9399 LOG.error("Application ID is mandatory");
....@@ -95,12 +101,28 @@
95101 }
96102
97103 EntityManager em = emProvider.get();
98
- Application app = em.find(Application.class, Integer.parseInt(appid));
104
+ em.clear();
105
+
106
+ Application app = null;
107
+ try {
108
+ LOG.info("READY to GET app: {}", appid);
109
+ app = em.find(Application.class, Integer.parseInt(appid));
110
+ } catch (Exception e) {
111
+ LOG.info("ERROR GETTING app: {}", e);
112
+ }
99113 if (app == null) {
100114 LOG.error("Application with id {} not found in DB", appid);
115
+ throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "Application not found with ID: " + appid);
116
+ }
101117
102
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
103
- .build();
118
+ try {
119
+ LOG.info("JSON for APP:\n\n\n");
120
+ LOG.info(JsonUtils.toJSON(app));
121
+ } catch (SeCurisException e) {
122
+ LOG.info("ERROR {}", e);
123
+
124
+ } catch (Exception e) {
125
+ LOG.info("ERROR??? {}", e);
104126 }
105127 return Response.ok(app).build();
106128 }
....@@ -199,14 +221,13 @@
199221 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
200222 .build();
201223 }
202
-
203
- if (app.getLicenseTypes() != null && !app.getLicenseTypes().isEmpty()) {
204
- return Response
205
- .status(Status.FORBIDDEN)
206
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
207
- "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build();
208
- }
209
-
224
+ /*
225
+ * if (app.getLicenseTypes() != null &&
226
+ * !app.getLicenseTypes().isEmpty()) { throw new
227
+ * SeCurisServiceException(ErrorCodes.NOT_FOUND,
228
+ * "Application can not be deleted becasue has assigned one or more License types, ID: "
229
+ * + appid); }
230
+ */
210231 em.remove(app);
211232 return Response.ok(Utils.createMap("success", true, "id", appid)).build();
212233 }