|
|
|
@ -83,7 +83,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
|
DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
|
|
|
|
if (existingGroup == null) {
|
|
|
|
|
this.groupDAO.addGroup(deviceGroup, tenantId);
|
|
|
|
|
int updatedGroupID = this.groupDAO.addGroup(deviceGroup, tenantId);
|
|
|
|
|
if (deviceGroup.getGroupProperties() != null && deviceGroup.getGroupProperties().size() > 0) {
|
|
|
|
|
this.groupDAO.addGroupProperties(deviceGroup, updatedGroupID, tenantId);
|
|
|
|
|
}
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
} else {
|
|
|
|
|
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
|
|
|
@ -132,6 +135,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
|
|
|
|
|
if (existingGroup != null) {
|
|
|
|
|
this.groupDAO.updateGroup(deviceGroup, groupId, tenantId);
|
|
|
|
|
if (deviceGroup.getGroupProperties() != null && deviceGroup.getGroupProperties().size() > 0) {
|
|
|
|
|
this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId);
|
|
|
|
|
}
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
} else {
|
|
|
|
|
throw new GroupNotExistException("Group with ID - '" + groupId + "' doesn't exists!");
|
|
|
|
@ -171,6 +177,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
try {
|
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
|
this.groupDAO.deleteGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
this.groupDAO.deleteAllGroupProperties(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("DeviceGroup " + deviceGroup.getName() + " removed.");
|
|
|
|
@ -206,6 +213,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
try {
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
deviceGroup = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
if(deviceGroup != null && deviceGroup.getGroupId() > 0) {
|
|
|
|
|
deviceGroup.setGroupProperties(this.groupDAO.getAllGroupProperties(deviceGroup.getGroupId(),
|
|
|
|
|
CarbonContext.getThreadLocalCarbonContext().getTenantId()));
|
|
|
|
|
}
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining group '" + groupId + "'";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -241,6 +252,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
try {
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
deviceGroup = this.groupDAO.getGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
if(deviceGroup != null && deviceGroup.getGroupId() > 0) {
|
|
|
|
|
deviceGroup.setGroupProperties(this.groupDAO.getAllGroupProperties(deviceGroup.getGroupId(),
|
|
|
|
|
CarbonContext.getThreadLocalCarbonContext().getTenantId()));
|
|
|
|
|
}
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining group with name: '" + groupName + "'";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -269,6 +284,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
deviceGroups = this.groupDAO.getGroups(tenantId);
|
|
|
|
|
if(deviceGroups != null && !deviceGroups.isEmpty()) {
|
|
|
|
|
for (DeviceGroup group : deviceGroups) {
|
|
|
|
|
group.setGroupProperties(this.groupDAO.getAllGroupProperties(group.getGroupId(), tenantId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving all groups in tenant";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -303,6 +323,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
deviceGroups = this.groupDAO.getGroups(request, tenantId);
|
|
|
|
|
if(deviceGroups != null && !deviceGroups.isEmpty()) {
|
|
|
|
|
for (DeviceGroup group : deviceGroups) {
|
|
|
|
|
group.setGroupProperties(this.groupDAO.getAllGroupProperties(group.getGroupId(), tenantId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving all groups in tenant";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -348,6 +373,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
}
|
|
|
|
|
deviceGroups = this.groupDAO.getGroups(roleList, tenantId);
|
|
|
|
|
for (DeviceGroup deviceGroup : deviceGroups) {
|
|
|
|
|
if(deviceGroup != null && deviceGroup.getGroupId() > 0) {
|
|
|
|
|
deviceGroup.setGroupProperties(this.groupDAO.getAllGroupProperties(deviceGroup.getGroupId(), tenantId));
|
|
|
|
|
}
|
|
|
|
|
groups.put(deviceGroup.getGroupId(), deviceGroup);
|
|
|
|
|
}
|
|
|
|
|
} catch (UserStoreException | SQLException | GroupManagementDAOException e) {
|
|
|
|
@ -410,6 +438,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
allMatchingGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
|
|
|
|
|
if(allMatchingGroups != null && !allMatchingGroups.isEmpty()) {
|
|
|
|
|
for (DeviceGroup group : allMatchingGroups) {
|
|
|
|
|
group.setGroupProperties(this.groupDAO.getAllGroupProperties(group.getGroupId(), tenantId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (GroupManagementDAOException | SQLException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving all groups in tenant";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|