Skip to content

Package: DeviceManagementOperationNotifications

DeviceManagementOperationNotifications

nameinstructionbranchcomplexitylinemethod
DeviceManagementOperationNotifications()
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, EntityId, EntityId, ManagementOperationNotificationQuery)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
deleteManagementOperationNotification(ScopeId, EntityId, EntityId, 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, EntityId, EntityId)
M: 54 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
query(ScopeId, EntityId, EntityId, ManagementOperationNotificationQuery)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
simpleQuery(ScopeId, EntityId, EntityId, String, int, int)
M: 46 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) 2018, 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.KapuaEntityAttributes;
24: import org.eclipse.kapua.model.query.predicate.AndPredicate;
25: import org.eclipse.kapua.service.KapuaService;
26: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotification;
27: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationAttributes;
28: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationFactory;
29: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationListResult;
30: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationQuery;
31: import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationService;
32: import org.eclipse.kapua.service.device.registry.Device;
33:
34: import javax.ws.rs.Consumes;
35: import javax.ws.rs.DELETE;
36: import javax.ws.rs.DefaultValue;
37: import javax.ws.rs.GET;
38: import javax.ws.rs.POST;
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}/devices/{deviceId}/operations/{operationId}/notifications")
47: public class DeviceManagementOperationNotifications extends AbstractKapuaResource {
48:
49: private final KapuaLocator locator = KapuaLocator.getInstance();
50: private final ManagementOperationNotificationService managementOperationNotificationService = locator.getService(ManagementOperationNotificationService.class);
51: private final ManagementOperationNotificationFactory managementOperationNotificationFactory = locator.getFactory(ManagementOperationNotificationFactory.class);
52:
53: /**
54: * Gets the {@link ManagementOperationNotification} list in the scope.
55: *
56: * @param scopeId The {@link ScopeId} in which to search results.
57: * @param operationId The id of the {@link Device} in which to search results
58: * @param resource The resource of the {@link ManagementOperationNotification} in which to search results
59: * @param offset The result set offset.
60: * @param limit The result set limit.
61: * @return The {@link ManagementOperationNotificationListResult} of all the ManagementOperationNotifications associated to the current selected scope.
62: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
63: * @since 1.0.0
64: */
65: @GET
66: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
67: public ManagementOperationNotificationListResult simpleQuery(
68: @PathParam("scopeId") ScopeId scopeId,
69: @PathParam("deviceId") EntityId deviceId,
70: @PathParam("operationId") EntityId operationId,
71: @QueryParam("resource") String resource,
72: @QueryParam("offset") @DefaultValue("0") int offset,
73: @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
74: ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId);
75:
76: AndPredicate andPredicate = query.andPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId));
77:
78:• if (!Strings.isNullOrEmpty(resource)) {
79: andPredicate.and(query.attributePredicate(ManagementOperationNotificationAttributes.RESOURCE, resource));
80: }
81:
82: query.setPredicate(andPredicate);
83:
84: query.setOffset(offset);
85: query.setLimit(limit);
86:
87: return query(scopeId, deviceId, operationId, query);
88: }
89:
90: /**
91: * Queries the results with the given {@link ManagementOperationNotificationQuery} parameter.
92: *
93: * @param scopeId The {@link ScopeId} in which to search results.
94: * @param operationId The id of the {@link Device} in which to search results
95: * @param query The {@link ManagementOperationNotificationQuery} to use to filter results.
96: * @return The {@link ManagementOperationNotificationListResult} of all the result matching the given {@link ManagementOperationNotificationQuery} parameter.
97: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
98: * @since 1.0.0
99: */
100: @POST
101: @Path("_query")
102: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
103: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
104: public ManagementOperationNotificationListResult query(
105: @PathParam("scopeId") ScopeId scopeId,
106: @PathParam("deviceId") EntityId deviceId,
107: @PathParam("operationId") EntityId operationId,
108: ManagementOperationNotificationQuery query) throws KapuaException {
109: query.setScopeId(scopeId);
110:
111: AndPredicate andPredicate = query.andPredicate();
112: andPredicate.and(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId));
113: query.setPredicate(andPredicate);
114:
115: return managementOperationNotificationService.query(query);
116: }
117:
118: /**
119: * Counts the results with the given {@link ManagementOperationNotificationQuery} parameter.
120: *
121: * @param scopeId The {@link ScopeId} in which to search results.
122: * @param operationId The id of the {@link Device} in which to search results
123: * @param query The {@link ManagementOperationNotificationQuery} to use to filter results.
124: * @return The count of all the result matching the given {@link ManagementOperationNotificationQuery} parameter.
125: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
126: * @since 1.0.0
127: */
128: @POST
129: @Path("_count")
130: @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
131: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
132: public CountResult count(
133: @PathParam("scopeId") ScopeId scopeId,
134: @PathParam("deviceId") EntityId deviceId,
135: @PathParam("operationId") EntityId operationId,
136: ManagementOperationNotificationQuery query) throws KapuaException {
137: query.setScopeId(scopeId);
138: query.setPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId));
139:
140: return new CountResult(managementOperationNotificationService.count(query));
141: }
142:
143: /**
144: * Returns the ManagementOperationNotification specified by the "ManagementOperationNotificationId" path parameter.
145: *
146: * @param scopeId The {@link ScopeId} of the requested {@link ManagementOperationNotification}.
147: * @param operationId The {@link Device} id of the request {@link ManagementOperationNotification}.
148: * @param managementOperationNotificationId The id of the requested ManagementOperationNotification.
149: * @return The requested ManagementOperationNotification object.
150: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
151: * @since 1.0.0
152: */
153: @GET
154: @Path("{managementOperationNotificationId}")
155: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
156: public ManagementOperationNotification find(
157: @PathParam("scopeId") ScopeId scopeId,
158: @PathParam("deviceId") EntityId deviceId,
159: @PathParam("operationId") EntityId operationId,
160: @PathParam("managementOperationNotificationId") EntityId managementOperationNotificationId) throws KapuaException {
161: ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId);
162:
163: AndPredicate andPredicate = query.andPredicate(
164: query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId),
165: query.attributePredicate(KapuaEntityAttributes.ENTITY_ID, managementOperationNotificationId)
166: );
167:
168: query.setPredicate(andPredicate);
169: query.setOffset(0);
170: query.setLimit(1);
171:
172: ManagementOperationNotificationListResult results = managementOperationNotificationService.query(query);
173:
174:• if (!results.isEmpty()) {
175: return results.getFirstItem();
176: } else {
177: throw new KapuaEntityNotFoundException(ManagementOperationNotification.TYPE, managementOperationNotificationId);
178: }
179: }
180:
181: /**
182: * Deletes the ManagementOperationNotification specified by the "ManagementOperationNotificationId" path parameter.
183: *
184: * @param operationId The id of the Device in which to delete the ManagementOperation
185: * @param managementOperationNotificationId The id of the ManagementOperationNotification to be deleted.
186: * @return HTTP 200 if operation has completed successfully.
187: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
188: * @since 1.0.0
189: */
190: @DELETE
191: @Path("{managementOperationNotificationId}")
192: public Response deleteManagementOperationNotification(
193: @PathParam("scopeId") ScopeId scopeId,
194: @PathParam("deviceId") EntityId deviceId,
195: @PathParam("operationId") EntityId operationId,
196: @PathParam("managementOperationNotificationId") EntityId managementOperationNotificationId) throws KapuaException {
197: managementOperationNotificationService.delete(scopeId, managementOperationNotificationId);
198:
199: return returnNoContent();
200: }
201: }