/** {@inheritDoc} */ private boolean sendPlfInformation(String accessTokencode) { try { String url = softwareRegistrationHost + "/portal/rest/registerSoftware/register"; HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); JsonPlatformInfo jsonPlatformInfo = platformInformationRESTService.getJsonPlatformInfo(); JSONObject jsonObj = new JSONObject(jsonPlatformInfo); String input = jsonObj.toString(); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); httpPost.setHeader("Authorization", "Bearer " + accessTokencode); httpPost.setEntity(new StringEntity(input)); HttpResponse response = client.execute(httpPost); if (response.getStatusLine().getStatusCode() != 200) { LOG.warn("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); return false; } return true; } catch (Exception e) { LOG.warn("Can not send Platform information to eXo community", e); return false; } }
/** {@inheritDoc} */ @Override public boolean isSoftwareRegistered() { // Check plf registration on local String currStatus = Utils.readFromFile(Utils.SW_REG_STATUS, Utils.HOME_CONFIG_FILE_LOCATION); String currVersions = Utils.readFromFile( platformInformationRESTService .getPlatformEdition() .concat("-") .concat(Utils.SW_REG_PLF_VERSION), Utils.HOME_CONFIG_FILE_LOCATION); if (StringUtils.isEmpty(currStatus) || StringUtils.isEmpty(currVersions)) return false; boolean plfRegistrationStatus = currStatus.contains(platformInformationRESTService.getPlatformEdition().concat("-true")); boolean plfVersionRegistrationStatus = currVersions.contains( platformInformationRESTService.getJsonPlatformInfo().getPlatformVersion()); return plfRegistrationStatus && plfVersionRegistrationStatus; }
/** {@inheritDoc} */ @Override public void checkSoftwareRegistration() { // Persisted registration status on local String currentRegStatus = Utils.readFromFile(Utils.SW_REG_STATUS, Utils.HOME_CONFIG_FILE_LOCATION); if (StringUtils.isEmpty(currentRegStatus)) { currentRegStatus = platformInformationRESTService.getPlatformEdition().concat("-true"); } else if (!currentRegStatus.contains( platformInformationRESTService.getPlatformEdition().concat("-true"))) { currentRegStatus = currentRegStatus .concat(",") .concat(platformInformationRESTService.getPlatformEdition().concat("-true")); } Utils.writeToFile(Utils.SW_REG_STATUS, currentRegStatus, Utils.HOME_CONFIG_FILE_LOCATION); String plfVersionsKey = platformInformationRESTService .getPlatformEdition() .concat("-") .concat(Utils.SW_REG_PLF_VERSION); String plfVersions = Utils.readFromFile(plfVersionsKey, Utils.HOME_CONFIG_FILE_LOCATION); if (StringUtils.isEmpty(plfVersions)) { plfVersions = platformInformationRESTService.getJsonPlatformInfo().getPlatformVersion(); } else if (!plfVersions.contains( platformInformationRESTService.getJsonPlatformInfo().getPlatformVersion())) { plfVersions = plfVersions .concat(",") .concat(platformInformationRESTService.getJsonPlatformInfo().getPlatformVersion()); } Utils.writeToFile( platformInformationRESTService .getPlatformEdition() .concat("-") .concat(Utils.SW_REG_PLF_VERSION), plfVersions, Utils.HOME_CONFIG_FILE_LOCATION); }