|
|
@ -1,17 +1,19 @@
|
|
|
|
/**
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
|
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
|
|
* you may not use this file except in compliance with the 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
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* limitations under the License.
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.wso2.carbon.device.mgt.core;
|
|
|
|
package org.wso2.carbon.device.mgt.core;
|
|
|
|
|
|
|
|
|
|
|
@ -36,8 +38,7 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
private DeviceManagementConfig config;
|
|
|
|
private DeviceManagementConfig config;
|
|
|
|
private DeviceManagementRepository pluginRepository;
|
|
|
|
private DeviceManagementRepository pluginRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceManagerImpl(DeviceManagementConfig config,
|
|
|
|
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
|
|
|
DeviceManagementRepository pluginRepository) {
|
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
this.config = config;
|
|
|
|
this.pluginRepository = pluginRepository;
|
|
|
|
this.pluginRepository = pluginRepository;
|
|
|
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
@ -46,58 +47,51 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.getDeviceTypeDAO().getDeviceType();
|
|
|
|
this.getDeviceTypeDAO().getDeviceType();
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
|
|
|
DeviceManagementDAOUtil.convertDevice(
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
|
|
|
device);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer deviceTypeId =
|
|
|
|
|
|
|
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
|
|
|
|
|
|
|
deviceDto.setDeviceType(deviceTypeId);
|
|
|
|
deviceDto.setDeviceType(deviceTypeId);
|
|
|
|
this.getDeviceDAO().addDevice(deviceDto);
|
|
|
|
this.getDeviceDAO().addDevice(deviceDto);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device '" +
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
|
|
|
device.getId() + "'", e);
|
|
|
|
e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
|
|
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device '" +
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'",
|
|
|
|
device.getId() + "'", e);
|
|
|
|
e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.disenrollDevice(deviceId);
|
|
|
|
return dms.disenrollDevice(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.isEnrolled(deviceId);
|
|
|
|
return dms.isEnrolled(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -118,29 +112,24 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.getDevice(deviceId);
|
|
|
|
return dms.getDevice(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
|
|
|
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(type);
|
|
|
|
|
|
|
|
return dms.getOperationManager();
|
|
|
|
return dms.getOperationManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|