Skip to content

Package: DeviceManagementAssets

DeviceManagementAssets

nameinstructionbranchcomplexitylinemethod
DeviceManagementAssets()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
get(ScopeId, EntityId, Long)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
get(ScopeId, EntityId, Long, DeviceAssets)
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%
getSettings(ScopeId, EntityId)
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%
postSettings(ScopeId, EntityId, DeviceAssetStoreSettings)
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%
read(ScopeId, EntityId, Long, DeviceAssets)
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%
write(ScopeId, EntityId, Long, DeviceAssets)
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%

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 org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.app.api.core.model.EntityId;
17: import org.eclipse.kapua.app.api.core.model.ScopeId;
18: import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
19: import org.eclipse.kapua.locator.KapuaLocator;
20: import org.eclipse.kapua.service.KapuaService;
21: import org.eclipse.kapua.service.device.management.asset.DeviceAssetChannel;
22: import org.eclipse.kapua.service.device.management.asset.DeviceAssetFactory;
23: import org.eclipse.kapua.service.device.management.asset.DeviceAssetManagementService;
24: import org.eclipse.kapua.service.device.management.asset.DeviceAssets;
25: import org.eclipse.kapua.service.device.management.asset.store.DeviceAssetStoreService;
26: import org.eclipse.kapua.service.device.management.asset.store.settings.DeviceAssetStoreSettings;
27: import org.eclipse.kapua.service.device.registry.Device;
28:
29: import javax.ws.rs.DefaultValue;
30: import javax.ws.rs.GET;
31: import javax.ws.rs.POST;
32: import javax.ws.rs.PUT;
33: import javax.ws.rs.Path;
34: import javax.ws.rs.PathParam;
35: import javax.ws.rs.Produces;
36: import javax.ws.rs.QueryParam;
37: import javax.ws.rs.core.MediaType;
38: import javax.ws.rs.core.Response;
39:
40: @Path("{scopeId}/devices/{deviceId}/assets")
41: public class DeviceManagementAssets extends AbstractKapuaResource {
42:
43: private final KapuaLocator locator = KapuaLocator.getInstance();
44: private final DeviceAssetManagementService deviceManagementAssetService = locator.getService(DeviceAssetManagementService.class);
45: private final DeviceAssetFactory deviceAssetFilter = locator.getFactory(DeviceAssetFactory.class);
46:
47: private final DeviceAssetStoreService deviceAssetStoreService = locator.getService(DeviceAssetStoreService.class);
48:
49: /**
50: * Returns the list of all the Assets configured on the device.
51: *
52: * @param scopeId The {@link ScopeId} of the {@link Device}.
53: * @param deviceId The id of the device
54: * @param timeout The timeout of the operation in milliseconds
55: * @return The list of Assets
56: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
57: * @since 1.0.0
58: */
59: @GET
60: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
61: public DeviceAssets get(
62: @PathParam("scopeId") ScopeId scopeId,
63: @PathParam("deviceId") EntityId deviceId,
64: @QueryParam("timeout") @DefaultValue("30000") Long timeout) throws KapuaException {
65: return get(scopeId, deviceId, timeout, deviceAssetFilter.newAssetListResult());
66: }
67:
68: /**
69: * Returns the list of all the Assets configured on the device filtered by the {@link DeviceAssets} parameter.
70: *
71: * @param scopeId The {@link ScopeId} of the {@link Device}.
72: * @param deviceId The id of the device
73: * @param timeout The timeout of the operation in milliseconds
74: * @return The list of Assets
75: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
76: * @since 1.0.0
77: */
78: @POST
79: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
80: public DeviceAssets get(
81: @PathParam("scopeId") ScopeId scopeId,
82: @PathParam("deviceId") EntityId deviceId,
83: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
84: DeviceAssets deviceAssetFilter) throws KapuaException {
85: return deviceManagementAssetService.get(scopeId, deviceId, deviceAssetFilter, timeout);
86: }
87:
88: /**
89: * Reads {@link DeviceAssetChannel}s values available on the device filtered by the {@link DeviceAssets} parameter.
90: *
91: * @param scopeId The {@link ScopeId} of the {@link Device}.
92: * @param deviceId The id of the device
93: * @param timeout The timeout of the operation in milliseconds
94: * @return The list of Assets
95: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
96: * @since 1.0.0
97: */
98: @POST
99: @Path("_read")
100: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
101: public DeviceAssets read(
102: @PathParam("scopeId") ScopeId scopeId,
103: @PathParam("deviceId") EntityId deviceId,
104: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
105: DeviceAssets deviceAssetFilter) throws KapuaException {
106: return deviceManagementAssetService.read(scopeId, deviceId, deviceAssetFilter, timeout);
107: }
108:
109: /**
110: * Writes {@link DeviceAssetChannel}s configured on the device filtered by the {@link DeviceAssets} parameter.
111: *
112: * @param scopeId The {@link ScopeId} of the {@link Device}.
113: * @param deviceId The id of the device
114: * @param timeout The timeout of the operation in milliseconds
115: * @return The list of Assets
116: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
117: * @since 1.0.0
118: */
119: @POST
120: @Path("_write")
121: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
122: public DeviceAssets write(
123: @PathParam("scopeId") ScopeId scopeId,
124: @PathParam("deviceId") EntityId deviceId,
125: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
126: DeviceAssets deviceAssetFilter) throws KapuaException {
127: return deviceManagementAssetService.write(scopeId, deviceId, deviceAssetFilter, timeout);
128: }
129:
130: @GET
131: @Path("_settings")
132: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
133: public DeviceAssetStoreSettings getSettings(
134: @PathParam("scopeId") ScopeId scopeId,
135: @PathParam("deviceId") EntityId deviceId)
136: throws KapuaException {
137: return deviceAssetStoreService.getApplicationSettings(scopeId, deviceId);
138: }
139:
140: @PUT
141: @Path("_settings")
142: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
143: public Response postSettings(
144: @PathParam("scopeId") ScopeId scopeId,
145: @PathParam("deviceId") EntityId deviceId,
146: DeviceAssetStoreSettings deviceAssetStoreSettings) throws KapuaException {
147: deviceAssetStoreService.setApplicationSettings(scopeId, deviceId, deviceAssetStoreSettings);
148:
149: return returnNoContent();
150: }
151:
152: }