Move slash to a constant

(cherry picked from commit 489aaabc44)
4.x.x
Saad Sahibjan 4 years ago committed by Pahansith
parent 996309f063
commit aea460c0d5

@ -84,4 +84,8 @@ public class DeviceGroupConstants {
public static final String[] DEFAULT_VIEW_EVENTS_PERMISSIONS = public static final String[] DEFAULT_VIEW_EVENTS_PERMISSIONS =
{"/permission/device-mgt/user/groups/device_events"}; {"/permission/device-mgt/user/groups/device_events"};
} }
public static final class HierarchicalGroup {
public static final String SEPERATOR = "/";
}
} }

@ -113,7 +113,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId); DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
if (existingGroup == null) { if (existingGroup == null) {
if (deviceGroup.getParentGroupId() == 0) { if (deviceGroup.getParentGroupId() == 0) {
deviceGroup.setParentPath("/"); deviceGroup.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
} else { } else {
DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId); DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId);
if (immediateParentGroup == null) { if (immediateParentGroup == null) {
@ -178,10 +178,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId); DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
if (existingGroup != null) { if (existingGroup != null) {
List<DeviceGroup> groupsToUpdate = new ArrayList<>(); List<DeviceGroup> groupsToUpdate = new ArrayList<>();
String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), "/"); String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
String parentPath = ""; String parentPath = "";
if (deviceGroup.getParentGroupId() == 0) { if (deviceGroup.getParentGroupId() == 0) {
deviceGroup.setParentPath("/"); deviceGroup.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
} else { } else {
DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId); DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId);
if (immediateParentGroup == null) { if (immediateParentGroup == null) {
@ -197,7 +197,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
deviceGroup.setGroupId(groupId); deviceGroup.setGroupId(groupId);
groupsToUpdate.add(deviceGroup); groupsToUpdate.add(deviceGroup);
if (StringUtils.isNotBlank(immediateParentID)) { if (StringUtils.isNotBlank(immediateParentID)) {
List<DeviceGroup> childrenGroups = groupDAO.getChildrenGroups(DeviceManagerUtil.createParentPath(existingGroup), tenantId); List<DeviceGroup> childrenGroups = groupDAO.getChildrenGroups(
DeviceManagerUtil.createParentPath(existingGroup), tenantId);
for (DeviceGroup childrenGroup : childrenGroups) { for (DeviceGroup childrenGroup : childrenGroups) {
childrenGroup.setParentPath(childrenGroup.getParentPath() childrenGroup.setParentPath(childrenGroup.getParentPath()
.replace(existingGroup.getParentPath(), parentPath)); .replace(existingGroup.getParentPath(), parentPath));
@ -258,9 +259,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} else { } else {
for (DeviceGroup childrenGroup : childrenGroups) { for (DeviceGroup childrenGroup : childrenGroups) {
String newParentPath = childrenGroup.getParentPath() String newParentPath = childrenGroup.getParentPath()
.replace("/" + deviceGroup.getGroupId(), ""); .replace(DeviceGroupConstants.HierarchicalGroup.SEPERATOR + deviceGroup.getGroupId(), "");
if (StringUtils.isEmpty(newParentPath)) { if (StringUtils.isEmpty(newParentPath)) {
newParentPath = "/"; newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR;
} }
childrenGroup.setParentPath(newParentPath); childrenGroup.setParentPath(newParentPath);
} }
@ -437,7 +438,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
request.setParentPath("/"); request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
rootGroups = this.groupDAO.getGroups(request, tenantId); rootGroups = this.groupDAO.getGroups(request, tenantId);
for (DeviceGroup rootGroup : rootGroups) { for (DeviceGroup rootGroup : rootGroups) {
if (requireGroupProps) { if (requireGroupProps) {
@ -480,7 +481,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
List<DeviceGroup> rootGroups; List<DeviceGroup> rootGroups;
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
request.setParentPath("/"); request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
rootGroups = groupDAO.getGroups(request, tenantId); rootGroups = groupDAO.getGroups(request, tenantId);
@ -616,7 +617,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection(); GroupManagementDAOFactory.openConnection();
request.setParentPath("/"); request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId); rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
for (DeviceGroup rootGroup : rootGroups) { for (DeviceGroup rootGroup : rootGroups) {
if (requireGroupProps) { if (requireGroupProps) {
@ -1306,7 +1307,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
while (iterator.hasNext()) { while (iterator.hasNext()) {
DeviceGroup childGroup = iterator.next(); DeviceGroup childGroup = iterator.next();
int immediateParentID = Integer.parseInt(StringUtils.substringAfterLast( int immediateParentID = Integer.parseInt(StringUtils.substringAfterLast(
childGroup.getParentPath(), "/")); childGroup.getParentPath(), DeviceGroupConstants.HierarchicalGroup.SEPERATOR));
if (immediateParentID == parentGroup.getGroupId()) { if (immediateParentID == parentGroup.getGroupId()) {
if (requireGroupProps) { if (requireGroupProps) {
populateGroupProperties(childGroup, tenantId); populateGroupProperties(childGroup, tenantId);

@ -70,6 +70,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData; import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException; import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
@ -1169,10 +1170,11 @@ public final class DeviceManagerUtil {
* @return created parent path * @return created parent path
*/ */
public static String createParentPath(DeviceGroup deviceGroup) { public static String createParentPath(DeviceGroup deviceGroup) {
if ("/".equals(deviceGroup.getParentPath())) { if (DeviceGroupConstants.HierarchicalGroup.SEPERATOR.equals(deviceGroup.getParentPath())) {
return deviceGroup.getParentPath() + deviceGroup.getGroupId(); return deviceGroup.getParentPath() + deviceGroup.getGroupId();
} else { } else {
return deviceGroup.getParentPath() + "/" + deviceGroup.getGroupId(); return deviceGroup.getParentPath() + DeviceGroupConstants.HierarchicalGroup.SEPERATOR
+ deviceGroup.getGroupId();
} }
} }
} }

Loading…
Cancel
Save