Skip to content

Package: AbstractTranslatorAppInventoryKuraKapua

AbstractTranslatorAppInventoryKuraKapua

nameinstructionbranchcomplexitylinemethod
AbstractTranslatorAppInventoryKuraKapua(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$null$4(DeviceInventoryManagementFactory, DeviceInventoryPackage, KuraInventoryBundle)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lambda$translate$0(DeviceInventoryManagementFactory, DeviceInventory, KuraInventoryItem)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
lambda$translate$1(DeviceInventoryManagementFactory, DeviceInventoryBundles, KuraInventoryBundle)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lambda$translate$2(DeviceInventoryManagementFactory, DeviceInventoryContainers, KuraInventoryContainer)
M: 62 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
lambda$translate$3(DeviceInventoryManagementFactory, DeviceInventorySystemPackages, KuraInventorySystemPackage)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
lambda$translate$5(DeviceInventoryManagementFactory, DeviceInventoryPackages, KuraInventoryPackage)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
translate(KuraInventoryBundles)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
translate(KuraInventoryContainers)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
translate(KuraInventoryItems)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
translate(KuraInventoryPackages)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
translate(KuraInventorySystemPackages)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
translateChannel(KuraResponseChannel)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 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.translator.kura.kapua.inventory;
14:
15: import org.eclipse.kapua.locator.KapuaLocator;
16: import org.eclipse.kapua.service.device.call.kura.model.inventory.InventoryMetrics;
17: import org.eclipse.kapua.service.device.call.kura.model.inventory.KuraInventoryItems;
18: import org.eclipse.kapua.service.device.call.kura.model.inventory.bundles.KuraInventoryBundles;
19: import org.eclipse.kapua.service.device.call.kura.model.inventory.containers.KuraInventoryContainers;
20: import org.eclipse.kapua.service.device.call.kura.model.inventory.packages.KuraInventoryPackages;
21: import org.eclipse.kapua.service.device.call.kura.model.inventory.system.KuraInventorySystemPackages;
22: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseChannel;
23: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseMessage;
24: import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementFactory;
25: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryResponseChannel;
26: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryResponseMessage;
27: import org.eclipse.kapua.service.device.management.inventory.internal.message.InventoryResponsePayload;
28: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundle;
29: import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundles;
30: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
31: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainerState;
32: import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainers;
33: import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventory;
34: import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventoryItem;
35: import org.eclipse.kapua.service.device.management.inventory.model.packages.DeviceInventoryPackage;
36: import org.eclipse.kapua.service.device.management.inventory.model.packages.DeviceInventoryPackages;
37: import org.eclipse.kapua.service.device.management.inventory.model.system.DeviceInventorySystemPackage;
38: import org.eclipse.kapua.service.device.management.inventory.model.system.DeviceInventorySystemPackages;
39: import org.eclipse.kapua.translator.Translator;
40: import org.eclipse.kapua.translator.exception.InvalidChannelException;
41: import org.eclipse.kapua.translator.kura.kapua.AbstractSimpleTranslatorResponseKuraKapua;
42: import org.eclipse.kapua.translator.kura.kapua.TranslatorKuraKapuaUtils;
43: import org.slf4j.Logger;
44: import org.slf4j.LoggerFactory;
45:
46: /**
47: * {@link Translator} {@code abstract} implementation from {@link KuraResponseMessage} to {@link InventoryResponseMessage}
48: *
49: * @since 1.5.0
50: */
51: public class AbstractTranslatorAppInventoryKuraKapua<M extends InventoryResponseMessage> extends AbstractSimpleTranslatorResponseKuraKapua<InventoryResponseChannel, InventoryResponsePayload, M> {
52:
53: private static final Logger LOG = LoggerFactory.getLogger(AbstractTranslatorAppInventoryKuraKapua.class);
54:
55: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
56:
57: /**
58: * Constructor.
59: *
60: * @param responseMessageClass The type of the {@link InventoryResponseMessage}.
61: * @since 1.5.0
62: */
63: public AbstractTranslatorAppInventoryKuraKapua(Class<M> responseMessageClass) {
64: super(responseMessageClass, InventoryResponsePayload.class);
65: }
66:
67: @Override
68: protected InventoryResponseChannel translateChannel(KuraResponseChannel kuraResponseChannel) throws InvalidChannelException {
69: try {
70: TranslatorKuraKapuaUtils.validateKuraResponseChannel(kuraResponseChannel, InventoryMetrics.APP_ID, InventoryMetrics.APP_VERSION);
71:
72: return new InventoryResponseChannel();
73: } catch (Exception e) {
74: throw new InvalidChannelException(e, kuraResponseChannel);
75: }
76: }
77:
78: /**
79: * Translates {@link KuraInventoryItems} to {@link DeviceInventory}
80: *
81: * @param kuraInventoryItems The {@link KuraInventoryItems} to translate.
82: * @return The translated {@link DeviceInventory}.
83: * @since 1.5.0
84: */
85: protected DeviceInventory translate(KuraInventoryItems kuraInventoryItems) {
86: DeviceInventoryManagementFactory deviceInventoryFactory = LOCATOR.getFactory(DeviceInventoryManagementFactory.class);
87: DeviceInventory deviceInventory = deviceInventoryFactory.newDeviceInventory();
88:
89: kuraInventoryItems.getInventoryItems().forEach(kuraInventoryItem -> {
90: DeviceInventoryItem deviceInventoryItem = deviceInventoryFactory.newDeviceInventoryItem();
91: deviceInventoryItem.setName(kuraInventoryItem.getName());
92: deviceInventoryItem.setVersion(kuraInventoryItem.getVersion());
93: deviceInventoryItem.setItemType(kuraInventoryItem.getType());
94:
95: deviceInventory.addInventoryItem(deviceInventoryItem);
96: });
97:
98: return deviceInventory;
99: }
100:
101: /**
102: * Translates {@link KuraInventoryBundles} to {@link DeviceInventoryBundles}
103: *
104: * @param kuraInventoryBundles The {@link KuraInventoryBundles} to translate.
105: * @return The translated {@link DeviceInventoryBundles}.
106: * @since 1.5.0
107: */
108: protected DeviceInventoryBundles translate(KuraInventoryBundles kuraInventoryBundles) {
109: DeviceInventoryManagementFactory deviceInventoryFactory = LOCATOR.getFactory(DeviceInventoryManagementFactory.class);
110: DeviceInventoryBundles deviceInventoryBundles = deviceInventoryFactory.newDeviceInventoryBundles();
111:
112: kuraInventoryBundles.getInventoryBundles().forEach(kuraInventoryBundle -> {
113: DeviceInventoryBundle deviceInventoryBundle = deviceInventoryFactory.newDeviceInventoryBundle();
114: deviceInventoryBundle.setId(String.valueOf(kuraInventoryBundle.getId()));
115: deviceInventoryBundle.setName(kuraInventoryBundle.getName());
116: deviceInventoryBundle.setVersion(kuraInventoryBundle.getVersion());
117: deviceInventoryBundle.setStatus(kuraInventoryBundle.getState());
118: deviceInventoryBundle.setSigned(kuraInventoryBundle.getSigned());
119:
120: deviceInventoryBundles.addInventoryBundle(deviceInventoryBundle);
121: });
122:
123: return deviceInventoryBundles;
124: }
125:
126: /**
127: * Translates {@link KuraInventoryContainers} to {@link DeviceInventoryContainers}
128: *
129: * @param kuraInventoryContainers The {@link KuraInventoryContainers} to translate.
130: * @return The translated {@link DeviceInventoryContainers}.
131: * @since 2.0.0
132: */
133: protected DeviceInventoryContainers translate(KuraInventoryContainers kuraInventoryContainers) {
134: DeviceInventoryManagementFactory deviceInventoryFactory = LOCATOR.getFactory(DeviceInventoryManagementFactory.class);
135: DeviceInventoryContainers deviceInventoryContainers = deviceInventoryFactory.newDeviceInventoryContainers();
136:
137: kuraInventoryContainers.getInventoryContainers().forEach(kuraInventoryContainer -> {
138: DeviceInventoryContainer deviceInventoryContainer = deviceInventoryFactory.newDeviceInventoryContainer();
139: deviceInventoryContainer.setName(kuraInventoryContainer.getName());
140: deviceInventoryContainer.setVersion(kuraInventoryContainer.getVersion());
141: deviceInventoryContainer.setContainerType(kuraInventoryContainer.getType());
142:
143:• if (deviceInventoryContainer.getState() != null) {
144: try {
145: deviceInventoryContainer.setState(DeviceInventoryContainerState.valueOf(kuraInventoryContainer.getState()));
146: } catch (IllegalArgumentException iae) {
147: LOG.warn("Unrecognised KuraInventoryContainer.state '{}' received. Defaulting to UNKNOWN state for DeviceInventoryContainer {}", kuraInventoryContainer.getState(), deviceInventoryContainer.getName(), iae);
148: deviceInventoryContainer.setState(DeviceInventoryContainerState.UNKNOWN);
149: }
150: } else {
151: LOG.warn("Property KuraInventoryContainer.state '{}' not present. Defaulting to UNKNOWN state for DeviceInventoryContainer {}", kuraInventoryContainer.getState(), deviceInventoryContainer.getName());
152: deviceInventoryContainer.setState(DeviceInventoryContainerState.UNKNOWN);
153: }
154:
155: deviceInventoryContainers.addInventoryContainer(deviceInventoryContainer);
156: });
157:
158: return deviceInventoryContainers;
159: }
160:
161: /**
162: * Translates {@link KuraInventorySystemPackages} to {@link DeviceInventorySystemPackages}
163: *
164: * @param kuraInventorySystemPackages The {@link KuraInventorySystemPackages} to translate.
165: * @return The translated {@link DeviceInventorySystemPackages}.
166: * @since 1.5.0
167: */
168: protected DeviceInventorySystemPackages translate(KuraInventorySystemPackages kuraInventorySystemPackages) {
169: DeviceInventoryManagementFactory deviceInventoryFactory = LOCATOR.getFactory(DeviceInventoryManagementFactory.class);
170: DeviceInventorySystemPackages deviceInventorySystemPackages = deviceInventoryFactory.newDeviceInventorySystemPackages();
171:
172: kuraInventorySystemPackages.getSystemPackages().forEach(kuraInventorySystemPackage -> {
173: DeviceInventorySystemPackage deviceInventorySystemPackage = deviceInventoryFactory.newDeviceInventorySystemPackage();
174: deviceInventorySystemPackage.setName(kuraInventorySystemPackage.getName());
175: deviceInventorySystemPackage.setVersion(kuraInventorySystemPackage.getVersion());
176: deviceInventorySystemPackage.setPackageType(kuraInventorySystemPackage.getType());
177:
178: deviceInventorySystemPackages.addSystemPackage(deviceInventorySystemPackage);
179: });
180:
181: return deviceInventorySystemPackages;
182: }
183:
184: /**
185: * Translates {@link KuraInventoryPackages} to {@link DeviceInventoryPackages}
186: *
187: * @param kuraInventoryPackages The {@link KuraInventorySystemPackages} to translate.
188: * @return The translated {@link DeviceInventorySystemPackages}.
189: * @since 1.5.0
190: */
191: protected DeviceInventoryPackages translate(KuraInventoryPackages kuraInventoryPackages) {
192: DeviceInventoryManagementFactory deviceInventoryFactory = LOCATOR.getFactory(DeviceInventoryManagementFactory.class);
193: DeviceInventoryPackages deviceInventoryPackages = deviceInventoryFactory.newDeviceInventoryPackages();
194:
195: kuraInventoryPackages.getPackages().forEach(kuraInventoryPackage -> {
196: DeviceInventoryPackage deviceInventoryPackage = deviceInventoryFactory.newDeviceInventoryPackage();
197: deviceInventoryPackage.setName(kuraInventoryPackage.getName());
198: deviceInventoryPackage.setVersion(kuraInventoryPackage.getVersion());
199:
200: kuraInventoryPackage.getPackageBundles().forEach(kuraInventoryBundle -> {
201: DeviceInventoryBundle deviceInventoryBundle = deviceInventoryFactory.newDeviceInventoryBundle();
202: deviceInventoryBundle.setId(String.valueOf(kuraInventoryBundle.getId()));
203: deviceInventoryBundle.setName(kuraInventoryBundle.getName());
204: deviceInventoryBundle.setVersion(kuraInventoryBundle.getVersion());
205: deviceInventoryBundle.setStatus(kuraInventoryBundle.getState());
206: deviceInventoryBundle.setSigned(kuraInventoryBundle.getSigned());
207:
208: deviceInventoryPackage.addPackageBundle(deviceInventoryBundle);
209: });
210:
211: deviceInventoryPackages.addPackage(deviceInventoryPackage);
212: });
213:
214: return deviceInventoryPackages;
215: }
216: }