| .. | .. |
|---|
| 303 | 303 | Map<String, Object> metadata = null; |
|---|
| 304 | 304 | try { |
|---|
| 305 | 305 | String metadataJson = IOUtils.toString(dummyMetadata.toURI()); |
|---|
| 306 | | - metadata = new TreeMap<>((Map<String, Object>)JsonUtils.json2map(metadataJson).get(req.getAppCode())); |
|---|
| 306 | + metadata = (Map<String, Object>)JsonUtils.json2map(metadataJson).get(req.getAppCode()); |
|---|
| 307 | + if (metadata == null) |
|---|
| 308 | + throw new SeCurisException("App code in request is unknown: " + req.getAppCode()); |
|---|
| 309 | + metadata = new TreeMap<>(metadata); |
|---|
| 307 | 310 | } catch (IOException e) { |
|---|
| 308 | 311 | LOG.error("Error reading dummy metadata file", e); |
|---|
| 309 | 312 | throw new SeCurisException("Error reading dummy metadata file"); |
|---|
| .. | .. |
|---|
| 311 | 314 | |
|---|
| 312 | 315 | return metadata; |
|---|
| 313 | 316 | } |
|---|
| 317 | + |
|---|
| 314 | 318 | private License getLicenseData(RequestBean req) throws SeCurisException { |
|---|
| 315 | 319 | // TODO: The dummy expiration date is temporal, this info should be read from DB |
|---|
| 316 | 320 | License lic = new License(); |
|---|
| .. | .. |
|---|
| 353 | 357 | return Response.ok(lic).build(); |
|---|
| 354 | 358 | } |
|---|
| 355 | 359 | |
|---|
| 360 | + /** |
|---|
| 361 | + * Returns a License file in JSON format from an uploaded Request file |
|---|
| 362 | + * @param mpfdi |
|---|
| 363 | + * @param bsc |
|---|
| 364 | + * @return |
|---|
| 365 | + * @throws IOException |
|---|
| 366 | + * @throws SeCurisServiceException |
|---|
| 367 | + * @throws SeCurisException |
|---|
| 368 | + */ |
|---|
| 356 | 369 | @POST |
|---|
| 357 | 370 | @Path("/request") |
|---|
| 358 | 371 | @Consumes(MediaType.MULTIPART_FORM_DATA) |
|---|
| .. | .. |
|---|
| 374 | 387 | return createFromRequest(req, bsc); |
|---|
| 375 | 388 | } |
|---|
| 376 | 389 | |
|---|
| 377 | | - |
|---|
| 390 | + /** |
|---|
| 391 | + * Create a new License file based in a previous one |
|---|
| 392 | + * |
|---|
| 393 | + * @param request |
|---|
| 394 | + * @param bsc |
|---|
| 395 | + * @return |
|---|
| 396 | + * @throws IOException |
|---|
| 397 | + * @throws SeCurisServiceException |
|---|
| 398 | + * @throws SeCurisException |
|---|
| 399 | + */ |
|---|
| 400 | + @POST |
|---|
| 401 | + @Path("/renew") |
|---|
| 402 | + @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 403 | + //TODO: Enable this: @Securable |
|---|
| 404 | + @Produces({ |
|---|
| 405 | + MediaType.APPLICATION_JSON |
|---|
| 406 | + }) |
|---|
| 407 | + @Transactional |
|---|
| 408 | + public Response renewFromPreviousLicense(LicenseBean previousLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException { |
|---|
| 409 | + LOG.info("Request to get license: {}", previousLic); |
|---|
| 378 | 410 | |
|---|
| 411 | + Map<String, Object> metadata = getLicenseMetadata(previousLic); |
|---|
| 412 | + License licDB = getLicenseData(previousLic); |
|---|
| 379 | 413 | |
|---|
| 414 | + Date expirationDate = licDB.getExpirationDate(); |
|---|
| 415 | + String licenseTypeCode = licDB.getPack().getLicenseType().getCode(); |
|---|
| 416 | + String licenseCode = licDB.getCode(); |
|---|
| 417 | + LicenseBean lic = licenseGenerator.generateLicense(previousLic, metadata, expirationDate, licenseTypeCode, licenseCode); |
|---|
| 418 | + return Response.ok(lic).build(); |
|---|
| 419 | + } |
|---|
| 420 | + |
|---|
| 421 | + /** |
|---|
| 422 | + * Returns a new License file in JSON format based in a previous license |
|---|
| 423 | + * @param mpfdi |
|---|
| 424 | + * @param bsc |
|---|
| 425 | + * @return |
|---|
| 426 | + * @throws IOException |
|---|
| 427 | + * @throws SeCurisServiceException |
|---|
| 428 | + * @throws SeCurisException |
|---|
| 429 | + */ |
|---|
| 430 | + @POST |
|---|
| 431 | + @Path("/renew") |
|---|
| 432 | + @Consumes(MediaType.MULTIPART_FORM_DATA) |
|---|
| 433 | + @Securable |
|---|
| 434 | + @Produces({ |
|---|
| 435 | + MediaType.APPLICATION_JSON |
|---|
| 436 | + }) |
|---|
| 437 | + @Transactional |
|---|
| 438 | + @SuppressWarnings("unchecked") |
|---|
| 439 | + public Response renewFromLicenseFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException { |
|---|
| 440 | + LicenseBean lic = new LicenseBean(); |
|---|
| 441 | + // TODO: Add more license parameters |
|---|
| 442 | + lic.setAppCode(mpfdi.getFormDataPart("appCode", String.class, null)); |
|---|
| 443 | + lic.setArch(mpfdi.getFormDataPart("arch", String.class, null)); |
|---|
| 444 | + lic.setCrcLogo(mpfdi.getFormDataPart("crcLogo", String.class, null)); |
|---|
| 445 | + lic.setCustomerCode(mpfdi.getFormDataPart("customerCode", String.class, null)); |
|---|
| 446 | + lic.setMacAddresses(mpfdi.getFormDataPart("macAddresses", List.class, null)); |
|---|
| 447 | + lic.setOsName(mpfdi.getFormDataPart("osName", String.class, null)); |
|---|
| 380 | 448 | |
|---|
| 449 | + return createFromRequest(lic, bsc); |
|---|
| 450 | + } |
|---|
| 451 | + |
|---|
| 452 | + |
|---|
| 453 | + |
|---|
| 454 | + |
|---|
| 381 | 455 | @PUT |
|---|
| 382 | 456 | @POST |
|---|
| 383 | 457 | @Path("/{licId}") |
|---|