mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Fixing Android and Windows plugin implementations to be compliant with the API changes introduced
This commit is contained in:
parent
2014902cfb
commit
ce348da6fb
@ -23,6 +23,9 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.*;
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
|
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.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
@ -39,230 +42,26 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class AndroidDeviceManagementService implements DeviceManagementService {
|
public class AndroidDeviceManagementService implements DeviceManagementService {
|
||||||
|
|
||||||
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
private DeviceManager deviceManager;
|
||||||
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
|
|
||||||
|
|
||||||
public AndroidDeviceManagementService() {
|
|
||||||
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProviderType() {
|
public String getType() {
|
||||||
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureManager getFeatureManager() {
|
public void init() throws DeviceManagementException {
|
||||||
return new AndroidFeatureManager();
|
this.deviceManager = new AndroidDeviceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public DeviceManager getDeviceManager() {
|
||||||
boolean status;
|
return deviceManager;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
||||||
try {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
||||||
}
|
|
||||||
AndroidDAOFactory.beginTransaction();
|
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public ApplicationManager getApplicationManager() {
|
||||||
boolean status;
|
return null;
|
||||||
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 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 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 boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
||||||
throws DeviceManagementException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 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);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
@ -283,8 +82,8 @@ public class AndroidDeviceManagementService implements DeviceManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
|
public void installApplication(Operation operation,
|
||||||
throws ApplicationManagementException {
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.license.mgt.License;
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
public AndroidDeviceManager() {
|
||||||
|
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureManager getFeatureManager() {
|
||||||
|
return featureManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
AndroidDAOFactory.beginTransaction();
|
||||||
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 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 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 boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 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);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.*;
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
@ -38,104 +39,36 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class WindowsDeviceManagementService implements DeviceManagementService {
|
public class WindowsDeviceManagementService implements DeviceManagementService {
|
||||||
|
|
||||||
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
private DeviceManager deviceManager;
|
||||||
|
|
||||||
public WindowsDeviceManagementService() {
|
|
||||||
mobileDeviceManagementDAOFactory = new WindowsDAOFactory();
|
|
||||||
}
|
|
||||||
private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProviderType() {
|
public String getType() {
|
||||||
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureManager getFeatureManager() {
|
public void init() throws DeviceManagementException {
|
||||||
|
this.deviceManager = new WindowsDeviceManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceManager getDeviceManager() {
|
||||||
|
return deviceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApplicationManager getApplicationManager() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnrolled(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
||||||
boolean status;
|
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
||||||
try {
|
|
||||||
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
|
||||||
mobileDevice);
|
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
|
||||||
String msg = "Error while enrolling the Windows device : " +
|
|
||||||
device.getDeviceIdentifier();
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Application[] getApplications(String s, int i, int i2) throws ApplicationManagementException {
|
public Application[] getApplications(String s, int i, int i2) throws ApplicationManagementException {
|
||||||
return new Application[0];
|
return new Application[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateApplicationStatus(DeviceIdentifier deviceIdentifier,
|
public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application,
|
||||||
Application application, String s) throws ApplicationManagementException {
|
String s) throws ApplicationManagementException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +81,6 @@ public class WindowsDeviceManagementService implements DeviceManagementService {
|
|||||||
@Override
|
@Override
|
||||||
public void installApplication(Operation operation,
|
public void installApplication(Operation operation,
|
||||||
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.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.windows.dao.WindowsDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WindowsDeviceManager implements DeviceManager {
|
||||||
|
|
||||||
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
||||||
|
private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class);
|
||||||
|
|
||||||
|
public WindowsDeviceManager() {
|
||||||
|
mobileDeviceManagementDAOFactory = new WindowsDAOFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureManager getFeatureManager() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnrolled(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||||
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
|
try {
|
||||||
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
||||||
|
mobileDevice);
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
String msg = "Error while enrolling the Windows device : " +
|
||||||
|
device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -52,7 +52,6 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class MobileDeviceManagementServiceComponent {
|
public class MobileDeviceManagementServiceComponent {
|
||||||
|
|
||||||
private ServiceRegistration serverStartupObserverRef;
|
|
||||||
private ServiceRegistration androidServiceRegRef;
|
private ServiceRegistration androidServiceRegRef;
|
||||||
private ServiceRegistration windowsServiceRegRef;
|
private ServiceRegistration windowsServiceRegRef;
|
||||||
|
|
||||||
@ -139,4 +138,5 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user