From a03e00c819cca1e4891da42f5d50cf9c7b0b8e33 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 21 Aug 2015 05:47:28 +0530 Subject: [PATCH 1/5] fixed slf4j conflict --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 06078031207..cd383c06add 100644 --- a/pom.xml +++ b/pom.xml @@ -923,6 +923,12 @@ org.wso2.carbon.commons org.wso2.carbon.ntask.core ${carbon.commons.version} + + + org.slf4j + slf4j-api + + From 8949992148661f27020ddf83f345a0d0add4ecd9 Mon Sep 17 00:00:00 2001 From: mharindu Date: Sat, 22 Aug 2015 00:12:24 +0530 Subject: [PATCH 2/5] Fixed 204 issue in LicenseManager --- .../mgt/common/DeviceManagementConstants.java | 4 +- .../GenericArtifactManagerFactory.java | 2 +- .../registry/RegistryBasedLicenseManager.java | 62 ++++++++++++------- .../src/main/resources/rxts/license.rxt | 6 -- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 6bd72a0e82b..7d26890f80d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -53,8 +53,8 @@ public final class DeviceManagementConstants { throw new AssertionError(); } - public final static String LANGUAGE_CODE_ENGLISH_US = "en-us"; - public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk"; + public final static String LANGUAGE_CODE_ENGLISH_US = "en_US"; + public final static String LANGUAGE_CODE_ENGLISH_UK = "en_UK"; } public static final class LicenseProperties { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/GenericArtifactManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/GenericArtifactManagerFactory.java index cb062a4d421..f98a1c600d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/GenericArtifactManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/registry/GenericArtifactManagerFactory.java @@ -46,7 +46,7 @@ public class GenericArtifactManagerFactory { tenantArtifactManagers.get(tenantId); if (artifactManager == null) { /* Hack, to fix https://wso2.org/jira/browse/REGISTRY-2427 */ - //GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); + GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); artifactManager = new GenericArtifactManager((org.wso2.carbon.registry.core.Registry) registry, DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY); 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 0fce3956fd7..6a69ed527d0 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 @@ -63,21 +63,11 @@ public class RegistryBasedLicenseManager implements LicenseManager { @Override public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException { try { - GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() { - @Override - public boolean matches(GenericArtifact artifact) throws GovernanceException { - String attributeNameVal = artifact.getAttribute( - DeviceManagementConstants.LicenseProperties.NAME); - String attributeLangVal = artifact.getAttribute( - DeviceManagementConstants.LicenseProperties.LANGUAGE); - return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals - (deviceType) && attributeLangVal.equals(languageCode)); - } - }); - if (artifacts == null || artifacts.length <= 0) { + GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode); + if (artifact == null) { return null; } - return this.populateLicense(artifacts[0]); + return this.populateLicense(artifact); } catch (GovernanceException e) { throw new LicenseManagementException("Error occurred while retrieving license corresponding to " + "device type '" + deviceType + "'", e); @@ -96,26 +86,35 @@ public class RegistryBasedLicenseManager implements LicenseManager { license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT)); DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); - license.setValidFrom(format.parse(artifact.getAttribute( - DeviceManagementConstants.LicenseProperties.VALID_FROM))); - license.setValidTo(format.parse(artifact.getAttribute( - DeviceManagementConstants.LicenseProperties.VALID_TO))); + String validFrom = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM); + if (validFrom != null && !validFrom.isEmpty()) { + license.setValidFrom(format.parse(validFrom)); + } + String validTo = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO); + if (validTo != null && !validTo.isEmpty()) { + license.setValidFrom(format.parse(validTo)); + } return license; } @Override public void addLicense(final String deviceType, final License license) throws LicenseManagementException { - GenericArtifactManager artifactManager = - GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry); try { - GenericArtifact artifact = - artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", - DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY)); + GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage()); + if (artifact != null) { + return; + } + GenericArtifactManager artifactManager = + GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry); + 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("name", license.getName()); + // artifact.setId(license.getName()); Date validTo = license.getValidTo(); if (validTo != null) { artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString()); @@ -131,4 +130,23 @@ public class RegistryBasedLicenseManager implements LicenseManager { } } + private GenericArtifact getGenericArtifact(final String deviceType, final String languageCode) + throws GovernanceException { + GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() { + @Override + public boolean matches(GenericArtifact artifact) throws GovernanceException { + String attributeNameVal = artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.NAME); + String attributeLangVal = artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.LANGUAGE); + return (attributeNameVal != null && attributeLangVal != null && attributeNameVal. + equalsIgnoreCase(deviceType) && attributeLangVal.equalsIgnoreCase(languageCode)); + } + }); + if (artifacts == null || artifacts.length < 1) { + return null; + } + return artifacts[0]; + } + } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt index b85f5b73fbd..3fa9d8b7c98 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt @@ -6,9 +6,6 @@ - - - @@ -21,9 +18,6 @@ - - Provider - Name From 47091077195d9fb1c730a4854916f7cf948c3592 Mon Sep 17 00:00:00 2001 From: mharindu Date: Sat, 22 Aug 2015 00:31:18 +0530 Subject: [PATCH 3/5] Refactored LicenseManager --- .../registry/RegistryBasedLicenseManager.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 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 6a69ed527d0..60528675b4b 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 @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.extensions.license.mgt.registry; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; @@ -44,6 +46,7 @@ public class RegistryBasedLicenseManager implements LicenseManager { private Registry registry; private GenericArtifactManager artifactManager; + private static final Log log = LogFactory.getLog(RegistryBasedLicenseManager.class); public RegistryBasedLicenseManager() { Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE); @@ -65,6 +68,10 @@ public class RegistryBasedLicenseManager implements LicenseManager { try { GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode); if (artifact == null) { + if (log.isDebugEnabled()) { + log.debug("Generic artifact is null for '" + deviceType + "' device type, Hence license does not " + + "have content"); + } return null; } return this.populateLicense(artifact); @@ -102,19 +109,16 @@ public class RegistryBasedLicenseManager implements LicenseManager { try { GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage()); if (artifact != null) { + return; } - GenericArtifactManager artifactManager = - GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry); 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("name", license.getName()); - // artifact.setId(license.getName()); Date validTo = license.getValidTo(); if (validTo != null) { artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString()); @@ -143,10 +147,7 @@ public class RegistryBasedLicenseManager implements LicenseManager { equalsIgnoreCase(deviceType) && attributeLangVal.equalsIgnoreCase(languageCode)); } }); - if (artifacts == null || artifacts.length < 1) { - return null; - } - return artifacts[0]; + return (artifacts == null || artifacts.length < 1) ? null : artifacts[0]; } } From 9002375f6de117e5f4fd037b495b808a83983481 Mon Sep 17 00:00:00 2001 From: Milan Perera Date: Sat, 22 Aug 2015 00:32:22 +0530 Subject: [PATCH 4/5] Update RegistryBasedLicenseManager.java --- .../license/mgt/registry/RegistryBasedLicenseManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 60528675b4b..5ce52408b32 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 @@ -69,7 +69,7 @@ public class RegistryBasedLicenseManager implements LicenseManager { GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode); if (artifact == null) { if (log.isDebugEnabled()) { - log.debug("Generic artifact is null for '" + deviceType + "' device type, Hence license does not " + + log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " + "have content"); } return null; From f36c82b059cd80698d14375f3fb25c32895d9878 Mon Sep 17 00:00:00 2001 From: mharindu Date: Sat, 22 Aug 2015 00:47:17 +0530 Subject: [PATCH 5/5] Refactored LicenseManager --- .../device/mgt/common/DeviceManagementConstants.java | 1 + .../org.wso2.carbon.device.mgt.extensions/pom.xml | 3 ++- .../mgt/registry/RegistryBasedLicenseManager.java | 11 +++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 7d26890f80d..69f95923e85 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -69,6 +69,7 @@ public final class DeviceManagementConstants { public static final String VALID_TO = "overview_validityTo"; public static final String TEXT = "overview_license"; public static final String LICENSE_REGISTRY_KEY = "license"; + public static final String ARTIFACT_NAME = "name"; } public static final class NotificationProperties { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 5ef446da40d..b96b3d4b5fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -71,7 +71,8 @@ org.wso2.carbon.registry.core.exceptions, org.wso2.carbon.registry.core.session, javax.xml.bind, - org.wso2.carbon.utils + org.wso2.carbon.utils, + org.apache.commons.logging 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 60528675b4b..7eb9f200a13 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 @@ -69,7 +69,7 @@ public class RegistryBasedLicenseManager implements LicenseManager { GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode); if (artifact == null) { if (log.isDebugEnabled()) { - log.debug("Generic artifact is null for '" + deviceType + "' device type, Hence license does not " + + log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " + "have content"); } return null; @@ -109,7 +109,10 @@ public class RegistryBasedLicenseManager implements LicenseManager { try { GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage()); if (artifact != null) { - + if (log.isDebugEnabled()) { + log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " + + "have content"); + } return; } artifact = artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", deviceType)); @@ -118,7 +121,7 @@ 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("name", license.getName()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.ARTIFACT_NAME, license.getName()); Date validTo = license.getValidTo(); if (validTo != null) { artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString()); @@ -147,7 +150,7 @@ public class RegistryBasedLicenseManager implements LicenseManager { equalsIgnoreCase(deviceType) && attributeLangVal.equalsIgnoreCase(languageCode)); } }); - return (artifacts == null || artifacts.length < 1) ? null : artifacts[0]; + return (artifacts == null || artifacts.length == 0) ? null : artifacts[0]; } }