Search in sources :

Example 1 with UserDbo

use of WEBPIECESxPACKAGE.base.libs.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) Query(javax.persistence.Query) UseQuery(org.webpieces.plugins.hibernate.UseQuery) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo)

Example 2 with UserDbo

use of WEBPIECESxPACKAGE.base.libs.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();
    return Actions.redirect(AjaxCrudUserRouteId.AJAX_LIST_USERS);
}
Also used : UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole)

Example 3 with UserDbo

use of WEBPIECESxPACKAGE.base.libs.UserDbo in project webpieces by deanhiller.

the class PopulateDatabase method createSomeData.

private void createSomeData() {
    EntityManager mgr = factory.createEntityManager();
    List<UserDbo> users = UserDbo.findAll(mgr);
    if (users.size() > 0)
        //This database has users, exit immediately to not screw up existing data 
        return;
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserDbo user1 = new UserDbo();
    user1.setEmail("dean@somewhere.com");
    user1.setName("SomeName");
    user1.setFirstName("Dean");
    user1.setLastName("Hill");
    UserDbo user2 = new UserDbo();
    user2.setEmail("bob@somewhere.com");
    user2.setName("Bob'sName");
    user2.setFirstName("Bob");
    user2.setLastName("LastBob");
    user2.setLevelOfEducation(EducationEnum.MIDDLE_SCHOOL);
    UserRole role1 = new UserRole(user2, RoleEnum.DELINQUINT);
    UserRole role2 = new UserRole(user2, RoleEnum.BADASS);
    mgr.persist(user1);
    mgr.persist(user2);
    mgr.persist(role1);
    mgr.persist(role2);
    mgr.flush();
    tx.commit();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole)

Example 4 with UserDbo

use of WEBPIECESxPACKAGE.base.libs.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());
    }
    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);
}
Also used : Logger(org.webpieces.util.logging.Logger) FlashAndRedirect(org.webpieces.router.api.actions.FlashAndRedirect) Redirect(org.webpieces.router.api.actions.Redirect) Render(org.webpieces.router.api.actions.Render) EntityManager(javax.persistence.EntityManager) Singleton(javax.inject.Singleton) RoleEnum(WEBPIECESxPACKAGE.base.libs.RoleEnum) GET_EDIT_USER_FORM(WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_EDIT_USER_FORM) Collectors(java.util.stream.Collectors) Action(org.webpieces.router.api.actions.Action) List(java.util.List) Query(javax.persistence.Query) Em(org.webpieces.plugins.hibernate.Em) GET_ADD_USER_FORM(WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_ADD_USER_FORM) UseQuery(org.webpieces.plugins.hibernate.UseQuery) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.actions.Actions) EducationEnum(WEBPIECESxPACKAGE.base.libs.EducationEnum) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole) RoleEnum(WEBPIECESxPACKAGE.base.libs.RoleEnum)

Example 5 with UserDbo

use of WEBPIECESxPACKAGE.base.libs.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();
    return Actions.redirect(CrudUserRouteId.LIST_USERS);
}
Also used : UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole)

Aggregations

UserDbo (WEBPIECESxPACKAGE.base.libs.UserDbo)6 UserRole (WEBPIECESxPACKAGE.base.libs.UserRole)4 EntityManager (javax.persistence.EntityManager)4 Query (javax.persistence.Query)3 UseQuery (org.webpieces.plugins.hibernate.UseQuery)2 GET_ADD_USER_FORM (WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_ADD_USER_FORM)1 GET_EDIT_USER_FORM (WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_EDIT_USER_FORM)1 EducationEnum (WEBPIECESxPACKAGE.base.libs.EducationEnum)1 RoleEnum (WEBPIECESxPACKAGE.base.libs.RoleEnum)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityTransaction (javax.persistence.EntityTransaction)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugins.hibernate.Em)1 Action (org.webpieces.router.api.actions.Action)1 Actions (org.webpieces.router.api.actions.Actions)1 FlashAndRedirect (org.webpieces.router.api.actions.FlashAndRedirect)1 Redirect (org.webpieces.router.api.actions.Redirect)1 Render (org.webpieces.router.api.actions.Render)1