Skip to content

Package: DeviceManagementPackages

DeviceManagementPackages

nameinstructionbranchcomplexitylinemethod
DeviceManagementPackages()
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%
download(ScopeId, EntityId, Long, boolean, DevicePackageDownloadRequest)
M: 34 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 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%
static {...}
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%
uninstall(ScopeId, EntityId, Long, boolean, DevicePackageUninstallRequest)
M: 34 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 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.app.api.core.settings.KapuaApiCoreSetting;
20: import org.eclipse.kapua.app.api.core.settings.KapuaApiCoreSettingKeys;
21: import org.eclipse.kapua.locator.KapuaLocator;
22: import org.eclipse.kapua.model.id.KapuaId;
23: import org.eclipse.kapua.service.KapuaService;
24: import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory;
25: import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService;
26: import org.eclipse.kapua.service.device.management.packages.model.DevicePackages;
27: import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions;
28: import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest;
29: import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions;
30: import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest;
31: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperation;
32: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationRegistryService;
33: import org.eclipse.kapua.service.device.registry.Device;
34:
35: import javax.ws.rs.DefaultValue;
36: import javax.ws.rs.GET;
37: import javax.ws.rs.POST;
38: import javax.ws.rs.Path;
39: import javax.ws.rs.PathParam;
40: import javax.ws.rs.Produces;
41: import javax.ws.rs.QueryParam;
42: import javax.ws.rs.core.MediaType;
43: import javax.ws.rs.core.Response;
44:
45: @Path("{scopeId}/devices/{deviceId}/packages")
46: public class DeviceManagementPackages extends AbstractKapuaResource {
47:
48: private static final Boolean RESPONSE_LEGACY_MODE = KapuaApiCoreSetting.getInstance().getBoolean(KapuaApiCoreSettingKeys.API_DEVICE_MANAGEMENT_PACKAGE_RESPONSE_LEGACY_MODE, false);
49:
50: private final KapuaLocator locator = KapuaLocator.getInstance();
51:
52: private final DevicePackageManagementService devicePackageManagementService = locator.getService(DevicePackageManagementService.class);
53: private final DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class);
54:
55: /**
56: * Returns the list of all the packages installed on the device.
57: *
58: * @param scopeId The {@link ScopeId} in which to search results.
59: * @param deviceId The id of the device
60: * @param timeout The timeout of the operation
61: * @return The list of packages installed.
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 DevicePackages get(
68: @PathParam("scopeId") ScopeId scopeId,
69: @PathParam("deviceId") EntityId deviceId,
70: @QueryParam("timeout") @DefaultValue("30000") Long timeout) throws KapuaException {
71: return devicePackageManagementService.getInstalled(scopeId, deviceId, timeout);
72: }
73:
74: private final DeviceManagementOperationRegistryService deviceManagementOperationRegistryService = locator.getService(DeviceManagementOperationRegistryService.class);
75:
76: /**
77: * Download and optionally installs a package into the device.
78: *
79: * @param scopeId The {@link ScopeId} in which to search results.
80: * @param deviceId The {@link Device} ID.
81: * @param timeout The timeout of the operation
82: * @param packageDownloadRequest Mandatory object with all the informations needed to download and install a package
83: * @return HTTP 200 if operation has completed successfully.
84: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
85: * @since 1.0.0
86: */
87: @POST
88: @Path("_download")
89: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
90: public Response download(
91: @PathParam("scopeId") ScopeId scopeId,
92: @PathParam("deviceId") EntityId deviceId,
93: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
94: @QueryParam("legacy") @DefaultValue("false") boolean legacy,
95: DevicePackageDownloadRequest packageDownloadRequest)
96: throws KapuaException {
97: DevicePackageDownloadOptions options = devicePackageFactory.newPackageDownloadOptions();
98: options.setTimeout(timeout);
99:
100: KapuaId deviceManagementOperationId = devicePackageManagementService.downloadExec(scopeId, deviceId, packageDownloadRequest, options);
101:
102: DeviceManagementOperation deviceManagementOperation = deviceManagementOperationRegistryService.find(scopeId, deviceManagementOperationId);
103:
104:• return RESPONSE_LEGACY_MODE || legacy ? returnNoContent() : returnOk(deviceManagementOperation);
105: }
106:
107: /**
108: * Uninstalls a package into the device.
109: *
110: * @param scopeId The {@link ScopeId} in which to search results.
111: * @param deviceId The {@link Device} ID.
112: * @param timeout The timeout of the operation
113: * @param packageUninstallRequest Mandatory object with all the informations needed to uninstall a package
114: * @return HTTP 200 if operation has completed successfully.
115: * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
116: * @since 1.0.0
117: */
118: @POST
119: @Path("_uninstall")
120: @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
121: public Response uninstall(
122: @PathParam("scopeId") ScopeId scopeId,
123: @PathParam("deviceId") EntityId deviceId,
124: @QueryParam("timeout") @DefaultValue("30000") Long timeout,
125: @QueryParam("legacy") @DefaultValue("false") boolean legacy,
126: DevicePackageUninstallRequest packageUninstallRequest) throws KapuaException {
127: DevicePackageUninstallOptions options = devicePackageFactory.newPackageUninstallOptions();
128: options.setTimeout(timeout);
129:
130: KapuaId deviceManagementOperationId = devicePackageManagementService.uninstallExec(scopeId, deviceId, packageUninstallRequest, options);
131:
132: DeviceManagementOperation deviceManagementOperation = deviceManagementOperationRegistryService.find(scopeId, deviceManagementOperationId);
133:
134:• return RESPONSE_LEGACY_MODE || legacy? returnNoContent() : returnOk(deviceManagementOperation);
135: }
136:
137: }