Skip to content

Package: ClientInfoSchema

ClientInfoSchema

nameinstructionbranchcomplexitylinemethod
getClientTypeSchema(boolean)
M: 129 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 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.ClientInfo;
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 ClientInfo} schema definition.
27: *
28: * @since 1.0.0
29: */
30: public class ClientInfoSchema {
31:
32: /**
33: * @since 1.0.0
34: */
35: private ClientInfoSchema() {
36: }
37:
38: /**
39: * Client information schema name.
40: *
41: * @since 1.0.0
42: */
43: public static final String CLIENT_TYPE_NAME = "client";
44:
45: /**
46: * Client information - client identifier
47: *
48: * @since 1.0.0
49: */
50: public static final String CLIENT_ID = "client_id";
51:
52: /**
53: * Client information - scope id
54: *
55: * @since 1.0.0
56: */
57: public static final String CLIENT_SCOPE_ID = "scope_id";
58:
59: /**
60: * Client information - message timestamp (of the first message published in this channel)
61: *
62: * @since 1.0.0
63: */
64: public static final String CLIENT_TIMESTAMP = "timestamp";
65:
66: /**
67: * Client information - message identifier (of the first message published in this channel)
68: *
69: * @since 1.0.0
70: */
71: public static final String CLIENT_MESSAGE_ID = "message_id";
72:
73: /**
74: * Create and return the Json representation of the client info schema
75: *
76: * @param sourceEnable
77: * @return
78: * @throws MappingException
79: * @since 1.0.0
80: */
81: public static JsonNode getClientTypeSchema(boolean sourceEnable) throws MappingException {
82:
83: ObjectNode clientNode = MappingUtils.newObjectNode();
84: {
85: ObjectNode sourceClient = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_ENABLED, sourceEnable) });
86: clientNode.set(SchemaKeys.KEY_SOURCE, sourceClient);
87:
88: ObjectNode propertiesNode = MappingUtils.newObjectNode();
89: {
90: ObjectNode clientId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
91: propertiesNode.set(CLIENT_ID, clientId);
92:
93: ObjectNode clientTimestamp = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
94: propertiesNode.set(CLIENT_TIMESTAMP, clientTimestamp);
95:
96: ObjectNode clientScopeId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
97: propertiesNode.set(CLIENT_SCOPE_ID, clientScopeId);
98:
99: ObjectNode clientMessageId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
100: propertiesNode.set(CLIENT_MESSAGE_ID, clientMessageId);
101: }
102: clientNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, propertiesNode);
103: }
104:
105: return clientNode;
106: }
107:
108: }