logging errors in devmgt service and groupmgt service

revert-70aa11f8
GDLMadushanka 7 years ago
parent 4bd64ef696
commit d7220d39af

Binary file not shown.

@ -65,6 +65,9 @@ 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 (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());
} }
@ -80,10 +83,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
throw new GroupManagementException("Error occurred while adding deviceGroup " + String msg = "Error occurred while adding deviceGroup '" + deviceGroup.getName() + "' to database.";
"'" + deviceGroup.getName() + "' to database.", e); log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new GroupManagementException("Error occurred while initiating transaction.", e); String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -99,6 +109,9 @@ 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 (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());
} }
@ -114,10 +127,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
throw new GroupManagementException("Error occurred while modifying deviceGroup " + String msg = "Error occurred while modifying deviceGroup '" + deviceGroup.getName() + "'.";
"'" + deviceGroup.getName() + "'.", e); log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new GroupManagementException("Error occurred while initiating transaction.", e); String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -128,6 +148,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public boolean deleteGroup(int groupId) throws GroupManagementException { public boolean deleteGroup(int groupId) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Delete group " +groupId );
}
DeviceGroup deviceGroup = getGroup(groupId); DeviceGroup deviceGroup = getGroup(groupId);
if (deviceGroup == null) { if (deviceGroup == null) {
return false; return false;
@ -142,9 +165,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return true; return true;
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
throw new GroupManagementException("Error occurred while removing group data.", e); String msg = "Error occurred while removing group data.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new GroupManagementException("Error occurred while initiating transaction.", e); String msg = "Error occurred while initiating transaction.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -155,14 +186,25 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public DeviceGroup getGroup(int groupId) throws GroupManagementException { public DeviceGroup getGroup(int groupId) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get group by id " + groupId);
}
DeviceGroup deviceGroup; DeviceGroup deviceGroup;
try { try {
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
deviceGroup = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceGroup = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while obtaining group '" + groupId + "'", e); String msg = "Error occurred while obtaining group '" + groupId + "'";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -174,14 +216,25 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public DeviceGroup getGroup(String groupName) throws GroupManagementException { public DeviceGroup getGroup(String groupName) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get group by name " + groupName);
}
DeviceGroup deviceGroup; DeviceGroup deviceGroup;
try { try {
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
deviceGroup = this.groupDAO.getGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceGroup = this.groupDAO.getGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId());
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while obtaining group with name: '" + groupName + "'", e); String msg = "Error occurred while obtaining group with name: '" + groupName + "'";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg= "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -190,15 +243,26 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public List<DeviceGroup> getGroups() throws GroupManagementException { public List<DeviceGroup> getGroups() throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups");
}
List<DeviceGroup> deviceGroups = new ArrayList<>(); List<DeviceGroup> deviceGroups = new ArrayList<>();
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
deviceGroups = this.groupDAO.getGroups(tenantId); deviceGroups = this.groupDAO.getGroups(tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -207,6 +271,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException { public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups with pagination");
}
request = DeviceManagerUtil.validateGroupListPageSize(request); request = DeviceManagerUtil.validateGroupListPageSize(request);
List<DeviceGroup> deviceGroups = new ArrayList<>(); List<DeviceGroup> deviceGroups = new ArrayList<>();
try { try {
@ -214,9 +281,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
deviceGroups = this.groupDAO.getGroups(request, tenantId); deviceGroups = this.groupDAO.getGroups(request, tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -228,6 +303,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public List<DeviceGroup> getGroups(String username) throws GroupManagementException { public List<DeviceGroup> getGroups(String username) throws GroupManagementException {
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 {
@ -245,11 +323,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
groups.put(deviceGroup.getGroupId(), deviceGroup); groups.put(deviceGroup.getGroupId(), deviceGroup);
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new GroupManagementException("Error occurred while getting user store manager.", e); String msg = "Error occurred while getting user store manager.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while retrieving all groups accessible to user.", e); String msg = "Error occurred while retrieving all groups accessible to user.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -257,6 +344,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
private List<Integer> getGroupIds(String username) throws GroupManagementException { private List<Integer> getGroupIds(String username) throws GroupManagementException {
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 {
@ -268,11 +358,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
deviceGroupIds = this.groupDAO.getOwnGroupIds(username, tenantId); deviceGroupIds = this.groupDAO.getOwnGroupIds(username, tenantId);
deviceGroupIds.addAll(this.groupDAO.getGroupIds(roleList, tenantId)); deviceGroupIds.addAll(this.groupDAO.getGroupIds(roleList, tenantId));
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new GroupManagementException("Error occurred while getting user store manager.", e); String msg = "Error occurred while getting user store manager.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while retrieving all groups accessible to user.", e); String msg = "Error occurred while retrieving all groups accessible to user.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -282,6 +381,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public PaginationResult getGroups(String currentUser, GroupPaginationRequest request) public PaginationResult getGroups(String currentUser, GroupPaginationRequest request)
throws GroupManagementException { throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get all groups of user "+currentUser);
}
request = DeviceManagerUtil.validateGroupListPageSize(request); request = DeviceManagerUtil.validateGroupListPageSize(request);
List<Integer> allDeviceGroupIdsOfUser = getGroupIds(currentUser); List<Integer> allDeviceGroupIdsOfUser = getGroupIds(currentUser);
List<DeviceGroup> allMatchingGroups = new ArrayList<>(); List<DeviceGroup> allMatchingGroups = new ArrayList<>();
@ -290,9 +392,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
allMatchingGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId); allMatchingGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -304,28 +414,50 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public int getGroupCount() throws GroupManagementException { public int getGroupCount() throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups count");
}
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
return groupDAO.getGroupCount(tenantId); return groupDAO.getGroupCount(tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg= "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
} }
private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException { private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups count");
}
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
return groupDAO.getGroupCount(request, tenantId); return groupDAO.getGroupCount(request, tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -336,6 +468,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public int getGroupCount(String username) throws GroupManagementException { public int getGroupCount(String username) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups count of "+username);
}
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
int count; int count;
try { try {
@ -348,11 +483,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
count += groupDAO.getGroupsCount(roleList, tenantId); count += groupDAO.getGroupsCount(roleList, tenantId);
return count; return count;
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new GroupManagementException("Error occurred while getting user store manager.", e); String msg = "Error occurred while getting user store manager.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving group count of user '" + username + "'", e); String msg = "Error occurred while retrieving group count of user '" + username + "'";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -364,6 +509,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void manageGroupSharing(int groupId, List<String> newRoles) public void manageGroupSharing(int groupId, List<String> newRoles)
throws GroupManagementException, RoleDoesNotExistException { throws GroupManagementException, RoleDoesNotExistException {
if (log.isDebugEnabled()) {
log.debug("Group sharing for group "+groupId);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
try { try {
@ -392,11 +540,19 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.commitTransaction(); GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new GroupManagementException("User store error in updating sharing roles.", e); String msg = "User store error in updating sharing roles.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
log.error(e);
throw new GroupManagementException(e); throw new GroupManagementException(e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -407,14 +563,25 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public List<String> getRoles(int groupId) throws GroupManagementException { public List<String> getRoles(int groupId) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Group roles for group "+groupId);
}
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
return groupDAO.getRoles(groupId, tenantId); return groupDAO.getRoles(groupId, tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -426,6 +593,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public List<Device> getDevices(int groupId, int startIndex, int rowCount) public List<Device> getDevices(int groupId, int startIndex, int rowCount)
throws GroupManagementException { throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Group devices of group "+groupId);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
List<Device> devices; List<Device> devices;
try { try {
@ -433,11 +603,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
devices = this.groupDAO.getDevices(groupId, startIndex, rowCount, tenantId); devices = this.groupDAO.getDevices(groupId, startIndex, rowCount, tenantId);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while getting devices in group.", e); String msg = "Error occurred while getting devices in group.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new GroupManagementException("Error occurred while validating the limit of the devices to be returned", e); String msg = "Error occurred while validating the limit of the devices to be returned";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -449,13 +629,24 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public int getDeviceCount(int groupId) throws GroupManagementException { public int getDeviceCount(int groupId) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Group devices count of group "+groupId);
}
try { try {
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
return groupDAO.getDeviceCount(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId()); return groupDAO.getDeviceCount(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); String msg = "Error occurred while opening a connection to the data source.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -467,6 +658,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void addDevices(int groupId, List<DeviceIdentifier> deviceIdentifiers) public void addDevices(int groupId, List<DeviceIdentifier> deviceIdentifiers)
throws GroupManagementException, DeviceNotFoundException { throws GroupManagementException, DeviceNotFoundException {
if (log.isDebugEnabled()) {
log.debug("Group devices to the group "+groupId);
}
Device device; Device device;
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -483,12 +677,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
GroupManagementDAOFactory.commitTransaction(); GroupManagementDAOFactory.commitTransaction();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new GroupManagementException("Error occurred while retrieving device.", e); String msg = "Error occurred while retrieving device.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
throw new GroupManagementException("Error occurred while adding device to group.", e); String msg = "Error occurred while adding device to group.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new GroupManagementException("Error occurred while initiating transaction.", e); String msg = "Error occurred while initiating transaction.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -500,6 +704,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
@Override @Override
public void removeDevice(int groupId, List<DeviceIdentifier> deviceIdentifiers) public void removeDevice(int groupId, List<DeviceIdentifier> deviceIdentifiers)
throws GroupManagementException, DeviceNotFoundException { throws GroupManagementException, DeviceNotFoundException {
if (log.isDebugEnabled()) {
log.debug("Remove devices from the group "+groupId);
}
Device device; Device device;
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -514,12 +721,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
GroupManagementDAOFactory.commitTransaction(); GroupManagementDAOFactory.commitTransaction();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new GroupManagementException("Error occurred while retrieving device.", e); String msg = "Error occurred while retrieving device.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new GroupManagementException("Error occurred while initiating transaction.", e); String msg = "Error occurred while initiating transaction.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction(); GroupManagementDAOFactory.rollbackTransaction();
throw new GroupManagementException("Error occurred while adding device to group.", e); String msg = "Error occurred while adding device to group.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -530,6 +747,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public List<DeviceGroup> getGroups(String username, String permission) throws GroupManagementException { public List<DeviceGroup> getGroups(String username, String permission) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups of user "+username);
}
List<DeviceGroup> deviceGroups = getGroups(username); List<DeviceGroup> deviceGroups = getGroups(username);
Map<Integer, DeviceGroup> permittedDeviceGroups = new HashMap<>(); Map<Integer, DeviceGroup> permittedDeviceGroups = new HashMap<>();
UserRealm userRealm; UserRealm userRealm;
@ -546,13 +766,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new GroupManagementException("Error occurred while getting user realm.", e); String msg = "Error occurred while getting user realm.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} }
return new ArrayList<>(permittedDeviceGroups.values()); return new ArrayList<>(permittedDeviceGroups.values());
} }
@Override @Override
public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException { public List<DeviceGroup> getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Get groups of device "+deviceIdentifier.getId());
}
DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl();
try { try {
Device device = managementProviderService.getDevice(deviceIdentifier, false); Device device = managementProviderService.getDevice(deviceIdentifier, false);
@ -560,11 +789,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return groupDAO.getGroups(device.getId(), return groupDAO.getGroups(device.getId(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new GroupManagementException("Error occurred while retrieving the device details.", e); String msg = "Error occurred while retrieving the device details.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (GroupManagementDAOException e) { } catch (GroupManagementDAOException e) {
throw new GroupManagementException("Error occurred while retrieving device groups.", e); String msg = "Error occurred while retrieving device groups.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new GroupManagementException("Error occurred while opening database connection.", e); String msg = "Error occurred while opening database connection.";
log.error(msg,e);
throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally { } finally {
GroupManagementDAOFactory.closeConnection(); GroupManagementDAOFactory.closeConnection();
} }
@ -575,7 +814,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/ */
@Override @Override
public DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException { public DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Create default group "+groupName);
}
DeviceGroup defaultGroup = this.getGroup(groupName); DeviceGroup defaultGroup = this.getGroup(groupName);
if (defaultGroup == null) { if (defaultGroup == null) {
defaultGroup = new DeviceGroup(groupName); defaultGroup = new DeviceGroup(groupName);
@ -586,10 +827,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
this.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE, this.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE,
DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS); DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS);
} catch (GroupAlreadyExistException e) { } catch (GroupAlreadyExistException e) {
if (log.isDebugEnabled()) { String msg = "Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.";
log.debug("Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.", log.error(msg,e);
e); throw new GroupManagementException(msg,e);
} } catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} }
return this.getGroup(groupName); return this.getGroup(groupName);
} else { } else {

Loading…
Cancel
Save