| .. | .. |
|---|
| 47 | 47 | @Path("/license") |
|---|
| 48 | 48 | public class LicenseResource { |
|---|
| 49 | 49 | |
|---|
| 50 | | - private static final Logger log = LogManager.getLogger(LicenseResource.class); |
|---|
| 50 | + private static final Logger LOG = LogManager.getLogger(LicenseResource.class); |
|---|
| 51 | 51 | |
|---|
| 52 | 52 | @Inject |
|---|
| 53 | 53 | TokenHelper tokenHelper; |
|---|
| .. | .. |
|---|
| 68 | 68 | @Produces( |
|---|
| 69 | 69 | { MediaType.APPLICATION_JSON }) |
|---|
| 70 | 70 | public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) { |
|---|
| 71 | | - log.info("Getting licenses list "); |
|---|
| 71 | + LOG.info("Getting licenses list "); |
|---|
| 72 | 72 | |
|---|
| 73 | 73 | EntityManager em = emProvider.get(); |
|---|
| 74 | 74 | |
|---|
| .. | .. |
|---|
| 77 | 77 | if (pack == null) |
|---|
| 78 | 78 | return Response.ok().build(); |
|---|
| 79 | 79 | if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) { |
|---|
| 80 | | - log.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal()); |
|---|
| 80 | + LOG.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal()); |
|---|
| 81 | 81 | return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack licenses").build(); |
|---|
| 82 | 82 | } |
|---|
| 83 | 83 | } |
|---|
| .. | .. |
|---|
| 99 | 99 | @Produces( |
|---|
| 100 | 100 | { MediaType.APPLICATION_JSON }) |
|---|
| 101 | 101 | public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 102 | | - log.info("Getting organization data for id: {}: ", licId); |
|---|
| 102 | + LOG.info("Getting organization data for id: {}: ", licId); |
|---|
| 103 | 103 | |
|---|
| 104 | 104 | EntityManager em = emProvider.get(); |
|---|
| 105 | 105 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| .. | .. |
|---|
| 122 | 122 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 123 | 123 | |
|---|
| 124 | 124 | if (lic.getLicenseData() == null) { |
|---|
| 125 | | - log.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal()); |
|---|
| 125 | + LOG.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal()); |
|---|
| 126 | 126 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file"); |
|---|
| 127 | 127 | } |
|---|
| 128 | 128 | if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) { |
|---|
| 129 | | - log.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal()); |
|---|
| 129 | + LOG.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal()); |
|---|
| 130 | 130 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License is not active, so It can not be downloaded"); |
|---|
| 131 | 131 | } |
|---|
| 132 | 132 | return Response.ok(lic.getLicenseData()).build(); |
|---|
| .. | .. |
|---|
| 146 | 146 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 147 | 147 | |
|---|
| 148 | 148 | if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) { |
|---|
| 149 | | - log.error("License with id {} can not be activated from current license status", licId); |
|---|
| 149 | + LOG.error("License with id {} can not be activated from current license status", licId); |
|---|
| 150 | 150 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status"); |
|---|
| 151 | 151 | } |
|---|
| 152 | 152 | |
|---|
| .. | .. |
|---|
| 193 | 193 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 194 | 194 | |
|---|
| 195 | 195 | if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) { |
|---|
| 196 | | - log.error("License with id {} can not be canceled from current license status", licId); |
|---|
| 196 | + LOG.error("License with id {} can not be canceled from current license status", licId); |
|---|
| 197 | 197 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status"); |
|---|
| 198 | 198 | } |
|---|
| 199 | 199 | |
|---|
| .. | .. |
|---|
| 214 | 214 | { MediaType.APPLICATION_JSON }) |
|---|
| 215 | 215 | @Transactional |
|---|
| 216 | 216 | public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 217 | | - log.info("Creating new license from create()"); |
|---|
| 217 | + LOG.info("Creating new license from create()"); |
|---|
| 218 | 218 | EntityManager em = emProvider.get(); |
|---|
| 219 | 219 | Pack pack = null; |
|---|
| 220 | 220 | if (lic.getPackId() != null) { |
|---|
| 221 | 221 | pack = em.find(Pack.class, lic.getPackId()); |
|---|
| 222 | 222 | if (pack == null) { |
|---|
| 223 | | - log.error("License pack with id {} not found in DB", lic.getPackId()); |
|---|
| 223 | + LOG.error("License pack with id {} not found in DB", lic.getPackId()); |
|---|
| 224 | 224 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 225 | 225 | } else { |
|---|
| 226 | 226 | if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 227 | 227 | if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) { |
|---|
| 228 | | - log.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal()); |
|---|
| 228 | + LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal()); |
|---|
| 229 | 229 | return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build(); |
|---|
| 230 | 230 | } |
|---|
| 231 | 231 | } |
|---|
| .. | .. |
|---|
| 273 | 273 | @Produces( |
|---|
| 274 | 274 | { MediaType.APPLICATION_JSON }) |
|---|
| 275 | 275 | public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 276 | | - log.info("Modifying organization with id: {}", licId); |
|---|
| 276 | + LOG.info("Modifying organization with id: {}", licId); |
|---|
| 277 | 277 | |
|---|
| 278 | 278 | EntityManager em = emProvider.get(); |
|---|
| 279 | 279 | |
|---|
| .. | .. |
|---|
| 296 | 296 | @Produces( |
|---|
| 297 | 297 | { MediaType.APPLICATION_JSON }) |
|---|
| 298 | 298 | public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { |
|---|
| 299 | | - log.info("Deleting license with id: {}", licId); |
|---|
| 299 | + LOG.info("Deleting license with id: {}", licId); |
|---|
| 300 | 300 | EntityManager em = emProvider.get(); |
|---|
| 301 | 301 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 302 | 302 | |
|---|
| 303 | 303 | if (lic.getStatus() != License.Status.CANCELED || lic.getStatus() != License.Status.CREATED) { |
|---|
| 304 | | - log.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus()); |
|---|
| 304 | + LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus()); |
|---|
| 305 | 305 | return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License can not be deleted in current status").build(); |
|---|
| 306 | 306 | } |
|---|
| 307 | 307 | |
|---|
| .. | .. |
|---|
| 311 | 311 | |
|---|
| 312 | 312 | private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException { |
|---|
| 313 | 313 | if (licId == null || licId.equals("")) { |
|---|
| 314 | | - log.error("License ID is mandatory"); |
|---|
| 314 | + LOG.error("License ID is mandatory"); |
|---|
| 315 | 315 | throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Missing license ID"); |
|---|
| 316 | 316 | } |
|---|
| 317 | 317 | |
|---|
| 318 | 318 | License lic = em.find(License.class, licId); |
|---|
| 319 | 319 | if (lic == null) { |
|---|
| 320 | | - log.error("License with id {} not found in DB", licId); |
|---|
| 320 | + LOG.error("License with id {} not found in DB", licId); |
|---|
| 321 | 321 | throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId); |
|---|
| 322 | 322 | } |
|---|
| 323 | 323 | if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 324 | 324 | if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) { |
|---|
| 325 | | - log.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal()); |
|---|
| 325 | + LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal()); |
|---|
| 326 | 326 | throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data"); |
|---|
| 327 | 327 | } |
|---|
| 328 | 328 | } |
|---|