Skip to content

Package: DeviceInventoryManagementServiceImpl$2

DeviceInventoryManagementServiceImpl$2

nameinstructionbranchcomplexitylinemethod
getResponseClass()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 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) 2021, 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.service.device.management.inventory.internal;
14:
15: import org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.KapuaIllegalArgumentException;
17: import org.eclipse.kapua.commons.util.ArgumentValidator;
18: import org.eclipse.kapua.locator.KapuaProvider;
19: import org.eclipse.kapua.model.domain.Actions;
20: import org.eclipse.kapua.model.id.KapuaId;
21: import org.eclipse.kapua.service.device.management.DeviceManagementDomains;
22: import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementServiceImpl;
23: import org.eclipse.kapua.service.device.management.commons.call.DeviceCallBuilder;
24: import org.eclipse.kapua.service.device.management.exception.DeviceManagementRequestContentException;
25: import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementService;
26: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryBundleExecRequestMessage;
27: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryBundlesResponseMessage;
28: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryContainerExecRequestMessage;
29: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryContainersResponseMessage;
30: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryEmptyRequestMessage;
31: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryListResponseMessage;
32: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryNoContentResponseMessage;
33: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryPackagesResponseMessage;
34: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryRequestChannel;
35: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryRequestPayload;
36: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventorySystemPackagesResponseMessage;
37: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundle;
38: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundleAction;
39: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundles;
40: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
41: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainerAction;
42: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainers;
43: import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventory;
44: import org.eclipse.kapua.service.device.management.inventory.model.packages.DeviceInventoryPackages;
45: import org.eclipse.kapua.service.device.management.inventory.model.system.DeviceInventorySystemPackages;
46: import org.eclipse.kapua.service.device.management.message.KapuaMethod;
47: import org.slf4j.Logger;
48: import org.slf4j.LoggerFactory;
49:
50: import java.util.Date;
51:
52: /**
53: * {@link DeviceInventoryManagementService} implementation.
54: *
55: * @since 1.5.0
56: */
57: @KapuaProvider
58: public class DeviceInventoryManagementServiceImpl extends AbstractDeviceManagementServiceImpl implements DeviceInventoryManagementService {
59:
60: private static final Logger LOG = LoggerFactory.getLogger(DeviceInventoryManagementServiceImpl.class);
61:
62: private static final String SCOPE_ID = "scopeId";
63: private static final String DEVICE_ID = "deviceId";
64:
65: @Override
66: public DeviceInventory getInventory(KapuaId scopeId, KapuaId deviceId, Long timeout)
67: throws KapuaException {
68: //
69: // Argument Validation
70: ArgumentValidator.notNull(scopeId, SCOPE_ID);
71: ArgumentValidator.notNull(deviceId, DEVICE_ID);
72:
73: //
74: // Check Access
75: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId));
76:
77: //
78: // Prepare the request
79: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
80: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
81: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
82: inventoryRequestChannel.setMethod(KapuaMethod.READ);
83: inventoryRequestChannel.setResource("inventory");
84:
85: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
86:
87: InventoryEmptyRequestMessage inventoryRequestMessage = new InventoryEmptyRequestMessage() {
88: @Override
89: public Class<InventoryListResponseMessage> getResponseClass() {
90: return InventoryListResponseMessage.class;
91: }
92: };
93:
94: inventoryRequestMessage.setScopeId(scopeId);
95: inventoryRequestMessage.setDeviceId(deviceId);
96: inventoryRequestMessage.setCapturedOn(new Date());
97: inventoryRequestMessage.setPayload(inventoryRequestPayload);
98: inventoryRequestMessage.setChannel(inventoryRequestChannel);
99:
100: //
101: // Build request
102: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryEmptyRequestMessage, InventoryListResponseMessage> inventoryDeviceCallBuilder =
103: DeviceCallBuilder
104: .newBuilder()
105: .withRequestMessage(inventoryRequestMessage)
106: .withTimeoutOrDefault(timeout);
107:
108: //
109: // Do get
110: InventoryListResponseMessage responseMessage;
111: try {
112: responseMessage = inventoryDeviceCallBuilder.send();
113: } catch (Exception e) {
114: LOG.error("Error while getting DeviceInventory for Device {}. Error: {}", deviceId, e.getMessage(), e);
115: throw e;
116: }
117:
118: //
119: // Create event
120: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
121:
122: //
123: // Check response
124: return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().getDeviceInventory());
125: }
126:
127: @Override
128: public DeviceInventoryBundles getBundles(KapuaId scopeId, KapuaId deviceId, Long timeout)
129: throws KapuaException {
130: //
131: // Argument Validation
132: ArgumentValidator.notNull(scopeId, SCOPE_ID);
133: ArgumentValidator.notNull(deviceId, DEVICE_ID);
134:
135: //
136: // Check Access
137: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId));
138:
139: //
140: // Prepare the request
141: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
142: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
143: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
144: inventoryRequestChannel.setMethod(KapuaMethod.READ);
145: inventoryRequestChannel.setResource("bundles");
146:
147: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
148:
149: InventoryEmptyRequestMessage inventoryRequestMessage = new InventoryEmptyRequestMessage() {
150: @Override
151: public Class<InventoryBundlesResponseMessage> getResponseClass() {
152: return InventoryBundlesResponseMessage.class;
153: }
154: };
155:
156: inventoryRequestMessage.setScopeId(scopeId);
157: inventoryRequestMessage.setDeviceId(deviceId);
158: inventoryRequestMessage.setCapturedOn(new Date());
159: inventoryRequestMessage.setPayload(inventoryRequestPayload);
160: inventoryRequestMessage.setChannel(inventoryRequestChannel);
161:
162: //
163: // Build request
164: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryEmptyRequestMessage, InventoryBundlesResponseMessage> inventoryDeviceCallBuilder =
165: DeviceCallBuilder
166: .newBuilder()
167: .withRequestMessage(inventoryRequestMessage)
168: .withTimeoutOrDefault(timeout);
169:
170: //
171: // Do get
172: InventoryBundlesResponseMessage responseMessage;
173: try {
174: responseMessage = inventoryDeviceCallBuilder.send();
175: } catch (Exception e) {
176: LOG.error("Error while getting DeviceInventoryBundles for Device {}. Error: {}", deviceId, e.getMessage(), e);
177: throw e;
178: }
179:
180: //
181: // Create event
182: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
183:
184: //
185: // Check response
186: return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().getDeviceInventoryBundles());
187: }
188:
189: @Override
190: public void execBundle(KapuaId scopeId, KapuaId deviceId, DeviceInventoryBundle deviceInventoryBundle, DeviceInventoryBundleAction deviceInventoryBundleAction, Long timeout) throws KapuaException {
191: //
192: // Argument Validation
193: ArgumentValidator.notNull(scopeId, SCOPE_ID);
194: ArgumentValidator.notNull(deviceId, DEVICE_ID);
195: ArgumentValidator.notNull(deviceInventoryBundle, "deviceInventoryBundle");
196: ArgumentValidator.notNull(deviceInventoryBundle.getId(), "deviceInventoryBundle.id");
197: ArgumentValidator.notNull(deviceInventoryBundle.getName(), "deviceInventoryBundle.name");
198: ArgumentValidator.notNull(deviceInventoryBundleAction, "deviceInventoryBundleAction");
199:
200: performAdditionalValidationOnDeviceInventoryBundleId(deviceInventoryBundle.getId());
201:
202: //
203: // Check Access
204: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId));
205:
206: //
207: // Prepare the request
208: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
209: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
210: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
211: inventoryRequestChannel.setMethod(KapuaMethod.EXECUTE);
212: inventoryRequestChannel.setResource("bundles");
213: inventoryRequestChannel.setBundleAction(deviceInventoryBundleAction);
214:
215: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
216: try {
217: inventoryRequestPayload.setDeviceInventoryBundle(deviceInventoryBundle);
218: } catch (Exception e) {
219: throw new DeviceManagementRequestContentException(e, deviceInventoryBundle);
220: }
221:
222: InventoryBundleExecRequestMessage inventoryRequestMessage = new InventoryBundleExecRequestMessage() {
223: @Override
224: public Class<InventoryNoContentResponseMessage> getResponseClass() {
225: return InventoryNoContentResponseMessage.class;
226: }
227: };
228:
229: inventoryRequestMessage.setScopeId(scopeId);
230: inventoryRequestMessage.setDeviceId(deviceId);
231: inventoryRequestMessage.setCapturedOn(new Date());
232: inventoryRequestMessage.setPayload(inventoryRequestPayload);
233: inventoryRequestMessage.setChannel(inventoryRequestChannel);
234:
235: //
236: // Build request
237: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryBundleExecRequestMessage, InventoryNoContentResponseMessage> inventoryDeviceCallBuilder =
238: DeviceCallBuilder
239: .newBuilder()
240: .withRequestMessage(inventoryRequestMessage)
241: .withTimeoutOrDefault(timeout);
242:
243: //
244: // Do exec
245: InventoryNoContentResponseMessage responseMessage;
246: try {
247: responseMessage = inventoryDeviceCallBuilder.send();
248: } catch (Exception e) {
249: LOG.error("Error while executing {} on DeviceInventoryBundle {} for Device {}. Error: {}", deviceInventoryBundleAction, deviceInventoryBundle.getName(), deviceId, e.getMessage(), e);
250: throw e;
251: }
252:
253: //
254: // Create event
255: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
256:
257: //
258: // Check response
259: checkResponseAcceptedOrThrowError(responseMessage);
260: }
261:
262: @Override
263: public DeviceInventoryContainers getContainers(KapuaId scopeId, KapuaId deviceId, Long timeout)
264: throws KapuaException {
265: //
266: // Argument Validation
267: ArgumentValidator.notNull(scopeId, SCOPE_ID);
268: ArgumentValidator.notNull(deviceId, DEVICE_ID);
269:
270: //
271: // Check Access
272: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId));
273:
274: //
275: // Prepare the request
276: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
277: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
278: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
279: inventoryRequestChannel.setMethod(KapuaMethod.READ);
280: inventoryRequestChannel.setResource("containers");
281:
282: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
283:
284: InventoryEmptyRequestMessage inventoryRequestMessage = new InventoryEmptyRequestMessage() {
285: @Override
286: public Class<InventoryContainersResponseMessage> getResponseClass() {
287: return InventoryContainersResponseMessage.class;
288: }
289: };
290:
291: inventoryRequestMessage.setScopeId(scopeId);
292: inventoryRequestMessage.setDeviceId(deviceId);
293: inventoryRequestMessage.setCapturedOn(new Date());
294: inventoryRequestMessage.setPayload(inventoryRequestPayload);
295: inventoryRequestMessage.setChannel(inventoryRequestChannel);
296:
297: //
298: // Build request
299: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryEmptyRequestMessage, InventoryContainersResponseMessage> inventoryDeviceCallBuilder =
300: DeviceCallBuilder
301: .newBuilder()
302: .withRequestMessage(inventoryRequestMessage)
303: .withTimeoutOrDefault(timeout);
304:
305: //
306: // Do get
307: InventoryContainersResponseMessage responseMessage;
308: try {
309: responseMessage = inventoryDeviceCallBuilder.send();
310: } catch (Exception e) {
311: LOG.error("Error while getting DeviceInventoryContainers {} for Device {}. Error: {}", deviceId, e.getMessage(), e);
312: throw e;
313: }
314:
315: //
316: // Create event
317: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
318:
319: //
320: // Check response
321: return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().getDeviceInventoryContainers());
322: }
323:
324: @Override
325: public void execContainer(KapuaId scopeId, KapuaId deviceId, DeviceInventoryContainer deviceInventoryContainer, DeviceInventoryContainerAction deviceInventoryContainerAction, Long timeout) throws KapuaException {
326: //
327: // Argument Validation
328: ArgumentValidator.notNull(scopeId, SCOPE_ID);
329: ArgumentValidator.notNull(deviceId, DEVICE_ID);
330: ArgumentValidator.notNull(deviceInventoryContainer, "deviceInventoryContainer");
331: ArgumentValidator.notNull(deviceInventoryContainer.getName(), "deviceInventoryContainer.name");
332: ArgumentValidator.notNull(deviceInventoryContainer.getVersion(), "deviceInventoryContainer.version");
333: ArgumentValidator.notNull(deviceInventoryContainerAction, "deviceInventoryContainerAction");
334:
335: //
336: // Check Access
337: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId));
338:
339: //
340: // Prepare the request
341: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
342: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
343: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
344: inventoryRequestChannel.setMethod(KapuaMethod.EXECUTE);
345: inventoryRequestChannel.setResource("containers");
346: inventoryRequestChannel.setContainerAction(deviceInventoryContainerAction);
347:
348: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
349: try {
350: inventoryRequestPayload.setDeviceInventoryContainer(deviceInventoryContainer);
351: } catch (Exception e) {
352: throw new DeviceManagementRequestContentException(e, deviceInventoryContainer);
353: }
354:
355: InventoryContainerExecRequestMessage inventoryRequestMessage = new InventoryContainerExecRequestMessage() {
356: @Override
357: public Class<InventoryNoContentResponseMessage> getResponseClass() {
358: return InventoryNoContentResponseMessage.class;
359: }
360: };
361:
362: inventoryRequestMessage.setScopeId(scopeId);
363: inventoryRequestMessage.setDeviceId(deviceId);
364: inventoryRequestMessage.setCapturedOn(new Date());
365: inventoryRequestMessage.setPayload(inventoryRequestPayload);
366: inventoryRequestMessage.setChannel(inventoryRequestChannel);
367:
368: //
369: // Build request
370: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryContainerExecRequestMessage, InventoryNoContentResponseMessage> inventoryDeviceCallBuilder =
371: DeviceCallBuilder
372: .newBuilder()
373: .withRequestMessage(inventoryRequestMessage)
374: .withTimeoutOrDefault(timeout);
375:
376: //
377: // Do exec
378: InventoryNoContentResponseMessage responseMessage;
379: try {
380: responseMessage = inventoryDeviceCallBuilder.send();
381: } catch (Exception e) {
382: LOG.error("Error while executing {} on DeviceInventoryContainer {}:{} for Device {}. Error: {}", deviceInventoryContainerAction, deviceInventoryContainer.getName(), deviceInventoryContainer.getVersion(), deviceId, e.getMessage(), e);
383: throw e;
384: }
385:
386: //
387: // Create event
388: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
389:
390: //
391: // Check response
392: checkResponseAcceptedOrThrowError(responseMessage);
393: }
394:
395: @Override
396: public DeviceInventorySystemPackages getSystemPackages(KapuaId scopeId, KapuaId deviceId, Long timeout)
397: throws KapuaException {
398: //
399: // Argument Validation
400: ArgumentValidator.notNull(scopeId, SCOPE_ID);
401: ArgumentValidator.notNull(deviceId, DEVICE_ID);
402:
403: //
404: // Check Access
405: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId));
406:
407: //
408: // Prepare the request
409: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
410: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
411: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
412: inventoryRequestChannel.setMethod(KapuaMethod.READ);
413: inventoryRequestChannel.setResource("systemPackages");
414:
415: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
416:
417: InventoryEmptyRequestMessage inventoryRequestMessage = new InventoryEmptyRequestMessage() {
418: @Override
419: public Class<InventorySystemPackagesResponseMessage> getResponseClass() {
420: return InventorySystemPackagesResponseMessage.class;
421: }
422: };
423:
424: inventoryRequestMessage.setScopeId(scopeId);
425: inventoryRequestMessage.setDeviceId(deviceId);
426: inventoryRequestMessage.setCapturedOn(new Date());
427: inventoryRequestMessage.setPayload(inventoryRequestPayload);
428: inventoryRequestMessage.setChannel(inventoryRequestChannel);
429:
430: //
431: // Build request
432: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryEmptyRequestMessage, InventorySystemPackagesResponseMessage> inventoryDeviceCallBuilder =
433: DeviceCallBuilder
434: .newBuilder()
435: .withRequestMessage(inventoryRequestMessage)
436: .withTimeoutOrDefault(timeout);
437:
438: //
439: // Do get
440: InventorySystemPackagesResponseMessage responseMessage;
441: try {
442: responseMessage = inventoryDeviceCallBuilder.send();
443: } catch (Exception e) {
444: LOG.error("Error while getting DeviceInventorySystemPackages for Device {}. Error: {}", deviceId, e.getMessage(), e);
445: throw e;
446: }
447:
448: //
449: // Create event
450: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
451:
452: //
453: // Check response
454: return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().getDeviceInventorySystemPackages());
455: }
456:
457: @Override
458: public DeviceInventoryPackages getDeploymentPackages(KapuaId scopeId, KapuaId deviceId, Long timeout)
459: throws KapuaException {
460: //
461: // Argument Validation
462: ArgumentValidator.notNull(scopeId, SCOPE_ID);
463: ArgumentValidator.notNull(deviceId, DEVICE_ID);
464:
465: //
466: // Check Access
467: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId));
468:
469: //
470: // Prepare the request
471: InventoryRequestChannel inventoryRequestChannel = new InventoryRequestChannel();
472: inventoryRequestChannel.setAppName(DeviceInventoryAppProperties.APP_NAME);
473: inventoryRequestChannel.setVersion(DeviceInventoryAppProperties.APP_VERSION);
474: inventoryRequestChannel.setMethod(KapuaMethod.READ);
475: inventoryRequestChannel.setResource("deploymentPackages");
476:
477: InventoryRequestPayload inventoryRequestPayload = new InventoryRequestPayload();
478:
479: InventoryEmptyRequestMessage inventoryRequestMessage = new InventoryEmptyRequestMessage() {
480: @Override
481: public Class<InventoryPackagesResponseMessage> getResponseClass() {
482: return InventoryPackagesResponseMessage.class;
483: }
484: };
485:
486: inventoryRequestMessage.setScopeId(scopeId);
487: inventoryRequestMessage.setDeviceId(deviceId);
488: inventoryRequestMessage.setCapturedOn(new Date());
489: inventoryRequestMessage.setPayload(inventoryRequestPayload);
490: inventoryRequestMessage.setChannel(inventoryRequestChannel);
491:
492: //
493: // Build request
494: DeviceCallBuilder<InventoryRequestChannel, InventoryRequestPayload, InventoryEmptyRequestMessage, InventoryPackagesResponseMessage> inventoryDeviceCallBuilder =
495: DeviceCallBuilder
496: .newBuilder()
497: .withRequestMessage(inventoryRequestMessage)
498: .withTimeoutOrDefault(timeout);
499:
500: //
501: // Do get
502: InventoryPackagesResponseMessage responseMessage;
503: try {
504: responseMessage = inventoryDeviceCallBuilder.send();
505: } catch (Exception e) {
506: LOG.error("Error while getting DeviceInventoryPackages for Device {}. Error: {}", deviceId, e.getMessage(), e);
507: throw e;
508: }
509:
510: //
511: // Create event
512: createDeviceEvent(scopeId, deviceId, inventoryRequestMessage, responseMessage);
513:
514: //
515: // Check response
516: return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().getDeviceInventoryPackages());
517: }
518:
519:
520: /**
521: * Performs an additional check on {@link DeviceInventoryBundle#getId()} to verify that it can be converted to a {@link Integer}.
522: * <p>
523: * This check is required because initially the property was created as a {@link String} even if in Kura it is a {@link Integer}.
524: * See Kura documentation on Device Inventory Bundle <a href="https://eclipse.github.io/kura/docs-release-5.4/administration/system-component-inventory/">here</a>
525: * <p>
526: * We cannot change the type of {@link DeviceInventoryBundle#getId()} from {@link String} to {@link Integer} because it would be an API breaking change.
527: * We can add a validation to improve the error returned in case a non-integer value is provided, since the current error returned is {@link NumberFormatException} (at line
528: * TranslatorAppInventoryBundleExecKapuaKura:74).
529: *
530: * @param deviceInventoryBundleId The {@link DeviceInventoryBundle#getId()} to check
531: * @throws KapuaIllegalArgumentException If {@link DeviceInventoryBundle#getId()} cannot be converted to a {@link Integer}.
532: * @since 2.0.0
533: */
534: private void performAdditionalValidationOnDeviceInventoryBundleId(String deviceInventoryBundleId) throws KapuaIllegalArgumentException {
535: try {
536: Integer.parseInt(deviceInventoryBundleId);
537: } catch (NumberFormatException nfe) {
538: throw new KapuaIllegalArgumentException("deviceInventoryBundle.id", deviceInventoryBundleId);
539: }
540: }
541:
542: }