Refactoring

revert-70aa11f8
GDLMadushanka 7 years ago
parent 92d6624bbf
commit 10a80fecf8

@ -65,15 +65,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions) public void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions)
throws GroupManagementException, GroupAlreadyExistException { throws GroupManagementException, GroupAlreadyExistException {
if (deviceGroup != null) { if (deviceGroup == null) {
if (log.isDebugEnabled()) { String msg = "Received incomplete data for createGroup";
log.debug("Creating group '" + deviceGroup.getName() + "'");
}
} else {
String msg = "received incomplete data for createGroup";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("Creating group '" + deviceGroup.getName() + "'");
}
if (deviceGroup == null) { if (deviceGroup == null) {
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
} }
@ -97,7 +96,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in creating group '" + deviceGroup.getName() + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -115,15 +114,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void updateGroup(DeviceGroup deviceGroup, int groupId) public void updateGroup(DeviceGroup deviceGroup, int groupId)
throws GroupManagementException, GroupAlreadyExistException { throws GroupManagementException, GroupAlreadyExistException {
if (deviceGroup != null) { if (deviceGroup == null) {
if (log.isDebugEnabled()) { String msg = "Received incomplete data for updateGroup";
log.debug("update group '" + deviceGroup.getName() + "'");
}
} else {
String msg = "received incomplete data for updateGroup";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("update group '" + deviceGroup.getName() + "'");
}
if (deviceGroup == null) { if (deviceGroup == null) {
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
} }
@ -147,7 +145,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in updating group '" + deviceGroup.getName() + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -185,7 +183,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in deleting group: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -214,7 +212,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroup for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -228,15 +226,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public DeviceGroup getGroup(String groupName) throws GroupManagementException { public DeviceGroup getGroup(String groupName) throws GroupManagementException {
if (groupName != null) { if (groupName == null) {
if (log.isDebugEnabled()) { String msg = "Received empty groupName for getGroup";
log.debug("Get group by name '" + groupName + "'");
}
} else {
String msg = "received empty groupName for getGroup";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("Get group by name '" + groupName + "'");
}
DeviceGroup deviceGroup; DeviceGroup deviceGroup;
try { try {
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
@ -250,7 +247,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroup with name " + groupName;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -278,7 +275,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg); log.error(msg);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -289,15 +286,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException { public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException {
if (request != null) { if (request == null) {
if (log.isDebugEnabled()) { String msg = "Received incomplete data for getGroup";
log.debug("Get groups with pagination " + request.toString());
}
} else {
String msg = "received incomplete data for getGroup";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("Get groups with pagination " + request.toString());
}
request = DeviceManagerUtil.validateGroupListPageSize(request); request = DeviceManagerUtil.validateGroupListPageSize(request);
List<DeviceGroup> deviceGroups = new ArrayList<>(); List<DeviceGroup> deviceGroups = new ArrayList<>();
try { try {
@ -313,7 +309,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -327,15 +323,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public List<DeviceGroup> getGroups(String username) throws GroupManagementException { public List<DeviceGroup> getGroups(String username) throws GroupManagementException {
if (username != null) { if (username == null || username.isEmpty()) {
if (log.isDebugEnabled()) { String msg = "Received null user name for getGroups";
log.debug("Get groups of owner '" + username + "'");
}
} else {
String msg = "received null user name for getGroups";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("Get groups of owner '" + username + "'");
}
Map<Integer, DeviceGroup> groups = new HashMap<>(); Map<Integer, DeviceGroup> groups = new HashMap<>();
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
try { try {
@ -364,7 +359,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(e); log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups for " + username;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -374,15 +369,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
private List<Integer> getGroupIds(String username) throws GroupManagementException { private List<Integer> getGroupIds(String username) throws GroupManagementException {
if (username != null) { if (username == null || username.isEmpty()) {
if (log.isDebugEnabled()) { String msg = "Received empty user name for getGroupIds";
log.debug("Get groups Ids of owner '" + username + "'");
}
} else {
String msg = "received empty user name for getGroupIds";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
if (log.isDebugEnabled()) {
log.debug("Get groups Ids of owner '" + username + "'");
}
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
List<Integer> deviceGroupIds = new ArrayList<>(); List<Integer> deviceGroupIds = new ArrayList<>();
try { try {
@ -405,7 +399,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(e); log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups for username '" + username + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -418,7 +412,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
public PaginationResult getGroups(String currentUser, GroupPaginationRequest request) public PaginationResult getGroups(String currentUser, GroupPaginationRequest request)
throws GroupManagementException { throws GroupManagementException {
if (currentUser == null || request == null) { if (currentUser == null || request == null) {
String msg = "received incomplete date for getGroups"; String msg = "Received incomplete date for getGroups";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
@ -441,7 +435,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -481,7 +475,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException { private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException {
if (request == null) { if (request == null) {
String msg = "received empty request for getGroupCount"; String msg = "Received empty request for getGroupCount";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
@ -501,7 +495,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroupCount";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -514,8 +508,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public int getGroupCount(String username) throws GroupManagementException { public int getGroupCount(String username) throws GroupManagementException {
if (username == null) { if (username == null || username.isEmpty()) {
String msg = "received empty user name for getGroupCount"; String msg = "Received empty user name for getGroupCount";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
@ -546,7 +540,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroupCount for username '" + username + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -601,7 +595,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(e); log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in manageGroupSharing for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -630,7 +624,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getRoles for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -666,7 +660,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getDevices for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -695,7 +689,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getDeviceCount for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -741,7 +735,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in addDevices for groupId " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -785,7 +779,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in removeDevice for groupId: " + groupId;
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -821,7 +815,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups for username '" + username + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} }
@ -831,7 +825,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException { public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException {
if (deviceIdentifier == null) { if (deviceIdentifier == null) {
String msg = "received empty device identifier for getGroups"; String msg = "Received empty device identifier for getGroups";
log.error(msg); log.error(msg);
throw new GroupManagementException(msg); throw new GroupManagementException(msg);
} }
@ -857,7 +851,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in getGroups";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} finally { } finally {
@ -887,7 +881,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred"; String msg = "Error occurred in createDefaultGroup for groupName '" + groupName + "'";
log.error(msg, e); log.error(msg, e);
throw new GroupManagementException(msg, e); throw new GroupManagementException(msg, e);
} }

Loading…
Cancel
Save