Skip to content

Package: KuraAsset

KuraAsset

nameinstructionbranchcomplexitylinemethod
KuraAsset()
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%
getChannels()
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%
getName()
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%
readJsonNode(JsonNode)
M: 35 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
setChannels(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%
setName(String)
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%
writeJsonNode(JsonGenerator)
M: 34 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 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.call.kura.model.asset;
14:
15: import java.io.IOException;
16: import java.util.ArrayList;
17: import java.util.Iterator;
18: import java.util.List;
19:
20: import org.eclipse.kapua.KapuaException;
21:
22: import com.fasterxml.jackson.core.JsonGenerator;
23: import com.fasterxml.jackson.databind.JsonNode;
24:
25: /**
26: * {@link KuraAsset} definition.
27: *
28: * @since 1.0.0
29: */
30: public class KuraAsset {
31:
32: private String name;
33: private List<KuraAssetChannel> channels;
34:
35: /**
36: * Gets name.
37: *
38: * @return The name.
39: *
40: * @since 1.0.0
41: */
42: public String getName() {
43: return name;
44: }
45:
46: /**
47: * Set asset name
48: *
49: * @param name
50: * The name to set.
51: *
52: * @since 1.0.0
53: */
54: public void setName(String name) {
55: this.name = name;
56: }
57:
58: /**
59: * Gets the channels available for this {@link KuraAsset}
60: *
61: * @return The channels available for this {@link KuraAsset}
62: *
63: * @since 1.0.0
64: */
65: public List<KuraAssetChannel> getChannels() {
66:• if (channels == null) {
67: channels = new ArrayList<>();
68: }
69:
70: return channels;
71: }
72:
73: /**
74: * Sets the channels for this {@link KuraAsset}.
75: *
76: * @param channels
77: * The channels to set for this {@link KuraAsset}.
78: *
79: * @since 1.0.0
80: */
81: public void setChannels(List<KuraAssetChannel> channels) {
82: this.channels = channels;
83: }
84:
85: /**
86: * Parse a {@link JsonNode} that represent the {@link KuraAsset} object.
87: *
88: * @param jsonKuraAsset
89: * The {@link JsonNode} to parse
90: * @return The parsed {@link KuraAsset} result.
91: *
92: * @throws KapuaException
93: *
94: * @since 1.0.0
95: */
96: public static KuraAsset readJsonNode(JsonNode jsonKuraAsset) throws KapuaException {
97:
98: KuraAsset kuraAsset = new KuraAsset();
99: kuraAsset.setName(jsonKuraAsset.get("name").asText());
100:
101: JsonNode jsonKuraAssetChannels = jsonKuraAsset.get("channels");
102:• if (jsonKuraAssetChannels != null) {
103: Iterator<JsonNode> jsonNodeIterator = jsonKuraAssetChannels.elements();
104:• while (jsonNodeIterator.hasNext()) {
105: JsonNode jsonNode = jsonNodeIterator.next();
106: kuraAsset.getChannels().add(KuraAssetChannel.readJsonNode(jsonNode));
107: }
108: }
109: return kuraAsset;
110: }
111:
112: /**
113: * Serialize {@code this} {@link KuraAsset} into json using the given {@link JsonGenerator}.
114: *
115: * @param jsonGenerator
116: * The {@link JsonGenerator} to put serialized {@link KuraAsset}.
117: * @throws IOException
118: * @since 1.0.0
119: */
120: public void writeJsonNode(JsonGenerator jsonGenerator) throws IOException {
121:
122: jsonGenerator.writeStartObject();
123: jsonGenerator.writeStringField("name", getName());
124:
125:• if (!getChannels().isEmpty()) {
126: jsonGenerator.writeArrayFieldStart("channels");
127:• for (KuraAssetChannel kuraAssetChannel : getChannels()) {
128: kuraAssetChannel.writeJsonNode(jsonGenerator);
129: }
130: jsonGenerator.writeEndArray();
131: }
132:
133: jsonGenerator.writeEndObject();
134: }
135: }