Skip to content

Package: AbstractTranslatorKuraKapua

AbstractTranslatorKuraKapua

nameinstructionbranchcomplexitylinemethod
AbstractTranslatorKuraKapua()
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%
lambda$translate$0(KuraResponseMessage)
M: 8 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: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
translate(KuraResponseMessage)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 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.KapuaEntityNotFoundException;
17: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
18: import org.eclipse.kapua.locator.KapuaLocator;
19: import org.eclipse.kapua.message.KapuaChannel;
20: import org.eclipse.kapua.message.KapuaMessage;
21: import org.eclipse.kapua.message.KapuaPayload;
22: import org.eclipse.kapua.service.account.Account;
23: import org.eclipse.kapua.service.account.AccountService;
24: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseChannel;
25: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseMessage;
26: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponsePayload;
27: import org.eclipse.kapua.translator.Translator;
28: import org.eclipse.kapua.translator.exception.InvalidChannelException;
29: import org.eclipse.kapua.translator.exception.InvalidMessageException;
30: import org.eclipse.kapua.translator.exception.InvalidPayloadException;
31: import org.eclipse.kapua.translator.exception.TranslateException;
32:
33: /**
34: * {@link Translator} {@code abstract} implementation from {@link KuraResponseMessage} to {@link KapuaMessage}
35: *
36: * @since 1.0.0
37: */
38: public abstract class AbstractTranslatorKuraKapua<TO_C extends KapuaChannel, TO_P extends KapuaPayload, TO_M extends KapuaMessage<TO_C, TO_P>> extends Translator<KuraResponseMessage, TO_M> {
39:
40: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
41:
42: private static final AccountService ACCOUNT_SERVICE = LOCATOR.getService(AccountService.class);
43:
44: @Override
45: public TO_M translate(KuraResponseMessage kuraMessage) throws TranslateException {
46: try {
47: Account account = KapuaSecurityUtils.doPrivileged(() -> ACCOUNT_SERVICE.findByName(kuraMessage.getChannel().getScope()));
48:
49:• if (account == null) {
50: throw new KapuaEntityNotFoundException(Account.TYPE, kuraMessage.getChannel().getScope());
51: }
52:
53: return translateMessage(kuraMessage, account);
54: } catch (TranslateException te) {
55: throw te;
56: } catch (Exception e) {
57: throw new InvalidMessageException(e, kuraMessage);
58: }
59: }
60:
61: /**
62: * @since 1.0.0
63: */
64: protected abstract TO_M translateMessage(KuraResponseMessage kuraMessage, Account account) throws TranslateException;
65:
66: /**
67: * @since 1.0.0
68: */
69: protected abstract TO_C translateChannel(KuraResponseChannel kuraChannel) throws InvalidChannelException;
70:
71: /**
72: * @since 1.0.0
73: */
74: protected abstract TO_P translatePayload(KuraResponsePayload kuraPayload) throws InvalidPayloadException;
75:
76: }