Fixing formatting issues

revert-70aa11f8
prabathabey 10 years ago
parent a4ffdf1aa5
commit d439691a01

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

Loading…
Cancel
Save