Search in sources :

Example 16 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method buildUserDetail.

private UserDetail buildUserDetail(User user) {
    UserDetail userDetail = new UserDetail();
    userDetail.setId(user.getId());
    for (UserIndex userIndex : user.getUserIndices()) {
        userDetail.setUsername(userIndex.getId().getValue());
    }
    for (UserRole role : user.getRoles()) {
        // There should be only one role
        userDetail.setRole(role.getName());
    }
    UserBean bean = userService.getUserAsBean(user);
    userDetail.setDisabled(bean.isDisabled());
    return userDetail;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) UserBean(org.onebusaway.users.client.model.UserBean) UserRole(org.onebusaway.users.model.UserRole)

Example 17 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method getUserDetails.

@Override
public List<UserDetail> getUserDetails(final int start, final int maxResults) {
    List<UserDetail> userDetails = new ArrayList<UserDetail>();
    List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME)).setFirstResult(start).setMaxResults(maxResults);
            List<User> users = criteria.list();
            return users;
        }
    });
    if (!users.isEmpty()) {
        for (User user : users) {
            if (!user.getUserIndices().isEmpty()) {
                UserDetail userDetail = buildUserDetail(user);
                userDetails.add(userDetail);
            }
        }
    }
    log.debug("Returning user details");
    return userDetails;
}
Also used : User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UserDetail(org.onebusaway.admin.model.ui.UserDetail) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session)

Example 18 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method getUserDetail.

@Override
public UserDetail getUserDetail(final String userName) {
    List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.like("id.value", userName));
            List<User> users = criteria.list();
            return users;
        }
    });
    UserDetail userDetail = null;
    if (!users.isEmpty()) {
        userDetail = buildUserDetail(users.get(0));
    }
    log.debug("Returning user details for user : {}", userName);
    return userDetail;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Aggregations

UserDetail (org.onebusaway.admin.model.ui.UserDetail)18 Test (org.junit.Test)6 UserIndex (org.onebusaway.users.model.UserIndex)6 StringReader (java.io.StringReader)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 User (org.onebusaway.users.model.User)4 UserRole (org.onebusaway.users.model.UserRole)4 UserBean (org.onebusaway.users.client.model.UserBean)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1