Skip to content

Package: MessageSchema

MessageSchema

nameinstructionbranchcomplexitylinemethod
getMesageTypeSchema(boolean)
M: 517 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 54 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.message.Message;
16: import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
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 Message} schema definition.
27: *
28: * @since 1.0.0
29: */
30: public class MessageSchema {
31:
32: /**
33: * @since 1.0.0
34: */
35: private MessageSchema() {
36: }
37:
38: /**
39: * Message schema name
40: *
41: * @since 1.0.0
42: */
43: public static final String MESSAGE_TYPE_NAME = "message";
44:
45: /**
46: * Message id
47: *
48: * @since 1.0.0
49: */
50: public static final String MESSAGE_ID = "message_id";
51:
52: /**
53: * Message timestamp
54: *
55: * @since 1.0.0
56: */
57: public static final String MESSAGE_TIMESTAMP = "timestamp";
58:
59: /**
60: * Message received on timestamp
61: *
62: * @since 1.0.0
63: */
64: public static final String MESSAGE_RECEIVED_ON = "received_on";
65:
66: /**
67: * Message received by address
68: *
69: * @since 1.0.0
70: */
71: public static final String MESSAGE_IP_ADDRESS = "ip_address";
72:
73: /**
74: * Message scope id
75: *
76: * @since 1.0.0
77: */
78: public static final String MESSAGE_SCOPE_ID = "scope_id";
79:
80: /**
81: * Message device identifier
82: *
83: * @since 1.0.0
84: */
85: public static final String MESSAGE_DEVICE_ID = "device_id";
86:
87: /**
88: * Message client identifier
89: *
90: * @since 1.0.0
91: */
92: public static final String MESSAGE_CLIENT_ID = "client_id";
93:
94: /**
95: * Message channel
96: *
97: * @since 1.0.0
98: */
99: public static final String MESSAGE_CHANNEL = "channel";
100:
101: /**
102: * Message channel parts
103: *
104: * @since 1.0.0
105: */
106: public static final String MESSAGE_CHANNEL_PARTS = "channel_parts";
107:
108: /**
109: * Message captured on timestamp
110: *
111: * @since 1.0.0
112: */
113: public static final String MESSAGE_CAPTURED_ON = "captured_on";
114:
115: /**
116: * Message sent on timestamp
117: *
118: * @since 1.0.0
119: */
120: public static final String MESSAGE_SENT_ON = "sent_on";
121:
122: /**
123: * Message position - (composed object)
124: *
125: * @since 1.0.0
126: */
127: public static final String MESSAGE_POSITION = "position";
128:
129: /**
130: * Message position - location (field name relative to the position object)
131: *
132: * @since 1.0.0
133: */
134: public static final String MESSAGE_POS_LOCATION = "location";
135:
136: /**
137: * Message position - location (full field name)
138: *
139: * @since 1.0.0
140: */
141: public static final String MESSAGE_POS_LOCATION_FULL = "position.location";
142:
143: /**
144: * Message position - altitude (field name relative to the position object)
145: *
146: * @since 1.0.0
147: */
148: public static final String MESSAGE_POS_ALT = "alt";
149:
150: /**
151: * Message position - altitude (full field name)
152: *
153: * @since 1.0.0
154: */
155: public static final String MESSAGE_POS_ALT_FULL = "position.alt";
156:
157: /**
158: * Message position - precision (field name relative to the position object)
159: *
160: * @since 1.0.0
161: */
162: public static final String MESSAGE_POS_PRECISION = "precision";
163:
164: /**
165: * Message position - precision (full field name)
166: *
167: * @since 1.0.0
168: */
169: public static final String MESSAGE_POS_PRECISION_FULL = "position.precision";
170:
171: /**
172: * Message position - heading (field name relative to the position object)
173: *
174: * @since 1.0.0
175: */
176: public static final String MESSAGE_POS_HEADING = "heading";
177:
178: /**
179: * Message position - heading (full field name)
180: *
181: * @since 1.0.0
182: */
183: public static final String MESSAGE_POS_HEADING_FULL = "position.heading";
184:
185: /**
186: * Message position - speed (field name relative to the position object)
187: *
188: * @since 1.0.0
189: */
190: public static final String MESSAGE_POS_SPEED = "speed";
191:
192: /**
193: * Message position - speed (full field name)
194: *
195: * @since 1.0.0
196: */
197: public static final String MESSAGE_POS_SPEED_FULL = "position.speed";
198:
199: /**
200: * Message position - timestamp (field name relative to the position object)
201: *
202: * @since 1.0.0
203: */
204: public static final String MESSAGE_POS_TIMESTAMP = "timestamp";
205:
206: /**
207: * Message position - timestamp (full field name)
208: *
209: * @since 1.0.0
210: */
211: public static final String MESSAGE_POS_TIMESTAMP_FULL = "position.timestamp";
212:
213: /**
214: * Message position - satellites (field name relative to the position object)
215: *
216: * @since 1.0.0
217: */
218: public static final String MESSAGE_POS_SATELLITES = "satellites";
219:
220: /**
221: * Message position - satellites (full field name)
222: *
223: * @since 1.0.0
224: */
225: public static final String MESSAGE_POS_SATELLITES_FULL = "position.satellites";
226:
227: /**
228: * Message position - status (field name relative to the position object)
229: *
230: * @since 1.0.0
231: */
232: public static final String MESSAGE_POS_STATUS = "status";
233:
234: /**
235: * Message position - status (full field name)
236: *
237: * @since 1.0.0
238: */
239: public static final String MESSAGE_POS_STATUS_FULL = "position.status";
240:
241: /**
242: * Message metrics
243: *
244: * @since 1.0.0
245: */
246: public static final String MESSAGE_METRICS = "metrics";
247:
248: /**
249: * Message body
250: *
251: * @since 1.0.0
252: */
253: public static final String MESSAGE_BODY = "body";
254:
255: // position internal fields
256: /**
257: * Position latitude inner field
258: *
259: * @since 1.0.0
260: */
261: public static final String MESSAGE_POSITION_LATITUDE = "lat";
262:
263: /**
264: * Position longitude inner field
265: *
266: * @since 1.0.0
267: */
268: public static final String MESSAGE_POSITION_LONGITUDE = "lon";
269:
270: /**
271: * Create and return the Json representation of the message schema
272: *
273: * @param sourceEnable
274: * @return
275: * @throws MappingException
276: * @since 1.0.0
277: */
278: public static JsonNode getMesageTypeSchema(boolean sourceEnable) throws MappingException {
279: ObjectNode messageNode = MappingUtils.newObjectNode();
280: {
281: ObjectNode sourceMessage = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_ENABLED, sourceEnable) });
282: messageNode.set(SchemaKeys.KEY_SOURCE, sourceMessage);
283:
284: ObjectNode propertiesNode = MappingUtils.newObjectNode();
285: {
286: ObjectNode messageId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
287: propertiesNode.set(MESSAGE_ID, messageId);
288:
289: ObjectNode messageTimestamp = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
290: propertiesNode.set(MESSAGE_TIMESTAMP, messageTimestamp);
291:
292: ObjectNode messageReceivedOn = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
293: propertiesNode.set(MESSAGE_RECEIVED_ON, messageReceivedOn);
294:
295: ObjectNode messageIp = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_IP) });
296: propertiesNode.set(MESSAGE_IP_ADDRESS, messageIp);
297:
298: ObjectNode messageScopeId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
299: propertiesNode.set(MESSAGE_SCOPE_ID, messageScopeId);
300:
301: ObjectNode messageDeviceId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
302: propertiesNode.set(MESSAGE_DEVICE_ID, messageDeviceId);
303:
304: ObjectNode messageClientId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
305: propertiesNode.set(MESSAGE_CLIENT_ID, messageClientId);
306:
307: ObjectNode messageChannel = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
308: propertiesNode.set(MESSAGE_CHANNEL, messageChannel);
309:
310: ObjectNode messageCapturedOn = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
311: propertiesNode.set(MESSAGE_CAPTURED_ON, messageCapturedOn);
312:
313: ObjectNode messageSentOn = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
314: propertiesNode.set(MESSAGE_SENT_ON, messageSentOn);
315:
316: ObjectNode positionNode = MappingUtils.newObjectNode(
317: new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_OBJECT), new KeyValueEntry(SchemaKeys.KEY_ENABLED, true),
318: new KeyValueEntry(SchemaKeys.KEY_DYNAMIC, false) });
319:
320: ObjectNode positionPropertiesNode = MappingUtils.newObjectNode();
321: {
322: ObjectNode messagePositionPropLocation = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_GEO_POINT) });
323: positionPropertiesNode.set(MESSAGE_POS_LOCATION, messagePositionPropLocation);
324:
325: ObjectNode messagePositionPropAlt = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DOUBLE) });
326: positionPropertiesNode.set(MESSAGE_POS_ALT, messagePositionPropAlt);
327:
328: ObjectNode messagePositionPropPrec = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DOUBLE) });
329: positionPropertiesNode.set(MESSAGE_POS_PRECISION, messagePositionPropPrec);
330:
331: ObjectNode messagePositionPropHead = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DOUBLE) });
332: positionPropertiesNode.set(MESSAGE_POS_HEADING, messagePositionPropHead);
333:
334: ObjectNode messagePositionPropSpeed = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DOUBLE) });
335: positionPropertiesNode.set(MESSAGE_POS_SPEED, messagePositionPropSpeed);
336:
337: ObjectNode messagePositionPropTime = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
338: positionPropertiesNode.set(MESSAGE_POS_TIMESTAMP, messagePositionPropTime);
339:
340: ObjectNode messagePositionPropSat = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_INTEGER) });
341: positionPropertiesNode.set(MESSAGE_POS_SATELLITES, messagePositionPropSat);
342:
343: ObjectNode messagePositionPropStat = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_INTEGER) });
344: positionPropertiesNode.set(MESSAGE_POS_STATUS, messagePositionPropStat);
345: }
346: positionNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, positionPropertiesNode);
347:
348: propertiesNode.set(SchemaKeys.FIELD_NAME_POSITION, positionNode);
349: }
350: messageNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, propertiesNode);
351:
352: ObjectNode messageMetrics = MappingUtils.newObjectNode(
353: new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_OBJECT), new KeyValueEntry(SchemaKeys.KEY_ENABLED, true),
354: new KeyValueEntry(SchemaKeys.KEY_DYNAMIC, true) });
355: propertiesNode.set(MESSAGE_METRICS, messageMetrics);
356:
357: ObjectNode messageBody = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_BINARY), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_FALSE) });
358: propertiesNode.set(MESSAGE_BODY, messageBody);
359: }
360: return messageNode;
361: }
362:
363: }