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