Skip to content

Package: JsonKapuaPayload

JsonKapuaPayload

nameinstructionbranchcomplexitylinemethod
JsonKapuaPayload()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
JsonKapuaPayload(KapuaPayload)
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%
getBody()
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%
getMetrics()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
lambda$new$0(Map.Entry)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$1(Map.Entry)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
setBody(byte[])
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setMetrics(List)
M: 4 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) 2018, 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.core.model.message;
14:
15: import org.eclipse.kapua.message.KapuaPayload;
16: import org.eclipse.kapua.message.xml.XmlAdaptedMetric;
17: import org.eclipse.kapua.model.type.ObjectValueConverter;
18: import org.eclipse.kapua.model.xml.BinaryXmlAdapter;
19:
20: import javax.xml.bind.annotation.XmlAccessType;
21: import javax.xml.bind.annotation.XmlAccessorType;
22: import javax.xml.bind.annotation.XmlElement;
23: import javax.xml.bind.annotation.XmlElementWrapper;
24: import javax.xml.bind.annotation.XmlRootElement;
25: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
26: import java.util.ArrayList;
27: import java.util.List;
28:
29: @XmlRootElement(name = "payload")
30: @XmlAccessorType(XmlAccessType.PROPERTY)
31: public class JsonKapuaPayload {
32:
33: private List<XmlAdaptedMetric> metrics;
34: private byte[] body;
35:
36: /**
37: * Constructor
38: */
39: public JsonKapuaPayload() {
40: }
41:
42: public JsonKapuaPayload(KapuaPayload payload) {
43:
44: setBody(payload.getBody());
45:
46:• payload.getMetrics().entrySet().stream().filter(metric -> metric.getValue() != null).forEach(metric -> {
47:
48: XmlAdaptedMetric jsonMetric = new XmlAdaptedMetric();
49: jsonMetric.setName(metric.getKey());
50: jsonMetric.setValueType(metric.getValue().getClass());
51: jsonMetric.setValue(ObjectValueConverter.toString(metric.getValue()));
52:
53: getMetrics().add(jsonMetric);
54: });
55: }
56:
57: @XmlElementWrapper(name = "metrics")
58: @XmlElement(name = "metric")
59: public List<XmlAdaptedMetric> getMetrics() {
60:• if (metrics == null) {
61: metrics = new ArrayList<>();
62: }
63:
64: return metrics;
65: }
66:
67: public void setMetrics(List<XmlAdaptedMetric> metrics) {
68: this.metrics = metrics;
69: }
70:
71: @XmlElement(name = "body")
72: @XmlJavaTypeAdapter(BinaryXmlAdapter.class)
73: public byte[] getBody() {
74: return body;
75: }
76:
77: public void setBody(byte[] body) {
78: this.body = body;
79: }
80:
81: }