From c41f6c300200f1afe56d2ef494428db2e6cd36cc Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 3 Aug 2015 17:22:46 +0530 Subject: [PATCH] Code cleanup --- .../device/mgt/common/license/mgt/License.java | 5 ----- .../registry/RegistryBasedLicenseManager.java | 17 +++++++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java index fb7d3a4fdf..7044eb4916 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java @@ -35,11 +35,6 @@ public class License { private Date validTo; private String text; - public License() { - this.validTo = new Date(); - this.validFrom = new Date(); - } - @XmlElement(name = "Provider", required = true) public String getProvider() { return provider; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/RegistryBasedLicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/RegistryBasedLicenseManager.java index 420c2799cb..0fce3956fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/RegistryBasedLicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/RegistryBasedLicenseManager.java @@ -36,6 +36,7 @@ import java.lang.String; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Locale; @SuppressWarnings("unused") @@ -79,10 +80,10 @@ public class RegistryBasedLicenseManager implements LicenseManager { return this.populateLicense(artifacts[0]); } catch (GovernanceException e) { throw new LicenseManagementException("Error occurred while retrieving license corresponding to " + - "device type '" + deviceType + "'"); + "device type '" + deviceType + "'", e); } catch (ParseException e) { throw new LicenseManagementException("Error occurred while parsing the ToDate/FromDate date string " + - "of the license configured upon the device type '" + deviceType + "'"); + "of the license configured upon the device type '" + deviceType + "'", e); } } @@ -115,10 +116,14 @@ public class RegistryBasedLicenseManager implements LicenseManager { artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText()); - artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, - license.getValidTo().toString()); - artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM, - license.getValidFrom().toString()); + Date validTo = license.getValidTo(); + if (validTo != null) { + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString()); + } + Date validFrom = license.getValidFrom(); + if (validFrom != null) { + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM, validFrom.toString()); + } artifactManager.addGenericArtifact(artifact); } catch (GovernanceException e) { throw new LicenseManagementException("Error occurred while adding license for device type " +