Search in sources :

Example 1 with DeviceRegistryService

use of org.eclipse.kapua.service.device.registry.DeviceRegistryService in project kapua by eclipse.

the class TranslatorAppCommandKapuaKura method translate.

@Override
public KuraRequestMessage translate(CommandRequestMessage 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 2 with DeviceRegistryService

use of org.eclipse.kapua.service.device.registry.DeviceRegistryService in project kapua by eclipse.

the class TranslatorAppBundleKapuaKura method translate.

@Override
public KuraRequestMessage translate(BundleRequestMessage 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 3 with DeviceRegistryService

use of org.eclipse.kapua.service.device.registry.DeviceRegistryService 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)

Example 4 with DeviceRegistryService

use of org.eclipse.kapua.service.device.registry.DeviceRegistryService in project kapua by eclipse.

the class TranslatorLifeBirthKuraKapua method translate.

@Override
public KapuaBirthMessage translate(KuraBirthMessage kuraBirthMessage) throws KapuaException {
    KapuaBirthMessage kapuaBirthMessage = new KapuaBirthMessageImpl();
    kapuaBirthMessage.setChannel(translate(kuraBirthMessage.getChannel()));
    kapuaBirthMessage.setPayload(translate(kuraBirthMessage.getPayload()));
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.findByName(kuraBirthMessage.getChannel().getScope());
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.findByClientId(account.getId(), kuraBirthMessage.getChannel().getClientId());
    kapuaBirthMessage.setScopeId(account.getId());
    if (device != null) {
        kapuaBirthMessage.setDeviceId(device.getId());
    } else {
        kapuaBirthMessage.setClientId(kuraBirthMessage.getChannel().getClientId());
    }
    kapuaBirthMessage.setCapturedOn(kuraBirthMessage.getPayload().getTimestamp());
    kapuaBirthMessage.setSentOn(kuraBirthMessage.getPayload().getTimestamp());
    kapuaBirthMessage.setReceivedOn(kuraBirthMessage.getTimestamp());
    kapuaBirthMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraBirthMessage.getPayload().getPosition()));
    return kapuaBirthMessage;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaBirthMessage(org.eclipse.kapua.message.device.lifecycle.KapuaBirthMessage) KapuaBirthMessageImpl(org.eclipse.kapua.message.internal.device.lifecycle.KapuaBirthMessageImpl) Device(org.eclipse.kapua.service.device.registry.Device) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) AccountService(org.eclipse.kapua.service.account.AccountService)

Example 5 with DeviceRegistryService

use of org.eclipse.kapua.service.device.registry.DeviceRegistryService in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method death.

@Override
public void death(KapuaId connectionId, KapuaDisconnectMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, message.getReceivedOn(), "DEATH");
    deviceEventCreator.setReceivedOn(message.getReceivedOn());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getSentOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)24 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)23 Device (org.eclipse.kapua.service.device.registry.Device)23 Account (org.eclipse.kapua.service.account.Account)11 AccountService (org.eclipse.kapua.service.account.AccountService)11 KapuaId (org.eclipse.kapua.model.id.KapuaId)10 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6 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 DeviceFactory (org.eclipse.kapua.service.device.registry.DeviceFactory)5 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)5 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)5 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)4 KapuaPosition (org.eclipse.kapua.message.KapuaPosition)4 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)4 KapuaPayload (org.eclipse.kapua.message.KapuaPayload)3 DeviceQuery (org.eclipse.kapua.service.device.registry.DeviceQuery)3 ArrayList (java.util.ArrayList)2 FieldSortCriteria (org.eclipse.kapua.commons.model.query.FieldSortCriteria)2