Skip to content

Package: DeviceConnectionOptions

DeviceConnectionOptions

nameinstructionbranchcomplexitylinemethod
DeviceConnectionOptions()
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%
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%
update(ScopeId, EntityId, DeviceConnectionOption)
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) 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 javax.ws.rs.GET;
16: import javax.ws.rs.PUT;
17: import javax.ws.rs.Path;
18: import javax.ws.rs.PathParam;
19: import javax.ws.rs.Produces;
20: import javax.ws.rs.core.MediaType;
21:
22: import org.eclipse.kapua.KapuaEntityNotFoundException;
23: import org.eclipse.kapua.KapuaException;
24: import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
25: import org.eclipse.kapua.app.api.core.model.EntityId;
26: import org.eclipse.kapua.app.api.core.model.ScopeId;
27: import org.eclipse.kapua.locator.KapuaLocator;
28: import org.eclipse.kapua.service.KapuaService;
29: import org.eclipse.kapua.service.device.registry.connection.DeviceConnection;
30: import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOption;
31: import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionService;
32:
33: @Path("{scopeId}/deviceconnections/{connectionId}/options")
34: public class DeviceConnectionOptions extends AbstractKapuaResource {
35:
36: private final KapuaLocator locator = KapuaLocator.getInstance();
37: private final DeviceConnectionOptionService deviceConnectionOptionsService = locator.getService(DeviceConnectionOptionService.class);
38:
39: /**
40: * Returns the {@link DeviceConnectionOption} specified by the given parameters.
41: *
42: * @param scopeId
43: * The {@link ScopeId} of the requested {@link DeviceConnectionOption}.
44: * @param connectionId
45: * The {@link DeviceConnectionOption} id of the request
46: * {@link DeviceConnectionOption}.
47: * @return The requested {@link DeviceConnectionOption} object.
48: * @throws KapuaException
49: * Whenever something bad happens. See specific {@link KapuaService} exceptions.
50: * @since 1.0.0
51: */
52: @GET
53: @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
54: public DeviceConnectionOption find(
55: @PathParam("scopeId") ScopeId scopeId,
56: @PathParam("connectionId") EntityId connectionId) throws KapuaException {
57: DeviceConnectionOption deviceConnectionOptions = deviceConnectionOptionsService.find(scopeId, connectionId);
58:
59:• if (deviceConnectionOptions != null) {
60: return deviceConnectionOptions;
61: } else {
62: throw new KapuaEntityNotFoundException(DeviceConnectionOption.TYPE, connectionId);
63: }
64:
65: }
66:
67: /**
68: * Returns the DeviceConnection specified by the "deviceConnectionId" path parameter.
69: *
70: * @param scopeId
71: * The {@link ScopeId} of the requested {@link DeviceConnection}.
72: * @param deviceConnectionId
73: * The id of the requested DeviceConnection.
74: * @return The requested DeviceConnection object.
75: * @throws KapuaException
76: * Whenever something bad happens. See specific {@link KapuaService} exceptions.
77: * @since 1.0.0
78: */
79: @PUT
80: @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
81: public DeviceConnectionOption update(
82: @PathParam("scopeId") ScopeId scopeId,
83: @PathParam("connectionId") EntityId deviceConnectionId,
84: DeviceConnectionOption deviceConnectionOptions)
85: throws KapuaException {
86:
87: deviceConnectionOptions.setScopeId(scopeId);
88: deviceConnectionOptions.setId(deviceConnectionId);
89:
90: return deviceConnectionOptionsService.update(deviceConnectionOptions);
91: }
92:
93: }