Skip to content

Package: InventoryRequestPayload

InventoryRequestPayload

nameinstructionbranchcomplexitylinemethod
InventoryRequestPayload()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeviceInventoryBundle()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeviceInventoryContainer()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setDeviceInventoryBundle(DeviceInventoryBundle)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setDeviceInventoryContainer(DeviceInventoryContainer)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
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%

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.message;
14:
15: import org.eclipse.kapua.commons.util.xml.XmlUtil;
16: import org.eclipse.kapua.locator.KapuaLocator;
17: import org.eclipse.kapua.message.internal.KapuaPayloadImpl;
18: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting;
19: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSettingKey;
20: import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementFactory;
21: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundle;
22: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
23: import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventory;
24: import org.eclipse.kapua.service.device.management.message.request.KapuaRequestPayload;
25:
26: import javax.validation.constraints.NotNull;
27:
28: /**
29: * {@link DeviceInventory} {@link KapuaRequestPayload} implementation.
30: *
31: * @since 1.5.0
32: */
33: public class InventoryRequestPayload extends KapuaPayloadImpl implements KapuaRequestPayload {
34:
35: private static final long serialVersionUID = 837931637524736407L;
36:
37: private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
38:
39: private static final DeviceInventoryManagementFactory DEVICE_INVENTORY_MANAGEMENT_FACTORY = KapuaLocator.getInstance().getFactory(DeviceInventoryManagementFactory.class);
40:
41: /**
42: * Gets the {@link DeviceInventoryBundle} from the {@link #getBody()}.
43: *
44: * @return The {@link DeviceInventoryBundle} from the {@link #getBody()}.
45: * @throws Exception if reading {@link #getBody()} errors.
46: * @since 1.5.0
47: */
48: public DeviceInventoryBundle getDeviceInventoryBundle() throws Exception {
49:• if (!hasBody()) {
50: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventoryBundle();
51: }
52:
53: String bodyString = new String(getBody(), CHAR_ENCODING);
54: return XmlUtil.unmarshal(bodyString, DeviceInventoryBundle.class);
55: }
56:
57: /**
58: * Sets the {@link DeviceInventoryBundle} in the {@link #getBody()}.
59: *
60: * @param deviceInventoryBundle The {@link DeviceInventoryBundle} in the {@link #getBody()}.
61: * @throws Exception if writing errors.
62: * @since 1.5.0
63: */
64: public void setDeviceInventoryBundle(@NotNull DeviceInventoryBundle deviceInventoryBundle) throws Exception {
65: String bodyString = XmlUtil.marshal(deviceInventoryBundle);
66: setBody(bodyString.getBytes(CHAR_ENCODING));
67: }
68:
69: /**
70: * Gets the {@link DeviceInventoryContainer} from the {@link #getBody()}.
71: *
72: * @return The {@link DeviceInventoryContainer} from the {@link #getBody()}.
73: * @throws Exception if reading {@link #getBody()} errors.
74: * @since 2.0.0
75: */
76: public DeviceInventoryContainer getDeviceInventoryContainer() throws Exception {
77:• if (!hasBody()) {
78: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventoryContainer();
79: }
80:
81: String bodyString = new String(getBody(), CHAR_ENCODING);
82: return XmlUtil.unmarshal(bodyString, DeviceInventoryContainer.class);
83: }
84:
85: /**
86: * Sets the {@link DeviceInventoryContainer} in the {@link #getBody()}.
87: *
88: * @param deviceInventoryContainer The {@link DeviceInventoryContainer} in the {@link #getBody()}.
89: * @throws Exception if writing errors.
90: * @since 2.0.0
91: */
92: public void setDeviceInventoryContainer(@NotNull DeviceInventoryContainer deviceInventoryContainer) throws Exception {
93: String bodyString = XmlUtil.marshal(deviceInventoryContainer);
94: setBody(bodyString.getBytes(CHAR_ENCODING));
95: }
96: }