/
TranslatorAppKeystoreQueryKapuaKura.java
62 lines (52 loc) · 2.92 KB
/
TranslatorAppKeystoreQueryKapuaKura.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
* Copyright (c) 2021 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.translator.kapua.kura.keystore;
import org.eclipse.kapua.service.device.call.kura.model.keystore.KuraKeystoreItemQuery;
import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestMessage;
import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestPayload;
import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting;
import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSettingKey;
import org.eclipse.kapua.service.device.management.keystore.message.internal.request.KeystoreQueryRequestMessage;
import org.eclipse.kapua.service.device.management.keystore.message.internal.request.KeystoreRequestPayload;
import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreItemQuery;
import org.eclipse.kapua.translator.exception.InvalidPayloadException;
/**
* {@link org.eclipse.kapua.translator.Translator} implementation from {@link KeystoreQueryRequestMessage} to {@link KuraRequestMessage}
*
* @since 1.5.0
*/
public class TranslatorAppKeystoreQueryKapuaKura extends AbstractTranslatorAppKeystoreKapuaKura<KeystoreQueryRequestMessage> {
private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);
@Override
protected KuraRequestPayload translatePayload(KeystoreRequestPayload kapuaPayload) throws InvalidPayloadException {
try {
KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
if (kapuaPayload.hasBody()) {
DeviceKeystoreItemQuery deviceKeystoreItemQuery = kapuaPayload.getItemQuery();
if (deviceKeystoreItemQuery.hasFilters()) {
KuraKeystoreItemQuery kuraItemQuery = new KuraKeystoreItemQuery();
kuraItemQuery.setKeystoreServicePid(deviceKeystoreItemQuery.getKeystoreId());
kuraItemQuery.setAlias(deviceKeystoreItemQuery.getAlias());
kuraRequestPayload.setBody(getJsonMapper().writeValueAsString(kuraItemQuery).getBytes(CHAR_ENCODING));
}
}
return kuraRequestPayload;
} catch (Exception e) {
throw new InvalidPayloadException(e, kapuaPayload);
}
}
@Override
public Class<KeystoreQueryRequestMessage> getClassFrom() {
return KeystoreQueryRequestMessage.class;
}
}