| .. | .. |
|---|
| 52 | 52 | import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes; |
|---|
| 53 | 53 | import net.curisit.securis.services.helpers.LicenseHelper; |
|---|
| 54 | 54 | import net.curisit.securis.services.helpers.UserHelper; |
|---|
| 55 | +import net.curisit.securis.utils.Config; |
|---|
| 55 | 56 | import net.curisit.securis.utils.EmailManager; |
|---|
| 56 | 57 | import net.curisit.securis.utils.JsonUtils; |
|---|
| 57 | | -import net.curisit.securis.utils.Params; |
|---|
| 58 | 58 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | import org.apache.commons.io.IOUtils; |
|---|
| .. | .. |
|---|
| 62 | 62 | import org.apache.logging.log4j.LogManager; |
|---|
| 63 | 63 | import org.apache.logging.log4j.Logger; |
|---|
| 64 | 64 | |
|---|
| 65 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; |
|---|
| 66 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|---|
| 67 | +import com.fasterxml.jackson.annotation.JsonProperty; |
|---|
| 65 | 68 | import com.google.inject.persist.Transactional; |
|---|
| 66 | 69 | |
|---|
| 67 | 70 | /** |
|---|
| .. | .. |
|---|
| 256 | 259 | |
|---|
| 257 | 260 | User user = userHelper.getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 258 | 261 | try { |
|---|
| 259 | | - String subject = MessageFormat.format(Params.get(Params.KEYS.EMAIL_LIC_DEFAULT_SUBJECT), lic.getPack().getAppName()); |
|---|
| 262 | + String subject = MessageFormat.format(Config.get(Config.KEYS.EMAIL_LIC_DEFAULT_SUBJECT), lic.getPack().getAppName()); |
|---|
| 260 | 263 | String email_tpl = IOUtils.toString(this.getClass().getResourceAsStream("/lic_email.template.en")); |
|---|
| 261 | 264 | String body = MessageFormat.format(email_tpl, lic.getFullName(), app.getName()); |
|---|
| 262 | 265 | licFile = licenseHelper.createTemporaryLicenseFile(lic, app.getLicenseFilename()); |
|---|
| .. | .. |
|---|
| 272 | 275 | } |
|---|
| 273 | 276 | } |
|---|
| 274 | 277 | |
|---|
| 275 | | - lic.setModificationTimestamp(new Date()); |
|---|
| 278 | + // lic.setModificationTimestamp(new Date()); |
|---|
| 276 | 279 | em.merge(lic); |
|---|
| 277 | 280 | em.persist(licenseHelper.createLicenseHistoryAction(lic, user, LicenseHistory.Actions.SEND, "Email sent to: " + lic.getEmail())); |
|---|
| 278 | 281 | return Response.ok(lic).build(); |
|---|
| .. | .. |
|---|
| 295 | 298 | @Produces({ |
|---|
| 296 | 299 | MediaType.APPLICATION_JSON |
|---|
| 297 | 300 | }) |
|---|
| 298 | | - public Response cancel(@PathParam("licId") Integer licId, @FormParam("reason") String reason, @Context BasicSecurityContext bsc) |
|---|
| 301 | + public Response cancel(@PathParam("licId") Integer licId, CancellationLicenseActionBean actionData, @Context BasicSecurityContext bsc) |
|---|
| 299 | 302 | throws SeCurisServiceException { |
|---|
| 300 | 303 | |
|---|
| 301 | 304 | EntityManager em = emProvider.get(); |
|---|
| .. | .. |
|---|
| 307 | 310 | + " can not be canceled from the current license status"); |
|---|
| 308 | 311 | } |
|---|
| 309 | 312 | |
|---|
| 310 | | - if (reason == null && (lic.getStatus() == LicenseStatus.ACTIVE || lic.getStatus() == LicenseStatus.PRE_ACTIVE)) { |
|---|
| 313 | + if (actionData.reason == null) { |
|---|
| 311 | 314 | LOG.error("To cancel an active License we need a reason, lic ID: {}, user: {}", lic.getId(), bsc.getUserPrincipal().getName()); |
|---|
| 312 | 315 | throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "Active license with id " + licId |
|---|
| 313 | 316 | + " can not be canceled without a reason"); |
|---|
| 314 | 317 | } |
|---|
| 315 | 318 | |
|---|
| 316 | | - licenseHelper.cancelLicense(lic, reason, bsc, em); |
|---|
| 319 | + licenseHelper.cancelLicense(lic, actionData.reason, bsc, em); |
|---|
| 317 | 320 | return Response.ok(lic).build(); |
|---|
| 318 | 321 | } |
|---|
| 319 | 322 | |
|---|
| .. | .. |
|---|
| 605 | 608 | f = new File(f, "config-server.lic"); |
|---|
| 606 | 609 | LOG.info("f: {}", f); |
|---|
| 607 | 610 | } |
|---|
| 611 | + |
|---|
| 612 | + @JsonAutoDetect |
|---|
| 613 | + @JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 614 | + static class CancellationLicenseActionBean { |
|---|
| 615 | + @JsonProperty |
|---|
| 616 | + private String reason; |
|---|
| 617 | + } |
|---|
| 608 | 618 | } |
|---|