Search in sources :

Example 1 with DeviceConnectionListResult

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

the class DeviceConnectionServiceImpl method findByClientId.

@Override
public DeviceConnection findByClientId(KapuaId scopeId, String clientId) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notEmptyOrNull(clientId, "clientId");
    // 
    // Build query
    DeviceConnectionQueryImpl query = new DeviceConnectionQueryImpl(scopeId);
    KapuaPredicate predicate = new AttributePredicate<String>(DeviceConnectionPredicates.CLIENT_ID, clientId);
    query.setPredicate(predicate);
    // 
    // Query and parse result
    DeviceConnection device = null;
    DeviceConnectionListResult result = query(query);
    if (result.getSize() == 1) {
        device = result.getItem(0);
    }
    return device;
}
Also used : DeviceConnectionListResult(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult) DeviceConnection(org.eclipse.kapua.service.device.registry.connection.DeviceConnection) KapuaPredicate(org.eclipse.kapua.model.query.predicate.KapuaPredicate) AttributePredicate(org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)

Example 2 with DeviceConnectionListResult

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

the class DeviceConnectionServiceImpl method query.

@Override
public DeviceConnectionListResult query(KapuaQuery<DeviceConnection> query) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(query, "query");
    ArgumentValidator.notNull(query.getScopeId(), "query.scopeId");
    // 
    // Check Access
    KapuaLocator locator = KapuaLocator.getInstance();
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    authorizationService.checkPermission(permissionFactory.newPermission(DeviceConnectionDomain.DEVICE_CONNECTION, Actions.read, query.getScopeId()));
    // 
    // Do Query
    DeviceConnectionListResult result = null;
    EntityManager em = DeviceEntityManagerFactory.getEntityManager();
    try {
        result = DeviceConnectionDAO.query(em, query);
    } catch (Exception e) {
        throw KapuaExceptionUtils.convertPersistenceException(e);
    } finally {
        em.close();
    }
    return result;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) DeviceConnectionListResult(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

DeviceConnectionListResult (org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult)2 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaException (org.eclipse.kapua.KapuaException)1 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)1 AttributePredicate (org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaPredicate (org.eclipse.kapua.model.query.predicate.KapuaPredicate)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1 DeviceConnection (org.eclipse.kapua.service.device.registry.connection.DeviceConnection)1