Search in sources :

Example 1 with TranslatorException

use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.

the class TranslatorResponseMqttKura method translate.

private KuraResponseChannel translate(MqttTopic mqttTopic) throws KapuaException {
    String[] mqttTopicTokens = mqttTopic.getSplittedTopic();
    if (!CONTROL_MESSAGE_CLASSIFIER.equals(mqttTopicTokens[0])) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, mqttTopicTokens[0]);
    }
    KuraResponseChannel kuraResponseChannel = new KuraResponseChannel(mqttTopicTokens[0], mqttTopicTokens[1], mqttTopicTokens[2]);
    kuraResponseChannel.setAppId(mqttTopicTokens[3]);
    kuraResponseChannel.setReplyPart(mqttTopicTokens[4]);
    kuraResponseChannel.setRequestId(mqttTopicTokens[5]);
    // Return Kura Channel
    return kuraResponseChannel;
}
Also used : KuraResponseChannel(org.eclipse.kapua.service.device.call.message.app.response.kura.KuraResponseChannel) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException)

Example 2 with TranslatorException

use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.

the class TranslatorAppBundleKuraKapua method translate.

private BundleResponsePayload translate(KuraResponsePayload kuraPayload) throws KapuaException {
    BundleResponsePayload bundleResponsePayload = new BundleResponsePayload();
    bundleResponsePayload.setExceptionMessage((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
    bundleResponsePayload.setExceptionStack((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
    if (kuraPayload.getBody() != null) {
        DeviceManagementSetting config = DeviceManagementSetting.getInstance();
        String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
        String body = null;
        try {
            body = new String(kuraPayload.getBody(), charEncoding);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kuraPayload.getBody());
        }
        KuraBundles kuraBundles = null;
        try {
            kuraBundles = XmlUtil.unmarshal(body, KuraBundles.class);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
        }
        translate(bundleResponsePayload, charEncoding, kuraBundles);
    }
    // Return Kapua Payload
    return bundleResponsePayload;
}
Also used : KuraBundles(org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundles) BundleResponsePayload(org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponsePayload) DeviceManagementSetting(org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Example 3 with TranslatorException

use of org.eclipse.kapua.translator.exception.TranslatorException 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 4 with TranslatorException

use of org.eclipse.kapua.translator.exception.TranslatorException 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 5 with TranslatorException

use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.

the class TranslatorAppConfigurationKuraKapua method translate.

private ConfigurationResponsePayload translate(KuraResponsePayload kuraPayload) throws KapuaException {
    ConfigurationResponsePayload configurationResponsePayload = new ConfigurationResponsePayload();
    configurationResponsePayload.setExceptionMessage((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
    configurationResponsePayload.setExceptionStack((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
    DeviceManagementSetting config = DeviceManagementSetting.getInstance();
    String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
    if (kuraPayload.getBody() != null) {
        String body = null;
        try {
            body = new String(kuraPayload.getBody(), charEncoding);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, configurationResponsePayload.getBody());
        }
        KuraDeviceConfiguration kuraDeviceConfiguration = null;
        try {
            kuraDeviceConfiguration = XmlUtil.unmarshal(body, KuraDeviceConfiguration.class);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
        }
        translateBody(configurationResponsePayload, charEncoding, kuraDeviceConfiguration);
    }
    // Return Kapua Payload
    return configurationResponsePayload;
}
Also used : KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) DeviceManagementSetting(org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting) ConfigurationResponsePayload(org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationResponsePayload) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)15 KapuaException (org.eclipse.kapua.KapuaException)9 StringWriter (java.io.StringWriter)4 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)4 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)3 KuraDeviceConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration)2 DeviceConfigurationImpl (org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl)2 BigInteger (java.math.BigInteger)1 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)1 KuraBundle (org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundle)1 KuraBundles (org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundles)1 KuraDeviceComponentConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceComponentConfiguration)1 KuraBundleInfo (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraBundleInfo)1 KuraDeploymentPackage (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage)1 KuraDeploymentPackages (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackages)1 KuraSnapshotIds (org.eclipse.kapua.service.device.call.kura.model.snapshot.KuraSnapshotIds)1 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)1 KuraResponseChannel (org.eclipse.kapua.service.device.call.message.app.response.kura.KuraResponseChannel)1 DeviceBundle (org.eclipse.kapua.service.device.management.bundle.DeviceBundle)1 DeviceBundleFactory (org.eclipse.kapua.service.device.management.bundle.DeviceBundleFactory)1