Search in sources :

Example 1 with BundleResponseChannel

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

Example 2 with 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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) BundleResponsePayload(org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponsePayload) BundleResponseChannel(org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseChannel) AccountService(org.eclipse.kapua.service.account.AccountService) BundleResponseMessage(org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseMessage)

Aggregations

BundleResponseChannel (org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseChannel)2 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 Account (org.eclipse.kapua.service.account.Account)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 BundleResponseMessage (org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponseMessage)1 BundleResponsePayload (org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponsePayload)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1