Skip to content

Package: ChannelInfoSchema

ChannelInfoSchema

nameinstructionbranchcomplexitylinemethod
getChannelTypeSchema(boolean)
M: 154 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 16 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.datastore.internal.schema;
14:
15: import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
16: import org.eclipse.kapua.service.datastore.model.ChannelInfo;
17: import org.eclipse.kapua.service.elasticsearch.client.SchemaKeys;
18: import org.eclipse.kapua.service.storable.exception.MappingException;
19: import org.eclipse.kapua.service.storable.model.utils.KeyValueEntry;
20: import org.eclipse.kapua.service.storable.model.utils.MappingUtils;
21:
22: import com.fasterxml.jackson.databind.JsonNode;
23: import com.fasterxml.jackson.databind.node.ObjectNode;
24:
25: /**
26: * {@link ChannelInfo} schema definition.
27: *
28: * @since 1.0.0
29: */
30: public class ChannelInfoSchema {
31:
32: /**
33: * @since 1.0.0
34: */
35: private ChannelInfoSchema() {
36: }
37:
38: /**
39: * Channel information schema name
40: *
41: * @since 1.0.0
42: */
43: public static final String CHANNEL_TYPE_NAME = "channel";
44: /**
45: * Channel information - channel
46: *
47: * @since 1.0.0
48: */
49: public static final String CHANNEL_NAME = "channel";
50: /**
51: * Channel information - client identifier
52: *
53: * @since 1.0.0
54: */
55: public static final String CHANNEL_CLIENT_ID = "client_id";
56: /**
57: * Channel information - scope id
58: *
59: * @since 1.0.0
60: */
61: public static final String CHANNEL_SCOPE_ID = "scope_id";
62: /**
63: * Channel information - message timestamp (of the first message published in this channel)
64: *
65: * @since 1.0.0
66: */
67: public static final String CHANNEL_TIMESTAMP = "timestamp";
68: /**
69: * Channel information - message identifier (of the first message published in this channel)
70: *
71: * @since 1.0.0
72: */
73: public static final String CHANNEL_MESSAGE_ID = "message_id";
74:
75: /**
76: * Create and return the Json representation of the channel info schema
77: *
78: * @param sourceEnable
79: * @return
80: * @throws MappingException
81: * @since 1.0.0
82: */
83: public static JsonNode getChannelTypeSchema(boolean sourceEnable) throws MappingException {
84: ObjectNode channelNode = MappingUtils.newObjectNode();
85:
86: {
87: ObjectNode sourceChannel = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_ENABLED, sourceEnable) });
88: channelNode.set(SchemaKeys.KEY_SOURCE, sourceChannel);
89:
90: ObjectNode propertiesNode = MappingUtils.newObjectNode();
91: {
92: ObjectNode channelScopeId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
93: propertiesNode.set(CHANNEL_SCOPE_ID, channelScopeId);
94:
95: ObjectNode channelClientId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
96: propertiesNode.set(CHANNEL_CLIENT_ID, channelClientId);
97:
98: ObjectNode channelName = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
99: propertiesNode.set(CHANNEL_NAME, channelName);
100:
101: ObjectNode channelTimestamp = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
102: propertiesNode.set(CHANNEL_TIMESTAMP, channelTimestamp);
103:
104: ObjectNode channelMessageId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
105: propertiesNode.set(CHANNEL_MESSAGE_ID, channelMessageId);
106: }
107: channelNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, propertiesNode);
108: }
109: return channelNode;
110: }
111:
112: }