revert-dabc3590
milanperera 10 years ago
commit c9bd29f40d

@ -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,51 +21,109 @@ 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;
public class AndroidDeviceManager implements DeviceManager {
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
private FeatureManager featureManager = new AndroidFeatureManager();
private License license;
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
private FeatureManager featureManager = new AndroidFeatureManager();
private License license;
public AndroidDeviceManager() {
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
}
public AndroidDeviceManager() {
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
}
@Override
public FeatureManager getFeatureManager() {
return featureManager;
}
@Override
public FeatureManager getFeatureManager() {
return featureManager;
}
@Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException {
return false;
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 {
return null;
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 = false;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
}
public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status = false;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
}
boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (isEnrolled) {
this.modifyEnrollment(device);
@ -75,201 +133,205 @@ public class AndroidDeviceManager implements DeviceManager {
mobileDevice);
AndroidDAOFactory.commitTransaction();
}
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try {
if (log.isDebugEnabled()) {
log.debug("Modifying the Android device enrollment data");
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice);
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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 : " +
device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try {
if (log.isDebugEnabled()) {
log.debug("Modifying the Android device enrollment data");
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice);
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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 : " +
device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Android device : " + deviceId);
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.deleteMobileDevice(deviceId.getId());
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Android device : " + deviceId);
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.deleteMobileDevice(deviceId.getId());
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
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();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false;
try {
if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
}
MobileDevice mobileDevice =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId());
if (mobileDevice != null) {
isEnrolled = true;
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Android device : " +
deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return isEnrolled;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false;
try {
if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
}
MobileDevice mobileDevice =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId());
if (mobileDevice != null) {
isEnrolled = true;
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Android device : " +
deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return isEnrolled;
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return true;
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return true;
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
return true;
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
return true;
}
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device;
try {
if (log.isDebugEnabled()) {
log.debug("Getting the details of Android device : " + deviceId.getId());
}
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getMobileDevice(deviceId.getId());
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching the Android device : " + deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return device;
}
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device;
try {
if (log.isDebugEnabled()) {
log.debug("Getting the details of Android device : " + deviceId.getId());
}
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getMobileDevice(deviceId.getId());
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching the Android device : " + deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return device;
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
return true;
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
return true;
}
@Override
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
EnrolmentInfo.Status status) throws DeviceManagementException {
return false;
}
@Override
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
EnrolmentInfo.Status status) throws DeviceManagementException {
return false;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
boolean status;
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
throws DeviceManagementException {
boolean status;
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
// This object holds the newly received device object from response
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
// This object holds the newly received device object from response
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
// Updating current object features using newer ones
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
// Updating current object features using newer ones
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
try {
if (log.isDebugEnabled()) {
log.debug(
"updating the details of Android device : " + device.getDeviceIdentifier());
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDeviceDB);
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
log.warn(msg, mobileDAOEx);
}
String msg =
"Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
try {
if (log.isDebugEnabled()) {
log.debug(
"updating the details of Android device : " + device.getDeviceIdentifier());
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDeviceDB);
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg =
"Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null;
try {
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Android devices");
}
List<MobileDevice> mobileDevices =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getAllMobileDevices();
if (mobileDevices != null) {
devices = new ArrayList<Device>();
for (MobileDevice mobileDevice : mobileDevices) {
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
}
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching all Android devices.";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return devices;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null;
try {
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Android devices");
}
List<MobileDevice> mobileDevices =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getAllMobileDevices();
if (mobileDevices != null) {
devices = new ArrayList<Device>();
for (MobileDevice mobileDevice : mobileDevices) {
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
}
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching all Android devices.";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return devices;
}
}

@ -21,6 +21,10 @@ 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.*;
<<<<<<< HEAD
=======
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
>>>>>>> d07c226dd52d29fbc7ee2993ecf0f9700aa43ece
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;
@ -29,6 +33,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 {
@ -44,6 +49,7 @@ public class WindowsDeviceManager implements DeviceManager {
return null;
}
<<<<<<< HEAD
@Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException {
return false;
@ -55,6 +61,20 @@ public class WindowsDeviceManager implements DeviceManager {
}
@Override
=======
@Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException {
return false;
}
@Override
public TenantConfiguration getConfiguration() throws DeviceManagementException {
return null;
}
@Override
>>>>>>> d07c226dd52d29fbc7ee2993ecf0f9700aa43ece
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,8 +62,9 @@ public class MobileDeviceManagementUtil {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : " + e.getMessage(), e);
throw new DeviceManagementException(
"Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : " + e.getMessage(), e);
}
}
@ -91,16 +100,16 @@ public class MobileDeviceManagementUtil {
mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE));
mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE));
if (device.getProperties() != null) {
Map<String, String> deviceProperties = new HashMap<String, String>();
for (Device.Property deviceProperty : device.getProperties()) {
deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue());
}
if (device.getProperties() != null) {
Map<String, String> deviceProperties = new HashMap<String, String>();
for (Device.Property deviceProperty : device.getProperties()) {
deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue());
}
mobileDevice.setDeviceProperties(deviceProperties);
} else {
mobileDevice.setDeviceProperties(new HashMap<String, String>());
}
mobileDevice.setDeviceProperties(deviceProperties);
} else {
mobileDevice.setDeviceProperties(new HashMap<String, String>());
}
}
return mobileDevice;
}
@ -119,13 +128,15 @@ public class MobileDeviceManagementUtil {
propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()));
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()));
}
}
if (mobileDevice.getDeviceProperties() != null) {
for (Map.Entry<String, String> deviceProperty : mobileDevice.getDeviceProperties()
.entrySet()) {
propertyList
.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue()));
}
}
device.setProperties(propertyList);
device.setProperties(propertyList);
device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
}
return device;
@ -162,27 +173,121 @@ 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;
}
public static MobileFeature convertToMobileFeature(Feature feature) {
MobileFeature mobileFeature = new MobileFeature();
mobileFeature.setName(feature.getName());
mobileFeature.setCode(feature.getCode());
mobileFeature.setDescription(feature.getDescription());
mobileFeature.setDeviceType(feature.getDeviceType());
return mobileFeature;
}
public static Feature convertToFeature(MobileFeature mobileFeature) {
Feature feature = new Feature();
feature.setDescription(mobileFeature.getDescription());
feature.setDeviceType(mobileFeature.getDeviceType());
feature.setCode(mobileFeature.getCode());
feature.setName(mobileFeature.getName());
return feature;
}
public static MobileFeature convertToMobileFeature(Feature feature) {
MobileFeature mobileFeature = new MobileFeature();
mobileFeature.setName(feature.getName());
mobileFeature.setCode(feature.getCode());
mobileFeature.setDescription(feature.getDescription());
mobileFeature.setDeviceType(feature.getDeviceType());
return mobileFeature;
}
public static Feature convertToFeature(MobileFeature mobileFeature) {
Feature feature = new Feature();
feature.setDescription(mobileFeature.getDescription());
feature.setDeviceType(mobileFeature.getDeviceType());
feature.setCode(mobileFeature.getCode());
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