|
|
|
@ -27,7 +27,6 @@ import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.excep
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtDAOException;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi.DeviceOrganizationService;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.util.LockManager;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
|
@ -47,18 +46,25 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
public List<DeviceNode> getChildrenOf(DeviceNode node, int maxDepth, boolean includeDevice)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (node == null || node.getDeviceId() <= 0 || maxDepth < 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
String msg = "Invalid input parameters for retrieving child devices : " +
|
|
|
|
|
"deviceID = " + (node != null ? node.getDeviceId() : null) + ", maxDepth = " + maxDepth +
|
|
|
|
|
", includeDevice = " + includeDevice;
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// Open a database connection
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
return deviceOrganizationDao.getChildrenOf(node, maxDepth, includeDevice);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve child devices";
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve child devices : " +
|
|
|
|
|
"deviceID = " + node.getDeviceId() + ", maxDepth = " + maxDepth + ", includeDevice = " +
|
|
|
|
|
includeDevice;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving child devices";
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving child devices : " +
|
|
|
|
|
"deviceID = " + node.getDeviceId() + ", maxDepth = " + maxDepth + ", includeDevice = " +
|
|
|
|
|
includeDevice;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -70,19 +76,26 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceNode> getParentsOf(DeviceNode node, int maxDepth, boolean includeDevice)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (node == null || node.getDeviceId() <= 0 || maxDepth < 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (node == null || node.getDeviceId() <= 0 || maxDepth <= 0) {
|
|
|
|
|
String msg = "Invalid input parameters for retrieving parent devices. Params : " +
|
|
|
|
|
"deviceID = " + (node != null ? node.getDeviceId() : null) + ", maxDepth = " + maxDepth +
|
|
|
|
|
", includeDevice = " + includeDevice;
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// Open a database connection
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
return deviceOrganizationDao.getParentsOf(node, maxDepth, includeDevice);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve parent devices";
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve parent devices for : " +
|
|
|
|
|
"device ID = " + node.getDeviceId() + ", maxDepth = " + maxDepth + ", includeDevice = " +
|
|
|
|
|
includeDevice;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving parent devices";
|
|
|
|
|
String msg = "Error occurred in the database level while retrieveing parent devices for : " +
|
|
|
|
|
"device ID = " + node.getDeviceId() + ", maxDepth = " + maxDepth + ", includeDevice = " +
|
|
|
|
|
includeDevice;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -91,76 +104,90 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In DeviceOrganizationServiceImpl.java (implementation)
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addDeviceOrganization(DeviceOrganization deviceOrganization)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (deviceOrganization == null || deviceOrganization.getDeviceId() == 0
|
|
|
|
|
|| deviceOrganization.getParentDeviceId() == 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
}
|
|
|
|
|
String msg = "";
|
|
|
|
|
// Check if an organization with the same deviceId and parentDeviceId already exists
|
|
|
|
|
if (organizationExists(deviceOrganization.getDeviceId(), deviceOrganization.getParentDeviceId())) {
|
|
|
|
|
msg = "Device organization with the same deviceId and parentDeviceId already exists.";
|
|
|
|
|
public List<DeviceOrganization> getAllDeviceOrganizations() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
try {
|
|
|
|
|
// Open a database connection
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
return deviceOrganizationDao.getAllDeviceOrganizations();
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve all device organizations.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving all device organizations.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
// Close the database connection
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use LockManager to get a lock object based on deviceId and parentDeviceId
|
|
|
|
|
// LockManager lockManager = LockManager.getInstance();
|
|
|
|
|
// Object lock = lockManager.getLock(deviceOrganization.getDeviceId(), deviceOrganization.getParentDeviceId());
|
|
|
|
|
//
|
|
|
|
|
// synchronized (lock) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addDeviceOrganization(DeviceOrganization deviceOrganization)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (deviceOrganization == null || deviceOrganization.getDeviceId() <= 0 ||
|
|
|
|
|
!(deviceOrganization.getParentDeviceId() == null || deviceOrganization.getParentDeviceId() > 0)) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters for adding deviceOrganizations : " +
|
|
|
|
|
"deviceOrganization = " + deviceOrganization +
|
|
|
|
|
", deviceID = " + "deviceID should be a positive number"
|
|
|
|
|
+ "parentDeviceID = " + "parentDeviceID should be a positive number or null");
|
|
|
|
|
}
|
|
|
|
|
String msg;
|
|
|
|
|
int deviceID = deviceOrganization.getDeviceId();
|
|
|
|
|
int parentDeviceID = deviceOrganization.getParentDeviceId();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
boolean result = deviceOrganizationDao.addDeviceOrganization(deviceOrganization);
|
|
|
|
|
if (result) {
|
|
|
|
|
msg = "Device organization added successfully, for device ID " + deviceOrganization.getDeviceId() +
|
|
|
|
|
" and parent device ID " + deviceOrganization.getParentDeviceId();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Device organization failed to add, for device ID " + deviceOrganization.getDeviceId() +
|
|
|
|
|
" and parent device ID " + deviceOrganization.getParentDeviceId();
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
boolean result = deviceOrganizationDao.addDeviceOrganization(deviceOrganization);
|
|
|
|
|
if (result) {
|
|
|
|
|
msg = "Device organization added successfully. Device Organization details : " +
|
|
|
|
|
"deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to add device organization for device ID "
|
|
|
|
|
+ deviceOrganization.getDeviceId() + " and parent device ID"
|
|
|
|
|
+ deviceOrganization.getParentDeviceId();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Error occurred in the database level while adding device organization for device ID " +
|
|
|
|
|
deviceOrganization.getDeviceId() + " and parent device ID"
|
|
|
|
|
+ deviceOrganization.getParentDeviceId();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
msg = "Device organization failed to add. Device Organization details : " +
|
|
|
|
|
"deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to add device organization. " +
|
|
|
|
|
"Device Organization details : deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Error occurred in the database level while adding device organization. "
|
|
|
|
|
+ "Device Organization details : device ID = " + deviceID + ", parent device ID = " + parentDeviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper method to check if an organization with the same deviceId and parentDeviceId already exists
|
|
|
|
|
// Helper method to check if an organization with the same deviceID and parentDeviceID already exists
|
|
|
|
|
@Override
|
|
|
|
|
public boolean organizationExists(int deviceId, int parentDeviceId) throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
public boolean organizationExists(int deviceID, int parentDeviceID) throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
boolean exists = deviceOrganizationDao.organizationExists(deviceId, parentDeviceId);
|
|
|
|
|
return exists;
|
|
|
|
|
return deviceOrganizationDao.organizationExists(deviceID, parentDeviceID);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to check organization existence.";
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to check organization existence. " +
|
|
|
|
|
"Params : deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while checking organization existence.";
|
|
|
|
|
String msg = "Error occurred in the database level while checking organization existence. " +
|
|
|
|
|
"Params : deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -171,14 +198,21 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateDeviceOrganization(DeviceOrganization organization)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (organization == null || organization.getOrganizationId() <= 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (organization == null || organization.getOrganizationId() <= 0 || organization.getDeviceId() <= 0
|
|
|
|
|
|| !(organization.getParentDeviceId() == null || organization.getParentDeviceId() > 0)) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters for deviceOrganization update. : "
|
|
|
|
|
+ "deviceOrganization = " + organization
|
|
|
|
|
+ ", deviceID = " + (organization != null ? organization.getDeviceId() :
|
|
|
|
|
"deviceID should be a positive number")
|
|
|
|
|
+ ", parentDeviceID = parentDeviceID should be a positive number or null"
|
|
|
|
|
+ ", organizationID = " + (organization != null ? organization.getOrganizationId() : null)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
String msg = "";
|
|
|
|
|
String msg;
|
|
|
|
|
DeviceOrganization deviceOrganization = getDeviceOrganizationByID(organization.getOrganizationId());
|
|
|
|
|
if (deviceOrganization == null) {
|
|
|
|
|
String errorMsg = "Cannot find device organization for organization ID " + organization.getOrganizationId();
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
msg = "Cannot find device organization for organizationID = " + organization.getOrganizationId();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -186,26 +220,26 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
boolean result = deviceOrganizationDao.updateDeviceOrganization(organization);
|
|
|
|
|
if (result) {
|
|
|
|
|
msg = "Device organization updated successfully,for " + organization.getOrganizationId();
|
|
|
|
|
msg = "Device organization updated successfully for organizationID = " + organization.getOrganizationId();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Device organization failed to update,for " + organization.getOrganizationId();
|
|
|
|
|
msg = "Device organization failed to update for organizationID = " + organization.getOrganizationId();
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to update device organization for " +
|
|
|
|
|
organization.getOrganizationId();
|
|
|
|
|
"organizationID = " + organization.getOrganizationId();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Error occurred in the database level while updating device organization for " +
|
|
|
|
|
organization.getOrganizationId();
|
|
|
|
|
"organizationID = " + organization.getOrganizationId();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -214,22 +248,25 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceOrganization getDeviceOrganizationByID(int organizationId)
|
|
|
|
|
public DeviceOrganization getDeviceOrganizationByID(int organizationID)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (organizationId <= 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (organizationID <= 0) {
|
|
|
|
|
throw new BadRequestException("organizationID must be a positive number. " +
|
|
|
|
|
"Invalid input parameters for getting deviceOrganization for : "
|
|
|
|
|
+ "organizationID = " + organizationID);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// Open a database connection
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
DeviceOrganization deviceOrganization = deviceOrganizationDao.getDeviceOrganizationByID(organizationId);
|
|
|
|
|
return deviceOrganization;
|
|
|
|
|
return deviceOrganizationDao.getDeviceOrganizationByID(organizationID);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve child devices";
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to retrieve deviceOrganization for : "
|
|
|
|
|
+ "organizationID = " + organizationID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving child devices";
|
|
|
|
|
String msg = "Error occurred in the database level while retrieving deviceOrganization for : "
|
|
|
|
|
+ "organizationID = " + organizationID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -239,42 +276,46 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteDeviceOrganizationByID(int organizationId)
|
|
|
|
|
public boolean deleteDeviceOrganizationByID(int organizationID)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (organizationId <= 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (organizationID <= 0) {
|
|
|
|
|
throw new BadRequestException("organizationID must be a positive number." +
|
|
|
|
|
"Invalid input parameters for deviceOrganization Deletion : " +
|
|
|
|
|
"organizationID = " + organizationID);
|
|
|
|
|
}
|
|
|
|
|
String msg = "";
|
|
|
|
|
String msg;
|
|
|
|
|
|
|
|
|
|
DeviceOrganization deviceOrganization = getDeviceOrganizationByID(organizationId);
|
|
|
|
|
DeviceOrganization deviceOrganization = getDeviceOrganizationByID(organizationID);
|
|
|
|
|
if (deviceOrganization == null) {
|
|
|
|
|
msg = "Cannot find device organization for organization ID " + organizationId;
|
|
|
|
|
msg = "Cannot find device organization for Deletion : organizationID = " + organizationID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
boolean result = deviceOrganizationDao.deleteDeviceOrganizationByID(organizationId);
|
|
|
|
|
boolean result = deviceOrganizationDao.deleteDeviceOrganizationByID(organizationID);
|
|
|
|
|
if (result) {
|
|
|
|
|
msg = "Device organization record deleted successfully,for " + organizationId;
|
|
|
|
|
msg = "Device organization record deleted successfully for organizationID = " + organizationID;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Device organization failed to delete,for " + organizationId;
|
|
|
|
|
msg = "Device organization failed to delete for organizationID = " + organizationID;
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to delete device organization for " + organizationId;
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to delete device organization for " +
|
|
|
|
|
"organizationID = " + organizationID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Error occurred in the database level while deleting device organization for " + organizationId;
|
|
|
|
|
msg = "Error occurred in the database level while deleting device organization for " +
|
|
|
|
|
"organizationID = " + organizationID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -284,42 +325,45 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteDeviceAssociations(int deviceId)
|
|
|
|
|
public boolean deleteDeviceAssociations(int deviceID)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (deviceId <= 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (deviceID <= 0) {
|
|
|
|
|
throw new BadRequestException("deviceID must be a positive number." +
|
|
|
|
|
"Invalid input parameters for deviceID = " + deviceID);
|
|
|
|
|
}
|
|
|
|
|
String msg = "";
|
|
|
|
|
String msg;
|
|
|
|
|
|
|
|
|
|
boolean deviceIdExist = doesDeviceIdExist(deviceId);
|
|
|
|
|
boolean deviceIdExist = doesDeviceIdExist(deviceID);
|
|
|
|
|
if (!deviceIdExist) {
|
|
|
|
|
msg = "Cannot find device organization associated with device ID " + deviceId;
|
|
|
|
|
msg = "Cannot find device organizations associated with deviceID = " + deviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
boolean result = deviceOrganizationDao.deleteDeviceAssociations(deviceId);
|
|
|
|
|
boolean result = deviceOrganizationDao.deleteDeviceAssociations(deviceID);
|
|
|
|
|
if (result) {
|
|
|
|
|
msg = "Device organization records deleted successfully,for " + deviceId;
|
|
|
|
|
msg = "Device organization records associated with deviceID = " + deviceID + " are deleted successfully.";
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Device organization failed to delete,for " + deviceId;
|
|
|
|
|
msg = "Device organization records associated with deviceID = " + deviceID + " have failed to delete.";
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg);
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to delete device organization for " + deviceId;
|
|
|
|
|
msg = "Error occurred while obtaining the database connection to delete device organizations associated with " +
|
|
|
|
|
"deviceID = " + deviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
msg = "Error occurred in the database level while deleting device organization for " + deviceId;
|
|
|
|
|
msg = "Error occurred in the database level while deleting device organizations associated with " +
|
|
|
|
|
"deviceID = " + deviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -329,22 +373,25 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean doesDeviceIdExist(int deviceId)
|
|
|
|
|
public boolean doesDeviceIdExist(int deviceID)
|
|
|
|
|
throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
if (deviceId <= 0) {
|
|
|
|
|
throw new BadRequestException("Invalid input parameters.");
|
|
|
|
|
if (deviceID <= 0) {
|
|
|
|
|
throw new BadRequestException("deviceID must be a positive number." +
|
|
|
|
|
"Invalid input parameters for checking deviceID existence " +
|
|
|
|
|
"in deviceOrganization : deviceID = " + deviceID);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// Open a database connection
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
boolean deviceIdExist = deviceOrganizationDao.doesDeviceIdExist(deviceId);
|
|
|
|
|
return deviceIdExist;
|
|
|
|
|
return deviceOrganizationDao.doesDeviceIdExist(deviceID);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to check deviceID exists";
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to check deviceID existence " +
|
|
|
|
|
"in deviceOrganization : deviceID = " + deviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} catch (DeviceOrganizationMgtDAOException e) {
|
|
|
|
|
String msg = "Error occurred in the database level while checking the existence of deviceID";
|
|
|
|
|
String msg = "Error occurred in the database level while checking the existence " +
|
|
|
|
|
"in deviceOrganization : deviceID = " + deviceID;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new DeviceOrganizationMgtPluginException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|