From 4b22589796211c9b6d4b8c444050216dcb65bfde Mon Sep 17 00:00:00 2001 From: harshanL Date: Tue, 9 Dec 2014 17:30:37 +0530 Subject: [PATCH] Modified DeviceManagerService to return operation status. --- .../mgt/common/spi/DeviceManagerService.java | 12 +-- .../carbon/device/mgt/core/DeviceManager.java | 26 +++--- .../carbon/device/mgt/core/dto/Device.java | 6 +- .../core/service/DeviceManagementService.java | 22 ++--- .../DeviceManagementSchemaInitializer.java | 2 +- .../impl/MobileDeviceManagementConstants.java | 28 +++++++ .../android/AndroidDeviceManagerService.java | 84 +++++++++---------- .../impl/ios/IOSDeviceManagerService.java | 44 +++++----- .../windows/WindowsDeviceManagerService.java | 46 +++++----- 9 files changed, 151 insertions(+), 119 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConstants.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java index eab1b03e1..93469177a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java @@ -39,7 +39,7 @@ public interface DeviceManagerService { * @param device Metadata corresponding to the device being enrolled * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - void enrollDevice(Device device) throws DeviceManagementException; + boolean enrollDevice(Device device) throws DeviceManagementException; /** * Method to modify the metadata corresponding to device enrollment @@ -48,7 +48,7 @@ public interface DeviceManagerService { * @throws DeviceManagementException If some unusual behaviour is observed while modify the enrollment of a * device */ - void modifyEnrollment(Device device) throws DeviceManagementException; + boolean modifyEnrollment(Device device) throws DeviceManagementException; /** * Method to disenroll a particular device from CDM. @@ -56,7 +56,7 @@ public interface DeviceManagerService { * @param deviceId Fully qualified device identifier * @throws DeviceManagementException If some unusual behaviour is observed while disenrolling a device */ - void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; /** * Method to retrieve the status of the registration process of a particular device. @@ -84,7 +84,7 @@ public interface DeviceManagerService { * @param status Indicates whether the device is active * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; + boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; /** * Method to retrieve metadata of all devices registered within CDM corresponding to a particular device type. @@ -108,7 +108,7 @@ public interface DeviceManagerService { * @param device Updated device information related data * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - void updateDeviceInfo(Device device) throws DeviceManagementException; + boolean updateDeviceInfo(Device device) throws DeviceManagementException; /** * Method to set the ownership type of a particular device. i.e. BYOD, COPE @@ -117,6 +117,6 @@ public interface DeviceManagerService { * @param ownershipType Type of ownership * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; + boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index b196bf802..4148b0755 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -47,36 +47,38 @@ public class DeviceManager implements DeviceManagerService { } @Override - public void enrollDevice(Device device) throws DeviceManagementException { + public boolean enrollDevice(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - dms.enrollDevice(device); + boolean status = dms.enrollDevice(device); try { this.getDeviceDAO().addDevice(device); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e); } + return status; } @Override - public void modifyEnrollment(Device device) throws DeviceManagementException { + public boolean modifyEnrollment(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - dms.modifyEnrollment(device); + boolean status = dms.modifyEnrollment(device); try { this.getDeviceDAO().updateDevice(device); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", e); } + return status; } @Override - public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - dms.disenrollDevice(deviceId); + return dms.disenrollDevice(deviceId); } @Override @@ -94,10 +96,10 @@ public class DeviceManager implements DeviceManagerService { } @Override - public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - dms.setActive(deviceId, status); + return dms.setActive(deviceId, status); } @Override @@ -115,17 +117,17 @@ public class DeviceManager implements DeviceManagerService { } @Override - public void updateDeviceInfo(Device device) throws DeviceManagementException { + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - dms.updateDeviceInfo(device); + return dms.updateDeviceInfo(device); } @Override - public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - dms.setOwnership(deviceId, ownershipType); + return dms.setOwnership(deviceId, ownershipType); } public DeviceDAO getDeviceDAO() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java index c988968ce..9d5b4b0aa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -23,7 +23,7 @@ import java.io.Serializable; public class Device implements Serializable { private static final long serialVersionUID = -8101106997837486245L; - private Long id; + private String id; private String description; private String name; private Long dateOfEnrolment; @@ -43,11 +43,11 @@ public class Device implements Serializable { this.deviceType = deviceType; } - public Long getId() { + public String getId() { return id; } - public void setId(Long id) { + public void setId(String id) { this.id = id; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 5ec213a33..a0a7eea3c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -31,18 +31,18 @@ public class DeviceManagementService implements DeviceManagerService { } @Override - public void enrollDevice(Device device) throws DeviceManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); + public boolean enrollDevice(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); } @Override - public void modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); } @Override - public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); } @Override @@ -56,8 +56,8 @@ public class DeviceManagementService implements DeviceManagerService { } @Override - public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); } @Override @@ -71,13 +71,13 @@ public class DeviceManagementService implements DeviceManagerService { } @Override - public void updateDeviceInfo(Device device) throws DeviceManagementException { + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); } @Override - public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java index 4bfbb9eea..4ed4e8ad5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java @@ -34,7 +34,7 @@ public final class DeviceManagementSchemaInitializer extends DatabaseCreator { } protected String getDbScriptLocation(String databaseType) { - String scriptName = "wso2_rss_" + databaseType + ".sql"; + String scriptName = "wso2_cdm_" + databaseType + ".sql"; if (log.isDebugEnabled()) { log.debug("Loading database script from :" + scriptName); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConstants.java new file mode 100644 index 000000000..66cb6c34e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConstants.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014, 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.mobile.impl; + +/** + * Constants used by Mobile device Management classes. + */ +public class MobileDeviceManagementConstants { + + public final static String MOBILE_DEVICE_TYPE_ANDROID = "android"; + public final static String MOBILE_DEVICE_TYPE_IOS = "ios"; + public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows"; + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java index 0fb043c85..599da59c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java @@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConstants; import java.util.List; @@ -28,62 +29,61 @@ import java.util.List; */ public class AndroidDeviceManagerService implements DeviceManagerService { - private static final String DEVICE_MANAGER_ANDROID = "android"; - - @Override - public String getProviderType() { - return DEVICE_MANAGER_ANDROID; - } - - @Override - public void enrollDevice(Device device) throws DeviceManagementException { - + @Override + public String getProviderType() { + return MobileDeviceManagementConstants.MOBILE_DEVICE_TYPE_ANDROID; } @Override - public void modifyEnrollment(Device device) throws DeviceManagementException { - + public boolean enrollDevice(Device device) throws DeviceManagementException { + return true; } - @Override - public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - - } - - @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; - } - - @Override - public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return true; + } - } + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } - @Override - public List getAllDevices(String type) throws DeviceManagementException { - return null; - } + @Override + public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return null; - } + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } - @Override - public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } - } + @Override + public List getAllDevices(String type) throws DeviceManagementException { + return null; + } @Override - public void updateDeviceInfo(Device device) throws DeviceManagementException{ + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return null; + } + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; } + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + return true; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java index 6bac82ae2..6e15c47bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java @@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConstants; import java.util.List; @@ -28,41 +29,40 @@ import java.util.List; */ public class IOSDeviceManagerService implements DeviceManagerService { - private static final String DEVICE_MANAGER_IOS = "ios"; - @Override public String getProviderType() { - return DEVICE_MANAGER_IOS; + return MobileDeviceManagementConstants.MOBILE_DEVICE_TYPE_IOS; } @Override - public void enrollDevice(Device device) throws DeviceManagementException { - - } - - @Override - public void modifyEnrollment(Device device) throws DeviceManagementException { - - } + public boolean enrollDevice(Device device) throws DeviceManagementException { + return true; + } @Override - public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return true; + } + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; } @Override public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; + return true; } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; + return true; } @Override - public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; } @Override @@ -76,13 +76,15 @@ public class IOSDeviceManagerService implements DeviceManagerService { } @Override - public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; } - @Override - public void updateDeviceInfo(Device device) throws DeviceManagementException{ + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + return true; + } - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java index e5a45af00..b4711f4e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java @@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConstants; import java.util.List; @@ -28,41 +29,40 @@ import java.util.List; */ public class WindowsDeviceManagerService implements DeviceManagerService { - private static final String DEVICE_MANAGER_WINDOWS = "windows"; - @Override public String getProviderType() { - return DEVICE_MANAGER_WINDOWS; + return MobileDeviceManagementConstants.MOBILE_DEVICE_TYPE_WINDOWS; } @Override - public void enrollDevice(Device device) throws DeviceManagementException { - - } - - @Override - public void modifyEnrollment(Device device) throws DeviceManagementException { - - } + public boolean enrollDevice(Device device) throws DeviceManagementException { + return true; + } @Override - public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return true; + } + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; } @Override public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; + return true; } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; + return true; } @Override - public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; } @Override @@ -75,15 +75,15 @@ public class WindowsDeviceManagerService implements DeviceManagerService { return null; } - @Override - public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; } - @Override - public void updateDeviceInfo(Device device) throws DeviceManagementException{ - - } + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + return true; + } }