From 1d4bba9807c2bf65959fd5a43ebb543ae0fea165 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 20 Oct 2015 08:12:02 +0530 Subject: [PATCH] License issue fixed --- .../registry/RegistryBasedLicenseManager.java | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) 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 a70f62d79e..fb777f6176 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 @@ -107,23 +107,42 @@ public class RegistryBasedLicenseManager implements LicenseManager { @Override public void addLicense(final String deviceType, final License license) throws LicenseManagementException { try { - GenericArtifact artifact = - artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", deviceType)); - artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName()); - artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion()); - 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.ARTIFACT_NAME, license.getName()); - 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()); + GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage()); + if(artifact != null) { + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion()); + 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.ARTIFACT_NAME, license.getName()); + 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.updateGenericArtifact(artifact); + } else { + artifact = + artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", deviceType)); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion()); + 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.ARTIFACT_NAME, license.getName()); + 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); } - artifactManager.addGenericArtifact(artifact); } catch (GovernanceException e) { throw new LicenseManagementException("Error occurred while adding license for device type " + deviceType + "'", e);