use of org.eclipse.kapua.message.device.lifecycle.KapuaAppsMessage in project kapua by eclipse.
the class TranslatorLifeAppsKuraKapua method translate.
@Override
public KapuaAppsMessage translate(KuraAppsMessage kuraAppsMessage) throws KapuaException {
KapuaAppsMessage kapuaAppsMessage = new KapuaAppsMessageImpl();
kapuaAppsMessage.setChannel(translate(kuraAppsMessage.getChannel()));
kapuaAppsMessage.setPayload(translate(kuraAppsMessage.getPayload()));
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraAppsMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraAppsMessage.getChannel().getClientId());
if (device == null) {
throw new KapuaEntityNotFoundException(Device.class.toString(), kuraAppsMessage.getChannel().getClientId());
}
kapuaAppsMessage.setDeviceId(device.getId());
kapuaAppsMessage.setScopeId(account.getId());
kapuaAppsMessage.setCapturedOn(kuraAppsMessage.getPayload().getTimestamp());
kapuaAppsMessage.setSentOn(kuraAppsMessage.getPayload().getTimestamp());
kapuaAppsMessage.setReceivedOn(kuraAppsMessage.getTimestamp());
kapuaAppsMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraAppsMessage.getPayload().getPosition()));
return kapuaAppsMessage;
}
Aggregations