Skip to content

Package: Domains

Domains

nameinstructionbranchcomplexitylinemethod
Domains()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
count(ScopeId, DomainQuery)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
find(ScopeId, EntityId)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
query(ScopeId, DomainQuery)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
simpleQuery(ScopeId, String, int, int)
M: 35 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 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.app.api.resources.v1.resources;
14:
15: import com.google.common.base.Strings;
16: import org.eclipse.kapua.KapuaEntityNotFoundException;
17: import org.eclipse.kapua.KapuaException;
18: import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
19: import org.eclipse.kapua.app.api.core.model.CountResult;
20: import org.eclipse.kapua.app.api.core.model.EntityId;
21: import org.eclipse.kapua.app.api.core.model.ScopeId;
22: import org.eclipse.kapua.locator.KapuaLocator;
23: import org.eclipse.kapua.model.KapuaNamedEntityAttributes;
24: import org.eclipse.kapua.model.query.predicate.AndPredicate;
25: import org.eclipse.kapua.service.KapuaService;
26: import org.eclipse.kapua.service.authorization.domain.Domain;
27: import org.eclipse.kapua.service.authorization.domain.DomainFactory;
28: import org.eclipse.kapua.service.authorization.domain.DomainListResult;
29: import org.eclipse.kapua.service.authorization.domain.DomainQuery;
30: import org.eclipse.kapua.service.authorization.domain.DomainRegistryService;
31:
32: import javax.ws.rs.Consumes;
33: import javax.ws.rs.DefaultValue;
34: import javax.ws.rs.GET;
35: import javax.ws.rs.POST;
36: import javax.ws.rs.Path;
37: import javax.ws.rs.PathParam;
38: import javax.ws.rs.Produces;
39: import javax.ws.rs.QueryParam;
40: import javax.ws.rs.core.MediaType;
41:
42: @Path("{scopeId}/domains")
43: public class Domains extends AbstractKapuaResource {
44:
45: private final KapuaLocator locator = KapuaLocator.getInstance();
46: private final DomainRegistryService domainRegistryService = locator.getService(DomainRegistryService.class);
47: private final DomainFactory domainFactory = locator.getFactory(DomainFactory.class);
48:
49: /**
50: * Gets the {@link Domain} list in the scope.
51: *
52: * @param scopeId The {@link ScopeId} in which to search results.
53: * @param name The {@link Domain} name in which to search results.
54: * @param offset The result set offset.
55: * @param limit The result set limit.
56: * @return The {@link DomainListResult} of all the domains associated to the current selected scope.
57: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
58: * @since 1.0.0
59: */
60: @GET
61: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
62: public DomainListResult simpleQuery(
63: @PathParam("scopeId") ScopeId scopeId,
64: @QueryParam("name") String name,
65: @QueryParam("offset") @DefaultValue("0") int offset,
66: @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
67: DomainQuery query = domainFactory.newQuery(null);
68:
69: AndPredicate andPredicate = query.andPredicate();
70:• if (!Strings.isNullOrEmpty(name)) {
71: andPredicate.and(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name));
72: }
73: query.setPredicate(andPredicate);
74:
75: query.setOffset(offset);
76: query.setLimit(limit);
77:
78: return query(scopeId, query);
79: }
80:
81: /**
82: * Queries the results with the given {@link DomainQuery} parameter.
83: *
84: * @param scopeId The {@link ScopeId} in which to search results.
85: * @param query The {@link DomainQuery} to use to filter results.
86: * @return The {@link DomainListResult} of all the result matching the given {@link DomainQuery} parameter.
87: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
88: * @since 1.0.0
89: */
90: @POST
91: @Path("_query")
92: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
93: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
94: public DomainListResult query(
95: @PathParam("scopeId") ScopeId scopeId,
96: DomainQuery query) throws KapuaException {
97: return domainRegistryService.query(query);
98: }
99:
100: /**
101: * Counts the results with the given {@link DomainQuery} parameter.
102: *
103: * @param scopeId The {@link ScopeId} in which to search results.
104: * @param query The {@link DomainQuery} to use to filter results.
105: * @return The count of all the result matching the given {@link DomainQuery} parameter.
106: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
107: * @since 1.0.0
108: */
109: @POST
110: @Path("_count")
111: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
112: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
113: public CountResult count(
114: @PathParam("scopeId") ScopeId scopeId,
115: DomainQuery query) throws KapuaException {
116: return new CountResult(domainRegistryService.count(query));
117: }
118:
119: /**
120: * Returns the Domain specified by the "domainId" path parameter.
121: *
122: * @param scopeId The {@link ScopeId} of the requested {@link Domain}.
123: * @param domainId The id of the requested {@link Domain}.
124: * @return The requested Domain object.
125: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
126: * @since 1.0.0
127: */
128: @GET
129: @Path("{domainId}")
130: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
131: public Domain find(
132: @PathParam("scopeId") ScopeId scopeId,
133: @PathParam("domainId") EntityId domainId) throws KapuaException {
134: Domain domain = domainRegistryService.find(scopeId, domainId);
135:
136:• if (domain == null) {
137: throw new KapuaEntityNotFoundException(Domain.TYPE, domainId);
138: }
139:
140: return domain;
141: }
142: }