| .. | .. |
|---|
| 9 | 9 | import javax.inject.Inject; |
|---|
| 10 | 10 | import javax.inject.Provider; |
|---|
| 11 | 11 | import javax.persistence.EntityManager; |
|---|
| 12 | +import javax.persistence.PersistenceContext; |
|---|
| 13 | +import javax.persistence.SynchronizationType; |
|---|
| 12 | 14 | import javax.persistence.TypedQuery; |
|---|
| 13 | 15 | import javax.ws.rs.Consumes; |
|---|
| 14 | 16 | import javax.ws.rs.DELETE; |
|---|
| .. | .. |
|---|
| 84 | 86 | |
|---|
| 85 | 87 | @Inject |
|---|
| 86 | 88 | private Provider<EntityManager> emProvider; |
|---|
| 89 | + |
|---|
| 90 | + @PersistenceContext(unitName = "localdb", synchronization = SynchronizationType.SYNCHRONIZED) |
|---|
| 91 | + private EntityManager entityManager; |
|---|
| 87 | 92 | |
|---|
| 88 | 93 | @Inject |
|---|
| 89 | 94 | private LicenseGenerator licenseGenerator; |
|---|
| .. | .. |
|---|
| 195 | 200 | |
|---|
| 196 | 201 | if (!License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) { |
|---|
| 197 | 202 | LOG.error("License with id {} can not be activated from current license status", licId); |
|---|
| 198 | | - throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId |
|---|
| 203 | + throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "License with id " + licId |
|---|
| 199 | 204 | + " can not be activated from the current license status"); |
|---|
| 200 | 205 | } |
|---|
| 201 | 206 | |
|---|
| 202 | 207 | if (lic.getPack().getNumAvailables() == 0) { |
|---|
| 203 | | - throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "The pack has not available licenses"); |
|---|
| 208 | + throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses"); |
|---|
| 204 | 209 | } |
|---|
| 205 | 210 | |
|---|
| 206 | 211 | validateRequestData(lic.getPack(), lic.getRequestData()); |
|---|
| 207 | 212 | |
|---|
| 208 | 213 | License existingLicense = License.findLicenseByRequestData(lic.getRequestData(), em); |
|---|
| 209 | | - if (existingLicense != null) { |
|---|
| 210 | | - return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE) |
|---|
| 211 | | - .header(DefaultExceptionHandler.ERROR_CODE_MESSAGE_HEADER, ErrorCodes.DUPLICATED_REQUEST_DATA) |
|---|
| 212 | | - .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "There is already an active license for current request data") |
|---|
| 213 | | - .type(MediaType.APPLICATION_JSON).entity(existingLicense).build(); |
|---|
| 214 | + if (existingLicense != null && existingLicense.getStatus() == LicenseStatus.ACTIVE) { |
|---|
| 215 | + throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses"); |
|---|
| 214 | 216 | } |
|---|
| 215 | 217 | |
|---|
| 216 | 218 | lic.setStatus(LicenseStatus.ACTIVE); |
|---|