use of org.eclipse.kapua.service.account.Account in project kapua by eclipse.
the class TranslatorLifeDisconnectKuraKapua method translate.
@Override
public KapuaDisconnectMessage translate(KuraDisconnectMessage kuraDisconnectMessage) throws KapuaException {
KapuaDisconnectMessage kapuaDisconnectMessage = new KapuaDisconnectMessageImpl();
kapuaDisconnectMessage.setChannel(translate(kuraDisconnectMessage.getChannel()));
kapuaDisconnectMessage.setPayload(translate(kuraDisconnectMessage.getPayload()));
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraDisconnectMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraDisconnectMessage.getChannel().getClientId());
if (device == null) {
throw new KapuaEntityNotFoundException(Device.class.toString(), kuraDisconnectMessage.getChannel().getClientId());
}
kapuaDisconnectMessage.setDeviceId(device.getId());
kapuaDisconnectMessage.setScopeId(account.getId());
kapuaDisconnectMessage.setCapturedOn(kuraDisconnectMessage.getPayload().getTimestamp());
kapuaDisconnectMessage.setSentOn(kuraDisconnectMessage.getPayload().getTimestamp());
kapuaDisconnectMessage.setReceivedOn(kuraDisconnectMessage.getTimestamp());
kapuaDisconnectMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraDisconnectMessage.getPayload().getPosition()));
return kapuaDisconnectMessage;
}
use of org.eclipse.kapua.service.account.Account in project kapua by eclipse.
the class TranslatorLifeMissingKuraKapua method translate.
@Override
public KapuaMissingMessage translate(KuraMissingMessage kuraMissingMessage) throws KapuaException {
KapuaMissingMessage kapuaMissingMessage = new KapuaMissingMessageImpl();
kapuaMissingMessage.setChannel(translate(kuraMissingMessage.getChannel()));
kapuaMissingMessage.setPayload(translate(kuraMissingMessage.getPayload()));
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraMissingMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraMissingMessage.getChannel().getClientId());
if (device == null) {
throw new KapuaEntityNotFoundException(Device.class.toString(), kuraMissingMessage.getChannel().getClientId());
}
kapuaMissingMessage.setDeviceId(device.getId());
kapuaMissingMessage.setScopeId(account.getId());
kapuaMissingMessage.setCapturedOn(kuraMissingMessage.getPayload().getTimestamp());
kapuaMissingMessage.setSentOn(kuraMissingMessage.getPayload().getTimestamp());
kapuaMissingMessage.setReceivedOn(kuraMissingMessage.getTimestamp());
kapuaMissingMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraMissingMessage.getPayload().getPosition()));
return kapuaMissingMessage;
}
Aggregations