Search in sources :

Example 41 with Account

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;
}
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 42 with Account

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;
}
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

Account (org.eclipse.kapua.service.account.Account)42 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)37 AccountService (org.eclipse.kapua.service.account.AccountService)31 KapuaId (org.eclipse.kapua.model.id.KapuaId)14 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)12 Device (org.eclipse.kapua.service.device.registry.Device)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)11 KapuaException (org.eclipse.kapua.KapuaException)10 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)10 KapuaIllegalAccessException (org.eclipse.kapua.KapuaIllegalAccessException)9 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)9 KapuaIllegalArgumentException (org.eclipse.kapua.KapuaIllegalArgumentException)8 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)8 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)7 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)7 Date (java.util.Date)5 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)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