Refactoring License management functionality

revert-70aa11f8
prabathabey 10 years ago
parent a9a0ac5899
commit 9ad8d6eab9

@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.common;
public final class DeviceManagementConstants {
public static final class DataSourceProperties {
private DataSourceProperties() {
throw new AssertionError();
}
@ -31,7 +30,6 @@ public final class DeviceManagementConstants {
}
public static final class SecureValueProperties {
private SecureValueProperties() {
throw new AssertionError();
}
@ -41,7 +39,6 @@ public final class DeviceManagementConstants {
}
public static final class MobileDeviceTypes {
private MobileDeviceTypes() {
throw new AssertionError();
}
@ -52,7 +49,6 @@ public final class DeviceManagementConstants {
}
public static final class LanguageCodes {
private LanguageCodes() {
throw new AssertionError();
}
@ -62,7 +58,6 @@ public final class DeviceManagementConstants {
}
public static final class LicenseProperties {
private LicenseProperties() {
throw new AssertionError();
}
@ -75,4 +70,5 @@ public final class DeviceManagementConstants {
public static final String LICENSE = "overview_license";
public static final String LICENSE_REGISTRY_KEY = "license";
}
}

@ -1,88 +0,0 @@
/*
* 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.
*/
package org.wso2.carbon.device.mgt.common;
import java.util.Date;
public class License {
private String name;
private String version;
private String language;
private String provider;
private Date validTo;
private Date validFrom;
private String text;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getProvider() {
return provider;
}
public void setProvider(String provider) {
this.provider = provider;
}
public Date getValidTo() {
return validTo;
}
public void setValidTo(Date validTo) {
this.validTo = validTo;
}
public Date getValidFrom() {
return validFrom;
}
public void setValidFrom(Date validFrom) {
this.validFrom = validFrom;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

@ -57,11 +57,9 @@
org.osgi.framework,
org.osgi.service.component,
org.apache.commons.logging,
javax.xml.bind.*,
javax.naming,
javax.xml.*,
javax.sql,
javax.xml.parsers,
javax.transaction.*,
org.wso2.carbon.governance.api.*,
org.wso2.carbon.base,
org.wso2.carbon.context,
@ -72,8 +70,7 @@
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.user.api,
org.wso2.carbon.user.core.*,
org.w3c.dom,
javax.xml.namespace.*;
org.w3c.dom
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.core.internal,

@ -23,8 +23,9 @@ public final class DeviceManagementConstants {
private Common() {
throw new AssertionError();
}
public static final String PROPERTY_SETUP = "setup";
public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "DefaultLicense.xml";
public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "license-config.xml";
}
}

@ -20,8 +20,10 @@
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.core.config.license.License;
public interface LicenseManager {
public License getLicense(String deviceType,String languageCodes) throws LicenseManagementException;
License getLicense(String deviceType,String languageCodes) throws LicenseManagementException;
}

@ -22,18 +22,13 @@ 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.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.License;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder;
import org.wso2.carbon.device.mgt.core.config.license.License;
import org.wso2.carbon.device.mgt.core.license.mgt.GenericArtifactManagerFactory;
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.api.RegistryException;
import org.wso2.carbon.registry.core.session.UserRegistry;
import java.text.DateFormat;
import java.text.ParseException;

@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.core.config.license;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
@XmlRootElement(name = "License")
public class License {
@ -30,12 +31,11 @@ public class License {
private String name;
private String version;
private String language;
private Date validFrom;
private Date validTo;
private String text;
private String validFrom;
private String validTo;
private String license;
@XmlElement(name = "provider")
@XmlElement(name = "Provider", required = true)
public String getProvider() {
return provider;
}
@ -44,7 +44,7 @@ public class License {
this.provider = provider;
}
@XmlElement(name = "name")
@XmlElement(name = "Name", required = true)
public String getName() {
return name;
}
@ -53,7 +53,7 @@ public class License {
this.name = name;
}
@XmlElement(name = "version")
@XmlElement(name = "Version", required = true)
public String getVersion() {
return version;
}
@ -62,7 +62,7 @@ public class License {
this.version = version;
}
@XmlElement(name = "language")
@XmlElement(name = "Language", required = true)
public String getLanguage() {
return language;
}
@ -71,30 +71,31 @@ public class License {
this.language = language;
}
@XmlElement(name = "license")
public String getLicense() {
return license;
@XmlElement(name = "Text", required = true)
public String getText() {
return text;
}
public void setLicense(String license) {
this.license = license;
public void setText(String text) {
this.text = text;
}
@XmlElement(name = "validFrom")
public String getValidFrom() {
@XmlElement(name = "ValidFrom")
public Date getValidFrom() {
return validFrom;
}
public void setValidFrom(String validFrom) {
public void setValidFrom(Date validFrom) {
this.validFrom = validFrom;
}
@XmlElement(name = "validTo")
public String getValidTo() {
@XmlElement(name = "ValidTo")
public Date getValidTo() {
return validTo;
}
public void setValidTo(String validTo) {
public void setValidTo(Date validTo) {
this.validTo = validTo;
}
}

@ -18,17 +18,15 @@
*
*/
package org.wso2.carbon.device.mgt.core.config;
import org.wso2.carbon.device.mgt.common.License;
package org.wso2.carbon.device.mgt.core.config.license;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "DefaultLicense")
public class LicenseManagementConfig {
@XmlRootElement(name = "LicenseConfig")
public class LicenseConfig {
private List<License> licenses;

@ -18,10 +18,10 @@
*
*/
package org.wso2.carbon.device.mgt.core.config;
package org.wso2.carbon.device.mgt.core.config.license;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;
@ -32,11 +32,11 @@ import java.io.File;
public class LicenseConfigurationManager {
private LicenseManagementConfig licenseMgtConfig;
private LicenseConfig licenseConfig;
private static LicenseConfigurationManager licenseConfigManager;
private static final String licenseMgtConfigXMLPath =
CarbonUtils.getCarbonConfigDirPath() + File.separator +
private static final String LICENSE_CONFIG_PATH =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME;
public static LicenseConfigurationManager getInstance() {
@ -51,23 +51,23 @@ public class LicenseConfigurationManager {
}
public synchronized void initConfig() throws LicenseManagementException {
//catch generic exception.if any exception occurs wrap and throw LicenseManagementException
try {
File licenseMgtConfig = new File(licenseMgtConfigXMLPath);
File licenseMgtConfig = new File(LicenseConfigurationManager.LICENSE_CONFIG_PATH);
Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig);
/* Un-marshaling License Management configuration */
JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class);
JAXBContext cdmContext = JAXBContext.newInstance(LicenseConfig.class);
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc);
this.licenseConfig = (LicenseConfig) unmarshaller.unmarshal(doc);
} catch (Exception e) {
throw new LicenseManagementException("Error occurred while initializing RSS config", e);
}
}
/* Catches generic exception as there's no specific task to be carried out catching a particular
exception */
throw new LicenseManagementException("Error occurred while initializing License Configurations", e);
}
}
public LicenseManagementConfig getLicenseMgtConfig() {
return licenseMgtConfig;
public LicenseConfig getLicenseConfig() {
return licenseConfig;
}
}

@ -0,0 +1,45 @@
/*
* *
* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* * Licensed 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.axis2.context.ConfigurationContext;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
public class DeviceManagementAxis2ConfigurationObserver implements Axis2ConfigurationContextObserver {
@Override
public void creatingConfigurationContext(int i) {
}
@Override
public void createdConfigurationContext(ConfigurationContext configurationContext) {
}
@Override
public void terminatingConfigurationContext(ConfigurationContext configurationContext) {
}
@Override
public void terminatedConfigurationContext(ConfigurationContext configurationContext) {
}
}

@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.LicenseManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.user.core.service.RealmService;
@ -87,8 +88,8 @@ public class DeviceManagementServiceComponent {
log.debug("Registering OSGi service DeviceManagementService");
}
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(),
new DeviceManagementService(), null);
bundleContext.registerService(DeviceManagementService.class.getName(), new DeviceManagementService(), null);
bundleContext.registerService(LicenseManagementService.class.getName(), new LicenseManagementService(), null);
if (log.isDebugEnabled()) {
log.debug("Device management core bundle has been successfully initialized");
}

@ -0,0 +1,55 @@
/*
* *
* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* * Licensed 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.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.util.LicenseManagerUtil;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
public class LicenseManagementAxis2ConfigurationObserver implements Axis2ConfigurationContextObserver {
private static final Log log = LogFactory.getLog(LicenseManagementAxis2ConfigurationObserver.class);
@Override
public void creatingConfigurationContext(int tenantId) {
}
@Override
public void createdConfigurationContext(ConfigurationContext configurationContext) {
try {
LicenseManagerUtil.addDefaultLicenses(null);
} catch (LicenseManagementException e) {
log.error("Error occurred while adding default license configurations of the tenant '");
}
}
@Override
public void terminatingConfigurationContext(ConfigurationContext configurationContext) {
}
@Override
public void terminatedConfigurationContext(ConfigurationContext configurationContext) {
}
}

@ -22,35 +22,18 @@ 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.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.License;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.LicenseManager;
import org.wso2.carbon.device.mgt.core.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.config.LicenseConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.LicenseManagementConfig;
import org.wso2.carbon.device.mgt.core.license.mgt.GenericArtifactManagerFactory;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
import org.wso2.carbon.device.mgt.core.service.LicenseManagementService;
import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.device.mgt.core.util.LicenseManagerUtil;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import javax.xml.namespace.QName;
/**
* @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"
* @scr.reference name="registryService.service"
* interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="1..1"
* policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
*/
public class LicenseManagementServiceComponent {
private static Log log = LogFactory.getLog(LicenseManagementServiceComponent.class);
@ -63,21 +46,36 @@ public class LicenseManagementServiceComponent {
LicenseManager licenseManager = new LicenseManagerImpl();
LicenseManagementDataHolder.getInstance().setLicenseManager(licenseManager);
/* If -Dsetup option enabled then create creates default license management */
String setupOption = System.getProperty(
org.wso2.carbon.device.mgt.core.DeviceManagementConstants.Common.PROPERTY_SETUP);
if (log.isDebugEnabled()) {
log.debug("Configuring default licenses to be used for device enrolment");
}
LicenseConfigurationManager.getInstance().initConfig();
LicenseConfig licenseConfig = LicenseConfigurationManager.getInstance().getLicenseConfig();
/* If -Dsetup option enabled then configure device management related default licenses */
String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
if (setupOption != null) {
if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled.Check default licenses and add if not exists in registry");
log.debug(
"-Dsetup is enabled. Configuring default device management licenses " +
"is about to begin");
}
/* It is required to specifically run the following code snippet as Super Tenant in order to use
* Super tenant registry to initialize the underlying GenericArtifactManager corresponding to the same */
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain
(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
LicenseManagerUtil.addDefaultLicenses(licenseConfig);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
LicenseConfigurationManager.getInstance().initConfig();
LicenseManagementConfig licenseManagementConfig = LicenseConfigurationManager.getInstance()
.getLicenseMgtConfig();
addDefaultLicenses(licenseManagementConfig);
}
if (log.isDebugEnabled()) {
log.debug("Registering OSGi service LicenseManagementService");
log.debug("Registering OSGi service 'LicenseManagementService'");
}
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext
@ -85,38 +83,9 @@ public class LicenseManagementServiceComponent {
if (log.isDebugEnabled()) {
log.debug("License management core bundle has been successfully initialized");
}
} catch (Throwable throwable) {
} catch (Throwable e) {
String msg = "Error occurred while initializing license management core bundle";
log.error(msg, throwable);
}
}
private void addDefaultLicenses(LicenseManagementConfig licenseManagementConfig) throws LicenseManagementException {
try {
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
GenericArtifact artifact;
for (License license : licenseManagementConfig.getLicenses()) {
artifact = artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY));
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_NAME, license.getName());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_VERSION,
license.getVersion());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_LANGUAGE,
license.getLanguage());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_PROVIDER,
license.getProvider());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO,
license.getValidTo().toString());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM,
license.getValidFrom().toString());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LICENSE, license.getText());
artifactManager.addGenericArtifact(artifact);
}
} catch (GovernanceException e) {
String msg = "Error occurred while initializing default licences";
throw new LicenseManagementException(msg, e);
log.error(msg, e);
}
}

@ -19,12 +19,14 @@
package org.wso2.carbon.device.mgt.core.license.mgt;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.registry.api.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.session.UserRegistry;
import java.util.HashMap;
import java.util.Map;
@ -37,18 +39,30 @@ public class GenericArtifactManagerFactory {
public static GenericArtifactManager getTenantAwareGovernanceArtifactManager() throws
LicenseManagementException {
Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.USER_GOVERNANCE);
Registry registry;
int tenantId;
try {
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
registry =
LicenseManagementDataHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(
tenantId);
} catch (RegistryException e) {
throw new LicenseManagementException("Error occurred while initializing tenant system registry " +
"to be used to manipulate License artifacts", e);
}
try {
GenericArtifactManager artifactManager;
synchronized (lock) {
artifactManager =
tenantArtifactManagers.get(CarbonContext.getThreadLocalCarbonContext().getTenantId());
tenantArtifactManagers.get(tenantId);
if (artifactManager == null) {
/* Hack, to fix https://wso2.org/jira/browse/REGISTRY-2427 */
//GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
artifactManager =
new GenericArtifactManager((org.wso2.carbon.registry.core.Registry) registry,
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY);
tenantArtifactManagers.put(CarbonContext.getThreadLocalCarbonContext().getTenantId(),
artifactManager);
tenantArtifactManagers.put(tenantId, artifactManager);
}
}
return artifactManager;

@ -17,20 +17,19 @@
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.License;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.LicenseManager;
import org.wso2.carbon.device.mgt.core.config.license.License;
import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder;
public class LicenseManagementService implements LicenseManager {
@Override
public License getLicense(String deviceType, String languageCode)
throws LicenseManagementException {
return LicenseManagementDataHolder.getInstance().getLicenseManager()
.getLicense(deviceType, languageCode);
}
@Override
public License getLicense(String deviceType, String languageCode)
throws LicenseManagementException {
return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
}
}

@ -0,0 +1,86 @@
/*
* *
* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* * Licensed 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.util;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.config.license.License;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.license.mgt.GenericArtifactManagerFactory;
import org.wso2.carbon.governance.api.common.GovernanceArtifactFilter;
import org.wso2.carbon.governance.api.common.GovernanceArtifactManager;
import org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact;
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 javax.xml.namespace.QName;
import java.util.Date;
public class LicenseManagerUtil {
public static void addDefaultLicenses(LicenseConfig licenseConfig) throws LicenseManagementException {
try {
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
for (License license : licenseConfig.getLicenses()) {
/* TODO: This method call can be expensive as it appears to do a complete table scan to check the existence
* of an artifact for each license configuration. Need to find the optimal way of doing this */
if (LicenseManagerUtil.isArtifactExists(artifactManager, license)) {
continue;
}
GenericArtifact artifact =
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY));
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_NAME, license.getName());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_VERSION,
license.getVersion());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_LANGUAGE,
license.getLanguage());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_PROVIDER,
license.getProvider());
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());
}
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LICENSE, license.getText());
artifactManager.addGenericArtifact(artifact);
}
} catch (GovernanceException e) {
throw new LicenseManagementException("Error occurred while initializing default licences", e);
}
}
private static boolean isArtifactExists(final GenericArtifactManager artifactManager,
final License license) throws GovernanceException {
GovernanceArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
@Override
public boolean matches(GenericArtifact artifact) throws GovernanceException {
return artifact.getAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_NAME).equals(
license.getName());
}
});
return (artifacts != null && artifacts.length > 0);
}
}

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~
~ 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.
~
-->
<DefaultLicense>
<License>
<provider>wso2</provider>
<name>android</name>
<version>1.0.0</version>
<language>1.0.0</language>
<validFrom>01-01-2014</validFrom>
<validTo>31-12-2035</validTo>
<license><![CDATA[Test License]]></license>
</License>
<License>
<provider>wso2</provider>
<name>ios</name>
<version>1.0.0</version>
<language>1.0.0</language>
<validFrom>01-01-2014</validFrom>
<validTo>31-12-2035</validTo>
<license><![CDATA[IOS License]]></license>
</License>
<License>
<provider>wso2</provider>
<name>windows</name>
<version>1.0.0</version>
<language>1.0.0</language>
<validFrom>01-01-2014</validFrom>
<validTo>31-12-2035</validTo>
<license><![CDATA[Windows License]]></license>
</License>
</DefaultLicense>

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~
~ 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.
~
-->
<LicenseConfig>
<Licenses>
<License>
<Provider>wso2</Provider>
<Name>android</Name>
<Version>1.0.0</Version>
<Language>1.0.0</Language>
<ValidFrom>01-01-2014</ValidFrom>
<ValidTo>31-12-2035</ValidTo>
<Text><![CDATA[Test License]]></Text>
</License>
<License>
<Provider>wso2</Provider>
<Name>ios</Name>
<Version>1.0.0</Version>
<Language>1.0.0</Language>
<ValidFrom>01-01-2014</ValidFrom>
<ValidTo>31-12-2035</ValidTo>
<Text><![CDATA[IOS License]]></Text>
</License>
<License>
<Provider>wso2</Provider>
<Name>windows</Name>
<Version>1.0.0</Version>
<Language>1.0.0</Language>
<ValidFrom>01-01-2014</ValidFrom>
<ValidTo>31-12-2035</ValidTo>
<Text><![CDATA[Windows License]]></Text>
</License>
</Licenses>
</LicenseConfig>

@ -1,4 +1,5 @@
instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<artifactType type="application/vnd.wso2-license+xml" shortName="license" singularLabel="License" pluralLabel="Licenses"
hasNamespace="false" iconSet="10">
<storagePath>/license/@{overview_provider}/@{overview_name}/@{overview_language}/@{overview_version}</storagePath>
<storagePath>/device-mgt/license/@{overview_name}/@{overview_language}/@{overview_version}</storagePath>
<nameAttribute>overview_name</nameAttribute>
<ui>
<list>

@ -612,7 +612,6 @@
<!-- Device Management -->
<carbon.device.mgt.version>0.9.1-SNAPSHOT</carbon.device.mgt.version>
</properties>
</project>

Loading…
Cancel
Save