Skip to content

Package: TranslatorAppResponseKuraKapua

TranslatorAppResponseKuraKapua

nameinstructionbranchcomplexitylinemethod
TranslatorAppResponseKuraKapua()
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%
static {...}
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%
translateChannel(KuraResponseChannel)
M: 76 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
translatePayload(KuraResponsePayload)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.translator.kura.kapua;
13:
14: import org.eclipse.kapua.locator.KapuaLocator;
15: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseChannel;
16: import org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponsePayload;
17: import org.eclipse.kapua.service.device.management.request.GenericRequestFactory;
18: import org.eclipse.kapua.service.device.management.request.internal.GenericAppProperties;
19: import org.eclipse.kapua.service.device.management.request.message.response.GenericResponseChannel;
20: import org.eclipse.kapua.service.device.management.request.message.response.GenericResponseMessage;
21: import org.eclipse.kapua.service.device.management.request.message.response.GenericResponsePayload;
22: import org.eclipse.kapua.translator.exception.InvalidChannelException;
23: import org.eclipse.kapua.translator.exception.InvalidPayloadException;
24: import org.eclipse.kapua.translator.exception.TranslatorErrorCodes;
25: import org.eclipse.kapua.translator.exception.TranslatorException;
26:
27: /**
28: * {@link org.eclipse.kapua.translator.Translator} implementation from {@link org.eclipse.kapua.service.device.call.message.kura.app.response.KuraResponseMessage} to {@link GenericResponseMessage}
29: *
30: * @since 1.0.0
31: */
32: public class TranslatorAppResponseKuraKapua extends AbstractSimpleTranslatorResponseKuraKapua<GenericResponseChannel, GenericResponsePayload, GenericResponseMessage> {
33:
34: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
35:
36: public TranslatorAppResponseKuraKapua() {
37: super(GenericResponseMessage.class);
38: }
39:
40: @Override
41: protected GenericResponseChannel translateChannel(KuraResponseChannel kuraChannel) throws InvalidChannelException {
42: try {
43: GenericRequestFactory genericRequestFactory = LOCATOR.getFactory(GenericRequestFactory.class);
44:
45:• if (!getControlMessageClassifier().equals(kuraChannel.getMessageClassification())) {
46: throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
47: }
48:
49: GenericResponseChannel genericResponseChannel = genericRequestFactory.newResponseChannel();
50: String[] appIdTokens = kuraChannel.getAppId().split("-");
51:
52:• if (appIdTokens.length < 1) {
53: throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, (Object) appIdTokens);
54: }
55:
56: genericResponseChannel.setAppName(new GenericAppProperties(appIdTokens[0]));
57:• if (appIdTokens.length > 1) {
58: genericResponseChannel.setVersion(new GenericAppProperties(appIdTokens[1]));
59: }
60:
61: return genericResponseChannel;
62: } catch (Exception e) {
63: throw new InvalidChannelException(e, kuraChannel);
64: }
65: }
66:
67: @Override
68: protected GenericResponsePayload translatePayload(KuraResponsePayload kuraPayload) throws InvalidPayloadException {
69: try {
70: GenericRequestFactory genericRequestFactory = LOCATOR.getFactory(GenericRequestFactory.class);
71:
72: GenericResponsePayload genericResponsePayload = genericRequestFactory.newResponsePayload();
73: genericResponsePayload.setBody(kuraPayload.getBody());
74: genericResponsePayload.setMetrics(kuraPayload.getMetrics());
75: genericResponsePayload.setExceptionMessage(kuraPayload.getExceptionMessage());
76: genericResponsePayload.setExceptionStack(kuraPayload.getExceptionStack());
77: return genericResponsePayload;
78: } catch (Exception e) {
79: throw new InvalidPayloadException(e, kuraPayload);
80: }
81: }
82: }