| .. | .. |
|---|
| 19 | 19 | |
|---|
| 20 | 20 | public class ReqGenerator { |
|---|
| 21 | 21 | |
|---|
| 22 | | - private static final Logger LOG = LogManager.getLogger(ReqGenerator.class); |
|---|
| 22 | + private static final Logger LOG = LogManager.getLogger(ReqGenerator.class); |
|---|
| 23 | 23 | |
|---|
| 24 | | - private static ReqGenerator singleton = new ReqGenerator(); |
|---|
| 24 | + private static ReqGenerator singleton = new ReqGenerator(); |
|---|
| 25 | 25 | |
|---|
| 26 | | - private ReqGenerator() { |
|---|
| 27 | | - } |
|---|
| 26 | + private ReqGenerator() { |
|---|
| 27 | + } |
|---|
| 28 | 28 | |
|---|
| 29 | | - public static ReqGenerator getInstance() { |
|---|
| 30 | | - return singleton; |
|---|
| 31 | | - } |
|---|
| 29 | + public static ReqGenerator getInstance() { |
|---|
| 30 | + return singleton; |
|---|
| 31 | + } |
|---|
| 32 | 32 | |
|---|
| 33 | | - public RequestBean createRequest(String appCode, String customerCode) throws SeCurisException { |
|---|
| 34 | | - RequestBean req = new RequestBean(); |
|---|
| 33 | + public RequestBean createRequest(String licTypeCode, String customerCode, String packCode) throws SeCurisException { |
|---|
| 34 | + RequestBean req = new RequestBean(); |
|---|
| 35 | 35 | |
|---|
| 36 | | - req.setAppCode(appCode); |
|---|
| 37 | | - req.setCustomerCode(customerCode); |
|---|
| 38 | | - req.setArch(HWInfo.getArch()); |
|---|
| 39 | | - req.setCrcLogo(getCrcLogo()); |
|---|
| 40 | | - req.setMacAddresses(HWInfo.getMACAddress()); |
|---|
| 41 | | - req.setOsName(HWInfo.getOsName()); |
|---|
| 36 | + req.setLicenseTypeCode(licTypeCode); |
|---|
| 37 | + req.setCustomerCode(customerCode); |
|---|
| 38 | + req.setPackCode(packCode); |
|---|
| 39 | + req.setArch(HWInfo.getArch()); |
|---|
| 40 | + req.setCrcLogo(getCrcLogo()); |
|---|
| 41 | + req.setMacAddresses(HWInfo.getMACAddress()); |
|---|
| 42 | + req.setOsName(HWInfo.getOsName()); |
|---|
| 42 | 43 | |
|---|
| 43 | | - return req; |
|---|
| 44 | | - } |
|---|
| 44 | + return req; |
|---|
| 45 | + } |
|---|
| 45 | 46 | |
|---|
| 46 | | - public RequestBean loadRequest(File requestFile) throws SeCurisException { |
|---|
| 47 | | - try { |
|---|
| 48 | | - String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8"); |
|---|
| 49 | | - RequestBean req = JsonUtils.json2object(json, RequestBean.class); |
|---|
| 50 | | - return req; |
|---|
| 51 | | - } catch (IOException e) { |
|---|
| 52 | | - LOG.error("Request file {} was not found or is not accesible"); |
|---|
| 53 | | - throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e); |
|---|
| 54 | | - } |
|---|
| 55 | | - } |
|---|
| 47 | + public RequestBean loadRequest(File requestFile) throws SeCurisException { |
|---|
| 48 | + try { |
|---|
| 49 | + String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8"); |
|---|
| 50 | + RequestBean req = JsonUtils.json2object(json, RequestBean.class); |
|---|
| 51 | + return req; |
|---|
| 52 | + } catch (IOException e) { |
|---|
| 53 | + LOG.error("Request file {} was not found or is not accesible"); |
|---|
| 54 | + throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e); |
|---|
| 55 | + } |
|---|
| 56 | + } |
|---|
| 56 | 57 | |
|---|
| 57 | | - /** |
|---|
| 58 | | - * Generate a request file using a {@link RequestBean} |
|---|
| 59 | | - * |
|---|
| 60 | | - * @param req |
|---|
| 61 | | - * @param file |
|---|
| 62 | | - * @throws SeCurisException |
|---|
| 63 | | - */ |
|---|
| 64 | | - public void save(RequestBean req, File file) throws SeCurisException { |
|---|
| 65 | | - byte[] json; |
|---|
| 66 | | - try { |
|---|
| 67 | | - json = JsonUtils.toJSON(req, true).getBytes("utf-8"); |
|---|
| 68 | | - Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 69 | | - } catch (UnsupportedEncodingException e) { |
|---|
| 70 | | - LOG.error("Error creating json doc from request: " + req, e); |
|---|
| 71 | | - throw new SeCurisException("Error creating json doc from request: " + req, e); |
|---|
| 72 | | - } catch (IOException e) { |
|---|
| 73 | | - LOG.error("Error creating request file: " + file, e); |
|---|
| 74 | | - throw new SeCurisException("Error creating request file: " + file, e); |
|---|
| 75 | | - } |
|---|
| 58 | + /** |
|---|
| 59 | + * Generate a request file using a {@link RequestBean} |
|---|
| 60 | + * |
|---|
| 61 | + * @param req |
|---|
| 62 | + * @param file |
|---|
| 63 | + * @throws SeCurisException |
|---|
| 64 | + */ |
|---|
| 65 | + public void save(RequestBean req, File file) throws SeCurisException { |
|---|
| 66 | + byte[] json; |
|---|
| 67 | + try { |
|---|
| 68 | + json = JsonUtils.toJSON(req, true).getBytes("utf-8"); |
|---|
| 69 | + Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 70 | + } catch (UnsupportedEncodingException e) { |
|---|
| 71 | + LOG.error("Error creating json doc from request: " + req, e); |
|---|
| 72 | + throw new SeCurisException("Error creating json doc from request: " + req, e); |
|---|
| 73 | + } catch (IOException e) { |
|---|
| 74 | + LOG.error("Error creating request file: " + file, e); |
|---|
| 75 | + throw new SeCurisException("Error creating request file: " + file, e); |
|---|
| 76 | + } |
|---|
| 76 | 77 | |
|---|
| 77 | | - LOG.debug("License saved in {}", file); |
|---|
| 78 | + LOG.debug("License saved in {}", file); |
|---|
| 78 | 79 | |
|---|
| 79 | | - } |
|---|
| 80 | + } |
|---|
| 80 | 81 | |
|---|
| 81 | | - private String getCrcLogo() { |
|---|
| 82 | | - String logResource = "images/logo_customer.png"; |
|---|
| 83 | | - InputStream is = getClass().getClassLoader().getResourceAsStream(logResource); |
|---|
| 84 | | - if (is == null) |
|---|
| 85 | | - return null; |
|---|
| 86 | | - try { |
|---|
| 87 | | - String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET); |
|---|
| 88 | | - return shaLogo; |
|---|
| 89 | | - } catch (IOException e) { |
|---|
| 90 | | - LOG.error("Customer logo was not found in classpath in " + logResource, e); |
|---|
| 91 | | - return null; |
|---|
| 92 | | - } |
|---|
| 93 | | - } |
|---|
| 82 | + private String getCrcLogo() { |
|---|
| 83 | + String logResource = "images/logo_customer.png"; |
|---|
| 84 | + InputStream is = getClass().getClassLoader().getResourceAsStream(logResource); |
|---|
| 85 | + if (is == null) |
|---|
| 86 | + return null; |
|---|
| 87 | + try { |
|---|
| 88 | + String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET); |
|---|
| 89 | + return shaLogo; |
|---|
| 90 | + } catch (IOException e) { |
|---|
| 91 | + LOG.error("Customer logo was not found in classpath in " + logResource, e); |
|---|
| 92 | + return null; |
|---|
| 93 | + } |
|---|
| 94 | + } |
|---|
| 94 | 95 | } |
|---|