| .. | .. |
|---|
| 32 | 32 | import net.curisit.securis.db.LicenseTypeMetadata; |
|---|
| 33 | 33 | import net.curisit.securis.security.BasicSecurityContext; |
|---|
| 34 | 34 | import net.curisit.securis.security.Securable; |
|---|
| 35 | +import net.curisit.securis.services.exception.SeCurisServiceException; |
|---|
| 36 | +import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes; |
|---|
| 35 | 37 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 36 | 38 | |
|---|
| 37 | 39 | import org.apache.logging.log4j.LogManager; |
|---|
| .. | .. |
|---|
| 73 | 75 | LOG.info("Getting license types list "); |
|---|
| 74 | 76 | |
|---|
| 75 | 77 | EntityManager em = emProvider.get(); |
|---|
| 78 | + em.clear(); |
|---|
| 76 | 79 | TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class); |
|---|
| 77 | 80 | List<LicenseType> list = q.getResultList(); |
|---|
| 78 | 81 | |
|---|
| .. | .. |
|---|
| 82 | 85 | /** |
|---|
| 83 | 86 | * |
|---|
| 84 | 87 | * @return the server version in format majorVersion.minorVersion |
|---|
| 88 | + * @throws SeCurisServiceException |
|---|
| 85 | 89 | */ |
|---|
| 86 | 90 | @GET |
|---|
| 87 | 91 | @Path("/{ltid}") |
|---|
| .. | .. |
|---|
| 89 | 93 | MediaType.APPLICATION_JSON |
|---|
| 90 | 94 | }) |
|---|
| 91 | 95 | @Securable |
|---|
| 92 | | - public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| 96 | + public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) throws SeCurisServiceException { |
|---|
| 93 | 97 | LOG.info("Getting license type data for id: {}: ", ltid); |
|---|
| 94 | 98 | if (ltid == null || "".equals(ltid)) { |
|---|
| 95 | 99 | LOG.error("LicenseType ID is mandatory"); |
|---|
| .. | .. |
|---|
| 97 | 101 | } |
|---|
| 98 | 102 | |
|---|
| 99 | 103 | EntityManager em = emProvider.get(); |
|---|
| 104 | + em.clear(); |
|---|
| 100 | 105 | LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid)); |
|---|
| 101 | 106 | if (lt == null) { |
|---|
| 102 | 107 | LOG.error("LicenseType with id {} not found in DB", ltid); |
|---|
| 103 | | - return Response.status(Status.NOT_FOUND).build(); |
|---|
| 108 | + throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "LicenseType was not found in DB"); |
|---|
| 104 | 109 | } |
|---|
| 105 | 110 | return Response.ok(lt).build(); |
|---|
| 106 | 111 | } |
|---|