Added tenant configuration related changes

revert-dabc3590
harshanl 9 years ago
parent 87073ffc5c
commit d07c226dd5

@ -65,11 +65,17 @@
javax.xml.parsers,
org.w3c.dom,
org.wso2.carbon.core,
org.wso2.carbon.context,
org.wso2.carbon.utils.*,
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.ndatasource.core,
org.wso2.carbon.policy.mgt.common.*,
org.wso2.carbon.policy.mgt.core.*
org.wso2.carbon.policy.mgt.core.*,
org.wso2.carbon.registry.core,
org.wso2.carbon.registry.core.exceptions,
org.wso2.carbon.registry.core.service,
org.wso2.carbon.registry.core.session,
org.wso2.carbon.registry.api,
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.mobile.internal,
@ -133,6 +139,14 @@
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.core</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.testng</groupId>
<artifactId>testng</artifactId>

@ -19,5 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.common;
public class MobilePluginConstants {
public static final String MOBILE_DB_SCRIPTS_FOLDER = "cdm";
public static final String MOBILE_CONFIG_REGISTRY_ROOT = "/_system/config";
}

@ -21,12 +21,18 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.mobile.common.MobileDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import org.wso2.carbon.registry.api.Collection;
import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.api.RegistryException;
import java.util.ArrayList;
import java.util.List;
@ -47,6 +53,68 @@ public class AndroidDeviceManager implements DeviceManager {
return featureManager;
}
@Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException {
boolean status = false;
Resource resource;
try {
if (log.isDebugEnabled()) {
log.debug("Persisting android configurations in Registry");
}
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
MobileDeviceManagementUtil.createRegistryCollection(resourcePath);
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
resource = MobileDeviceManagementUtil.getRegistry().newResource();
resource.setContent(configEntry.getValue());
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
}
status = true;
} catch (MobileDeviceMgtPluginException e) {
throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
} catch (RegistryException e) {
throw new DeviceManagementException(
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
}
return status;
}
@Override
public TenantConfiguration getConfiguration() throws DeviceManagementException {
Collection dsCollection = null;
TenantConfiguration tenantConfiguration;
List<ConfigurationEntry> configs = new ArrayList<ConfigurationEntry>();
ConfigurationEntry entry;
Resource resource;
try {
String androidRegPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
dsCollection = (Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
String[] dsmPaths = dsCollection.getChildren();
for (String dsmPath : dsmPaths) {
entry = new ConfigurationEntry();
resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath);
entry.setValue(resource.getContent());
entry.setName(resource.getId());
configs.add(entry);
}
tenantConfiguration = new TenantConfiguration();
tenantConfiguration.setConfiguration(configs);
tenantConfiguration.setType(DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
} catch (MobileDeviceMgtPluginException e) {
throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
} catch (RegistryException e) {
throw new DeviceManagementException(
"Error occurred while retrieving the Registry data : " + e.getMessage(), e);
}
return tenantConfiguration;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status;
@ -63,10 +131,12 @@ public class AndroidDeviceManager implements DeviceManager {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
String msg = "Error occurred while roll back the device enrol transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
String msg =
"Error while enrolling the Android device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
@ -89,7 +159,8 @@ public class AndroidDeviceManager implements DeviceManager {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
String msg = "Error occurred while roll back the update device transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while updating the enrollment of the Android device : " +
@ -115,7 +186,8 @@ public class AndroidDeviceManager implements DeviceManager {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
String msg = "Error occurred while roll back the device dis enrol transaction :" +
deviceId.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while removing the Android device : " + deviceId.getId();
@ -194,7 +266,8 @@ public class AndroidDeviceManager implements DeviceManager {
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
throws DeviceManagementException {
boolean status;
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
@ -221,7 +294,8 @@ public class AndroidDeviceManager implements DeviceManager {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
String msg = "Error occurred while roll back the update device info transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg =

@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
@ -28,6 +30,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import java.util.List;
import java.util.Map;
public class WindowsDeviceManager implements DeviceManager {
@ -43,6 +46,17 @@ public class WindowsDeviceManager implements DeviceManager {
return null;
}
@Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException {
return false;
}
@Override
public TenantConfiguration getConfiguration() throws DeviceManagementException {
return null;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return true;

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementSer
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsPolicyMonitoringService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.registry.core.service.RegistryService;
import java.util.Map;
@ -48,6 +49,9 @@ import java.util.Map;
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
* @scr.reference name="registry.service"
* interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="0..1"
* policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
* <p/>
* Adding reference to API Manager Configuration service is an unavoidable hack to get rid of NPEs thrown while
* initializing APIMgtDAOs attempting to register APIs programmatically. APIMgtDAO needs to be proper cleaned up
@ -149,4 +153,15 @@ public class MobileDeviceManagementServiceComponent {
//do nothing
}
protected void setRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("RegistryService acquired");
}
MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(registryService);
}
protected void unsetRegistryService(RegistryService registryService) {
MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(null);
}
}

@ -0,0 +1,47 @@
/*
* 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.mobile.internal;
import org.wso2.carbon.registry.core.service.RegistryService;
/**
* DataHolder class of Mobile plugins component.
*/
public class MobileDeviceManagementServiceDataHolder {
private RegistryService registryService;
private static MobileDeviceManagementServiceDataHolder thisInstance = new MobileDeviceManagementServiceDataHolder();
private MobileDeviceManagementServiceDataHolder() {
}
public static MobileDeviceManagementServiceDataHolder getInstance() {
return thisInstance;
}
public RegistryService getRegistryService() {
return registryService;
}
public void setRegistryService(RegistryService registryService) {
this.registryService = registryService;
}
}

@ -21,11 +21,19 @@ package org.wso2.carbon.device.mgt.mobile.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants;
import org.wso2.carbon.device.mgt.mobile.dto.*;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementServiceDataHolder;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -54,7 +62,8 @@ public class MobileDeviceManagementUtil {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while parsing file, while converting " +
throw new DeviceManagementException(
"Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : " + e.getMessage(), e);
}
}
@ -120,8 +129,10 @@ public class MobileDeviceManagementUtil {
propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial()));
if (mobileDevice.getDeviceProperties() != null) {
for (Map.Entry<String, String> deviceProperty : mobileDevice.getDeviceProperties().entrySet()) {
propertyList.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue()));
for (Map.Entry<String, String> deviceProperty : mobileDevice.getDeviceProperties()
.entrySet()) {
propertyList
.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue()));
}
}
@ -162,7 +173,8 @@ public class MobileDeviceManagementUtil {
Properties properties = new Properties();
operation.setCode(mobileOperation.getFeatureCode());
for (MobileOperationProperty mobileOperationProperty : mobileOperation.getProperties()) {
properties.put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue());
properties
.put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue());
}
operation.setProperties(properties);
return operation;
@ -185,4 +197,97 @@ public class MobileDeviceManagementUtil {
feature.setName(mobileFeature.getName());
return feature;
}
public static Registry getRegistry() throws MobileDeviceMgtPluginException {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
return MobileDeviceManagementServiceDataHolder.getInstance().getRegistryService()
.getConfigSystemRegistry(
tenantId);
} catch (RegistryException e) {
throw new MobileDeviceMgtPluginException(
"Error in retrieving conf registry instance: " +
e.getMessage(), e);
}
}
public static Resource getRegistryResource(String path) throws MobileDeviceMgtPluginException {
try {
return MobileDeviceManagementUtil.getRegistry().get(path);
} catch (RegistryException e) {
throw new MobileDeviceMgtPluginException("Error in retrieving registry resource : " +
e.getMessage(), e);
}
}
public static boolean putRegistryResource(String path,
Resource resource)
throws MobileDeviceMgtPluginException {
boolean status = false;
try {
MobileDeviceManagementUtil.getRegistry().beginTransaction();
MobileDeviceManagementUtil.getRegistry().put(path, resource);
MobileDeviceManagementUtil.getRegistry().commitTransaction();
status = true;
} catch (RegistryException e) {
throw new MobileDeviceMgtPluginException(
"Error occurred while persisting registry resource : " +
e.getMessage(), e);
}
return status;
}
public static String getResourcePath(String resourceName, String platform) {
String regPath = "";
switch (platform) {
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID:
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID +
"/" + resourceName;
break;
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS:
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS +
"/" + resourceName;
break;
}
return regPath;
}
public static String getPlatformConfigPath(String platform) {
String regPath = "";
switch (platform) {
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID:
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
break;
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS:
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
break;
}
return regPath;
}
public static boolean createRegistryCollection(String path)
throws MobileDeviceMgtPluginException {
try {
if (! MobileDeviceManagementUtil.getRegistry().resourceExists(path)) {
Resource resource = MobileDeviceManagementUtil.getRegistry().newCollection();
MobileDeviceManagementUtil.getRegistry().beginTransaction();
MobileDeviceManagementUtil.getRegistry().put(path, resource);
MobileDeviceManagementUtil.getRegistry().commitTransaction();
}
return true;
} catch (MobileDeviceMgtPluginException e) {
throw new MobileDeviceMgtPluginException(
"Error occurred while creating a registry collection : " +
e.getMessage(), e);
} catch (RegistryException e) {
throw new MobileDeviceMgtPluginException(
"Error occurred while creating a registry collection : " +
e.getMessage(), e);
}
}
}

@ -419,6 +419,72 @@
</exclusions>
</dependency>
<!-- Governance dependencies -->
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.api</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.core</artifactId>
<version>${carbon.kernel.version}</version>
<exclusions>
<exclusion>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.ws.commons.schema.wso2</groupId>
<artifactId>XmlSchema</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>javax.cache.wso2</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.xboot</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.securevault</groupId>
<artifactId>org.wso2.securevault</artifactId>
</exclusion>
<exclusion>
<groupId>org.compass-project.wso2</groupId>
<artifactId>compass</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.abdera.wso2</groupId>
<artifactId>abdera</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.rdbms</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi.wso2</groupId>
<artifactId>poi-scratchpad</artifactId>
</exclusion>
<exclusion>
<groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>commons-pool.wso2</groupId>
<artifactId>commons-pool</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
@ -521,8 +587,8 @@
<version>2.3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>

Loading…
Cancel
Save