Skip to content

Package: GroupDAO

GroupDAO

nameinstructionbranchcomplexitylinemethod
GroupDAO()
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, GroupCreator)
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, Group)
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.group.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.group.Group;
22: import org.eclipse.kapua.service.authorization.group.GroupCreator;
23: import org.eclipse.kapua.service.authorization.group.GroupListResult;
24: import org.eclipse.kapua.service.authorization.group.GroupQuery;
25:
26: /**
27: * {@link Group} DAO
28: *
29: * @since 1.0.0
30: */
31: public class GroupDAO extends ServiceDAO {
32:
33: /**
34: * Creates and returns new {@link Group}
35: *
36: * @param em
37: * The {@link EntityManager} that holds the transaction.
38: * @param creator
39: * The {@link GroupCreator} object from which create the new {@link Group}.
40: * @return The newly created {@link Group}.
41: * @throws KapuaException
42: * @since 1.0.0
43: */
44: public static Group create(EntityManager em, GroupCreator creator)
45: throws KapuaException {
46: Group group = new GroupImpl(creator.getScopeId());
47: group.setName(creator.getName());
48: group.setDescription(creator.getDescription());
49:
50: return ServiceDAO.create(em, group);
51: }
52:
53: /**
54: * Updates and returns the updated {@link Group}
55: *
56: * @param em
57: * The {@link EntityManager} that holds the transaction.
58: * @param group
59: * The {@link Group} to update
60: * @return The updated {@link Group}.
61: * @throws KapuaEntityNotFoundException
62: * If {@link Group} is not found.
63: */
64: public static Group update(EntityManager em, Group group) throws KapuaEntityNotFoundException {
65: GroupImpl groupImpl = (GroupImpl) group;
66: return ServiceDAO.update(em, GroupImpl.class, groupImpl);
67: }
68:
69: /**
70: * Finds the {@link Group} by {@link Group} identifier
71: *
72: * @param em
73: * The {@link EntityManager} that holds the transaction.
74: * @param groupId
75: * The {@link Group} id to search.
76: * @return The found {@link Group} or {@code null} if not found.
77: * @since 1.0.0
78: */
79: public static Group find(EntityManager em, KapuaId scopeId, KapuaId groupId) {
80: return ServiceDAO.find(em, GroupImpl.class, scopeId, groupId);
81: }
82:
83: /**
84: * Returns the {@link Group} list matching the provided query.
85: *
86: * @param em
87: * The {@link EntityManager} that holds the transaction.
88: * @param groupQuery
89: * The {@link GroupQuery} used to filter results.
90: * @return The list of {@link Group}s that matches the given query.
91: * @throws KapuaException
92: * @since 1.0.0
93: */
94: public static GroupListResult query(EntityManager em, KapuaQuery groupQuery)
95: throws KapuaException {
96: return ServiceDAO.query(em, Group.class, GroupImpl.class, new GroupListResultImpl(), groupQuery);
97: }
98:
99: /**
100: * Return the {@link Group} count matching the provided query
101: *
102: * @param em
103: * The {@link EntityManager} that holds the transaction.
104: * @param groupQuery
105: * The {@link GroupQuery} used to filter results.
106: * @return The count of {@link Group}s that matches the given query.
107: * @throws KapuaException
108: * @since 1.0.0
109: */
110: public static long count(EntityManager em, KapuaQuery groupQuery)
111: throws KapuaException {
112: return ServiceDAO.count(em, Group.class, GroupImpl.class, groupQuery);
113: }
114:
115: /**
116: * Deletes the {@link Group} by {@link Group} identifier
117: *
118: * @param em
119: * The {@link EntityManager} that holds the transaction.
120: * @param scopeId
121: * @param groupId
122: * The {@link Group} id to delete.
123: * @return deleted entity
124: * @throws KapuaEntityNotFoundException
125: * If {@link Group} is not found.
126: * @since 1.0.0
127: */
128: public static Group delete(EntityManager em, KapuaId scopeId, KapuaId groupId) throws KapuaEntityNotFoundException {
129: return ServiceDAO.delete(em, GroupImpl.class, scopeId, groupId);
130: }
131: }