Skip to content

Package: InventoryResponsePayload

InventoryResponsePayload

nameinstructionbranchcomplexitylinemethod
InventoryResponsePayload()
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%
getDeviceInventory()
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%
getDeviceInventoryBundles()
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%
getDeviceInventoryContainers()
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%
getDeviceInventoryPackages()
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%
getDeviceInventorySystemPackages()
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%
setDeviceInventory(DeviceInventory)
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%
setDeviceInventoryBundles(DeviceInventoryBundles)
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%
setDeviceInventoryContainers(DeviceInventoryContainers)
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%
setDeviceInventoryPackages(DeviceInventoryPackages)
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%
setDeviceInventorySystemPackages(DeviceInventorySystemPackages)
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.service.device.management.commons.message.response.KapuaResponsePayloadImpl;
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.DeviceInventoryBundles;
22: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainers;
23: import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventory;
24: import org.eclipse.kapua.service.device.management.inventory.model.packages.DeviceInventoryPackages;
25: import org.eclipse.kapua.service.device.management.inventory.model.system.DeviceInventorySystemPackages;
26: import org.eclipse.kapua.service.device.management.message.response.KapuaResponsePayload;
27:
28: import javax.validation.constraints.NotNull;
29:
30: /**
31: * {@link DeviceInventory} {@link KapuaResponsePayload} implementation.
32: *
33: * @since 1.5.0
34: */
35: public class InventoryResponsePayload extends KapuaResponsePayloadImpl implements KapuaResponsePayload {
36:
37: private static final long serialVersionUID = 4380715272822080425L;
38:
39: private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
40:
41: private static final DeviceInventoryManagementFactory DEVICE_INVENTORY_MANAGEMENT_FACTORY = KapuaLocator.getInstance().getFactory(DeviceInventoryManagementFactory.class);
42:
43: /**
44: * Gets the {@link DeviceInventory} from the {@link #getBody()}.
45: *
46: * @return The {@link DeviceInventory} from the {@link #getBody()}.
47: * @throws Exception if reading {@link #getBody()} errors.
48: * @since 1.5.0
49: */
50: public DeviceInventory getDeviceInventory() throws Exception {
51:• if (!hasBody()) {
52: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventory();
53: }
54:
55: String bodyString = new String(getBody(), CHAR_ENCODING);
56: return XmlUtil.unmarshal(bodyString, DeviceInventory.class);
57: }
58:
59: /**
60: * Sets the {@link DeviceInventory} in the {@link #getBody()}.
61: *
62: * @param deviceInventory The {@link DeviceInventory} in the {@link #getBody()}.
63: * @throws Exception if writing errors.
64: * @since 1.5.0
65: */
66: public void setDeviceInventory(@NotNull DeviceInventory deviceInventory) throws Exception {
67: String bodyString = XmlUtil.marshal(deviceInventory);
68: setBody(bodyString.getBytes(CHAR_ENCODING));
69: }
70:
71: /**
72: * Gets the {@link DeviceInventoryBundles} from the {@link #getBody()}.
73: *
74: * @return The {@link DeviceInventoryBundles} from the {@link #getBody()}.
75: * @throws Exception if reading {@link #getBody()} errors.
76: * @since 1.5.0
77: */
78: public DeviceInventoryBundles getDeviceInventoryBundles() throws Exception {
79:• if (!hasBody()) {
80: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventoryBundles();
81: }
82:
83: String bodyString = new String(getBody(), CHAR_ENCODING);
84: return XmlUtil.unmarshal(bodyString, DeviceInventoryBundles.class);
85: }
86:
87: /**
88: * Sets the {@link DeviceInventoryBundles} in the {@link #getBody()}.
89: *
90: * @param inventoryBundles The {@link DeviceInventoryBundles} in the {@link #getBody()}.
91: * @throws Exception if writing errors.
92: * @since 1.5.0
93: */
94: public void setDeviceInventoryBundles(@NotNull DeviceInventoryBundles inventoryBundles) throws Exception {
95: String bodyString = XmlUtil.marshal(inventoryBundles);
96: setBody(bodyString.getBytes(CHAR_ENCODING));
97: }
98:
99: /**
100: * Gets the {@link DeviceInventoryContainers} from the {@link #getBody()}.
101: *
102: * @return The {@link DeviceInventoryContainers} from the {@link #getBody()}.
103: * @throws Exception if reading {@link #getBody()} errors.
104: * @since 2.0.0
105: */
106: public DeviceInventoryContainers getDeviceInventoryContainers() throws Exception {
107:• if (!hasBody()) {
108: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventoryContainers();
109: }
110:
111: String bodyString = new String(getBody(), CHAR_ENCODING);
112: return XmlUtil.unmarshal(bodyString, DeviceInventoryContainers.class);
113: }
114:
115: /**
116: * Sets the {@link DeviceInventoryContainers} in the {@link #getBody()}.
117: *
118: * @param inventoryContainers The {@link DeviceInventoryContainers} in the {@link #getBody()}.
119: * @throws Exception if writing errors.
120: * @since 2.0.0
121: */
122: public void setDeviceInventoryContainers(@NotNull DeviceInventoryContainers inventoryContainers) throws Exception {
123: String bodyString = XmlUtil.marshal(inventoryContainers);
124: setBody(bodyString.getBytes(CHAR_ENCODING));
125: }
126:
127: /**
128: * Gets the {@link DeviceInventorySystemPackages} from the {@link #getBody()}.
129: *
130: * @return The {@link DeviceInventorySystemPackages} from the {@link #getBody()}.
131: * @throws Exception if reading {@link #getBody()} errors.
132: * @since 1.5.0
133: */
134: public DeviceInventorySystemPackages getDeviceInventorySystemPackages() throws Exception {
135:• if (!hasBody()) {
136: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventorySystemPackages();
137: }
138:
139: String bodyString = new String(getBody(), CHAR_ENCODING);
140: return XmlUtil.unmarshal(bodyString, DeviceInventorySystemPackages.class);
141: }
142:
143: /**
144: * Sets the {@link DeviceInventorySystemPackages} in the {@link #getBody()}.
145: *
146: * @param systemPackages The {@link DeviceInventorySystemPackages} in the {@link #getBody()}.
147: * @throws Exception if writing errors.
148: * @since 1.5.0
149: */
150: public void setDeviceInventorySystemPackages(@NotNull DeviceInventorySystemPackages systemPackages) throws Exception {
151: String bodyString = XmlUtil.marshal(systemPackages);
152: setBody(bodyString.getBytes(CHAR_ENCODING));
153: }
154:
155: /**
156: * Gets the {@link DeviceInventoryPackages} from the {@link #getBody()}.
157: *
158: * @return The {@link DeviceInventoryPackages} from the {@link #getBody()}.
159: * @throws Exception if reading {@link #getBody()} errors.
160: * @since 1.5.0
161: */
162: public DeviceInventoryPackages getDeviceInventoryPackages() throws Exception {
163:• if (!hasBody()) {
164: return DEVICE_INVENTORY_MANAGEMENT_FACTORY.newDeviceInventoryPackages();
165: }
166:
167: String bodyString = new String(getBody(), CHAR_ENCODING);
168: return XmlUtil.unmarshal(bodyString, DeviceInventoryPackages.class);
169: }
170:
171: /**
172: * Sets the {@link DeviceInventoryPackages} in the {@link #getBody()}.
173: *
174: * @param packages The {@link DeviceInventoryPackages} in the {@link #getBody()}.
175: * @throws Exception if writing errors.
176: * @since 1.5.0
177: */
178: public void setDeviceInventoryPackages(@NotNull DeviceInventoryPackages packages) throws Exception {
179: String bodyString = XmlUtil.marshal(packages);
180: setBody(bodyString.getBytes(CHAR_ENCODING));
181: }
182: }