| .. | .. |
|---|
| 125 | 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 | | - if (lic.getStatus() != License.Status.ACTIVE) { |
|---|
| 128 | + if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) { |
|---|
| 129 | 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 | } |
|---|
| .. | .. |
|---|
| 145 | 145 | EntityManager em = emProvider.get(); |
|---|
| 146 | 146 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 147 | 147 | |
|---|
| 148 | | - User user = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 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); |
|---|
| 150 | + throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status"); |
|---|
| 151 | + } |
|---|
| 149 | 152 | |
|---|
| 150 | 153 | lic.setStatus(License.Status.ACTIVE); |
|---|
| 151 | 154 | lic.setModificationTimestamp(new Date()); |
|---|
| 152 | 155 | em.persist(lic); |
|---|
| 156 | + User user = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 153 | 157 | em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.ACTIVATE)); |
|---|
| 154 | 158 | return Response.ok(lic).build(); |
|---|
| 155 | 159 | } |
|---|
| .. | .. |
|---|
| 188 | 192 | EntityManager em = emProvider.get(); |
|---|
| 189 | 193 | License lic = getCurrentLicense(licId, bsc, em); |
|---|
| 190 | 194 | |
|---|
| 191 | | - User user = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 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); |
|---|
| 197 | + throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status"); |
|---|
| 198 | + } |
|---|
| 192 | 199 | |
|---|
| 193 | 200 | lic.setStatus(License.Status.CANCELED); |
|---|
| 194 | 201 | lic.setModificationTimestamp(new Date()); |
|---|
| 195 | 202 | em.persist(lic); |
|---|
| 203 | + |
|---|
| 204 | + User user = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 196 | 205 | em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.CANCEL)); |
|---|
| 197 | 206 | return Response.ok(lic).build(); |
|---|
| 198 | 207 | } |
|---|