Removed governance dependencies

revert-70aa11f8
harshanL 10 years ago
parent b52f8d8697
commit 021c27666c

@ -67,9 +67,6 @@
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.user.api,
org.wso2.carbon.user.core.*,
org.wso2.carbon.governance.api.exception,
org.wso2.carbon.governance.api.generic,
org.wso2.carbon.governance.api.generic.dataobjects,
org.wso2.carbon.registry.core,
org.wso2.carbon.registry.core.exceptions,
org.wso2.carbon.registry.core.service,
@ -139,10 +136,6 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.api</artifactId>

@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.core.config;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;

@ -1,45 +0,0 @@
/*
* *
* * 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) {
}
}

@ -20,6 +20,7 @@
package org.wso2.carbon.device.mgt.core.internal;
import org.wso2.carbon.device.mgt.core.DeviceManager;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@ -32,6 +33,8 @@ public class DeviceManagementDataHolder {
private DeviceManager deviceManager;
private LicenseManager licenseManager;
private RegistryService registryService;
private LicenseConfig licenseConfig;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
private DeviceManagementDataHolder() {
@ -85,4 +88,12 @@ public class DeviceManagementDataHolder {
this.licenseManager = licenseManager;
}
public LicenseConfig getLicenseConfig() {
return licenseConfig;
}
public void setLicenseConfig(LicenseConfig licenseConfig) {
this.licenseConfig = licenseConfig;
}
}

@ -74,7 +74,7 @@ public class DeviceManagementServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Initializing device management core bundle");
}
/* Initializing Device Management Configuration */
/* Initializing Device Management Configuration */
DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
@ -85,11 +85,13 @@ public class DeviceManagementServiceComponent {
DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
LicenseConfigurationManager.getInstance().initConfig();
LicenseConfig licenseConfig = LicenseConfigurationManager.getInstance().getLicenseConfig();
LicenseConfigurationManager.getInstance().initConfig();
LicenseConfig licenseConfig =
LicenseConfigurationManager.getInstance().getLicenseConfig();
LicenseManager licenseManager = new LicenseManagerImpl();
DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager);
LicenseManager licenseManager = new LicenseManagerImpl();
DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager);
DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig);
/* If -Dsetup option enabled then create device management database schema */
String setupOption =
@ -101,7 +103,7 @@ public class DeviceManagementServiceComponent {
"is about to begin");
}
this.setupDeviceManagementSchema(dsConfig);
this.setupDefaultLicenses(licenseConfig);
// this.setupDefaultLicenses(licenseConfig);
}
if (log.isDebugEnabled()) {
@ -109,10 +111,11 @@ public class DeviceManagementServiceComponent {
}
/* Registering Device Management service */
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(), new DeviceManagementService(), null);
bundleContext.registerService(DeviceManagementService.class.getName(),
new DeviceManagementService(), null);
/* Registering License Management service */
bundleContext.registerService(LicenseManagementService.class.getName(),
new LicenseManagementService(), null);
bundleContext.registerService(LicenseManagementService.class.getName(),
new LicenseManagementService(), null);
if (log.isDebugEnabled()) {
log.debug("Device management core bundle has been successfully initialized");
}
@ -141,16 +144,19 @@ public class DeviceManagementServiceComponent {
}
}
private void setupDefaultLicenses(LicenseConfig licenseConfig) throws LicenseManagementException {
LicenseManager licenseManager = DeviceManagementDataHolder.getInstance().getLicenseManager();
for (License license : licenseConfig.getLicenses()) {
License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage());
if (extLicense != null) {
continue;
}
licenseManager.addLicense(license);
}
}
private void setupDefaultLicenses(LicenseConfig licenseConfig)
throws LicenseManagementException {
LicenseManager licenseManager =
DeviceManagementDataHolder.getInstance().getLicenseManager();
for (License license : licenseConfig.getLicenses()) {
License extLicense =
licenseManager.getLicense(license.getName(), license.getLanguage());
if (extLicense != null) {
continue;
}
licenseManager.addLicense(license);
}
}
/**
* Sets Device Manager service.
@ -202,29 +208,29 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setRealmService(null);
}
/**
* Sets Registry Service.
*
* @param registryService An instance of RegistryService
*/
protected void setRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("Setting Registry Service");
}
DeviceManagementDataHolder.getInstance().setRegistryService(registryService);
}
/**
* Unsets Registry Service.
*
* @param registryService An instance of RegistryService
*/
protected void unsetRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("Unsetting Registry Service");
}
DeviceManagementDataHolder.getInstance().setRegistryService(null);
}
/**
* Sets Registry Service.
*
* @param registryService An instance of RegistryService
*/
protected void setRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("Setting Registry Service");
}
DeviceManagementDataHolder.getInstance().setRegistryService(registryService);
}
/**
* Unsets Registry Service.
*
* @param registryService An instance of RegistryService
*/
protected void unsetRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("Unsetting Registry Service");
}
DeviceManagementDataHolder.getInstance().setRegistryService(null);
}
private DeviceManagementRepository getPluginRepository() {
return pluginRepository;

@ -1,72 +0,0 @@
/*
* 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.license.mgt;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.registry.api.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.HashMap;
import java.util.Map;
public class GenericArtifactManagerFactory {
private static Map<Integer, GenericArtifactManager> tenantArtifactManagers =
new HashMap<Integer, GenericArtifactManager>();
private static final Object lock = new Object();
public static GenericArtifactManager getTenantAwareGovernanceArtifactManager() throws
LicenseManagementException {
Registry registry;
int tenantId;
try {
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
registry =
DeviceManagementDataHolder.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(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(tenantId, artifactManager);
}
}
return artifactManager;
} catch (RegistryException e) {
throw new LicenseManagementException("Error occurred while initializing GovernanceArtifactManager " +
"associated with tenant '" + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + "'");
}
}
}

@ -20,89 +20,38 @@ package org.wso2.carbon.device.mgt.core.license.mgt;
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.core.DeviceManagerImpl;
import org.wso2.carbon.device.mgt.core.config.license.License;
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.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import javax.xml.namespace.QName;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
public class LicenseManagerImpl implements LicenseManager {
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
@Override
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
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) {
return null;
}
return this.populateLicense(artifacts[0]);
} catch (GovernanceException e) {
throw new LicenseManagementException("Error occurred while retrieving license corresponding to " +
"device type '" + deviceType + "'");
} catch (ParseException e) {
throw new LicenseManagementException("Error occurred while parsing the ToDate/FromDate date string " +
"of the license configured upon the device type '" + deviceType + "'");
}
}
private License populateLicense(GenericArtifact artifact) throws GovernanceException, ParseException {
License license = new License();
license.setName(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.NAME));
license.setProvider(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER));
license.setVersion(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VERSION));
license.setLanguage(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE));
license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT));
license.setValidFrom(format.parse(artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.VALID_FROM)));
license.setValidTo(format.parse(artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.VALID_TO)));
return license;
}
@Override
public void addLicense(License license) throws LicenseManagementException {
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
try {
GenericArtifact artifact =
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY));
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.VALID_TO,
license.getValidTo().toString());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM,
license.getValidFrom().toString());
artifactManager.addGenericArtifact(artifact);
} catch (GovernanceException e) {
throw new LicenseManagementException("Error occurred while adding license artifact", e);
}
}
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
@Override
public License getLicense(final String deviceType, final String languageCode)
throws LicenseManagementException {
License deviceLicense = new License();
LicenseConfig licenseConfig = DeviceManagementDataHolder.getInstance().getLicenseConfig();
for (License license : licenseConfig.getLicenses()) {
if ((deviceType.equals(license.getName())) &&
(languageCode.equals(license.getLanguage()))) {
deviceLicense = license;
break;
}
}
return deviceLicense;
}
@Override
public void addLicense(License license) throws LicenseManagementException {
}
}

@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
import javax.sql.DataSource;
import java.io.File;
public final class DeviceManagementSchemaInitializer extends DatabaseCreator {

@ -93,7 +93,7 @@
<artifactId>org.wso2.carbon.base</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<!--dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
<version>${carbon.governance.version}</version>
@ -143,7 +143,7 @@
<artifactId>org.wso2.carbon.registry.extensions</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency-->
<!-- End of Governance dependencies -->
<!-- OSGi dependencies-->

Loading…
Cancel
Save