Skip to content

Package: AbstractTranslatorResponseKuraKapua

AbstractTranslatorResponseKuraKapua

nameinstructionbranchcomplexitylinemethod
AbstractTranslatorResponseKuraKapua()
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%
getControlMessageClassifier()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
translateMessage(KuraResponseMessage, Account)
M: 60 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 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: * Red Hat Inc
13: *******************************************************************************/
14: package org.eclipse.kapua.translator.kura.kapua;
15:
16: import org.eclipse.kapua.KapuaException;
17: import org.eclipse.kapua.commons.setting.system.SystemSetting;
18: import org.eclipse.kapua.service.account.Account;
19: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseChannel;
20: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseMessage;
21: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponsePayload;
22: import org.eclipse.kapua.service.device.management.message.response.KapuaResponseChannel;
23: import org.eclipse.kapua.service.device.management.message.response.KapuaResponseMessage;
24: import org.eclipse.kapua.service.device.management.message.response.KapuaResponsePayload;
25: import org.eclipse.kapua.translator.exception.InvalidChannelException;
26: import org.eclipse.kapua.translator.exception.InvalidMessageException;
27: import org.eclipse.kapua.translator.exception.InvalidPayloadException;
28: import org.eclipse.kapua.translator.exception.TranslateException;
29:
30: /**
31: * {@link org.eclipse.kapua.translator.Translator} {@code abstract} implementation from {@link KuraResponseMessage} to {@link KapuaResponseMessage}
32: *
33: * @since 1.0.0
34: */
35: public abstract class AbstractTranslatorResponseKuraKapua<TO_C extends KapuaResponseChannel, TO_P extends KapuaResponsePayload, TO_M extends KapuaResponseMessage<TO_C, TO_P>> extends AbstractTranslatorKuraKapua<TO_C, TO_P, TO_M> {
36:
37: private static final String CONTROL_MESSAGE_CLASSIFIER = SystemSetting.getInstance().getMessageClassifier();
38:
39: @Override
40: protected TO_M translateMessage(KuraResponseMessage kuraMessage, Account account) throws TranslateException {
41:
42: try {
43: // Translate channel
44: TO_C bundleResponseChannel = translateChannel(kuraMessage.getChannel());
45:
46: // Translate payload
47: TO_P responsePayload = translatePayload(kuraMessage.getPayload());
48:
49: // Process messsage
50: TO_M kapuaMessage = createMessage();
51: kapuaMessage.setScopeId(account.getId());
52: kapuaMessage.setChannel(bundleResponseChannel);
53: kapuaMessage.setPayload(responsePayload);
54: kapuaMessage.setCapturedOn(kuraMessage.getPayload().getTimestamp());
55: kapuaMessage.setSentOn(kuraMessage.getPayload().getTimestamp());
56: kapuaMessage.setReceivedOn(kuraMessage.getTimestamp());
57: kapuaMessage.setResponseCode(TranslatorKuraKapuaUtils.translate(kuraMessage.getPayload().getResponseCode()));
58:
59: // Return Kapua Message
60: return kapuaMessage;
61: } catch (InvalidChannelException | InvalidPayloadException te) {
62: throw te;
63: } catch (Exception e) {
64: throw new InvalidMessageException(e, kuraMessage);
65: }
66: }
67:
68: /**
69: * Gets the value from {@link SystemSetting#getMessageClassifier()}
70: *
71: * @return The value from {@link SystemSetting#getMessageClassifier()}
72: * @since 1.2.0
73: */
74: protected static String getControlMessageClassifier() {
75: return CONTROL_MESSAGE_CLASSIFIER;
76: }
77:
78: protected abstract TO_M createMessage() throws KapuaException;
79:
80: @Override
81: protected abstract TO_C translateChannel(KuraResponseChannel kuraChannel) throws InvalidChannelException;
82:
83: @Override
84: protected abstract TO_P translatePayload(KuraResponsePayload kuraPayload) throws InvalidPayloadException;
85:
86: }