Search in sources :

Example 1 with UserDbo

use of webpiecesxxxxxpackage.db.UserDbo in project webpieces by deanhiller.

the class CrudUserController method userList.

public Action userList() {
    EntityManager mgr = Em.get();
    Query query = mgr.createNamedQuery("findAllUsers");
    @SuppressWarnings("unchecked") List<UserDbo> users = query.getResultList();
    return Actions.renderThis("users", users);
}
Also used : EntityManager(javax.persistence.EntityManager) UseQuery(org.webpieces.plugin.hibernate.UseQuery) Query(javax.persistence.Query) UserDbo(webpiecesxxxxxpackage.db.UserDbo)

Example 2 with UserDbo

use of webpiecesxxxxxpackage.db.UserDbo in project webpieces by deanhiller.

the class CrudUserController method postDeleteUser.

public Redirect postDeleteUser(int id) {
    UserDbo ref = Em.get().find(UserDbo.class, id);
    List<UserRole> roles = ref.getRoles();
    for (UserRole r : roles) {
        Em.get().remove(r);
    }
    Em.get().remove(ref);
    Em.get().flush();
    Current.flash().setMessage("User deleted");
    Current.flash().keep(true);
    Current.validation().keep(false);
    return Actions.redirect(CrudUserRouteId.LIST_USERS);
}
Also used : UserDbo(webpiecesxxxxxpackage.db.UserDbo) UserRole(webpiecesxxxxxpackage.db.UserRole)

Example 3 with UserDbo

use of webpiecesxxxxxpackage.db.UserDbo in project webpieces by deanhiller.

the class CrudUserController method userAddEdit.

public Action userAddEdit(Integer id) {
    if (id == null) {
        return Actions.renderThis("entity", new UserDbo(), "levels", EducationEnum.values(), "roles", RoleEnum.values(), "selectedRoles", null, "password", null);
    }
    UserDbo user = UserDbo.findWithJoin(Em.get(), id);
    List<UserRole> roles = user.getRoles();
    List<RoleEnum> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
    return Actions.renderThis("entity", user, "levels", EducationEnum.values(), "roles", RoleEnum.values(), "selectedRoles", selectedRoles, "password", null);
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) UserDbo(webpiecesxxxxxpackage.db.UserDbo) Size(javax.validation.constraints.Size) NotBlank(javax.validation.constraints.NotBlank) Logger(org.slf4j.Logger) UseQuery(org.webpieces.plugin.hibernate.UseQuery) Render(org.webpieces.router.api.controller.actions.Render) FlashAndRedirect(org.webpieces.router.api.controller.actions.FlashAndRedirect) GET_EDIT_USER_FORM(webpiecesxxxxxpackage.web.secure.crud.CrudUserRouteId.GET_EDIT_USER_FORM) LoggerFactory(org.slf4j.LoggerFactory) EntityManager(javax.persistence.EntityManager) Singleton(javax.inject.Singleton) UserRole(webpiecesxxxxxpackage.db.UserRole) Collectors(java.util.stream.Collectors) EducationEnum(webpiecesxxxxxpackage.db.EducationEnum) List(java.util.List) Query(javax.persistence.Query) GET_ADD_USER_FORM(webpiecesxxxxxpackage.web.secure.crud.CrudUserRouteId.GET_ADD_USER_FORM) Em(org.webpieces.plugin.hibernate.Em) Redirect(org.webpieces.router.api.controller.actions.Redirect) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.controller.actions.Actions) RoleEnum(webpiecesxxxxxpackage.db.RoleEnum) UserDbo(webpiecesxxxxxpackage.db.UserDbo) UserRole(webpiecesxxxxxpackage.db.UserRole) RoleEnum(webpiecesxxxxxpackage.db.RoleEnum)

Example 4 with UserDbo

use of webpiecesxxxxxpackage.db.UserDbo in project webpieces by deanhiller.

the class AjaxCrudUserController method postDeleteUser.

public Redirect postDeleteUser(int id) {
    UserDbo ref = Em.get().find(UserDbo.class, id);
    List<UserRole> roles = ref.getRoles();
    for (UserRole r : roles) {
        Em.get().remove(r);
    }
    Em.get().remove(ref);
    Em.get().flush();
    Current.flash().setMessage("User deleted");
    Current.flash().keep(true);
    Current.validation().keep(false);
    return Actions.redirect(AjaxCrudUserRouteId.AJAX_LIST_USERS);
}
Also used : UserDbo(webpiecesxxxxxpackage.db.UserDbo) UserRole(webpiecesxxxxxpackage.db.UserRole)

Example 5 with UserDbo

use of webpiecesxxxxxpackage.db.UserDbo in project webpieces by deanhiller.

the class AjaxCrudUserController method userList.

public Action userList() {
    EntityManager mgr = Em.get();
    Query query = mgr.createNamedQuery("findAllUsers");
    @SuppressWarnings("unchecked") List<UserDbo> users = query.getResultList();
    boolean showEditPopup = Current.flash().isShowEditPopup();
    return Actions.renderThis("users", users, "showPopup", showEditPopup);
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) UserDbo(webpiecesxxxxxpackage.db.UserDbo)

Aggregations

UserDbo (webpiecesxxxxxpackage.db.UserDbo)6 EntityManager (javax.persistence.EntityManager)4 UserRole (webpiecesxxxxxpackage.db.UserRole)4 Query (javax.persistence.Query)3 UseQuery (org.webpieces.plugin.hibernate.UseQuery)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityTransaction (javax.persistence.EntityTransaction)1 NotBlank (javax.validation.constraints.NotBlank)1 Size (javax.validation.constraints.Size)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugin.hibernate.Em)1 Action (org.webpieces.router.api.controller.actions.Action)1 Actions (org.webpieces.router.api.controller.actions.Actions)1 FlashAndRedirect (org.webpieces.router.api.controller.actions.FlashAndRedirect)1 Redirect (org.webpieces.router.api.controller.actions.Redirect)1 Render (org.webpieces.router.api.controller.actions.Render)1