Skip to content

Package: DefaultSystemMessageCreator

DefaultSystemMessageCreator

nameinstructionbranchcomplexitylinemethod
DefaultSystemMessageCreator()
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%
convertFrom(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createMessage(SystemMessageCreator.SystemMessageType, KapuaSecurityContext)
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getDeviceId(Map)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getUsername(Map)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 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.broker.core.message.system;
14:
15: import java.util.Map;
16:
17: import org.eclipse.kapua.broker.core.plugin.KapuaSecurityContext;
18:
19: import com.google.common.base.Splitter;
20:
21: /**
22: * Default system message creator
23: *
24: * @since 1.0
25: */
26: public class DefaultSystemMessageCreator implements SystemMessageCreator {
27:
28: private static final String FIELD_SEPARATOR = ",,";
29: private static final String PAIR_SEPARATOR = ",";
30: private static final String DEVICE_ID_KEY = "DeviceId";
31: private static final String EVENT_KEY = "Event";
32: private static final String USERNAME_KEY = "Username";
33:
34: @Override
35: public String createMessage(SystemMessageType systemMessageType, KapuaSecurityContext kapuaSecurityContext) {
36: StringBuilder builder = new StringBuilder();
37: builder.append(EVENT_KEY).append(PAIR_SEPARATOR).append(systemMessageType.name());
38: builder.append(FIELD_SEPARATOR).append(DEVICE_ID_KEY).append(PAIR_SEPARATOR).append(kapuaSecurityContext.getClientId());
39: builder.append(FIELD_SEPARATOR).append(USERNAME_KEY).append(PAIR_SEPARATOR).append(kapuaSecurityContext.getUserName());
40: return builder.toString();
41: }
42:
43: public Map<String, String> convertFrom(String message) {
44: return Splitter.on(FIELD_SEPARATOR).withKeyValueSeparator(PAIR_SEPARATOR).split(message);
45: }
46:
47: public String getDeviceId(Map<String, String> map) {
48: return map.get(DEVICE_ID_KEY);
49: }
50:
51: public String getUsername(Map<String, String> map) {
52: return map.get(USERNAME_KEY);
53: }
54:
55: }