HierarchicalGrouping #137
Merged
inosh
merged 9 commits from ThilinaPremachandra/device-mgt-core:syncHierarchicalGrouping
into master
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'ThilinaPremachandra/device-mgt-core:syncHierarchicalGrouping'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Goals
Complete hierarchical grouping task
(https://gitlab.com/entgra/product-iots/-/issues/1535) and (https://gitlab.com/entgra/product-iots/-/issues/1536)
Approach
create new API for consolidate group creation and roles sharing.
changes script regarding to the hierarchical grouping.
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<groupId>org. wso2.tomcat</groupId>
Is this correct?
yes. this should be changed and this has been fixed now.
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
Remove unnecessary new line
@POST
@Path("/create-with-roles")
Don't use verbs in API context path
required = true)
@Valid DeviceGroup group);
Remove unnecessary new lines
@POST
@Path("/create-with-roles")
Don't use verbs in API context paths
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.policy.mgt.common.PolicyAdministratorPoint;
import io.entgra.device.mgt.core.policy.mgt.common.PolicyManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Don't use wild card imports.
}
@POST
@Path("/create-with-roles")
Don't use verbs in API context paths
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Don't use wild card imports
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
Don't use wild card imports
}
}
@POST
@Path("/create-with-roles")
Don't use verbs in API context path
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name : " + group.getName() + ".";
log.warn(msg);
What's the reason for adding warn message instead of error message
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
Use correct License text. This is WSO2 license and license has been updated in device mgt core. Please check other files.
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Don't use wild card imports.
* @param deviceGroup to update.
* @param groupId of the group.
* @throws GroupManagementException
*
Remove unnecessary new lines
package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Don't use wild card imports
9996a2614d
to145740fec6
1 year agoWIP: HierarchicalGroupingto HierarchicalGrouping 1 year ago@Path("/roles/share")
@Override
public Response createGroupWithRoles(DeviceGroupRoleWrapper groups) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
We don't need to assign this to a variable since there is a single usage of this and we don't check the value of it. Please check other occurannces and do the required modifications of other methods as well.
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (GroupManagementException e) {
String msg = "Error occurred while adding new group.";
Improve this log by adding more details into the log, like group name etc.
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name : " + groups.getName() + ".";
log.warn(msg);
What's the reason for having warn log here? Please check other occurannces and do the required modifications of other methods as well.
If the group already exist with same name, It is not an error and it should be a warning. that is why a warning is logged.
return Response.status(Response.Status.CREATED).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while adding new group.";
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
Why haven't we logged the error in this method?
}
}
public int addGroupWithRoles(DeviceGroupRoleWrapper groups, int tenantId) throws GroupManagementDAOException {
Don't we need to add the '@Override' annotation?
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
hasStatus = true;
}
stmt = conn.prepareStatement(sql, new String[]{"ID"});
Use try with resources
stmt.setString(7, groups.getStatus());
}
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
use try with resources
}
return groupId;
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
Log and throw the message and error
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
groups.getName() + "'", e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
With the try with resources you can remove this finally block.
PreparedStatement stmt = null;
try {
Connection conn = GroupManagementDAOFactory.getConnection();
stmt = conn.prepareStatement(
Use try with resources
status = true;
} catch (SQLException e) {
String msg = "Error occurred while adding properties for group '" +
groups.getName() + "' values : " + groups.getGroupProperties();
Log the message and the error
groups.getName() + "' values : " + groups.getGroupProperties();
throw new GroupManagementDAOException(msg, e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
With try with resources you can remove this finally block.
"VALUES (?, ?, ?, ?, ?) RETURNING ID";
hasStatus = true;
}
stmt = conn.prepareStatement(sql);
Use try with resources
stmt.setString(6, groups.getStatus());
}
stmt.execute();
rs = stmt.getGeneratedKeys();
Use try with resources
}
return groupId;
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
Log the error message and the error
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
groups.getName() + "'", e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
With try with resources you can remove this finally block
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Don't use wild card imports
d17925cf7f
into master 1 year agoRelated tickets:
https://roadmap.entgra.net/issues/9529
https://roadmap.entgra.net/issues/9528
Reviewers
d17925cf7f
.