Skip to content

Package: RolePermissionDAO

RolePermissionDAO

nameinstructionbranchcomplexitylinemethod
RolePermissionDAO()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
count(EntityManager, KapuaQuery)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(EntityManager, RolePermissionCreator)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
delete(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
find(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
query(EntityManager, KapuaQuery)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.authorization.role.shiro;
14:
15: import org.eclipse.kapua.KapuaEntityNotFoundException;
16: import org.eclipse.kapua.KapuaException;
17: import org.eclipse.kapua.commons.jpa.EntityManager;
18: import org.eclipse.kapua.commons.service.internal.ServiceDAO;
19: import org.eclipse.kapua.model.id.KapuaId;
20: import org.eclipse.kapua.model.query.KapuaQuery;
21: import org.eclipse.kapua.service.authorization.role.RolePermission;
22: import org.eclipse.kapua.service.authorization.role.RolePermissionCreator;
23: import org.eclipse.kapua.service.authorization.role.RolePermissionListResult;
24:
25: /**
26: * {@link RolePermission} DAO
27: *
28: * @since 1.0
29: *
30: */
31: public class RolePermissionDAO extends ServiceDAO {
32:
33: /**
34: * Creates and return new role permission
35: *
36: * @param em
37: * @param creator
38: * @return
39: * @throws KapuaException
40: */
41: public static RolePermission create(EntityManager em, RolePermissionCreator creator)
42: throws KapuaException {
43: RolePermission rolePermission = new RolePermissionImpl(creator.getScopeId());
44:
45: rolePermission.setRoleId(creator.getRoleId());
46: rolePermission.setPermission(creator.getPermission());
47:
48: return ServiceDAO.create(em, rolePermission);
49: }
50:
51: /**
52: * Find the role by role identifier
53: *
54: * @param em
55: * @param scopeId
56: * @param roleId
57: * @return
58: */
59: public static RolePermission find(EntityManager em, KapuaId scopeId, KapuaId roleId) {
60: return ServiceDAO.find(em, RolePermissionImpl.class, scopeId, roleId);
61: }
62:
63: /**
64: * Return the {@link RolePermission} list matching the provided query
65: *
66: * @param em
67: * @param rolePermissionQuery
68: * @return
69: * @throws KapuaException
70: */
71: public static RolePermissionListResult query(EntityManager em, KapuaQuery rolePermissionQuery)
72: throws KapuaException {
73: return ServiceDAO.query(em, RolePermission.class, RolePermissionImpl.class, new RolePermissionListResultImpl(), rolePermissionQuery);
74: }
75:
76: /**
77: * Return the count of {@link RolePermission} matching the provided query
78: *
79: * @param em
80: * @param rolePermissionQuery
81: * @return
82: * @throws KapuaException
83: */
84: public static long count(EntityManager em, KapuaQuery rolePermissionQuery)
85: throws KapuaException {
86: return ServiceDAO.count(em, RolePermission.class, RolePermissionImpl.class, rolePermissionQuery);
87: }
88:
89: /**
90: * Delete the role by role identifier
91: *
92: * @param em
93: * @param scopeId
94: * @param rolePermissionId
95: * @return the deleted {@link RolePermission}
96: * @throws KapuaEntityNotFoundException
97: * If {@link RolePermission} is not found.
98: */
99: public static RolePermission delete(EntityManager em, KapuaId scopeId, KapuaId rolePermissionId) throws KapuaEntityNotFoundException {
100: return ServiceDAO.delete(em, RolePermissionImpl.class, scopeId, rolePermissionId);
101: }
102: }