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;
}
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;
}
Aggregations