Search in sources :

Example 1 with KapuaAppsMessage

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaAppsMessageImpl(org.eclipse.kapua.message.internal.device.lifecycle.KapuaAppsMessageImpl) Device(org.eclipse.kapua.service.device.registry.Device) KapuaAppsMessage(org.eclipse.kapua.message.device.lifecycle.KapuaAppsMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) AccountService(org.eclipse.kapua.service.account.AccountService) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException)

Aggregations

KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaAppsMessage (org.eclipse.kapua.message.device.lifecycle.KapuaAppsMessage)1 KapuaAppsMessageImpl (org.eclipse.kapua.message.internal.device.lifecycle.KapuaAppsMessageImpl)1 Account (org.eclipse.kapua.service.account.Account)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 Device (org.eclipse.kapua.service.device.registry.Device)1 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)1