Roberto Sánchez
2014-09-19 d58c85d0b65e43f8c0ced84ee816d0adaf16dd20
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -303,7 +303,10 @@
303303 Map<String, Object> metadata = null;
304304 try {
305305 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);
307310 } catch (IOException e) {
308311 LOG.error("Error reading dummy metadata file", e);
309312 throw new SeCurisException("Error reading dummy metadata file");
....@@ -311,6 +314,7 @@
311314
312315 return metadata;
313316 }
317
+
314318 private License getLicenseData(RequestBean req) throws SeCurisException {
315319 // TODO: The dummy expiration date is temporal, this info should be read from DB
316320 License lic = new License();
....@@ -353,6 +357,15 @@
353357 return Response.ok(lic).build();
354358 }
355359
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
+ */
356369 @POST
357370 @Path("/request")
358371 @Consumes(MediaType.MULTIPART_FORM_DATA)
....@@ -374,10 +387,71 @@
374387 return createFromRequest(req, bsc);
375388 }
376389
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);
378410
411
+ Map<String, Object> metadata = getLicenseMetadata(previousLic);
412
+ License licDB = getLicenseData(previousLic);
379413
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));
380448
449
+ return createFromRequest(lic, bsc);
450
+ }
451
+
452
+
453
+
454
+
381455 @PUT
382456 @POST
383457 @Path("/{licId}")