Search in sources :

Example 21 with Device

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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 22 with Device

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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KuraPayload(org.eclipse.kapua.service.device.call.message.kura.KuraPayload) Device(org.eclipse.kapua.service.device.registry.Device) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraChannel(org.eclipse.kapua.service.device.call.message.kura.KuraChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraMessage(org.eclipse.kapua.service.device.call.message.kura.KuraMessage) Date(java.util.Date)

Example 23 with Device

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaDataMessage(org.eclipse.kapua.message.device.data.KapuaDataMessage) Device(org.eclipse.kapua.service.device.registry.Device) KapuaDataChannel(org.eclipse.kapua.message.device.data.KapuaDataChannel) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KapuaDataMessageImpl(org.eclipse.kapua.message.internal.device.data.KapuaDataMessageImpl) KapuaDataPayload(org.eclipse.kapua.message.device.data.KapuaDataPayload) AccountService(org.eclipse.kapua.service.account.AccountService)

Example 24 with Device

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

Example 25 with Device

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

Aggregations

Device (org.eclipse.kapua.service.device.registry.Device)31 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)23 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)22 KapuaId (org.eclipse.kapua.model.id.KapuaId)11 Account (org.eclipse.kapua.service.account.Account)11 AccountService (org.eclipse.kapua.service.account.AccountService)11 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)5 KuraRequestChannel (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)5 KuraRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage)5 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)5 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)5 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)5 KapuaPosition (org.eclipse.kapua.message.KapuaPosition)4 DeviceFactory (org.eclipse.kapua.service.device.registry.DeviceFactory)4 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)4 ArrayList (java.util.ArrayList)3 AttributePredicate (org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)3 KapuaPayload (org.eclipse.kapua.message.KapuaPayload)3 FieldSortCriteria (org.eclipse.kapua.commons.model.query.FieldSortCriteria)2