| .. | .. |
|---|
| 4 | 4 | import java.io.IOException; |
|---|
| 5 | 5 | import java.text.MessageFormat; |
|---|
| 6 | 6 | import java.util.Date; |
|---|
| 7 | | -import java.util.HashMap; |
|---|
| 8 | 7 | import java.util.List; |
|---|
| 9 | | -import java.util.Map; |
|---|
| 10 | | -import java.util.Set; |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | import javax.inject.Inject; |
|---|
| 13 | 10 | import javax.inject.Provider; |
|---|
| .. | .. |
|---|
| 42 | 39 | import net.curisit.securis.db.LicenseHistory; |
|---|
| 43 | 40 | import net.curisit.securis.db.LicenseStatus; |
|---|
| 44 | 41 | import net.curisit.securis.db.Pack; |
|---|
| 45 | | -import net.curisit.securis.db.PackMetadata; |
|---|
| 46 | 42 | import net.curisit.securis.db.PackStatus; |
|---|
| 47 | 43 | import net.curisit.securis.db.User; |
|---|
| 48 | 44 | import net.curisit.securis.security.BasicSecurityContext; |
|---|
| .. | .. |
|---|
| 380 | 376 | if (lic.getRequestData() != null) { |
|---|
| 381 | 377 | License existingLicense = License.findLicenseByRequestData(lic.getRequestData(), em); |
|---|
| 382 | 378 | if (existingLicense != null) { |
|---|
| 383 | | - return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE) |
|---|
| 384 | | - .header(DefaultExceptionHandler.ERROR_CODE_MESSAGE_HEADER, ErrorCodes.DUPLICATED_REQUEST_DATA) |
|---|
| 385 | | - .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "There is already an active license for current request data") |
|---|
| 386 | | - .type(MediaType.APPLICATION_JSON).entity(existingLicense).build(); |
|---|
| 379 | + throw new SeCurisServiceException(ErrorCodes.DUPLICATED_REQUEST_DATA, "There is already an active license for current request data"); |
|---|
| 387 | 380 | } |
|---|
| 388 | 381 | |
|---|
| 389 | 382 | if (pack.getNumAvailables() > 0) { |
|---|
| .. | .. |
|---|
| 414 | 407 | em.persist(lic); |
|---|
| 415 | 408 | em.persist(licenseHelper.createLicenseHistoryAction(lic, createdBy, LicenseHistory.Actions.CREATE)); |
|---|
| 416 | 409 | if (lic.getStatus() == LicenseStatus.ACTIVE) { |
|---|
| 417 | | - em.persist(licenseHelper.createLicenseHistoryAction(lic, createdBy, LicenseHistory.Actions.CREATE, "Activated on creation")); |
|---|
| 410 | + em.persist(licenseHelper.createLicenseHistoryAction(lic, createdBy, LicenseHistory.Actions.ACTIVATE, "Activated on creation")); |
|---|
| 418 | 411 | } |
|---|
| 419 | 412 | |
|---|
| 420 | 413 | return Response.ok(lic).build(); |
|---|
| .. | .. |
|---|
| 425 | 418 | Pack pack = em.find(Pack.class, license.getPackId()); |
|---|
| 426 | 419 | RequestBean rb = validateRequestData(pack, license.getRequestData()); |
|---|
| 427 | 420 | try { |
|---|
| 428 | | - LicenseBean lb = licenseGenerator.generateLicense(rb, extractPackMetadata(pack.getMetadata()), license.getExpirationDate(), |
|---|
| 429 | | - pack.getLicenseTypeCode(), license.getCode()); |
|---|
| 421 | + LicenseBean lb = licenseGenerator.generateLicense(rb, licenseHelper.extractPackMetadata(pack.getMetadata()), |
|---|
| 422 | + licenseHelper.getExpirationDateFromPack(pack, false), license.getCode(), pack.getAppName()); |
|---|
| 430 | 423 | sl = new SignedLicenseBean(lb); |
|---|
| 431 | 424 | } catch (SeCurisException e) { |
|---|
| 432 | 425 | throw new SeCurisServiceException(ErrorCodes.INVALID_LICENSE_REQUEST_DATA, "Error generating license: " + e.toString()); |
|---|
| 433 | 426 | } |
|---|
| 434 | 427 | return sl; |
|---|
| 435 | | - } |
|---|
| 436 | | - |
|---|
| 437 | | - private Map<String, Object> extractPackMetadata(Set<PackMetadata> packMetadata) { |
|---|
| 438 | | - Map<String, Object> metadata = new HashMap<>(); |
|---|
| 439 | | - for (PackMetadata md : packMetadata) { |
|---|
| 440 | | - metadata.put(md.getKey(), md.getValue()); |
|---|
| 441 | | - } |
|---|
| 442 | | - |
|---|
| 443 | | - return metadata; |
|---|
| 444 | 428 | } |
|---|
| 445 | 429 | |
|---|
| 446 | 430 | /** |
|---|