Skip to content

Package: EndpointInfos

EndpointInfos

nameinstructionbranchcomplexitylinemethod
EndpointInfos()
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, String, EndpointInfoQuery)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
create(ScopeId, EndpointInfoCreator)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
deleteEndpointInfo(ScopeId, EntityId)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
find(ScopeId, EntityId)
M: 17 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, String, EndpointInfoQuery)
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%
simpleQuery(ScopeId, String, String, int, int)
M: 39 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
update(ScopeId, EntityId, EndpointInfo)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 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.query.predicate.AndPredicate;
24: import org.eclipse.kapua.service.KapuaService;
25: import org.eclipse.kapua.service.endpoint.EndpointInfo;
26: import org.eclipse.kapua.service.endpoint.EndpointInfoAttributes;
27: import org.eclipse.kapua.service.endpoint.EndpointInfoCreator;
28: import org.eclipse.kapua.service.endpoint.EndpointInfoFactory;
29: import org.eclipse.kapua.service.endpoint.EndpointInfoListResult;
30: import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;
31: import org.eclipse.kapua.service.endpoint.EndpointInfoService;
32:
33: import javax.ws.rs.Consumes;
34: import javax.ws.rs.DELETE;
35: import javax.ws.rs.DefaultValue;
36: import javax.ws.rs.GET;
37: import javax.ws.rs.POST;
38: import javax.ws.rs.PUT;
39: import javax.ws.rs.Path;
40: import javax.ws.rs.PathParam;
41: import javax.ws.rs.Produces;
42: import javax.ws.rs.QueryParam;
43: import javax.ws.rs.core.MediaType;
44: import javax.ws.rs.core.Response;
45:
46: @Path("{scopeId}/endpointInfos")
47: public class EndpointInfos extends AbstractKapuaResource {
48:
49: private final KapuaLocator locator = KapuaLocator.getInstance();
50: private final EndpointInfoService endpointInfoService = locator.getService(EndpointInfoService.class);
51: private final EndpointInfoFactory endpointInfoFactory = locator.getFactory(EndpointInfoFactory.class);
52:
53: /**
54: * Gets the {@link EndpointInfo} list in the scope.
55: *
56: * @param scopeId The {@link ScopeId} in which to search results.
57: * @param usage The {@link EndpointInfo} usage to filter results
58: * @param offset The result set offset.
59: * @param limit The result set limit.
60: * @return The {@link EndpointInfoListResult} of all the endpointInfos associated to the current selected scope.
61: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
62: * @since 1.0.0
63: */
64:
65: @GET
66: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
67: public EndpointInfoListResult simpleQuery(
68: @PathParam("scopeId") ScopeId scopeId,
69: @QueryParam("usage") String usage,
70: @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType,
71: @QueryParam("offset") @DefaultValue("0") int offset,
72: @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
73: EndpointInfoQuery query = endpointInfoFactory.newQuery(scopeId);
74:
75: AndPredicate andPredicate = query.andPredicate();
76:• if (!Strings.isNullOrEmpty(usage)) {
77: andPredicate.and(query.attributePredicate(EndpointInfoAttributes.USAGES, endpointInfoFactory.newEndpointUsage(usage)));
78: }
79: query.setPredicate(andPredicate);
80:
81: query.setOffset(offset);
82: query.setLimit(limit);
83:
84: return query(scopeId, endpointType, query);
85: }
86:
87: /**
88: * Queries the results with the given {@link EndpointInfoQuery} parameter.
89: *
90: * @param scopeId The {@link ScopeId} in which to search results.
91: * @param query The {@link EndpointInfoQuery} to use to filter results.
92: * @return The {@link EndpointInfoListResult} of all the result matching the given {@link EndpointInfoQuery} parameter.
93: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
94: * @since 1.0.0
95: */
96:
97: @POST
98: @Path("_query")
99: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
100: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
101: public EndpointInfoListResult query(
102: @PathParam("scopeId") ScopeId scopeId,
103: @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType,
104: EndpointInfoQuery query) throws KapuaException {
105: query.setScopeId(scopeId);
106:
107: return endpointInfoService.query(query, endpointType);
108: }
109:
110: /**
111: * Counts the results with the given {@link EndpointInfoQuery} parameter.
112: *
113: * @param scopeId The {@link ScopeId} in which to search results.
114: * @param query The {@link EndpointInfoQuery} to use to filter results.
115: * @return The count of all the result matching the given {@link EndpointInfoQuery} parameter.
116: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
117: * @since 1.0.0
118: */
119:
120: @POST
121: @Path("_count")
122: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
123: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
124: public CountResult count(
125: @PathParam("scopeId") ScopeId scopeId,
126: @QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType,
127: EndpointInfoQuery query) throws KapuaException {
128: query.setScopeId(scopeId);
129:
130: return new CountResult(endpointInfoService.count(query, endpointType));
131: }
132:
133: /**
134: * Creates a new EndpointInfo based on the information provided in EndpointInfoCreator
135: * parameter.
136: *
137: * @param scopeId The {@link ScopeId} in which to create the {@link EndpointInfo}
138: * @param endpointInfoCreator Provides the information for the new {@link EndpointInfo} to be created.
139: * @return The newly created {@link EndpointInfo} object.
140: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
141: * @since 1.0.0
142: */
143:
144: @POST
145: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
146: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
147: public Response create(
148: @PathParam("scopeId") ScopeId scopeId,
149: EndpointInfoCreator endpointInfoCreator) throws KapuaException {
150: endpointInfoCreator.setScopeId(scopeId);
151:
152: return returnCreated(endpointInfoService.create(endpointInfoCreator));
153: }
154:
155: /**
156: * Returns the EndpointInfo specified by the "endpointInfoId" path parameter.
157: *
158: * @param scopeId The {@link ScopeId} of the requested {@link EndpointInfo}.
159: * @param endpointInfoId The id of the requested EndpointInfo.
160: * @return The requested EndpointInfo object.
161: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
162: * @since 1.0.0
163: */
164:
165: @GET
166: @Path("{endpointInfoId}")
167: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
168: public EndpointInfo find(
169: @PathParam("scopeId") ScopeId scopeId,
170: @PathParam("endpointInfoId") EntityId endpointInfoId) throws KapuaException {
171: EndpointInfo endpointInfo = endpointInfoService.find(scopeId, endpointInfoId);
172:
173:• if (endpointInfo == null) {
174: throw new KapuaEntityNotFoundException(EndpointInfo.TYPE, endpointInfoId);
175: }
176:
177: return endpointInfo;
178: }
179:
180: /**
181: * Updates the EndpointInfo based on the information provided in the EndpointInfo parameter.
182: *
183: * @param scopeId The ScopeId of the requested {@link EndpointInfo}.
184: * @param endpointInfoId The id of the requested {@link EndpointInfo}
185: * @param endpointInfo The modified EndpointInfo whose attributed need to be updated.
186: * @return The updated endpointInfo.
187: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
188: * @since 1.0.0
189: */
190:
191: @PUT
192: @Path("{endpointInfoId}")
193: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
194: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
195: public EndpointInfo update(
196: @PathParam("scopeId") ScopeId scopeId,
197: @PathParam("endpointInfoId") EntityId endpointInfoId,
198: EndpointInfo endpointInfo) throws KapuaException {
199: endpointInfo.setScopeId(scopeId);
200: endpointInfo.setId(endpointInfoId);
201:
202: return endpointInfoService.update(endpointInfo);
203: }
204:
205: /**
206: * Deletes the EndpointInfo specified by the "endpointInfoId" path parameter.
207: *
208: * @param scopeId The ScopeId of the requested {@link EndpointInfo}.
209: * @param endpointInfoId The id of the EndpointInfo to be deleted.
210: * @return HTTP 200 if operation has completed successfully.
211: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
212: * @since 1.0.0
213: */
214:
215: @DELETE
216: @Path("{endpointInfoId}")
217: public Response deleteEndpointInfo(
218: @PathParam("scopeId") ScopeId scopeId,
219: @PathParam("endpointInfoId") EntityId endpointInfoId) throws KapuaException {
220: endpointInfoService.delete(scopeId, endpointInfoId);
221:
222: return returnNoContent();
223: }
224: }