Skip to content

Package: TranslatorAppKeystoreKeypairKapuaKura

TranslatorAppKeystoreKeypairKapuaKura

nameinstructionbranchcomplexitylinemethod
TranslatorAppKeystoreKeypairKapuaKura()
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%
getClassFrom()
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: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
translatePayload(KeystoreRequestPayload)
M: 55 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2021, 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.kapua.kura.keystore;
14:
15: import org.eclipse.kapua.service.device.call.kura.model.keystore.KuraKeystoreKeypair;
16: import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestMessage;
17: import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestPayload;
18: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting;
19: import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSettingKey;
20: import org.eclipse.kapua.service.device.management.keystore.internal.message.request.KeystoreKeypairRequestMessage;
21: import org.eclipse.kapua.service.device.management.keystore.internal.message.request.KeystoreRequestPayload;
22: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreKeypair;
23: import org.eclipse.kapua.translator.Translator;
24: import org.eclipse.kapua.translator.exception.InvalidPayloadException;
25:
26: /**
27: * {@link Translator} implementation from {@link KeystoreKeypairRequestMessage} to {@link KuraRequestMessage}
28: *
29: * @since 1.5.0
30: */
31: public class TranslatorAppKeystoreKeypairKapuaKura extends AbstractTranslatorAppKeystoreKapuaKura<KeystoreKeypairRequestMessage> {
32:
33: private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
34:
35: @Override
36: protected KuraRequestPayload translatePayload(KeystoreRequestPayload keystoreRequestPayload) throws InvalidPayloadException {
37: try {
38: KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
39:
40:• if (keystoreRequestPayload.hasBody()) {
41: DeviceKeystoreKeypair deviceKeystoreKeypair = keystoreRequestPayload.getKeypair();
42:
43: KuraKeystoreKeypair kuraKeystoreKeypair = new KuraKeystoreKeypair();
44: kuraKeystoreKeypair.setKeystoreServicePid(deviceKeystoreKeypair.getKeystoreId());
45: kuraKeystoreKeypair.setAlias(deviceKeystoreKeypair.getAlias());
46: kuraKeystoreKeypair.setAlgorithm(deviceKeystoreKeypair.getAlgorithm());
47: kuraKeystoreKeypair.setSize(deviceKeystoreKeypair.getSize());
48: kuraKeystoreKeypair.setSignatureAlgorithm(deviceKeystoreKeypair.getSignatureAlgorithm());
49: kuraKeystoreKeypair.setAttributes(deviceKeystoreKeypair.getAttributes());
50:
51: kuraRequestPayload.setBody(getJsonMapper().writeValueAsString(kuraKeystoreKeypair).getBytes(CHAR_ENCODING));
52: }
53:
54: return kuraRequestPayload;
55: } catch (Exception e) {
56: throw new InvalidPayloadException(e, keystoreRequestPayload);
57: }
58: }
59:
60: @Override
61: public Class<KeystoreKeypairRequestMessage> getClassFrom() {
62: return KeystoreKeypairRequestMessage.class;
63: }
64: }