Skip to content

Package: DeviceManagementConfigurations

DeviceManagementConfigurations

nameinstructionbranchcomplexitylinemethod
DeviceManagementConfigurations()
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%
get(ScopeId, EntityId, Long)
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%
getComponent(ScopeId, EntityId, String, 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%
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, DeviceConfigurationStoreSettings)
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%
update(ScopeId, EntityId, Long, DeviceConfiguration)
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%
updateComponent(ScopeId, EntityId, String, Long, DeviceComponentConfiguration)
M: 13 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) 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.configuration.DeviceComponentConfiguration;
22: import org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration;
23: import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationManagementService;
24: import org.eclipse.kapua.service.device.management.configuration.store.DeviceConfigurationStoreService;
25: import org.eclipse.kapua.service.device.management.configuration.store.settings.DeviceConfigurationStoreSettings;
26: import org.eclipse.kapua.service.device.registry.Device;
27:
28: import javax.ws.rs.Consumes;
29: import javax.ws.rs.DefaultValue;
30: import javax.ws.rs.GET;
31: import javax.ws.rs.PUT;
32: import javax.ws.rs.Path;
33: import javax.ws.rs.PathParam;
34: import javax.ws.rs.Produces;
35: import javax.ws.rs.QueryParam;
36: import javax.ws.rs.core.MediaType;
37: import javax.ws.rs.core.Response;
38:
39: @Path("{scopeId}/devices/{deviceId}/configurations")
40: public class DeviceManagementConfigurations extends AbstractKapuaResource {
41:
42: private final KapuaLocator locator = KapuaLocator.getInstance();
43: private final DeviceConfigurationManagementService configurationService = locator.getService(DeviceConfigurationManagementService.class);
44:
45: private final DeviceConfigurationStoreService deviceConfigurationStoreService = locator.getService(DeviceConfigurationStoreService.class);
46:
47: /**
48: * Returns the current configuration of the device.
49: *
50: * @param scopeId The {@link ScopeId} of the {@link Device}.
51: * @param deviceId The id of the device
52: * @param timeout The timeout of the operation in milliseconds
53: * @return The requested configurations
54: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
55: * @since 1.0.0
56: */
57: @GET
58: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
59: public DeviceConfiguration get(
60: @PathParam("scopeId") ScopeId scopeId,
61: @PathParam("deviceId") EntityId deviceId,
62: @QueryParam("timeout") @DefaultValue("30000") Long timeout) throws KapuaException {
63: return getComponent(scopeId, deviceId, null, timeout);
64: }
65:
66: /**
67: * Updates the configuration of a {@link Device}
68: *
69: * @param scopeId The {@link ScopeId} of the {@link Device}.
70: * @param deviceId The id of the device
71: * @param timeout The timeout of the operation in milliseconds
72: * @param deviceConfiguration The configuration to send to the {@link Device}
73: * @return The {@link Response} of the operation
74: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
75: * @since 1.0.0
76: */
77: @PUT
78: @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
79: public Response update(
80: @PathParam("scopeId") ScopeId scopeId,
81: @PathParam("deviceId") EntityId deviceId,
82: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
83: DeviceConfiguration deviceConfiguration) throws KapuaException {
84: configurationService.put(scopeId, deviceId, deviceConfiguration, timeout);
85:
86: return returnNoContent();
87: }
88:
89: /**
90: * Returns the configuration of a device or the configuration of the OSGi component
91: * identified with specified PID (service's persistent identity).
92: * In the OSGi framework, the service's persistent identity is defined as the name attribute of the
93: * Component Descriptor XML file; at runtime, the same value is also available
94: * in the component.name and in the service.pid attributes of the Component Configuration.
95: *
96: * @param scopeId The {@link ScopeId} of the {@link Device}.
97: * @param deviceId The id of the device
98: * @param componentId An optional id of the component to get the configuration for
99: * @param timeout The timeout of the operation in milliseconds
100: * @return The requested configurations
101: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
102: * @since 1.0.0
103: */
104: @GET
105: @Path("{componentId}")
106: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
107: public DeviceConfiguration getComponent(
108: @PathParam("scopeId") ScopeId scopeId,
109: @PathParam("deviceId") EntityId deviceId,
110: @PathParam("componentId") String componentId,
111: @QueryParam("timeout") @DefaultValue("30000") Long timeout) throws KapuaException {
112: return configurationService.get(scopeId, deviceId, null, componentId, timeout);
113: }
114:
115: /**
116: * Updates the configuration of the OSGi component
117: * identified with specified PID (service's persistent identity).
118: * In the OSGi framework, the service's persistent identity is defined as the name attribute of the
119: * Component Descriptor XML file; at runtime, the same value is also available
120: * in the component.name and in the service.pid attributes of the Component Configuration.
121: *
122: * @param scopeId The {@link ScopeId} of the {@link Device}.
123: * @param deviceId The id of the device
124: * @param componentId An optional id of the component to get the configuration for
125: * @param timeout The timeout of the operation in milliseconds
126: * @param deviceComponentConfiguration The component configuration to send to the {@link Device}
127: * @return The requested configurations
128: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
129: * @since 1.0.0
130: */
131: @PUT
132: @Path("{componentId}")
133: @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
134: public Response updateComponent(
135: @PathParam("scopeId") ScopeId scopeId,
136: @PathParam("deviceId") EntityId deviceId,
137: @PathParam("componentId") String componentId,
138: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
139: DeviceComponentConfiguration deviceComponentConfiguration) throws KapuaException {
140: deviceComponentConfiguration.setId(componentId);
141:
142: configurationService.put(scopeId, deviceId, deviceComponentConfiguration, timeout);
143:
144: return returnNoContent();
145: }
146:
147: @GET
148: @Path("_settings")
149: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
150: public DeviceConfigurationStoreSettings getSettings(
151: @PathParam("scopeId") ScopeId scopeId,
152: @PathParam("deviceId") EntityId deviceId)
153: throws KapuaException {
154: return deviceConfigurationStoreService.getApplicationSettings(scopeId, deviceId);
155: }
156:
157: @PUT
158: @Path("_settings")
159: @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
160: public Response postSettings(
161: @PathParam("scopeId") ScopeId scopeId,
162: @PathParam("deviceId") EntityId deviceId,
163: DeviceConfigurationStoreSettings deviceConfigurationStoreSettings) throws KapuaException {
164: deviceConfigurationStoreService.setApplicationSettings(scopeId, deviceId, deviceConfigurationStoreSettings);
165: return returnNoContent();
166: }
167:
168: }