From 0e96d829682e1dbe1fd8bd6131c883cde27c39ec Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 10:04:41 +0530 Subject: [PATCH 1/4] License Managemnt --- .../carbon/device/mgt/common/DeviceManagementConstants.java | 6 ++++++ .../carbon/device/mgt/common/DeviceManagementException.java | 1 - .../mgt/core/internal/DeviceManagementServiceComponent.java | 1 - 3 files changed, 6 insertions(+), 2 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 9802fe30fe..76c541d337 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 @@ -43,4 +43,10 @@ public final class DeviceManagementConstants { public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows"; } + public static final class LanguageCodes{ + private LanguageCodes() { throw new AssertionError();} + public final static String LANGUAGE_CODE_ENGLISH_US = "en-us"; + public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java index 48c409b894..4d261973e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java @@ -15,7 +15,6 @@ */ package org.wso2.carbon.device.mgt.common; -@SuppressWarnings("unused") public class DeviceManagementException extends Exception { private static final long serialVersionUID = -3151279311929070297L; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 311e59d961..96a591ef75 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -50,7 +50,6 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setDeviceManagerService" * unbind="unsetDeviceManagerService" */ -@SuppressWarnings("unused") public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); From f4e9f1f15b0f89a218afd3bc682befd3d6d55714 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 10:08:42 +0530 Subject: [PATCH 2/4] License Management --- .../common/LicenseManagementException.java | 62 ++++++++++++++ .../device/mgt/core/LicenseManager.java | 42 +++++----- .../device/mgt/core/LicenseManagerImpl.java | 37 +++++++++ .../internal/LicenseManagementDataHolder.java | 63 ++++++++++++++ .../LicenseManagementServiceComponent.java | 83 +++++++++++++++++++ .../service/LicenseManagementService.java | 38 +++++++++ 6 files changed, 304 insertions(+), 21 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java new file mode 100644 index 0000000000..1b39a74981 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.common; + +public class LicenseManagementException extends Exception{ + + private static final long serialVersionUID = 8606378077242945475L; + private String errorMessage; + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public LicenseManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public LicenseManagementException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public LicenseManagementException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public LicenseManagementException() { + super(); + } + + public LicenseManagementException(Throwable cause) { + super(cause); + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java index 0275a1bc20..dc13149fa4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java @@ -1,30 +1,30 @@ /* * - * * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * * - * * WSO2 Inc. licenses this file to you under the Apache License, - * * Version 2.0 (the "License"); you may not use this file except - * * in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, - * * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * * KIND, either express or implied. See the License for the - * * specific language governing permissions and limitations - * * under the License. - * / + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * */ package org.wso2.carbon.device.mgt.core; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; - -public class LicenseManager { +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -/* public void addLicense(DeviceType deviceType,String langCode, String - );*/ +public interface LicenseManager { + public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, + DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java new file mode 100644 index 0000000000..aa55100774 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.core; + +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; + +public class LicenseManagerImpl implements LicenseManager{ + + @Override + public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, + DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException { + + + return null; + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java new file mode 100644 index 0000000000..1d81f8f10c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.core.internal; + +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.user.core.tenant.TenantManager; + +public class LicenseManagementDataHolder { + + private RealmService realmService; + private TenantManager tenantManager; + private LicenseManager licenseManager; + private static LicenseManagementDataHolder thisInstance = new LicenseManagementDataHolder(); + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } + + public TenantManager getTenantManager() { + return tenantManager; + } + + public void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; + } + + private LicenseManagementDataHolder() { + } + + public static LicenseManagementDataHolder getInstance() { + return thisInstance; + } + public LicenseManager getLicenseManager() { + return licenseManager; + } + + public void setLicenseManager(LicenseManager licenseManager) { + this.licenseManager = licenseManager; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java new file mode 100644 index 0000000000..3be323e27c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java @@ -0,0 +1,83 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.core.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.device.mgt.core.LicenseManagerImpl; +import org.wso2.carbon.device.mgt.core.service.LicenseManagementService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.license.manager" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + */ +public class LicenseManagementServiceComponent { + + private static Log log = LogFactory.getLog(LicenseManagementServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + + if (log.isDebugEnabled()) { + log.debug("Initializing license management core bundle"); + } + LicenseManager licenseManager = new LicenseManagerImpl(); + LicenseManagementDataHolder.getInstance().setLicenseManager(licenseManager); + + if (log.isDebugEnabled()) { + log.debug("Registering OSGi service LicenseManagementService"); + } + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(LicenseManagementService.class.getName(), new LicenseManagementService(), null); + if (log.isDebugEnabled()) { + log.debug("License management core bundle has been successfully initialized"); + } + } + + /** + * Sets Realm Service. + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + LicenseManagementDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + LicenseManagementDataHolder.getInstance().setRealmService(null); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java new file mode 100644 index 0000000000..3f383ba4ab --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.core.service; + +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.License; +import org.wso2.carbon.device.mgt.common.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder; + +public class LicenseManagementService implements LicenseManager{ + + @Override + public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, + DeviceManagementConstants.LanguageCodes languageCode) throws LicenseManagementException { + + return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); + } +} From 0135051d84c3fe044cb10b8030e9a13267564255 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 18:17:40 +0530 Subject: [PATCH 3/4] License Management --- .../org.wso2.carbon.device.mgt.core/pom.xml | 5 + .../device/mgt/core/DeviceManagerImpl.java | 3 + .../device/mgt/core/LicenseManager.java | 5 +- .../device/mgt/core/LicenseManagerImpl.java | 98 +++++++++++++++++-- .../LicenseManagementServiceComponent.java | 5 +- .../service/LicenseManagementService.java | 8 +- .../src/repository/resources/rxts/license.rxt | 15 ++- 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 8690a2e3fd..30cd0d32cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -121,6 +121,11 @@ org.wso2.carbon org.wso2.carbon.user.api + + org.wso2.carbon + org.wso2.carbon.governance.api + 4.2.1 + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 726c43c343..8f8f24328b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.device.mgt.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; @@ -35,6 +37,7 @@ import java.util.List; public class DeviceManagerImpl implements DeviceManager { + private static Log log = LogFactory.getLog(DeviceManagerImpl.class); private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private DeviceManagementConfig config; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java index dc13149fa4..35c846ac2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java @@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; public interface LicenseManager { - public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, - DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException; - + public License getLicense(String deviceType,String languageCodes) throws LicenseManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java index aa55100774..d00936e3fa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java @@ -17,21 +17,103 @@ * under the License. * */ - package org.wso2.carbon.device.mgt.core; -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.device.mgt.common.License; +import org.wso2.carbon.device.mgt.common.LicenseManagementException; +import org.wso2.carbon.governance.api.exception.GovernanceException; +import org.wso2.carbon.governance.api.generic.GenericArtifactFilter; +import org.wso2.carbon.governance.api.generic.GenericArtifactManager; +import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact; +import org.wso2.carbon.governance.api.util.GovernanceUtils; +import org.wso2.carbon.registry.core.Registry; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.registry.core.session.UserRegistry; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + + +public class LicenseManagerImpl implements LicenseManager { -public class LicenseManagerImpl implements LicenseManager{ + private static Log log = LogFactory.getLog(DeviceManagerImpl.class); @Override - public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, - DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException { + public License getLicense(final String deviceType, + final String languageCodes) throws LicenseManagementException { + if (log.isDebugEnabled()){ + log.debug("entered get License in license manager impl"); + } + // TODO: After completes JAX-RX user login, this need to be change to CarbonContext + PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin"); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - return null; - } + Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry( + RegistryType.USER_GOVERNANCE); + + GenericArtifact[] filteredArtifacts; + License license = new License(); + try { + GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); + GenericArtifactManager artifactManager = new GenericArtifactManager(registry, "license"); + + filteredArtifacts = artifactManager.findGenericArtifacts( + new GenericArtifactFilter() { + public boolean matches(GenericArtifact artifact) throws GovernanceException { + String attributeNameVal = artifact.getAttribute("overview_name"); + String attributeLangVal = artifact.getAttribute("overview_language"); + return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals + (deviceType) && attributeLangVal.equals(languageCodes)); + } + }); + String validFrom; + String validTo; + DateFormat format; + Date fromDate; + Date toDate; + + for (GenericArtifact artifact : filteredArtifacts) { + if (log.isDebugEnabled()){ + log.debug("Overview name:"+artifact.getAttribute("overview_name")); + log.debug("Overview provider:"+artifact.getAttribute("overview_provider")); + log.debug("Overview Language:"+artifact.getAttribute("overview_language")); + log.debug("overview_validityFrom:"+artifact.getAttribute("overview_validityFrom")); + log.debug("overview_validityTo:"+artifact.getAttribute("overview_validityTo")); + } + validFrom = artifact.getAttribute("overview_validityFrom"); + validTo = artifact.getAttribute("overview_validityTo"); + format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); + try { + fromDate = format.parse(validFrom); + toDate = format.parse(validTo); + if (fromDate.getTime()<= new Date().getTime() && new Date().getTime() <= toDate.getTime()){ + license.setLicenseText(artifact.getAttribute("overview_license")); + } + } catch (ParseException e) { + log.error("validFrom:"+ validFrom); + log.error("validTo:"+validTo); + log.error("Valid date parse error:",e); + } + } + } catch (RegistryException regEx) { + log.error("registry exception:",regEx); + throw new LicenseManagementException(); + }finally { + PrivilegedCarbonContext.endTenantFlow(); + } + + return license; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java index 3be323e27c..b1316eff5c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java @@ -16,7 +16,6 @@ * under the License. * */ - package org.wso2.carbon.device.mgt.core.internal; import org.apache.commons.logging.Log; @@ -65,7 +64,7 @@ public class LicenseManagementServiceComponent { */ protected void setRealmService(RealmService realmService) { if (log.isDebugEnabled()) { - log.debug("Setting Realm Service"); + log.debug("Setting Realm Service in license management"); } LicenseManagementDataHolder.getInstance().setRealmService(realmService); } @@ -76,7 +75,7 @@ public class LicenseManagementServiceComponent { */ protected void unsetRealmService(RealmService realmService) { if (log.isDebugEnabled()) { - log.debug("Unsetting Realm Service"); + log.debug("Un setting Realm Service in license management"); } LicenseManagementDataHolder.getInstance().setRealmService(null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java index 3f383ba4ab..bccbcea3c7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java @@ -20,19 +20,15 @@ package org.wso2.carbon.device.mgt.core.service; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.License; import org.wso2.carbon.device.mgt.common.LicenseManagementException; import org.wso2.carbon.device.mgt.core.LicenseManager; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder; -public class LicenseManagementService implements LicenseManager{ +public class LicenseManagementService implements LicenseManager { @Override - public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, - DeviceManagementConstants.LanguageCodes languageCode) throws LicenseManagementException { - + public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); } } diff --git a/product/modules/distribution/src/repository/resources/rxts/license.rxt b/product/modules/distribution/src/repository/resources/rxts/license.rxt index 72f5c2618a..2fc84c6db9 100644 --- a/product/modules/distribution/src/repository/resources/rxts/license.rxt +++ b/product/modules/distribution/src/repository/resources/rxts/license.rxt @@ -1,16 +1,19 @@ - /license/@{overview_provider}/@{overview_name}/@{overview_version} + /license/@{overview_provider}/@{overview_name}/@{overview_language}/@{overview_version} overview_name - + + + + @@ -24,11 +27,17 @@ Name + + Language + Version - Createdtime + Validity From + + + Validity To License From 10e97b3ae1d831266adbb30acbfeb82af7e6bc3e Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 18:32:21 +0530 Subject: [PATCH 4/4] License Management --- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 1 - pom.xml | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 30cd0d32cc..fece8a1afb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -124,7 +124,6 @@ org.wso2.carbon org.wso2.carbon.governance.api - 4.2.1 diff --git a/pom.xml b/pom.xml index e4618c0556..cc71985697 100644 --- a/pom.xml +++ b/pom.xml @@ -120,8 +120,11 @@ org.wso2.carbon.policy.mgt.core ${project.version} - - + + org.wso2.carbon + org.wso2.carbon.governance.api + ${carbon.platform.version} + org.eclipse.osgi @@ -201,6 +204,7 @@ ${project.version} +