use of org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseChannel in project kapua by eclipse.
the class TranslatorAppCommandKuraKapua method translate.
private CommandResponseChannel translate(KuraResponseChannel kuraChannel) throws KapuaException {
if (!CONTROL_MESSAGE_CLASSIFIER.equals(kuraChannel.getMessageClassification())) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
}
CommandResponseChannel kapuaChannel = new CommandResponseChannel();
String[] appIdTokens = kuraChannel.getAppId().split("-");
if (!CommandMetrics.APP_ID.getValue().equals(appIdTokens[0])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, appIdTokens[0]);
}
if (!CommandMetrics.APP_VERSION.getValue().equals(appIdTokens[1])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_VERSION, null, appIdTokens[1]);
}
kapuaChannel.setAppName(CommandAppProperties.APP_NAME);
kapuaChannel.setVersion(CommandAppProperties.APP_VERSION);
// Return Kapua Channel
return kapuaChannel;
}
use of org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseChannel in project kapua by eclipse.
the class TranslatorAppCommandKuraKapua method translate.
@Override
public CommandResponseMessage translate(KuraResponseMessage kuraMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraMessage.getChannel().getScope());
CommandResponseChannel commandResponseChannel = translate(kuraMessage.getChannel());
//
// Kura payload
CommandResponsePayload responsePayload = translate(kuraMessage.getPayload());
//
// Kura Message
CommandResponseMessage kapuaMessage = new CommandResponseMessage();
kapuaMessage.setScopeId(account.getId());
kapuaMessage.setChannel(commandResponseChannel);
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