use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorAppSnapshotKapuaKura method translate.
@Override
public KuraRequestMessage translate(SnapshotRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// Return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorDataKapuaKura method translate.
@Override
public KuraMessage translate(KapuaMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KuraChannel kuraChannel = translate(kapuaMessage.getChannel());
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
Device device = deviceRegistryService.find(account.getId(), kapuaMessage.getDeviceId());
kuraChannel.setScope(account.getName());
kuraChannel.setClientId(device.getClientId());
//
// Kura payload
KuraPayload kuraPayload = translate(kapuaMessage.getPayload());
kuraPayload.setPosition(translate(kapuaMessage.getPosition()));
// Kura Message
return new KuraMessage<KuraChannel, KuraPayload>(kuraChannel, new Date(), kuraPayload);
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorDataKuraKapua method translate.
@Override
public KapuaDataMessage translate(KuraDataMessage kuraDataMessage) throws KapuaException {
//
// Kapua Channel
KapuaDataChannel kapuaDataChannel = translate(kuraDataMessage.getChannel());
//
// Kapua payload
KapuaDataPayload kapuaDataPayload = translate(kuraDataMessage.getPayload());
//
// Kapua message
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraDataMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraDataMessage.getChannel().getClientId());
KapuaDataMessage kapuaDataMessage = new KapuaDataMessageImpl();
kapuaDataMessage.setScopeId(account.getId());
kapuaDataMessage.setDeviceId(device != null ? device.getId() : null);
kapuaDataMessage.setClientId(kuraDataMessage.getChannel().getClientId());
kapuaDataMessage.setChannel(kapuaDataChannel);
kapuaDataMessage.setPayload(kapuaDataPayload);
kapuaDataMessage.setCapturedOn(kuraDataMessage.getPayload().getTimestamp());
kapuaDataMessage.setSentOn(kuraDataMessage.getPayload().getTimestamp());
kapuaDataMessage.setReceivedOn(kuraDataMessage.getTimestamp());
kapuaDataMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraDataMessage.getPayload().getPosition()));
// Return Kapua Message
return null;
}
use of org.eclipse.kapua.service.device.registry.Device 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.device.registry.Device 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