diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 54289504836..1b75f2dd4b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -160,15 +160,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean enrollDevice(Device device) throws DeviceManagementException { - if (device != null) { - if (log.isDebugEnabled()) { - log.debug("Enrolling the device " + device.getId() + "of type '" + device.getType() + "'"); - } - } else { - String msg = "required values are not set for device enrollment"; + if (device == null) { + String msg = "Received empty device for device enrollment"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Enrolling the device " + device.getId() + "of type '" + device.getType() + "'"); + } boolean status = false; DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); @@ -237,15 +236,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while adding enrolment related metadata"; + String msg = "Error occurred while adding enrolment related metadata for device: " + device.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - String msg = "Error occurred while initiating transaction"; + String msg = "Error occurred while initiating transaction to enrol device: " + device.getId(); log.error(msg); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred while enrolling device: " + device.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -272,7 +271,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred while enrolling device: " + device.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -298,16 +297,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { - if (device != null) { - if (log.isDebugEnabled()) { - log.debug("Modifying enrollment for device: " + device.getId() + " of type '" + device.getType() + "'"); - } - } else { - String msg = "required values are not set to modify device enrollment"; + if (device == null) { + String msg = "Required values are not set to modify device enrollment"; log.error(msg); throw new DeviceManagementException(msg); } - + if (log.isDebugEnabled()) { + log.debug("Modifying enrollment for device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); if (deviceManager == null) { @@ -339,11 +336,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg); throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - String msg = "Error occurred while initiating transaction"; + String msg = "Error occurred while initiating transaction to modify device: " + device.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred while modifying device: " + device.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -354,6 +351,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private List getEnrollmentsOfUser(int deviceId, String user) throws DeviceManagementException { + if (user == null || user.isEmpty()) { + String msg = "Required values are not set to getEnrollmentsOfUser"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get enrollments for user '" + user + "' device: " + deviceId); + } List enrolmentInfos = new ArrayList<>(); try { DeviceManagementDAOFactory.openConnection(); @@ -368,7 +373,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getEnrollmentsOfUser user '" + user + "' device: " + deviceId; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -379,15 +384,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Dis-enrolling device: " + deviceId.getId() + " of type '" + deviceId.getType() + "'"); - } - } else { - String msg = "required values are not set to dis-enroll device"; + if (deviceId == null) { + String msg = "Required values are not set to dis-enroll device"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling device: " + deviceId.getId() + " of type '" + deviceId.getType() + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -409,7 +413,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) { if (log.isDebugEnabled()) { - log.debug("Device has already disenrolled : " + deviceId.getId() + "'"); + log.debug("Device has already dis-enrolled : " + deviceId.getId() + "'"); } return true; } @@ -433,7 +437,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred while dis-enrolling device: " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -484,15 +488,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAllDevices(String deviceType, boolean requireDeviceInfo) throws DeviceManagementException { - if (deviceType != null) { - if (log.isDebugEnabled()) { - log.debug("Getting all devices of type '" + deviceType + "' and requiredDeviceInfo: " + requireDeviceInfo); - } - } else { + if (deviceType == null) { String msg = "Device type is empty for method getAllDevices"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Getting all devices of type '" + deviceType + "' and requiredDeviceInfo: " + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); @@ -513,7 +516,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred while getting all devices of device type '" + deviceType + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -548,7 +551,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in get all devices"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -568,16 +571,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevices(Date since, boolean requireDeviceInfo) throws DeviceManagementException { - if (since != null) { - if (log.isDebugEnabled()) { - log.debug("Getting all devices since date '" + since.toString() + "' and required device info: " - + requireDeviceInfo); - } - } else { + if (since == null) { String msg = "Given date is empty for method getDevices"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Getting all devices since date '" + since.toString() + "' and required device info: " + + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); @@ -591,7 +593,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred get devices since '" + since.toString() + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -611,15 +613,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices with pagination " + request.toString() + " and required deviceinfo: " + requireDeviceInfo); - } - } else { - String msg = "received incomplete pagination request for getDevicesByType"; + if (request == null) { + String msg = "Received incomplete pagination request for getDevicesByType"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices with pagination " + request.toString() + " and required deviceinfo: " + + requireDeviceInfo); + } PaginationResult paginationResult = new PaginationResult(); List allDevices = new ArrayList<>(); int count = 0; @@ -640,7 +642,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceByType"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -665,15 +667,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getAllDevices(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices with pagination " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); - } - } else { - String msg = "received incomplete pagination request for method getAllDevices"; + if (request == null) { + String msg = "Received incomplete pagination request for method getAllDevices"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices with pagination " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); + } List devicesForRoles = null; PaginationResult paginationResult = new PaginationResult(); List allDevices = new ArrayList<>(); @@ -702,7 +703,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getAllDevices"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -721,16 +722,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, boolean requireDeviceInfo) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Get device by device id :" + deviceId.getId() + " of type '" + deviceId.getType() - + "' and requiredDeviceInfo: " + requireDeviceInfo); - } - } else { - String msg = "received null device identifier for method getDevice"; + if (deviceId == null) { + String msg = "Received null device identifier for method getDevice"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get device by device id :" + deviceId.getId() + " of type '" + deviceId.getType() + + "' and requiredDeviceInfo: " + requireDeviceInfo); + } int tenantId = this.getTenantId(); Device device = this.getDeviceFromCache(deviceId); if (device == null) { @@ -755,7 +755,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevice: " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -770,15 +770,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException { - if (metaInfo != null) { - if (log.isDebugEnabled()) { - log.debug("Send enrollment invitation, templateName '" + templateName + "'"); - } - } else { - String msg = "received incomplete data to method sendEnrolmentInvitation"; + if (metaInfo == null) { + String msg = "Received incomplete data to method sendEnrolmentInvitation"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Send enrollment invitation, templateName '" + templateName + "'"); + } Map, Object>> params = new HashMap<>(); Properties props = metaInfo.getProperties(); Enumeration e = props.propertyNames(); @@ -800,7 +799,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, ex); throw new DeviceManagementException(msg, ex); } catch (Exception ex) { - String msg = "Error occurred"; + String msg = "Error occurred in setEnrollmentInvitation"; log.error(msg, ex); throw new DeviceManagementException(msg, ex); } @@ -808,15 +807,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException { - if (metaInfo != null) { - if (log.isDebugEnabled()) { - log.debug("Send registration email"); - } - } else { - String msg = "received incomplete request for sendRegistrationEmail"; + if (metaInfo == null) { + String msg = "Received incomplete request for sendRegistrationEmail"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Send registration email"); + } Map, Object>> params = new HashMap<>(); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME, new TypedValue, Object>(String.class, metaInfo.getProperty("first-name"))); @@ -843,7 +841,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in sendRegistrationEmail"; log.error(msg, e); throw new DeviceManagementException(msg, e); } @@ -851,16 +849,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public HashMap getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - if (deviceIdentifier != null) { - if (log.isDebugEnabled()) { - log.debug("Get tenanted device with id: " + deviceIdentifier.getId() + " of type '" + - deviceIdentifier.getType() + "'"); - } - } else { - String msg = "received null deviceIdentifier for getTenantedDevice"; + if (deviceIdentifier == null) { + String msg = "Received null deviceIdentifier for getTenantedDevice"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get tenanted device with id: " + deviceIdentifier.getId() + " of type '" + + deviceIdentifier.getType() + "'"); + } HashMap deviceHashMap; try { DeviceManagementDAOFactory.openConnection(); @@ -881,7 +878,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getTenantedDevice device: " + deviceIdentifier.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -897,15 +894,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDeviceWithTypeProperties(DeviceIdentifier deviceId) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Get tenanted device with type properties, deviceId: " + deviceId.getId()); - } - } else { - String msg = "received null deviceIdentifier for getDeviceWithTypeProperties"; + if (deviceId == null) { + String msg = "Received null deviceIdentifier for getDeviceWithTypeProperties"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get tenanted device with type properties, deviceId: " + deviceId.getId()); + } Device device = this.getDevice(deviceId, false); DeviceManager deviceManager = this.getDeviceManager(device.getType()); @@ -932,16 +928,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, Date since, boolean requireDeviceInfo) throws DeviceManagementException { - if (deviceId != null && since != null) { - if (log.isDebugEnabled()) { - log.debug("Get device since '" + since.toString() + "' with identifier: " + deviceId.getId() - + " and type '" + deviceId.getType() + "'"); - } - } else { - String msg = "received incomplete data for getDevice"; + if (deviceId == null || since == null) { + String msg = "Received incomplete data for getDevice"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get device since '" + since.toString() + "' with identifier: " + deviceId.getId() + + " and type '" + deviceId.getType() + "'"); + } Device device; try { DeviceManagementDAOFactory.openConnection(); @@ -962,7 +957,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevice for device: " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -982,15 +977,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status, boolean requireDeviceInfo) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Get device with identifier: " + deviceId.getId() + " and type '" + deviceId.getType() + "'"); - } - } else { - String msg = "received null deviceIdentifier for getDevice"; + if (deviceId == null) { + String msg = "Received null deviceIdentifier for getDevice"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get device with identifier: " + deviceId.getId() + " and type '" + deviceId.getType() + "'"); + } Device device; try { DeviceManagementDAOFactory.openConnection(); @@ -1011,7 +1005,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevice for device: " + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1071,7 +1065,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.info(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getAvailableDeviceTypes"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1082,15 +1076,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { - if (deviceId != null && device != null) { - if (log.isDebugEnabled()) { - log.debug("Update device info of device: " + deviceId.getId()); - } - } else { - String msg = "received incomplete data for updateDeviceInfo"; + if (deviceId == null || device == null) { + String msg = "Received incomplete data for updateDeviceInfo"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Update device info of device: " + deviceId.getId()); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -1104,15 +1097,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Set ownership of device: " + deviceId.getId() + " ownership type '" + ownershipType + "'"); - } - } else { - String msg = "received incomplete data for setOwnership"; + if (deviceId == null) { + String msg = "Received incomplete data for setOwnership"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Set ownership of device: " + deviceId.getId() + " ownership type '" + ownershipType + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -1140,15 +1132,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException { - if (deviceId != null) { - if (log.isDebugEnabled()) { - log.debug("Set status of device: " + deviceId.getId()); - } - } else { - String msg = "received null deviceIdentifier for setStatus"; + if (deviceId == null) { + String msg = "Received null deviceIdentifier for setStatus"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Set status of device: " + deviceId.getId()); + } try { boolean success = false; int tenantId = this.getTenantId(); @@ -1171,7 +1162,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in setStatus for device :" + deviceId.getId(); log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1202,7 +1193,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in setStatus"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1226,15 +1217,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public License getLicense(String deviceType, String languageCode) throws DeviceManagementException { - if (deviceType != null && languageCode != null) { - if (log.isDebugEnabled()) { - log.debug("Get the licence for device type '" + deviceType + "' languageCode '" + languageCode + "'"); - } - } else { - String msg = "received incomplete data for getLicence"; + if (deviceType == null || languageCode == null) { + String msg = "Received incomplete data for getLicence"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get the licence for device type '" + deviceType + "' languageCode '" + languageCode + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceType); License license; if (deviceManager == null) { @@ -1258,7 +1248,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getLicence for device type '" + deviceType + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } @@ -1266,15 +1256,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void addLicense(String deviceType, License license) throws DeviceManagementException { - if (deviceType != null && license != null) { - if (log.isDebugEnabled()) { - log.debug("Add the licence for device type '" + deviceType + "'"); - } - } else { - String msg = "received incomplete data for addLicence"; + if (deviceType == null || license == null) { + String msg = "Received incomplete data for addLicence"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Add the licence for device type '" + deviceType + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceType); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -1290,7 +1279,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in addLicence for device type '" + deviceType + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } @@ -1425,7 +1414,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesOfUser(String username, boolean requireDeviceInfo) throws DeviceManagementException { if (username == null) { - String msg = "username null in getDevicesOfUser"; + String msg = "Username null in getDevicesOfUser"; log.error(msg); throw new DeviceManagementException(msg); } @@ -1446,7 +1435,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesOfUser for username '" + username + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1467,16 +1456,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesOfUser(String username, String deviceType, boolean requireDeviceInfo) throws DeviceManagementException { - if (username != null && deviceType != null) { - if (log.isDebugEnabled()) { - log.debug("Get '" + deviceType + "' devices of user with username '" + username + "' requiredDeviceInfo: " - + requireDeviceInfo); - } - } else { - String msg = "received incomplete data for getDevicesOfUser"; + if (username == null || deviceType == null) { + String msg = "Received incomplete data for getDevicesOfUser"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get '" + deviceType + "' devices of user with username '" + username + "' requiredDeviceInfo: " + + requireDeviceInfo); + } List userDevices; try { DeviceManagementDAOFactory.openConnection(); @@ -1491,7 +1479,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesOfUser for '" + username + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1512,16 +1500,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesOfUser(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get paginated results of devices of user " + request.toString() + " and requiredDeviceInfo: " - + requireDeviceInfo); - } - } else { - String msg = "received incomplete pagination request for getDevicesOfUser"; + if (request == null) { + String msg = "Received incomplete pagination request for getDevicesOfUser"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get paginated results of devices of user " + request.toString() + " and requiredDeviceInfo: " + + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); int deviceCount = 0; int tenantId = this.getTenantId(); @@ -1541,7 +1528,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesOfUser"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1568,15 +1555,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByOwnership(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices by ownership " + request.toString()); - } - } else { - String msg = "received incomplete data for getDevicesByOwnership"; + if (request == null) { + String msg = "Received incomplete data for getDevicesByOwnership"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices by ownership " + request.toString()); + } PaginationResult result = new PaginationResult(); List allDevices; int deviceCount = 0; @@ -1596,7 +1582,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesByOwnership"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1620,15 +1606,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAllDevicesOfRole(String role, boolean requireDeviceInfo) throws DeviceManagementException { - if (role != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices of role '" + role + "' and requiredDeviceInfo: " + requireDeviceInfo); - } - } else { - String msg = "received empty role for the method getAllDevicesOfRole"; + if (role == null || role.isEmpty()) { + String msg = "Received empty role for the method getAllDevicesOfRole"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices of role '" + role + "' and requiredDeviceInfo: " + requireDeviceInfo); + } List devices = new ArrayList<>(); String[] users; int tenantId = this.getTenantId(); @@ -1640,7 +1625,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getAllDevicesOfRole for role '" + role + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } @@ -1656,7 +1641,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred getAllDevicesOfRole for role '" + role + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1671,15 +1656,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public int getDeviceCount(String username) throws DeviceManagementException { - if (username != null) { - if (log.isDebugEnabled()) { - log.debug("Getting device count of the user '" + username + "'"); - } - } else { - String msg = "received empty username for getDeviceCount"; + if (username == null) { + String msg = "Received empty username for getDeviceCount"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Getting device count of the user '" + username + "'"); + } try { DeviceManagementDAOFactory.openConnection(); return deviceDAO.getDeviceCount(username, this.getTenantId()); @@ -1692,7 +1676,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceCount for username '" + username + "'"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1717,7 +1701,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceCount"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1728,15 +1712,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesByNameAndType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices by name " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); - } - } else { - String msg = "received incomplete data for getDevicesByNameAndType"; + if (request == null) { + String msg = "Received incomplete data for getDevicesByNameAndType"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices by name " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); + } List devices = new ArrayList<>(); List allDevices; int limit = DeviceManagerUtil.validateDeviceListPageSize(request.getRowCount()); @@ -1756,7 +1739,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesByNameAndType"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1777,15 +1760,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByName(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get devices by name " + request.toString() + " requiredDeviceInfo: " + requireDeviceInfo); - } - } else { - String msg = "received incomplete data for getDevicesByName"; + if (request == null) { + String msg = "Received incomplete data for getDevicesByName"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices by name " + request.toString() + " requiredDeviceInfo: " + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); int tenantId = this.getTenantId(); List allDevices = new ArrayList<>(); @@ -1806,7 +1788,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesByName"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1823,15 +1805,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException { try { - if (device != null && status != null) { - if (log.isDebugEnabled()) { - log.debug("Updating enrolment for device: " + device.getId() + " of type '" + device.getType() + "'"); - } - } else { - String msg = "received incomplete data for updateDeviceEnrolmentInfo"; + if (device == null || status == null) { + String msg = "Received incomplete data for updateDeviceEnrolmentInfo"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Updating enrolment for device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceManagementDAOFactory.beginTransaction(); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.getEnrolmentInfo().setStatus(status); @@ -1848,7 +1829,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in updateDeviceEnrolmentInfo"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1868,7 +1849,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv deviceManagementService.getType() + "'"; log.error(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in registerDeviceManagementService"; log.error(msg, e); } } @@ -1884,7 +1865,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error("Error occurred while un-registering device management plugin '" + deviceManagementService.getType() + "'", e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in unregisterDeviceManagementService"; log.error(msg, e); } } @@ -1912,7 +1893,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesByStatus"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -1932,16 +1913,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByStatus(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("get devices by status " + request.toString() + " and requiredDeviceInfo: " - + requireDeviceInfo); - } - } else { - String msg = "received incomplete data for getDevicesByStatus"; + if (request == null) { + String msg = "Received incomplete data for getDevicesByStatus"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get devices by status " + request.toString() + " and requiredDeviceInfo: " + + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); List allDevices; int tenantId = this.getTenantId(); @@ -1962,7 +1942,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevicesByStatus"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -2007,16 +1987,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) throws DeviceManagementException { - if (deviceIdentifier != null) { - if (log.isDebugEnabled()) { - log.debug("Change device status of device: " + deviceIdentifier.getId() + " of type '" - + deviceIdentifier.getType() + "'"); - } - } else { - String msg = "received incomplete data for getDevicesByStatus"; + if (deviceIdentifier == null) { + String msg = "Received incomplete data for getDevicesByStatus"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Change device status of device: " + deviceIdentifier.getId() + " of type '" + + deviceIdentifier.getType() + "'"); + } boolean isDeviceUpdated = false; Device device = getDevice(deviceIdentifier, false); int deviceId = device.getId(); @@ -2056,7 +2035,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceEnrolledTenants"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -2089,7 +2068,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in updateEnrollment for deviceId: " + deviceId; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -2130,15 +2109,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv */ private void addDeviceToGroups(DeviceIdentifier deviceIdentifier, EnrolmentInfo.OwnerShip ownership) throws DeviceManagementException { - if (deviceIdentifier != null) { - if (log.isDebugEnabled()) { - log.debug("Add device:" + deviceIdentifier.getId() + " to default group"); - } - } else { - String msg = "received incomplete data for addDeviceToGroup"; + if (deviceIdentifier == null) { + String msg = "Received incomplete data for addDeviceToGroup"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Add device:" + deviceIdentifier.getId() + " to default group"); + } GroupManagementProviderService groupManagementProviderService = new GroupManagementProviderServiceImpl(); try { DeviceGroup defaultGroup = createDefaultGroup(groupManagementProviderService, ownership.toString()); @@ -2163,16 +2141,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } private void addInitialOperations(DeviceIdentifier deviceIdentifier, String deviceType) throws DeviceManagementException { - if (deviceIdentifier != null && deviceType != null) { - if (log.isDebugEnabled()) { - log.debug("Add initial operations to the device:" + deviceIdentifier.getId() + " of type '" - + deviceType + "'"); - } - } else { - String msg = "received incomplete data for getDevicesByStatus"; + if (deviceIdentifier == null || deviceType == null) { + String msg = "Received incomplete data for getDevicesByStatus"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Add initial operations to the device:" + deviceIdentifier.getId() + " of type '" + + deviceType + "'"); + } DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). getDeviceManagementProvider(); DeviceManagementService deviceManagementService = @@ -2218,15 +2195,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv */ private DeviceGroup createDefaultGroup(GroupManagementProviderService service, String groupName) throws GroupManagementException { - if (service != null && groupName != null) { - if (log.isDebugEnabled()) { - log.debug("Create default group with name '" + groupName + "'"); - } - } else { - String msg = "received incomplete data for createDefaultGroup"; + if (service == null || groupName == null) { + String msg = "Received incomplete data for createDefaultGroup"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Create default group with name '" + groupName + "'"); + } DeviceGroup defaultGroup = service.getGroup(groupName); if (defaultGroup == null) { defaultGroup = new DeviceGroup(groupName); @@ -2262,10 +2238,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public DeviceType getDeviceType(String deviceType) throws DeviceManagementException { if (deviceType != null) { if (log.isDebugEnabled()) { - log.debug("get device type '" + deviceType + "'"); + log.debug("Get device type '" + deviceType + "'"); } } else { - String msg = "received null deviceType for getDeviceType"; + String msg = "Received null deviceType for getDeviceType"; log.error(msg); throw new DeviceManagementException(msg); } @@ -2308,7 +2284,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceTypes"; log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { @@ -2344,15 +2320,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv * Returns all the device-info including location of the given device. */ private DeviceInfo getDeviceInfo(Device device) throws DeviceManagementException { - if (device != null) { - if (log.isDebugEnabled()) { - log.debug("Get device info of device: " + device.getId() + " of type '" + device.getType() + "'"); - } - } else { - String msg = "received incomplete data for getDeviceInfo"; + if (device == null) { + String msg = "Received incomplete data for getDeviceInfo"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get device info of device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceInfo info = null; try { DeviceManagementDAOFactory.openConnection(); @@ -2371,7 +2346,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceInfo for device: " + device.getId(); log.error(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); @@ -2397,7 +2372,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } catch (SQLException e) { log.error("Error occurred while opening a connection to the data source", e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getInstalledApplications"; log.error(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); @@ -2410,15 +2385,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv * of the given device list. */ private List getAllDeviceInfo(List allDevices) throws DeviceManagementException { - if (allDevices.size() > 0) { - if (log.isDebugEnabled()) { - log.debug("Get all device info of devices, num of devices: " + allDevices.size()); - } - } else { - String msg = "received empty device list for getAllDeviceInfo"; + if (allDevices.size() == 0) { + String msg = "Received empty device list for getAllDeviceInfo"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get all device info of devices, num of devices: " + allDevices.size()); + } List devices = new ArrayList<>(); if (allDevices != null) { for (Device device : allDevices) { @@ -2450,15 +2424,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv * of a given device. */ private Device getAllDeviceInfo(Device device) throws DeviceManagementException { - if (device != null) { - if (log.isDebugEnabled()) { - log.debug("Get all device info of device: " + device.getId() + " of type '" + device.getType() + "'"); - } - } else { - String msg = "received empty device for getAllDeviceInfo"; + if (device == null) { + String msg = "Received empty device for getAllDeviceInfo"; log.error(msg); throw new DeviceManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get all device info of device: " + device.getId() + " of type '" + device.getType() + "'"); + } device.setDeviceInfo(this.getDeviceInfo(device)); device.setApplications(this.getInstalledApplications(device)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 592d8a4f655..b5a2a4f635e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -65,15 +65,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions) throws GroupManagementException, GroupAlreadyExistException { - if (deviceGroup != null) { - if (log.isDebugEnabled()) { - log.debug("Creating group '" + deviceGroup.getName() + "'"); - } - } else { - String msg = "received incomplete data for createGroup"; + if (deviceGroup == null) { + String msg = "Received incomplete data for createGroup"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Creating group '" + deviceGroup.getName() + "'"); + } if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } @@ -97,7 +96,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in creating group '" + deviceGroup.getName() + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -115,15 +114,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void updateGroup(DeviceGroup deviceGroup, int groupId) throws GroupManagementException, GroupAlreadyExistException { - if (deviceGroup != null) { - if (log.isDebugEnabled()) { - log.debug("update group '" + deviceGroup.getName() + "'"); - } - } else { - String msg = "received incomplete data for updateGroup"; + if (deviceGroup == null) { + String msg = "Received incomplete data for updateGroup"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("update group '" + deviceGroup.getName() + "'"); + } if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } @@ -147,7 +145,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in updating group '" + deviceGroup.getName() + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -185,7 +183,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in deleting group: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -214,7 +212,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroup for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -228,15 +226,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public DeviceGroup getGroup(String groupName) throws GroupManagementException { - if (groupName != null) { - if (log.isDebugEnabled()) { - log.debug("Get group by name '" + groupName + "'"); - } - } else { - String msg = "received empty groupName for getGroup"; + if (groupName == null) { + String msg = "Received empty groupName for getGroup"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get group by name '" + groupName + "'"); + } DeviceGroup deviceGroup; try { GroupManagementDAOFactory.openConnection(); @@ -250,7 +247,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroup with name " + groupName; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -278,7 +275,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -289,15 +286,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException { - if (request != null) { - if (log.isDebugEnabled()) { - log.debug("Get groups with pagination " + request.toString()); - } - } else { - String msg = "received incomplete data for getGroup"; + if (request == null) { + String msg = "Received incomplete data for getGroup"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get groups with pagination " + request.toString()); + } request = DeviceManagerUtil.validateGroupListPageSize(request); List deviceGroups = new ArrayList<>(); try { @@ -313,7 +309,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -327,15 +323,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public List getGroups(String username) throws GroupManagementException { - if (username != null) { - if (log.isDebugEnabled()) { - log.debug("Get groups of owner '" + username + "'"); - } - } else { - String msg = "received null user name for getGroups"; + if (username == null || username.isEmpty()) { + String msg = "Received null user name for getGroups"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get groups of owner '" + username + "'"); + } Map groups = new HashMap<>(); UserStoreManager userStoreManager; try { @@ -364,7 +359,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(e); throw new GroupManagementException(e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups for " + username; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -374,15 +369,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } private List getGroupIds(String username) throws GroupManagementException { - if (username != null) { - if (log.isDebugEnabled()) { - log.debug("Get groups Ids of owner '" + username + "'"); - } - } else { - String msg = "received empty user name for getGroupIds"; + if (username == null || username.isEmpty()) { + String msg = "Received empty user name for getGroupIds"; log.error(msg); throw new GroupManagementException(msg); } + if (log.isDebugEnabled()) { + log.debug("Get groups Ids of owner '" + username + "'"); + } UserStoreManager userStoreManager; List deviceGroupIds = new ArrayList<>(); try { @@ -405,7 +399,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(e); throw new GroupManagementException(e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups for username '" + username + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -418,7 +412,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid public PaginationResult getGroups(String currentUser, GroupPaginationRequest request) throws GroupManagementException { if (currentUser == null || request == null) { - String msg = "received incomplete date for getGroups"; + String msg = "Received incomplete date for getGroups"; log.error(msg); throw new GroupManagementException(msg); } @@ -441,7 +435,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -481,7 +475,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException { if (request == null) { - String msg = "received empty request for getGroupCount"; + String msg = "Received empty request for getGroupCount"; log.error(msg); throw new GroupManagementException(msg); } @@ -501,7 +495,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroupCount"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -514,8 +508,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public int getGroupCount(String username) throws GroupManagementException { - if (username == null) { - String msg = "received empty user name for getGroupCount"; + if (username == null || username.isEmpty()) { + String msg = "Received empty user name for getGroupCount"; log.error(msg); throw new GroupManagementException(msg); } @@ -546,7 +540,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroupCount for username '" + username + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -601,7 +595,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(e); throw new GroupManagementException(e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in manageGroupSharing for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -630,7 +624,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getRoles for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -666,7 +660,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDevices for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -695,7 +689,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getDeviceCount for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -741,7 +735,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in addDevices for groupId " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -785,7 +779,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in removeDevice for groupId: " + groupId; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -821,7 +815,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups for username '" + username + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); } @@ -831,7 +825,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public List getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException { if (deviceIdentifier == null) { - String msg = "received empty device identifier for getGroups"; + String msg = "Received empty device identifier for getGroups"; log.error(msg); throw new GroupManagementException(msg); } @@ -857,7 +851,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in getGroups"; log.error(msg, e); throw new GroupManagementException(msg, e); } finally { @@ -887,7 +881,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid log.error(msg, e); throw new GroupManagementException(msg, e); } catch (Exception e) { - String msg = "Error occurred"; + String msg = "Error occurred in createDefaultGroup for groupName '" + groupName + "'"; log.error(msg, e); throw new GroupManagementException(msg, e); }