Skip to content

Package: DomainDAO

DomainDAO

nameinstructionbranchcomplexitylinemethod
DomainDAO()
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: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
create(EntityManager, DomainCreator)
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 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%
findByName(EntityManager, String)
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: 13 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.domain.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.KapuaNamedEntityAttributes;
20: import org.eclipse.kapua.model.id.KapuaId;
21: import org.eclipse.kapua.model.query.KapuaQuery;
22: import org.eclipse.kapua.service.authorization.domain.Domain;
23: import org.eclipse.kapua.service.authorization.domain.DomainCreator;
24: import org.eclipse.kapua.service.authorization.domain.DomainListResult;
25: import org.eclipse.kapua.service.authorization.domain.DomainQuery;
26:
27: /**
28: * {@link Domain} DAO
29: *
30: * @since 1.0.0
31: */
32: public class DomainDAO extends ServiceDAO {
33:
34: /**
35: * Creates and returns new {@link Domain}
36: *
37: * @param em The {@link EntityManager} that holds the transaction.
38: * @param creator The {@link DomainCreator} object from which create the new {@link Domain}.
39: * @return The newly created {@link Domain}.
40: * @since 1.0.0
41: */
42: public static Domain create(EntityManager em, DomainCreator creator) {
43: Domain domain = new DomainImpl();
44:
45: domain.setName(creator.getName());
46: domain.setServiceName(creator.getServiceName());
47: domain.setGroupable(creator.getGroupable());
48:
49:• if (creator.getActions() != null) {
50: domain.setActions(creator.getActions());
51: }
52:
53: return ServiceDAO.create(em, domain);
54: }
55:
56: /**
57: * Finds the {@link Domain} by {@link Domain} identifier
58: *
59: * @param em The {@link EntityManager} that holds the transaction.
60: * @param scopeId
61: * @param domainId The {@link Domain} id to search.
62: * @return The found {@link Domain} or {@code null} if not found.
63: * @since 1.0.0
64: */
65: public static Domain find(EntityManager em, KapuaId scopeId, KapuaId domainId) {
66: return ServiceDAO.find(em, DomainImpl.class, scopeId, domainId);
67: }
68:
69: /**
70: * Returns the {@link Domain} list matching the provided query.
71: *
72: * @param em The {@link EntityManager} that holds the transaction.
73: * @param domainQuery The {@link DomainQuery} used to filter results.
74: * @return The list of {@link Domain}s that matches the given query.
75: * @throws KapuaException
76: * @since 1.0.0
77: */
78: public static DomainListResult query(EntityManager em, KapuaQuery domainQuery)
79: throws KapuaException {
80: domainQuery.setScopeId(null);
81: return ServiceDAO.query(em, Domain.class, DomainImpl.class, new DomainListResultImpl(), domainQuery);
82: }
83:
84: /**
85: * Return the {@link Domain} count matching the provided query
86: *
87: * @param em The {@link EntityManager} that holds the transaction.
88: * @param domainQuery The {@link DomainQuery} used to filter results.
89: * @return
90: * @throws KapuaException
91: * @since 1.0.0
92: */
93: public static long count(EntityManager em, KapuaQuery domainQuery)
94: throws KapuaException {
95: domainQuery.setScopeId(null);
96: return ServiceDAO.count(em, Domain.class, DomainImpl.class, domainQuery);
97: }
98:
99: /**
100: * Deletes the {@link Domain} by {@link Domain} identifier
101: *
102: * @param em The {@link EntityManager} that holds the transaction.
103: * @param scopeId
104: * @param domainId The {@link Domain} id to delete.
105: * @return deleted entity
106: * @throws KapuaEntityNotFoundException If {@link Domain} is not found.
107: * @since 1.0.0
108: */
109: public static Domain delete(EntityManager em, KapuaId scopeId, KapuaId domainId) throws KapuaEntityNotFoundException {
110: return ServiceDAO.delete(em, DomainImpl.class, scopeId, domainId);
111: }
112:
113: public static Domain findByName(EntityManager em, String name) {
114: return ServiceDAO.findByField(em, DomainImpl.class, KapuaNamedEntityAttributes.NAME, name);
115: }
116:
117: }