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 =
{"/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);
if (existingGroup == null) {
if (deviceGroup.getParentGroupId() == 0) {
deviceGroup.setParentPath("/");
deviceGroup.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
} else {
DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId);
if (immediateParentGroup == null) {
@ -178,10 +178,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
if (existingGroup != null) {
List<DeviceGroup> groupsToUpdate = new ArrayList<>();
String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), "/");
String immediateParentID = StringUtils.substringAfterLast(existingGroup.getParentPath(), DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
String parentPath = "";
if (deviceGroup.getParentGroupId() == 0) {
deviceGroup.setParentPath("/");
deviceGroup.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
} else {
DeviceGroup immediateParentGroup = groupDAO.getGroup(deviceGroup.getParentGroupId(), tenantId);
if (immediateParentGroup == null) {
@ -197,7 +197,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
deviceGroup.setGroupId(groupId);
groupsToUpdate.add(deviceGroup);
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) {
childrenGroup.setParentPath(childrenGroup.getParentPath()
.replace(existingGroup.getParentPath(), parentPath));
@ -258,9 +259,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} else {
for (DeviceGroup childrenGroup : childrenGroups) {
String newParentPath = childrenGroup.getParentPath()
.replace("/" + deviceGroup.getGroupId(), "");
.replace(DeviceGroupConstants.HierarchicalGroup.SEPERATOR + deviceGroup.getGroupId(), "");
if (StringUtils.isEmpty(newParentPath)) {
newParentPath = "/";
newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR;
}
childrenGroup.setParentPath(newParentPath);
}
@ -437,7 +438,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection();
request.setParentPath("/");
request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
rootGroups = this.groupDAO.getGroups(request, tenantId);
for (DeviceGroup rootGroup : rootGroups) {
if (requireGroupProps) {
@ -480,7 +481,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
List<DeviceGroup> rootGroups;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
request.setParentPath("/");
request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
if (StringUtils.isBlank(username)) {
GroupManagementDAOFactory.openConnection();
rootGroups = groupDAO.getGroups(request, tenantId);
@ -616,7 +617,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection();
request.setParentPath("/");
request.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
for (DeviceGroup rootGroup : rootGroups) {
if (requireGroupProps) {
@ -1306,7 +1307,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
while (iterator.hasNext()) {
DeviceGroup childGroup = iterator.next();
int immediateParentID = Integer.parseInt(StringUtils.substringAfterLast(
childGroup.getParentPath(), "/"));
childGroup.getParentPath(), DeviceGroupConstants.HierarchicalGroup.SEPERATOR));
if (immediateParentID == parentGroup.getGroupId()) {
if (requireGroupProps) {
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.geo.service.GeofenceData;
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.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
@ -1169,10 +1170,11 @@ public final class DeviceManagerUtil {
* @return created parent path
*/
public static String createParentPath(DeviceGroup deviceGroup) {
if ("/".equals(deviceGroup.getParentPath())) {
if (DeviceGroupConstants.HierarchicalGroup.SEPERATOR.equals(deviceGroup.getParentPath())) {
return deviceGroup.getParentPath() + deviceGroup.getGroupId();
} else {
return deviceGroup.getParentPath() + "/" + deviceGroup.getGroupId();
return deviceGroup.getParentPath() + DeviceGroupConstants.HierarchicalGroup.SEPERATOR
+ deviceGroup.getGroupId();
}
}
}

Loading…
Cancel
Save