Package: DefaultSystemMessageCreator
DefaultSystemMessageCreator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultSystemMessageCreator() |
|
|
|
|
|
||||||||||||||||||||
convertFrom(String) |
|
|
|
|
|
||||||||||||||||||||
createMessage(SystemMessageCreator.SystemMessageType, KapuaSecurityContext) |
|
|
|
|
|
||||||||||||||||||||
getDeviceId(Map) |
|
|
|
|
|
||||||||||||||||||||
getUsername(Map) |
|
|
|
|
|
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: }