HierarchicalGrouping #137

Merged
inosh merged 9 commits from ThilinaPremachandra/device-mgt-core:syncHierarchicalGrouping into master 1 year ago
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.

##### **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.
ThilinaPremachandra added 1 commit 1 year ago
tcdlpds reviewed 1 year ago
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<groupId>org. wso2.tomcat</groupId>
Owner

Is this correct?

Is this correct?

yes. this should be changed and this has been fixed now.

yes. this should be changed and this has been fixed now.
ThilinaPremachandra marked this conversation as resolved
tcdlpds requested changes 1 year ago
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;
Owner

Remove unnecessary new line

Remove unnecessary new line
ThilinaPremachandra marked this conversation as resolved
@POST
@Path("/create-with-roles")
Owner

Don't use verbs in API context path

Don't use verbs in API context path
ThilinaPremachandra marked this conversation as resolved
required = true)
@Valid DeviceGroup group);
Owner

Remove unnecessary new lines

Remove unnecessary new lines
ThilinaPremachandra marked this conversation as resolved
@POST
@Path("/create-with-roles")
Owner

Don't use verbs in API context paths

Don't use verbs in API context paths
ThilinaPremachandra marked this conversation as resolved
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.*;
Owner

Don't use wild card imports.

Don't use wild card imports.
ThilinaPremachandra marked this conversation as resolved
}
@POST
@Path("/create-with-roles")
Owner

Don't use verbs in API context paths

Don't use verbs in API context paths
ThilinaPremachandra marked this conversation as resolved
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Owner

Don't use wild card imports

Don't use wild card imports
ThilinaPremachandra marked this conversation as resolved
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
Owner

Don't use wild card imports

Don't use wild card imports
ThilinaPremachandra marked this conversation as resolved
}
}
@POST
@Path("/create-with-roles")
Owner

Don't use verbs in API context path

Don't use verbs in API context path
ThilinaPremachandra marked this conversation as resolved
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);
Owner

What's the reason for adding warn message instead of error message

What's the reason for adding warn message instead of error message
ThilinaPremachandra marked this conversation as resolved
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
Owner

Use correct License text. This is WSO2 license and license has been updated in device mgt core. Please check other files.

Use correct License text. This is WSO2 license and license has been updated in device mgt core. Please check other files.
ThilinaPremachandra marked this conversation as resolved
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.*;
Owner

Don't use wild card imports.

Don't use wild card imports.
ThilinaPremachandra marked this conversation as resolved
* @param deviceGroup to update.
* @param groupId of the group.
* @throws GroupManagementException
*
Owner

Remove unnecessary new lines

Remove unnecessary new lines
ThilinaPremachandra marked this conversation as resolved
package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
Owner

Don't use wild card imports

Don't use wild card imports
ThilinaPremachandra marked this conversation as resolved
ThilinaPremachandra force-pushed syncHierarchicalGrouping from 9996a2614d to 145740fec6 1 year ago
ThilinaPremachandra changed title from WIP: HierarchicalGrouping to HierarchicalGrouping 1 year ago
ThilinaPremachandra added 1 commit 1 year ago
ThilinaPremachandra added 1 commit 1 year ago
ThilinaPremachandra added 1 commit 1 year ago
tcdlpds requested changes 1 year ago
@Path("/roles/share")
@Override
public Response createGroupWithRoles(DeviceGroupRoleWrapper groups) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Owner

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.

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.
ThilinaPremachandra marked this conversation as resolved
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (GroupManagementException e) {
String msg = "Error occurred while adding new group.";
Owner

Improve this log by adding more details into the log, like group name etc.

Improve this log by adding more details into the log, like group name etc.
ThilinaPremachandra marked this conversation as resolved
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);
Owner

What's the reason for having warn log here? Please check other occurannces and do the required modifications of other methods as well.

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.

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.
ThilinaPremachandra marked this conversation as resolved
ThilinaPremachandra added 1 commit 1 year ago
tcdlpds requested changes 1 year ago
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();
Owner

Why haven't we logged the error in this method?

Why haven't we logged the error in this method?
ThilinaPremachandra marked this conversation as resolved
tcdlpds requested changes 1 year ago
}
}
public int addGroupWithRoles(DeviceGroupRoleWrapper groups, int tenantId) throws GroupManagementDAOException {
Owner

Don't we need to add the '@Override' annotation?

Don't we need to add the '@Override' annotation?
ThilinaPremachandra marked this conversation as resolved
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
hasStatus = true;
}
stmt = conn.prepareStatement(sql, new String[]{"ID"});
Owner

Use try with resources

Use try with resources
ThilinaPremachandra marked this conversation as resolved
stmt.setString(7, groups.getStatus());
}
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
Owner

use try with resources

use try with resources
ThilinaPremachandra marked this conversation as resolved
}
return groupId;
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
Owner

Log and throw the message and error

Log and throw the message and error
ThilinaPremachandra marked this conversation as resolved
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
groups.getName() + "'", e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
Owner

With the try with resources you can remove this finally block.

With the try with resources you can remove this finally block.
ThilinaPremachandra marked this conversation as resolved
PreparedStatement stmt = null;
try {
Connection conn = GroupManagementDAOFactory.getConnection();
stmt = conn.prepareStatement(
Owner

Use try with resources

Use try with resources
ThilinaPremachandra marked this conversation as resolved
status = true;
} catch (SQLException e) {
String msg = "Error occurred while adding properties for group '" +
groups.getName() + "' values : " + groups.getGroupProperties();
Owner

Log the message and the error

Log the message and the error
ThilinaPremachandra marked this conversation as resolved
groups.getName() + "' values : " + groups.getGroupProperties();
throw new GroupManagementDAOException(msg, e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
Owner

With try with resources you can remove this finally block.

With try with resources you can remove this finally block.
ThilinaPremachandra marked this conversation as resolved
"VALUES (?, ?, ?, ?, ?) RETURNING ID";
hasStatus = true;
}
stmt = conn.prepareStatement(sql);
Owner

Use try with resources

Use try with resources
ThilinaPremachandra marked this conversation as resolved
stmt.setString(6, groups.getStatus());
}
stmt.execute();
rs = stmt.getGeneratedKeys();
Owner

Use try with resources

Use try with resources
ThilinaPremachandra marked this conversation as resolved
}
return groupId;
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
Owner

Log the error message and the error

Log the error message and the error
ThilinaPremachandra marked this conversation as resolved
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
groups.getName() + "'", e);
} finally {
GroupManagementDAOUtil.cleanupResources(stmt, null);
Owner

With try with resources you can remove this finally block

With try with resources you can remove this finally block
ThilinaPremachandra marked this conversation as resolved
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.*;
Owner

Don't use wild card imports

Don't use wild card imports
ThilinaPremachandra marked this conversation as resolved
ThilinaPremachandra added 1 commit 1 year ago
ThilinaPremachandra added 2 commits 1 year ago
inosh merged commit d17925cf7f into master 1 year ago
Collaborator
Related tickets: https://roadmap.entgra.net/issues/9529 https://roadmap.entgra.net/issues/9528

Reviewers

tcdlpds requested changes 1 year ago
The pull request has been merged as d17925cf7f.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: community/device-mgt-core#137
Loading…
There is no content yet.