set active status for enroll device

revert-70aa11f8
manoj 10 years ago
parent b56e42792a
commit 60e539b583

@ -39,141 +39,140 @@ import java.util.List;
public class DeviceManagerImpl implements DeviceManager { public class DeviceManagerImpl implements DeviceManager {
private static Log log = LogFactory.getLog(DeviceManagerImpl.class); private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementConfig config; private DeviceManagementConfig config;
private DeviceManagementRepository pluginRepository; private DeviceManagementRepository pluginRepository;
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
this.config = config; this.config = config;
this.pluginRepository = pluginRepository; this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
} }
@Override public boolean enrollDevice(Device device) throws DeviceManagementException { @Override public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.enrollDevice(device); boolean status = dms.enrollDevice(device);
try { try {
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
deviceDto.setStatus(Status.ACTIVE); deviceDto.setStatus(Status.ACTIVE);
deviceDto.setDeviceTypeId(deviceTypeId); deviceDto.setDeviceTypeId(deviceTypeId);
this.getDeviceDAO().addDevice(deviceDto); this.getDeviceDAO().addDevice(deviceDto);
} catch (DeviceManagementDAOException e) {
} catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e);
e); }
} return status;
return status; }
}
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException {
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
DeviceManagerService dms = 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 '" + device.getId() + "'",
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", e);
e); }
} return status;
return status; }
}
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.disenrollDevice(deviceId);
return dms.disenrollDevice(deviceId); }
}
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.isEnrolled(deviceId);
return dms.isEnrolled(deviceId); }
}
@Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.isActive(deviceId);
return dms.isActive(deviceId); }
}
@Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
@Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.setActive(deviceId, status);
return dms.setActive(deviceId, status); }
}
@Override public List<Device> getAllDevices(String type) throws DeviceManagementException {
@Override public List<Device> getAllDevices(String type) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); List<Device> devicesList = new ArrayList<Device>();
List<Device> devicesList = new ArrayList<Device>(); try {
try { Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); Device dmsDevice = dms.getDevice(deviceIdentifier);
Device dmsDevice = dms.getDevice(deviceIdentifier); if (dmsDevice != null) {
if (dmsDevice != null) { convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setProperties(dmsDevice.getProperties()); convertedDevice.setFeatures(dmsDevice.getFeatures());
convertedDevice.setFeatures(dmsDevice.getFeatures()); }
} devicesList.add(convertedDevice);
devicesList.add(convertedDevice); }
} } catch (DeviceManagementDAOException e) {
} catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e); }
} return devicesList;
return devicesList; }
}
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); Device convertedDevice = null;
Device convertedDevice = null; try {
try { Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); org.wso2.carbon.device.mgt.core.dto.Device device =
org.wso2.carbon.device.mgt.core.dto.Device device = this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); if (device != null) {
if (device != null) { convertedDevice = DeviceManagementDAOUtil
convertedDevice = DeviceManagementDAOUtil .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); Device dmsDevice = dms.getDevice(deviceId);
Device dmsDevice = dms.getDevice(deviceId); if (dmsDevice != null) {
if (dmsDevice != null) { convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setProperties(dmsDevice.getProperties()); convertedDevice.setFeatures(dmsDevice.getFeatures());
convertedDevice.setFeatures(dmsDevice.getFeatures()); }
} }
} } catch (DeviceManagementDAOException e) {
} catch (DeviceManagementDAOException e) { throw new DeviceManagementException(
throw new DeviceManagementException( "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e);
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e); }
} return convertedDevice;
return convertedDevice; }
}
@Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
@Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); return dms.updateDeviceInfo(device);
return dms.updateDeviceInfo(device); }
}
@Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
@Override 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 = this.getPluginRepository().getDeviceManagementProvider(type);
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); return dms.getOperationManager();
return dms.getOperationManager(); }
}
public DeviceDAO getDeviceDAO() {
public DeviceDAO getDeviceDAO() { return deviceDAO;
return deviceDAO; }
}
public DeviceTypeDAO getDeviceTypeDAO() {
public DeviceTypeDAO getDeviceTypeDAO() { return deviceTypeDAO;
return deviceTypeDAO; }
}
public DeviceManagementRepository getPluginRepository() {
public DeviceManagementRepository getPluginRepository() { return pluginRepository;
return pluginRepository; }
}
} }

Loading…
Cancel
Save