Search in sources :

Example 1 with CommandResponseChannel

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;
}
Also used : CommandResponseChannel(org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseChannel) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException)

Example 2 with CommandResponseChannel

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;
}
Also used : CommandResponsePayload(org.eclipse.kapua.service.device.management.command.message.internal.CommandResponsePayload) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) CommandResponseChannel(org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseChannel) CommandResponseMessage(org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseMessage) AccountService(org.eclipse.kapua.service.account.AccountService)

Aggregations

CommandResponseChannel (org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseChannel)2 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 Account (org.eclipse.kapua.service.account.Account)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 CommandResponseMessage (org.eclipse.kapua.service.device.management.command.message.internal.CommandResponseMessage)1 CommandResponsePayload (org.eclipse.kapua.service.device.management.command.message.internal.CommandResponsePayload)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1