use of org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseChannel in project kapua by eclipse.
the class TranslatorAppBundleKuraKapua method translate.
private BundleResponseChannel translate(KuraResponseChannel kuraChannel) throws KapuaException {
if (!CONTROL_MESSAGE_CLASSIFIER.equals(kuraChannel.getMessageClassification())) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
}
BundleResponseChannel bundleResponseChannel = new BundleResponseChannel();
String[] appIdTokens = kuraChannel.getAppId().split("-");
if (!BundleMetrics.APP_ID.getValue().equals(appIdTokens[0])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, appIdTokens[0]);
}
if (!BundleMetrics.APP_VERSION.getValue().equals(appIdTokens[1])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_VERSION, null, appIdTokens[1]);
}
bundleResponseChannel.setAppName(DeviceBundleAppProperties.APP_NAME);
bundleResponseChannel.setVersion(DeviceBundleAppProperties.APP_VERSION);
// Return Kapua Channel
return bundleResponseChannel;
}
use of org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseChannel in project kapua by eclipse.
the class TranslatorAppBundleKuraKapua method translate.
@Override
public BundleResponseMessage translate(KuraResponseMessage kuraMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraMessage.getChannel().getScope());
BundleResponseChannel bundleResponseChannel = translate(kuraMessage.getChannel());
//
// Kura payload
BundleResponsePayload responsePayload = translate(kuraMessage.getPayload());
//
// Kura Message
BundleResponseMessage kapuaMessage = new BundleResponseMessage();
kapuaMessage.setScopeId(account.getId());
kapuaMessage.setChannel(bundleResponseChannel);
kapuaMessage.setPayload(responsePayload);
kapuaMessage.setCapturedOn(kuraMessage.getPayload().getTimestamp());
kapuaMessage.setSentOn(kuraMessage.getPayload().getTimestamp());
kapuaMessage.setReceivedOn(kuraMessage.getTimestamp());
kapuaMessage.setResponseCode(TranslatorKuraKapuaUtils.translate((Integer) kuraMessage.getPayload().getMetrics().get(ResponseMetrics.RESP_METRIC_EXIT_CODE.getValue())));
// Return Kapua Message
return kapuaMessage;
}
Aggregations