|
|
@ -87,24 +87,47 @@ public final class DeviceManagerUtil {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Adds a new device type to the database if it does not exists.
|
|
|
|
* Adds a new device type to the database if it does not exists.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param deviceTypeName device type
|
|
|
|
* @param deviceType device type
|
|
|
|
* @return status of the operation
|
|
|
|
* @return status of the operation
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean registerDeviceType(String deviceTypeName) throws DeviceManagementException{
|
|
|
|
public static boolean registerDeviceType(String deviceType) throws DeviceManagementException {
|
|
|
|
boolean status = false;
|
|
|
|
boolean status;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceTypeName);
|
|
|
|
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
|
|
|
if(deviceTypeId == null){
|
|
|
|
if (deviceTypeId == null) {
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
DeviceType dt = new DeviceType();
|
|
|
|
deviceType.setName(deviceTypeName);
|
|
|
|
dt.setName(deviceType);
|
|
|
|
deviceTypeDAO.addDeviceType(deviceType);
|
|
|
|
deviceTypeDAO.addDeviceType(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status = true;
|
|
|
|
status = true;
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
String msg = "Error occurred while registering the device type " + deviceTypeName;
|
|
|
|
String msg = "Error occurred while registering the device type " + deviceType;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Unregisters an existing device type from the device management metadata repository.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceType device type
|
|
|
|
|
|
|
|
* @return status of the operation
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
|
|
|
|
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
|
|
|
|
|
|
|
if (deviceTypeId == null) {
|
|
|
|
|
|
|
|
DeviceType dt = new DeviceType();
|
|
|
|
|
|
|
|
dt.setName(deviceType);
|
|
|
|
|
|
|
|
deviceTypeDAO.removeDeviceType(dt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while registering the device type " + deviceType;
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|