Skip to content

Package: RoleDAO

RoleDAO

nameinstructionbranchcomplexitylinemethod
RoleDAO()
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, RoleCreator)
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%
update(EntityManager, Role)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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.Role;
22: import org.eclipse.kapua.service.authorization.role.RoleCreator;
23: import org.eclipse.kapua.service.authorization.role.RoleListResult;
24:
25: /**
26: * Role DAO
27: *
28: * @since 1.0
29: *
30: */
31: public class RoleDAO extends ServiceDAO {
32:
33: /**
34: * Creates and return new role
35: *
36: * @param em
37: * @param creator
38: * @return
39: * @throws KapuaException
40: */
41: public static Role create(EntityManager em, RoleCreator creator)
42: throws KapuaException {
43: Role role = new RoleImpl(creator.getScopeId());
44:
45: role.setName(creator.getName());
46: role.setDescription(creator.getDescription());
47:
48: return ServiceDAO.create(em, role);
49: }
50:
51: /**
52: * Updates and returns the updated {@link Role}
53: *
54: * @param em
55: * @param role
56: * @return
57: * @throws KapuaEntityNotFoundException
58: * If {@link Role} is not found.
59: */
60: public static Role update(EntityManager em, Role role) throws KapuaEntityNotFoundException {
61: RoleImpl roleImpl = (RoleImpl) role;
62: return ServiceDAO.update(em, RoleImpl.class, roleImpl);
63: }
64:
65: /**
66: * Find the role by role identifier
67: *
68: * @param em
69: * @param scopeId
70: * @param roleId
71: * @return
72: */
73: public static Role find(EntityManager em, KapuaId scopeId, KapuaId roleId) {
74: return ServiceDAO.find(em, RoleImpl.class, scopeId, roleId);
75: }
76:
77: /**
78: * Return the role list matching the provided query
79: *
80: * @param em
81: * @param roleQuery
82: * @return
83: * @throws KapuaException
84: */
85: public static RoleListResult query(EntityManager em, KapuaQuery roleQuery)
86: throws KapuaException {
87: return ServiceDAO.query(em, Role.class, RoleImpl.class, new RoleListResultImpl(), roleQuery);
88: }
89:
90: /**
91: * Return the role count matching the provided query
92: *
93: * @param em
94: * @param roleQuery
95: * @return
96: * @throws KapuaException
97: */
98: public static long count(EntityManager em, KapuaQuery roleQuery)
99: throws KapuaException {
100: return ServiceDAO.count(em, Role.class, RoleImpl.class, roleQuery);
101: }
102:
103: /**
104: * Delete the role by role identifier
105: *
106: * @param em
107: * @param scopeId
108: * @param roleId
109: * @return the deleted {@link Role}
110: * @throws KapuaEntityNotFoundException
111: * If {@link Role} is not found.
112: */
113: public static Role delete(EntityManager em, KapuaId scopeId, KapuaId roleId)
114: throws KapuaEntityNotFoundException {
115: return ServiceDAO.delete(em, RoleImpl.class, scopeId, roleId);
116: }
117: }