Search in sources :

Example 1 with PackageResponseChannel

use of org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseChannel in project kapua by eclipse.

the class TranslatorAppPackageKuraKapua method translate.

private PackageResponseChannel translate(KuraResponseChannel kuraChannel) throws KapuaException {
    if (!CONTROL_MESSAGE_CLASSIFIER.equals(kuraChannel.getMessageClassification())) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
    }
    PackageResponseChannel responseChannel = new PackageResponseChannel();
    String[] appIdTokens = kuraChannel.getAppId().split("-");
    if (!PackageMetrics.APP_ID.getValue().equals(appIdTokens[0])) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, appIdTokens[0]);
    }
    if (!PackageMetrics.APP_VERSION.getValue().equals(appIdTokens[1])) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_VERSION, null, appIdTokens[1]);
    }
    responseChannel.setAppName(PackageAppProperties.APP_NAME);
    responseChannel.setVersion(PackageAppProperties.APP_VERSION);
    // Return Kapua Channel
    return responseChannel;
}
Also used : PackageResponseChannel(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseChannel) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException)

Example 2 with PackageResponseChannel

use of org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseChannel in project kapua by eclipse.

the class TranslatorAppPackageKuraKapua method translate.

@Override
public PackageResponseMessage translate(KuraResponseMessage kuraMessage) throws KapuaException {
    // 
    // Kura channel
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.findByName(kuraMessage.getChannel().getScope());
    PackageResponseChannel responseChannel = translate(kuraMessage.getChannel());
    // 
    // Kura payload
    PackageResponsePayload responsePayload = translate(kuraMessage.getPayload());
    // 
    // Kura Message
    PackageResponseMessage kapuaMessage = new PackageResponseMessage();
    kapuaMessage.setScopeId(account.getId());
    kapuaMessage.setChannel(responseChannel);
    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 : BigInteger(java.math.BigInteger) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) PackageResponsePayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload) PackageResponseMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage) PackageResponseChannel(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseChannel) AccountService(org.eclipse.kapua.service.account.AccountService)

Aggregations

PackageResponseChannel (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseChannel)2 BigInteger (java.math.BigInteger)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 Account (org.eclipse.kapua.service.account.Account)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 PackageResponseMessage (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage)1 PackageResponsePayload (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1