mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Making license manager a util exposed as part of org.wso2.carbon.device.mgt.extensions
This commit is contained in:
parent
701228810b
commit
8394b63e0c
@ -18,6 +18,8 @@
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -144,4 +146,8 @@ public interface DeviceManager {
|
||||
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||
|
||||
License getLicense(String languageCode) throws LicenseManagementException;
|
||||
|
||||
void addLicense(License license) throws LicenseManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,6 @@ public interface LicenseManager {
|
||||
|
||||
License getLicense(String deviceType, String languageCode) throws LicenseManagementException;
|
||||
|
||||
boolean addLicense(String deviceType, License license) throws LicenseManagementException;
|
||||
void addLicense(String deviceType, License license) throws LicenseManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -31,9 +31,19 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
|
||||
private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0";
|
||||
|
||||
private static final String PARAM_MANAGE_API_NAME = "managed-api-name";
|
||||
private static final String PARAM_MANAGE_API_VERSION = "managed-api-version";
|
||||
private static final String PARAM_MANAGE_API_CONTEXT = "managed-api-context";
|
||||
private static final String PARAM_MANAGE_API_ENDPOINT = "managed-api-endpoint";
|
||||
private static final String PARAM_MANAGE_API_OWNER = "managed-api-owner";
|
||||
private static final String PARAM_MANAGE_API_TRANSPORTS = "managed-api-transports";
|
||||
private static final String PARAM_MANAGE_API_IS_SECURED = "managed-api-isSecured";
|
||||
|
||||
private static final Log log = LogFactory.getLog(APIPublisherLifecycleListener.class);
|
||||
|
||||
@Override
|
||||
@ -64,7 +74,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
private APIConfig buildApiConfig(ServletContext servletContext) {
|
||||
APIConfig apiConfig = new APIConfig();
|
||||
|
||||
String name = servletContext.getInitParameter("managed-api-name");
|
||||
String name = servletContext.getInitParameter(PARAM_MANAGE_API_NAME);
|
||||
if (name == null || "".equals(name)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-name' attribute is not configured. Therefore, using the default, " +
|
||||
@ -74,7 +84,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
}
|
||||
apiConfig.setName(name);
|
||||
|
||||
String version = servletContext.getInitParameter("managed-api-version");
|
||||
String version = servletContext.getInitParameter(PARAM_MANAGE_API_VERSION);
|
||||
if (version == null || "".equals(version)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-version' attribute is not configured. Therefore, using the " +
|
||||
@ -84,7 +94,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
}
|
||||
apiConfig.setVersion(version);
|
||||
|
||||
String context = servletContext.getInitParameter("managed-api-context");
|
||||
String context = servletContext.getInitParameter(PARAM_MANAGE_API_CONTEXT);
|
||||
if (context == null || "".equals(context)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-context' attribute is not configured. Therefore, using the default, " +
|
||||
@ -94,7 +104,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
}
|
||||
apiConfig.setContext(context);
|
||||
|
||||
String endpoint = servletContext.getInitParameter("managed-api-endpoint");
|
||||
String endpoint = servletContext.getInitParameter(PARAM_MANAGE_API_ENDPOINT);
|
||||
if (endpoint == null || "".equals(endpoint)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-endpoint' attribute is not configured");
|
||||
@ -102,7 +112,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
}
|
||||
apiConfig.setEndpoint(endpoint);
|
||||
|
||||
String owner = servletContext.getInitParameter("managed-api-owner");
|
||||
String owner = servletContext.getInitParameter(PARAM_MANAGE_API_OWNER);
|
||||
if (owner == null || "".equals(owner)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-owner' attribute is not configured");
|
||||
@ -110,12 +120,12 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
||||
}
|
||||
apiConfig.setOwner(owner);
|
||||
|
||||
String isSecuredParam = servletContext.getInitParameter("managed-api-isSecured");
|
||||
String isSecuredParam = servletContext.getInitParameter(PARAM_MANAGE_API_IS_SECURED);
|
||||
boolean isSecured =
|
||||
(isSecuredParam != null && !"".equals(isSecuredParam)) && Boolean.parseBoolean(isSecuredParam);
|
||||
apiConfig.setSecured(isSecured);
|
||||
|
||||
String transports = servletContext.getInitParameter("managed-api-transports");
|
||||
String transports = servletContext.getInitParameter(PARAM_MANAGE_API_TRANSPORTS);
|
||||
if (transports == null || "".equals(transports)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("'managed-api-transports' attribute is not configured. Therefore using the defaults, " +
|
||||
|
||||
@ -43,10 +43,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
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.config.license.LicenseConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
@ -109,6 +106,7 @@ public class DeviceManagementServiceComponent {
|
||||
private static List<PluginInitializationListener> listeners = new ArrayList<PluginInitializationListener>();
|
||||
private static List<DeviceManagementService> deviceManagers = new ArrayList<DeviceManagementService>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -122,8 +120,6 @@ public class DeviceManagementServiceComponent {
|
||||
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
||||
DeviceManagementDAOFactory.init(dsConfig);
|
||||
|
||||
/* Initializing license manager */
|
||||
this.initLicenseManager();
|
||||
/*Initialize Operation Manager*/
|
||||
this.initOperationsManager();
|
||||
|
||||
@ -137,7 +133,6 @@ public class DeviceManagementServiceComponent {
|
||||
"begin");
|
||||
}
|
||||
this.setupDeviceManagementSchema(dsConfig);
|
||||
this.setupDefaultLicenses(DeviceManagementDataHolder.getInstance().getLicenseConfig());
|
||||
}
|
||||
|
||||
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
||||
@ -151,6 +146,7 @@ public class DeviceManagementServiceComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//do nothing
|
||||
}
|
||||
@ -164,16 +160,6 @@ public class DeviceManagementServiceComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private void initLicenseManager() throws LicenseManagementException {
|
||||
LicenseConfigurationManager.getInstance().initConfig();
|
||||
LicenseConfig licenseConfig =
|
||||
LicenseConfigurationManager.getInstance().getLicenseConfig();
|
||||
|
||||
LicenseManager licenseManager = new LicenseManagerImpl();
|
||||
DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager);
|
||||
DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig);
|
||||
}
|
||||
|
||||
private void initOperationsManager() throws OperationManagementException {
|
||||
OperationManager operationManager = new OperationManagerImpl();
|
||||
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
|
||||
@ -189,10 +175,6 @@ public class DeviceManagementServiceComponent {
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
|
||||
bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null);
|
||||
|
||||
LicenseManagementService licenseManagementService = new LicenseManagementService();
|
||||
DeviceManagementDataHolder.getInstance().setLicenseManager(new LicenseManagerImpl());
|
||||
bundleContext.registerService(LicenseManagementService.class.getName(), licenseManagementService, null);
|
||||
|
||||
APIPublisherService publisher = new APIPublisherServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher);
|
||||
bundleContext.registerService(APIPublisherService.class, publisher, null);
|
||||
@ -225,17 +207,6 @@ 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) {
|
||||
licenseManager.addLicense(license.getName(), license);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Device Manager service.
|
||||
*
|
||||
|
||||
@ -21,6 +21,7 @@ import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import java.util.List;
|
||||
@ -29,9 +30,9 @@ import java.util.List;
|
||||
* Proxy class for all Device Management related operations that take the corresponding plugin type in
|
||||
* and resolve the appropriate plugin implementation
|
||||
*/
|
||||
public interface DeviceManagementProviderService extends DeviceManager, LicenseManager, OperationManager {
|
||||
public interface DeviceManagementProviderService extends OperationManager {
|
||||
|
||||
List<Device> getAllDevices(String type) throws DeviceManagementException;
|
||||
List<Device> getAllDevices(String deviceType) throws DeviceManagementException;
|
||||
|
||||
List<Device> getAllDevices() throws DeviceManagementException;
|
||||
|
||||
@ -39,17 +40,17 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
|
||||
|
||||
void sendRegistrationEmail(EmailMessageProperties config) throws DeviceManagementException;
|
||||
|
||||
FeatureManager getFeatureManager(String type) throws DeviceManagementException;
|
||||
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Proxy method to get the tenant configuration of a given platform.
|
||||
*
|
||||
* @param type Device platform
|
||||
* @param deviceType Device platform
|
||||
* @return Tenant configuration settings of the particular tenant and platform.
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while fetching the
|
||||
* configuration.
|
||||
*/
|
||||
TenantConfiguration getConfiguration(String type) throws DeviceManagementException;
|
||||
TenantConfiguration getConfiguration(String deviceType) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to get the list of devices owned by an user.
|
||||
@ -99,4 +100,38 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||
|
||||
License getLicense(String deviceType, String languageCode) throws DeviceManagementException;
|
||||
|
||||
void addLicense(String deviceType, License license) throws DeviceManagementException;
|
||||
|
||||
boolean modifyEnrollment(Device device) throws DeviceManagementException;
|
||||
|
||||
boolean enrollDevice(Device device) throws DeviceManagementException;
|
||||
|
||||
TenantConfiguration getConfiguration() throws DeviceManagementException;
|
||||
|
||||
boolean saveConfiguration(TenantConfiguration configuration) throws DeviceManagementException;
|
||||
|
||||
boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException;
|
||||
|
||||
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException;
|
||||
|
||||
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
||||
|
||||
boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -67,11 +67,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This constructor calls from unit tests
|
||||
* @param pluginRepo
|
||||
*/
|
||||
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){
|
||||
this.pluginRepository = pluginRepo;
|
||||
initDataAccessObjects();
|
||||
@ -84,13 +79,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration configuration)
|
||||
throws DeviceManagementException {
|
||||
public boolean saveConfiguration(TenantConfiguration configuration) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(configuration.getType()).getDeviceManager();
|
||||
return dms.saveConfiguration(configuration);
|
||||
@ -231,8 +220,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
|
||||
return dms.setActive(deviceId, status);
|
||||
@ -467,8 +455,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
|
||||
return dms.setOwnership(deviceId, ownershipType);
|
||||
@ -510,13 +497,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
|
||||
public License getLicense(String deviceType, String languageCode) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(deviceType).getDeviceManager();
|
||||
try {
|
||||
return dms.getLicense(languageCode);
|
||||
} catch (LicenseManagementException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving license configured for " +
|
||||
"device type '" + deviceType + "' and language code '" + languageCode + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String type, License license) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license);
|
||||
public void addLicense(String deviceType, License license) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(deviceType).getDeviceManager();
|
||||
try {
|
||||
dms.addLicense(license);
|
||||
} catch (LicenseManagementException e) {
|
||||
throw new DeviceManagementException("Error occurred while adding license for " +
|
||||
"device type '" + deviceType + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceManagementPluginRepository getPluginRepository() {
|
||||
|
||||
@ -16,14 +16,18 @@
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TestDeviceManager implements DeviceManager {
|
||||
|
||||
public TestDeviceManager() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return null;
|
||||
@ -101,4 +105,15 @@ public class TestDeviceManager implements DeviceManager {
|
||||
throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Device Management Extensions</name>
|
||||
<description>WSO2 Carbon - Device Management Extensions</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>axiom-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Device Management Extensions Bundle</Bundle-Description>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.device.mgt.extensions.*
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -16,12 +16,11 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
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;
|
||||
@ -35,21 +34,10 @@ public class GenericArtifactManagerFactory {
|
||||
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);
|
||||
}
|
||||
|
||||
public static GenericArtifactManager getTenantAwareGovernanceArtifactManager(
|
||||
Registry registry) throws LicenseManagementException {
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GenericArtifactManager artifactManager;
|
||||
synchronized (lock) {
|
||||
artifactManager =
|
||||
@ -16,23 +16,23 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
|
||||
public class LicenseManagementService implements LicenseManager {
|
||||
|
||||
@Override
|
||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
|
||||
//return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(deviceType, license);
|
||||
public void addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||
//return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(deviceType, license);
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
|
||||
public class LicenseManagementUtil {
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
@ -27,19 +27,36 @@ 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.registry.api.Registry;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.lang.String;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LicenseManagerImpl implements LicenseManager {
|
||||
public class RegistryBasedLicenseManager implements LicenseManager {
|
||||
|
||||
private Registry registry;
|
||||
private GenericArtifactManager artifactManager;
|
||||
|
||||
public RegistryBasedLicenseManager(Registry registry) {
|
||||
if (registry == null) {
|
||||
throw new IllegalArgumentException("Registry instance provided is null. Hence, " +
|
||||
"'Registry based license manager cannot be initialized'");
|
||||
}
|
||||
this.registry = registry;
|
||||
try {
|
||||
this.artifactManager = GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
|
||||
} catch (LicenseManagementException e) {
|
||||
throw new IllegalStateException("Failed to initialize generic artifact manager bound to " +
|
||||
"Registry based license manager", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
|
||||
GenericArtifactManager artifactManager =
|
||||
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
|
||||
try {
|
||||
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
|
||||
@Override
|
||||
@ -82,9 +99,9 @@ public class LicenseManagerImpl implements LicenseManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||
public void addLicense(final String deviceType, final License license) throws LicenseManagementException {
|
||||
GenericArtifactManager artifactManager =
|
||||
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
|
||||
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
|
||||
try {
|
||||
GenericArtifact artifact =
|
||||
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
|
||||
@ -99,7 +116,6 @@ public class LicenseManagerImpl implements LicenseManager {
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM,
|
||||
license.getValidFrom().toString());
|
||||
artifactManager.addGenericArtifact(artifact);
|
||||
return true;
|
||||
} catch (GovernanceException e) {
|
||||
throw new LicenseManagementException("Error occurred while adding license for device type " +
|
||||
deviceType + "'", e);
|
||||
@ -37,6 +37,7 @@
|
||||
<modules>
|
||||
<module>org.wso2.carbon.device.mgt.core</module>
|
||||
<module>org.wso2.carbon.device.mgt.common</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user