Search in sources :

Example 1 with UserRoleDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo in project webpieces by deanhiller.

the class CrudTestController method multiSelect.

public Render multiSelect(Integer id) {
    if (id == null) {
        return Actions.renderThis("entity", new UserTestDbo(), "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", new ArrayList<>());
    }
    UserTestDbo user = UserTestDbo.findWithJoin(Em.get(), id);
    List<UserRoleDbo> roles = user.getRoles();
    List<Role> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
    return Actions.renderThis("entity", user, "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", selectedRoles);
}
Also used : Logger(org.webpieces.util.logging.Logger) EDIT_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE) 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) Collectors(java.util.stream.Collectors) Role(org.webpieces.plugins.hibernate.app.dbo.Role) ArrayList(java.util.ArrayList) ADD_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE) List(java.util.List) Query(javax.persistence.Query) Em(org.webpieces.plugins.hibernate.Em) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo) LevelEducation(org.webpieces.plugins.hibernate.app.dbo.LevelEducation) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.actions.Actions) Role(org.webpieces.plugins.hibernate.app.dbo.Role) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)

Example 2 with UserRoleDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo in project webpieces by deanhiller.

the class TestFlashAndSelect method loadDataInDb.

public static UserTestDbo loadDataInDb() {
    String email = "dean2@sync.xsoftware.biz";
    //populate database....
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo manager = new UserTestDbo();
    manager.setEmail("asdf@asf.com");
    manager.setName("somadsf");
    UserTestDbo user = new UserTestDbo();
    user.setEmail(email);
    user.setName("SomeName");
    user.setFirstName("Dean");
    user.setLastName("Hill");
    user.setLevelOfEducation(LevelEducation.KINDERGARTEN);
    user.setManager(manager);
    UserRoleDbo role1 = new UserRoleDbo(user, Role.DELINQUINT);
    UserRoleDbo role2 = new UserRoleDbo(user, Role.BADASS);
    mgr.persist(manager);
    mgr.persist(user);
    mgr.persist(role1);
    mgr.persist(role2);
    mgr.flush();
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)

Aggregations

EntityManager (javax.persistence.EntityManager)2 UserRoleDbo (org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)2 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 EntityTransaction (javax.persistence.EntityTransaction)1 Query (javax.persistence.Query)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugins.hibernate.Em)1 ADD_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE)1 EDIT_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE)1 LevelEducation (org.webpieces.plugins.hibernate.app.dbo.LevelEducation)1 Role (org.webpieces.plugins.hibernate.app.dbo.Role)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