| .. | .. |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | import net.curisit.integrity.commons.Utils; |
|---|
| 28 | 28 | import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 29 | +import net.curisit.securis.SeCurisException; |
|---|
| 29 | 30 | import net.curisit.securis.db.Application; |
|---|
| 30 | 31 | import net.curisit.securis.db.ApplicationMetadata; |
|---|
| 31 | 32 | import net.curisit.securis.security.BasicSecurityContext; |
|---|
| 32 | 33 | 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; |
|---|
| 33 | 37 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 34 | 38 | |
|---|
| 35 | 39 | import org.apache.logging.log4j.LogManager; |
|---|
| .. | .. |
|---|
| 71 | 75 | LOG.info("Getting applications list "); |
|---|
| 72 | 76 | |
|---|
| 73 | 77 | EntityManager em = emProvider.get(); |
|---|
| 78 | + em.clear(); |
|---|
| 74 | 79 | TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class); |
|---|
| 75 | 80 | List<Application> list = q.getResultList(); |
|---|
| 76 | 81 | |
|---|
| .. | .. |
|---|
| 80 | 85 | /** |
|---|
| 81 | 86 | * |
|---|
| 82 | 87 | * @return the server version in format majorVersion.minorVersion |
|---|
| 88 | + * @throws SeCurisServiceException |
|---|
| 83 | 89 | */ |
|---|
| 84 | 90 | @GET |
|---|
| 85 | 91 | @Path("/{appid}") |
|---|
| .. | .. |
|---|
| 87 | 93 | MediaType.APPLICATION_JSON |
|---|
| 88 | 94 | }) |
|---|
| 89 | 95 | @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 { |
|---|
| 91 | 97 | LOG.info("Getting application data for id: {}: ", appid); |
|---|
| 92 | 98 | if (appid == null || "".equals(appid)) { |
|---|
| 93 | 99 | LOG.error("Application ID is mandatory"); |
|---|
| .. | .. |
|---|
| 95 | 101 | } |
|---|
| 96 | 102 | |
|---|
| 97 | 103 | 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 | + } |
|---|
| 99 | 113 | if (app == null) { |
|---|
| 100 | 114 | LOG.error("Application with id {} not found in DB", appid); |
|---|
| 115 | + throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "Application not found with ID: " + appid); |
|---|
| 116 | + } |
|---|
| 101 | 117 | |
|---|
| 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); |
|---|
| 104 | 126 | } |
|---|
| 105 | 127 | return Response.ok(app).build(); |
|---|
| 106 | 128 | } |
|---|
| .. | .. |
|---|
| 199 | 221 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid) |
|---|
| 200 | 222 | .build(); |
|---|
| 201 | 223 | } |
|---|
| 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 | + */ |
|---|
| 210 | 231 | em.remove(app); |
|---|
| 211 | 232 | return Response.ok(Utils.createMap("success", true, "id", appid)).build(); |
|---|
| 212 | 233 | } |
|---|