Skip to content

Package: KeystoreResponsePayload

KeystoreResponsePayload

nameinstructionbranchcomplexitylinemethod
KeystoreResponsePayload()
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%
getCSR()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getKeystoreItem()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getKeystoreItems()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getKeystores()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setCSR(DeviceKeystoreCSR)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setKeystoreItem(DeviceKeystoreItem)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setKeystoreItems(DeviceKeystoreItems)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setKeystores(DeviceKeystores)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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.service.device.management.keystore.internal.message.response;
14:
15: import org.eclipse.kapua.commons.util.xml.XmlUtil;
16: import org.eclipse.kapua.locator.KapuaLocator;
17: import org.eclipse.kapua.service.device.management.commons.message.response.KapuaResponsePayloadImpl;
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.DeviceKeystoreManagementFactory;
21: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystore;
22: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreCSR;
23: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreItem;
24: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreItems;
25: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystores;
26: import org.eclipse.kapua.service.device.management.message.response.KapuaResponsePayload;
27:
28: import javax.validation.constraints.NotNull;
29:
30: /**
31: * {@link DeviceKeystore} {@link KapuaResponsePayload} implementation.
32: *
33: * @since 1.5.0
34: */
35: public class KeystoreResponsePayload extends KapuaResponsePayloadImpl implements KapuaResponsePayload {
36:
37: private static final long serialVersionUID = 4380715272822080425L;
38:
39: private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
40:
41: private static final DeviceKeystoreManagementFactory DEVICE_KEYSTORE_MANAGEMENT_FACTORY = KapuaLocator.getInstance().getFactory(DeviceKeystoreManagementFactory.class);
42:
43: /**
44: * Gets the {@link DeviceKeystores} from the {@link #getBody()}.
45: *
46: * @return The {@link DeviceKeystores} from the {@link #getBody()}.
47: * @throws Exception if reading {@link #getBody()} errors.
48: * @since 1.5.0
49: */
50: public DeviceKeystores getKeystores() throws Exception {
51:• if (!hasBody()) {
52: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystores();
53: }
54:
55: String bodyString = new String(getBody(), CHAR_ENCODING);
56: return XmlUtil.unmarshal(bodyString, DeviceKeystores.class);
57: }
58:
59: /**
60: * Sets the {@link DeviceKeystores} in the {@link #getBody()}.
61: *
62: * @param keystores The {@link DeviceKeystores} in the {@link #getBody()}.
63: * @throws Exception if writing errors.
64: * @since 1.5.0
65: */
66: public void setKeystores(@NotNull DeviceKeystores keystores) throws Exception {
67: String bodyString = XmlUtil.marshal(keystores);
68: setBody(bodyString.getBytes(CHAR_ENCODING));
69: }
70:
71: /**
72: * Gets the {@link DeviceKeystoreItems} from the {@link #getBody()}.
73: *
74: * @return The {@link DeviceKeystoreItems} from the {@link #getBody()}.
75: * @throws Exception if reading {@link #getBody()} errors.
76: * @since 1.5.0
77: */
78: public DeviceKeystoreItems getKeystoreItems() throws Exception {
79:• if (!hasBody()) {
80: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreItems();
81: }
82:
83: String bodyString = new String(getBody(), CHAR_ENCODING);
84: return XmlUtil.unmarshal(bodyString, DeviceKeystoreItems.class);
85: }
86:
87: /**
88: * Sets the {@link DeviceKeystoreItems} in the {@link #getBody()}.
89: *
90: * @param keystoreItems The {@link DeviceKeystoreItems} in the {@link #getBody()}.
91: * @throws Exception if writing errors.
92: * @since 1.5.0
93: */
94: public void setKeystoreItems(@NotNull DeviceKeystoreItems keystoreItems) throws Exception {
95: String bodyString = XmlUtil.marshal(keystoreItems);
96: setBody(bodyString.getBytes(CHAR_ENCODING));
97: }
98:
99: /**
100: * Gets the {@link DeviceKeystoreItem} from the {@link #getBody()}.
101: *
102: * @return The {@link DeviceKeystoreItem} from the {@link #getBody()}.
103: * @throws Exception if reading {@link #getBody()} errors.
104: * @since 1.5.0
105: */
106: public DeviceKeystoreItem getKeystoreItem() throws Exception {
107:• if (!hasBody()) {
108: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreItem();
109: }
110:
111: String bodyString = new String(getBody(), CHAR_ENCODING);
112: return XmlUtil.unmarshal(bodyString, DeviceKeystoreItem.class);
113: }
114:
115: /**
116: * Sets the {@link DeviceKeystoreItem} in the {@link #getBody()}.
117: *
118: * @param keystoreItem The {@link DeviceKeystoreItem} in the {@link #getBody()}.
119: * @throws Exception if writing errors.
120: * @since 1.5.0
121: */
122: public void setKeystoreItem(@NotNull DeviceKeystoreItem keystoreItem) throws Exception {
123: String bodyString = XmlUtil.marshal(keystoreItem);
124: setBody(bodyString.getBytes(CHAR_ENCODING));
125: }
126:
127: /**
128: * Gets the {@link DeviceKeystoreCSR} from the {@link #getBody()}.
129: *
130: * @return The {@link DeviceKeystoreCSR} from the {@link #getBody()}.
131: * @throws Exception if reading {@link #getBody()} errors.
132: * @since 1.5.0
133: */
134: public DeviceKeystoreCSR getCSR() throws Exception {
135:• if (!hasBody()) {
136: return DEVICE_KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreCSR();
137: }
138:
139: String bodyString = new String(getBody(), CHAR_ENCODING);
140: return XmlUtil.unmarshal(bodyString, DeviceKeystoreCSR.class);
141: }
142:
143: /**
144: * Sets the {@link DeviceKeystoreCSR} in the {@link #getBody()}.
145: *
146: * @param deviceCSR The {@link DeviceKeystoreCSR} in the {@link #getBody()}.
147: * @throws Exception if writing errors.
148: * @since 1.5.0
149: */
150: public void setCSR(@NotNull DeviceKeystoreCSR deviceCSR) throws Exception {
151: String bodyString = XmlUtil.marshal(deviceCSR);
152: setBody(bodyString.getBytes(CHAR_ENCODING));
153: }
154: }