Search in sources :

Example 1 with UserListResult

use of org.eclipse.kapua.service.user.UserListResult in project kapua by eclipse.

the class UserServiceImpl method query.

@Override
public UserListResult query(KapuaQuery<User> query) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(query, "query");
    ArgumentValidator.notNull(query.getScopeId(), "query.scopeId");
    // 
    // Check Access
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    authorizationService.checkPermission(permissionFactory.newPermission(UserDomain.USER, Actions.read, query.getScopeId()));
    // 
    // Do count
    UserListResult result = null;
    EntityManager em = UserEntityManagerFactory.getInstance().createEntityManager();
    ;
    try {
        result = UserDAO.query(em, query);
    } catch (Exception e) {
        throw KapuaExceptionUtils.convertPersistenceException(e);
    } finally {
        em.close();
    }
    return result;
}
Also used : EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaIllegalArgumentException(org.eclipse.kapua.KapuaIllegalArgumentException) KapuaException(org.eclipse.kapua.KapuaException) UserListResult(org.eclipse.kapua.service.user.UserListResult)

Example 2 with UserListResult

use of org.eclipse.kapua.service.user.UserListResult in project kapua by eclipse.

the class GwtUserServiceImpl method findAll.

public ListLoadResult<GwtUser> findAll(String scopeIdString) throws GwtKapuaException {
    KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
    List<GwtUser> gwtUserList = new ArrayList<GwtUser>();
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        UserService userService = locator.getService(UserService.class);
        UserFactory userFactory = locator.getFactory(UserFactory.class);
        UserQuery query = userFactory.newQuery(scopeId);
        UserListResult list = userService.query(query);
        for (User user : list.getItems()) {
            gwtUserList.add(KapuaGwtConverter.convert(user));
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtUser>(gwtUserList);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) User(org.eclipse.kapua.service.user.User) GwtUserService(org.eclipse.kapua.app.console.shared.service.GwtUserService) UserService(org.eclipse.kapua.service.user.UserService) UserQuery(org.eclipse.kapua.service.user.UserQuery) ArrayList(java.util.ArrayList) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) UserFactory(org.eclipse.kapua.service.user.UserFactory) KapuaId(org.eclipse.kapua.model.id.KapuaId) UserListResult(org.eclipse.kapua.service.user.UserListResult)

Example 3 with UserListResult

use of org.eclipse.kapua.service.user.UserListResult in project kapua by eclipse.

the class Users method getUsers.

/**
 * Returns the list of all the users associated to the account of the
 * currently connected user.
 *
 * @return The list of requested User objects.
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public UserListResult getUsers() {
    UserListResult userResult = userFactory.newUserListResult();
    try {
        UserQuery query = userFactory.newQuery(KapuaSecurityUtils.getSession().getScopeId());
        userResult = (UserListResult) userService.query(query);
    } catch (Throwable t) {
        handleException(t);
    }
    return userResult;
}
Also used : UserQuery(org.eclipse.kapua.service.user.UserQuery) UserListResult(org.eclipse.kapua.service.user.UserListResult) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UserListResult (org.eclipse.kapua.service.user.UserListResult)3 UserQuery (org.eclipse.kapua.service.user.UserQuery)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaIllegalArgumentException (org.eclipse.kapua.KapuaIllegalArgumentException)1 GwtUser (org.eclipse.kapua.app.console.shared.model.GwtUser)1 GwtUserService (org.eclipse.kapua.app.console.shared.service.GwtUserService)1 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1 User (org.eclipse.kapua.service.user.User)1 UserFactory (org.eclipse.kapua.service.user.UserFactory)1 UserService (org.eclipse.kapua.service.user.UserService)1