Skip to content

Package: AbstractTranslatorEventJmsKura

AbstractTranslatorEventJmsKura

nameinstructionbranchcomplexitylinemethod
AbstractTranslatorEventJmsKura(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
translate(JmsTopic)
M: 50 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2020, 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.translator.jms.kura.event;
14:
15: import org.eclipse.kapua.service.device.call.message.app.event.DeviceManagementEventChannel;
16: import org.eclipse.kapua.service.device.call.message.app.event.DeviceManagementEventMessage;
17: import org.eclipse.kapua.service.device.call.message.app.event.DeviceManagementEventPayload;
18: import org.eclipse.kapua.service.device.call.message.lifecycle.DeviceLifecycleChannel;
19: import org.eclipse.kapua.service.device.call.message.lifecycle.DeviceLifecycleMessage;
20: import org.eclipse.kapua.service.device.call.message.lifecycle.DeviceLifecyclePayload;
21: import org.eclipse.kapua.translator.Translator;
22: import org.eclipse.kapua.translator.exception.InvalidChannelException;
23: import org.eclipse.kapua.translator.exception.TranslatorErrorCodes;
24: import org.eclipse.kapua.translator.exception.TranslatorException;
25: import org.eclipse.kapua.translator.jms.kura.AbstractTranslatorJmsKura;
26: import org.eclipse.kapua.transport.message.jms.JmsMessage;
27: import org.eclipse.kapua.transport.message.jms.JmsTopic;
28:
29: /**
30: * {@link Translator} {@code abstract} base implementation from {@link JmsMessage} to {@link DeviceLifecycleMessage}
31: *
32: * @param <C> The {@link DeviceLifecycleChannel} type.
33: * @param <P> The {@link DeviceLifecyclePayload} type.
34: * @param <M> The {@link DeviceLifecycleMessage} type.
35: * @since 1.2.0
36: */
37: public abstract class AbstractTranslatorEventJmsKura<C extends DeviceManagementEventChannel, P extends DeviceManagementEventPayload, M extends DeviceManagementEventMessage<C, P>>
38: extends AbstractTranslatorJmsKura<C, P, M> {
39:
40: /**
41: * Constructor.
42: * <p>
43: * Defines the {@link DeviceManagementEventMessage} type.
44: *
45: * @param deviceManagementEventClazz The specific {@link DeviceManagementEventMessage} type.
46: * @since 2.0.0
47: */
48: public AbstractTranslatorEventJmsKura(Class<M> deviceManagementEventClazz) {
49: super(deviceManagementEventClazz);
50: }
51:
52: /**
53: * Translates the given {@link JmsTopic}.
54: * <p>
55: * Checks that the {@link JmsTopic#getSplittedTopic()} has at least 3 tokens.
56: *
57: * @param jmsTopic The {@link JmsTopic} to translate
58: * @return The translated {@link DeviceManagementEventChannel}
59: * @throws InvalidChannelException in case that @link JmsTopic#getSplittedTopic()} has less than 3 tokens.
60: * @since 1.2.0
61: */
62: @Override
63: public C translate(JmsTopic jmsTopic) throws InvalidChannelException {
64: try {
65: String[] topicTokens = jmsTopic.getSplittedTopic();
66:
67: // $EDC/{account}/{clientId}/{appName}/(appVersion}/...
68:• if (topicTokens.length < 5) {
69: throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL, null, (Object) topicTokens);
70: }
71:
72: C deviceManagementEventChannel = createChannel(topicTokens[0], topicTokens[1], topicTokens[2]);
73: deviceManagementEventChannel.setAppName(topicTokens[3]);
74: deviceManagementEventChannel.setAppVersion(topicTokens[4]);
75:
76: return deviceManagementEventChannel;
77: } catch (Exception e) {
78: throw new InvalidChannelException(e, jmsTopic);
79: }
80: }
81:
82: /**
83: * Instantiates the specific {@link DeviceManagementEventChannel} with the given parameters.
84: *
85: * @param messageClassifier The message classification.
86: * @param scopeName The scope namespace.
87: * @param clientId The clientId.
88: * @return The newly instantiated {@link DeviceManagementEventChannel}.
89: * @since 2.0.0
90: */
91: @Override
92: public abstract C createChannel(String messageClassifier, String scopeName, String clientId);
93: }
94:
95: