New file |
| | |
| | | .classpath |
| | | .project |
| | | .tern-project |
| | | .settings |
| | | target |
New file |
| | |
| | | -- MySQL dump 10.14 Distrib 5.5.52-MariaDB, for Linux (x86_64) |
| | | -- |
| | | -- Host: services Database: todo |
| | | -- ------------------------------------------------------ |
| | | -- Server version 5.5.52-MariaDB |
| | | |
| | | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
| | | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
| | | /*!40101 SET NAMES utf8 */; |
| | | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; |
| | | /*!40103 SET TIME_ZONE='+00:00' */; |
| | | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; |
| | | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
| | | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
| | | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
| | | |
| | | USE todo; |
| | | |
| | | -- |
| | | -- Table structure for table `Email` |
| | | -- |
| | | |
| | | DROP TABLE IF EXISTS `Email`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `Email` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `address` varchar(255) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `Email` |
| | | -- |
| | | |
| | | LOCK TABLES `Email` WRITE; |
| | | /*!40000 ALTER TABLE `Email` DISABLE KEYS */; |
| | | INSERT INTO `Email` VALUES (1,'development@example.com'),(2,'admin@example.com'),(3,'sales@example.com'),(4,'research@example.com'),(5,'ceo@example.com'),(6,'problems@example.com'),(7,'help-desk@example.com'),(8,'hr@example.com'),(9,'supplies@example.com'); |
| | | /*!40000 ALTER TABLE `Email` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | |
| | | -- |
| | | -- Table structure for table `User` |
| | | -- |
| | | |
| | | DROP TABLE IF EXISTS `User`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `User` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(255) DEFAULT NULL, |
| | | `emailID` bigint(20) DEFAULT NULL, |
| | | `groupID` bigint(20) DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | KEY `FK4ac5lo10mt8w444x6qyag7noi` (`emailID`), |
| | | KEY `FKqw2hxxa638ygi29htecfitk9j` (`groupID`), |
| | | CONSTRAINT `FKqw2hxxa638ygi29htecfitk9j` FOREIGN KEY (`groupID`) REFERENCES `UserGroup` (`id`), |
| | | CONSTRAINT `FK4ac5lo10mt8w444x6qyag7noi` FOREIGN KEY (`emailID`) REFERENCES `Email` (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `User` |
| | | -- |
| | | |
| | | LOCK TABLES `User` WRITE; |
| | | /*!40000 ALTER TABLE `User` DISABLE KEYS */; |
| | | INSERT INTO `User` (`id`,`name`,`emailID`,`groupID`) VALUES (1,'William',1,1),(2,'Rose',2,1),(3,'Pat',3,1),(4,'Rodney',4,2),(5,'Kim',5,2),(6,'Tom',6,2),(7,'Matt',7,3),(8,'George',8,3),(9,'Jean',9,3); |
| | | /*!40000 ALTER TABLE `User` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | |
| | | -- |
| | | -- Table structure for table `UserGroup` |
| | | -- |
| | | |
| | | DROP TABLE IF EXISTS `UserGroup`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `UserGroup` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(255) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `UserGroup` |
| | | -- |
| | | |
| | | LOCK TABLES `UserGroup` WRITE; |
| | | /*!40000 ALTER TABLE `UserGroup` DISABLE KEYS */; |
| | | INSERT INTO `UserGroup` VALUES (1,'dev'),(2,'qa'),(3,'stage'); |
| | | /*!40000 ALTER TABLE `UserGroup` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; |
| | | |
| | | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; |
| | | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; |
| | | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; |
| | | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
| | | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
| | | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
| | | |
| | | -- Dump completed on 2017-10-06 8:57:43 |
New file |
| | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | <artifactId>entity-relationships</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Configure Relationships web app Project</name> |
| | | <description>This is the entity relationships project.</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for typesafe |
| | | criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | | <artifactId>junit</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.arquillian.junit</groupId> |
| | | <artifactId>arquillian-junit-container</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.arquillian.protocol</groupId> |
| | | <artifactId>arquillian-protocol-servlet</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <!-- Need to explicitly reference this version, or else there will be an |
| | | exception due to a bug in Arquilian --> |
| | | <dependency> |
| | | <groupId>org.wildfly.arquillian</groupId> |
| | | <artifactId>wildfly-arquillian-common</artifactId> |
| | | <version>2.0.0.Final</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>entity-relationships</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | <profiles> |
| | | <profile> |
| | | <!-- This profile skips all tests, though you can tune it to run just |
| | | unit tests based on a custom pattern --> |
| | | <!-- Separate profiles are provided for running all tests, including Arquillian |
| | | tests that execute in the specified container --> |
| | | <!-- Use this profile if you just want to build a WAR file without running |
| | | any unit tests --> |
| | | <!-- Run like this: mvn clean package -Pdefault --> |
| | | <id>default</id> |
| | | <build> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <version>${version.surefire.plugin}</version> |
| | | <configuration> |
| | | <skip>true</skip> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | </profile> |
| | | <profile> |
| | | <!-- An optional Arquillian testing profile that executes tests in a remote |
| | | JBoss EAP instance --> |
| | | <!-- Run with: mvn clean test -Parq-wildfly-remote or, simply run: mvn |
| | | test --> |
| | | <!-- To make it easy to run tests from within JBDS, this profile is set |
| | | as active by default --> |
| | | <id>arq-wildfly-remote</id> |
| | | <activation> |
| | | <activeByDefault>true</activeByDefault> |
| | | </activation> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.wildfly.arquillian</groupId> |
| | | <artifactId>wildfly-arquillian-container-remote</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | </profile> |
| | | </profiles> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.ejb; |
| | | |
| | | import java.util.logging.Logger; |
| | | |
| | | import javax.enterprise.inject.Produces; |
| | | import javax.enterprise.inject.spi.InjectionPoint; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.PersistenceContext; |
| | | |
| | | public class Resources { |
| | | |
| | | @Produces |
| | | @PersistenceContext |
| | | private EntityManager em; |
| | | |
| | | @Produces |
| | | public Logger produceLog(InjectionPoint injectionPoint) { |
| | | return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ejb; |
| | | |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | import javax.ejb.Stateless; |
| | | import javax.inject.Inject; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.TypedQuery; |
| | | |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @Stateless |
| | | public class UserBean { |
| | | |
| | | @Inject |
| | | private EntityManager em; |
| | | |
| | | //TODO Add JOIN FETCH |
| | | public Set<UserGroup> getAllUserGroups(){ |
| | | TypedQuery<UserGroup> query = em.createQuery("SELECT g FROM UserGroup g" , UserGroup.class); |
| | | |
| | | return new HashSet<UserGroup>(query.getResultList()); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.OneToOne; |
| | | |
| | | @Entity |
| | | public class Email { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String address; |
| | | |
| | | //TODO map relationship |
| | | |
| | | private User user; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public User getUser() { |
| | | return user; |
| | | } |
| | | |
| | | public void setUser(User user) { |
| | | this.user = user; |
| | | } |
| | | |
| | | public String getAddress() { |
| | | return address; |
| | | } |
| | | |
| | | public void setAddress(String address) { |
| | | this.address = address; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "Email [id=" + id + "]"; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Email other = (Email) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.FetchType; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.JoinColumn; |
| | | import javax.persistence.ManyToOne; |
| | | import javax.persistence.OneToOne; |
| | | |
| | | @Entity |
| | | public class User { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | //TODO map relationship |
| | | |
| | | private Email email; |
| | | |
| | | //TODO map relationship |
| | | |
| | | private UserGroup userGroup; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public UserGroup getDepartment() { |
| | | return userGroup; |
| | | } |
| | | |
| | | public void setDepartment(UserGroup userGroup) { |
| | | this.userGroup = userGroup; |
| | | } |
| | | |
| | | public Email getEmail() { |
| | | return email; |
| | | } |
| | | |
| | | public void setEmail(Email email) { |
| | | this.email = email; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | User other = (User) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "User [id=" + id + ", name=" + name + ", group=" + userGroup + ", email=" + email + "]"; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import java.util.Set; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.FetchType; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.OneToMany; |
| | | |
| | | @Entity |
| | | public class UserGroup { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | //TODO map relationship |
| | | |
| | | private Set<User> users; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Set<User> getUsers() { |
| | | return users; |
| | | } |
| | | |
| | | public void setUsers(Set<User> users) { |
| | | this.users = users; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | UserGroup other = (UserGroup) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "UserGroup [id=" + id + ", name=" + name + "]"; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.logging.Logger; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.ejb.Stateless; |
| | | import javax.faces.bean.RequestScoped; |
| | | import javax.faces.event.ValueChangeEvent; |
| | | import javax.inject.Inject; |
| | | import javax.inject.Named; |
| | | |
| | | import com.redhat.training.ejb.UserBean; |
| | | import com.redhat.training.model.User; |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @Named("groupView") |
| | | @Stateless |
| | | @RequestScoped |
| | | public class GroupViewBean { |
| | | |
| | | private Set<UserGroup> groups; |
| | | |
| | | private UserGroup currentGroup; |
| | | |
| | | private Set<User> users; |
| | | |
| | | @Inject |
| | | private Logger log; |
| | | |
| | | @Inject |
| | | UserBean peopleBean; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | log.info("INIT!!!"); |
| | | groups = peopleBean.getAllUserGroups(); |
| | | |
| | | } |
| | | |
| | | public void update(ValueChangeEvent event) { |
| | | |
| | | |
| | | UserGroup group = (UserGroup) event.getNewValue(); |
| | | users = new HashSet<User>(group.getUsers()); |
| | | // users = peopleBean.getUsers(group); |
| | | |
| | | } |
| | | |
| | | public Set<UserGroup> getGroups() { |
| | | return groups; |
| | | } |
| | | |
| | | public void setGroups(Set<UserGroup> userGroups) { |
| | | this.groups = userGroups; |
| | | } |
| | | |
| | | public Set<User> getUsers() { |
| | | return users; |
| | | } |
| | | |
| | | public void setUsers(Set<User> users) { |
| | | this.users = users; |
| | | } |
| | | |
| | | public UserGroup getCurrentGroup() { |
| | | return currentGroup; |
| | | } |
| | | |
| | | public void setCurrentGroup(UserGroup currentGroup) { |
| | | this.currentGroup = currentGroup; |
| | | } |
| | | |
| | | public List<User> getUserList(){ |
| | | if(users != null) { |
| | | return new ArrayList<User>(users); |
| | | }else { |
| | | return new ArrayList<User>(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import java.util.Set; |
| | | import java.util.function.Predicate; |
| | | |
| | | import javax.faces.component.UIComponent; |
| | | import javax.faces.component.UISelectItems; |
| | | import javax.faces.context.FacesContext; |
| | | import javax.faces.convert.Converter; |
| | | import javax.faces.convert.FacesConverter; |
| | | |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @FacesConverter(value = "SelectItemToEntityConverter") |
| | | public class SelectItemConverter implements Converter { |
| | | |
| | | @Override |
| | | public Object getAsObject(FacesContext ctx, UIComponent comp, String value) { |
| | | Object o = null; |
| | | if (!(value == null || value.isEmpty())) { |
| | | o = this.getSelectedItemAsEntity(comp, value); |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | @Override |
| | | public String getAsString(FacesContext ctx, UIComponent comp, Object value) { |
| | | String s = ""; |
| | | if (value != null) { |
| | | s = ((UserGroup) value).getId().toString(); |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | private UserGroup getSelectedItemAsEntity(UIComponent comp, String value) { |
| | | UserGroup item = null; |
| | | |
| | | Set<UserGroup> selectItems = null; |
| | | for (UIComponent uic : comp.getChildren()) { |
| | | if (uic instanceof UISelectItems) { |
| | | Long itemId = Long.valueOf(value); |
| | | selectItems = (Set<UserGroup>) ((UISelectItems) uic).getValue(); |
| | | |
| | | if (itemId != null && selectItems != null && !selectItems.isEmpty()) { |
| | | Predicate<UserGroup> predicate = i -> i.getId().equals(itemId); |
| | | item = selectItems.stream().filter(predicate).findFirst().orElse(null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item; |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="People" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="update" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Group View web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Group View web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Group View web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Select a Group:" for="group" /> |
| | | <h:selectOneMenu id="group" value="#{groupView.currentGroup}" valueChangeListener="#{groupView.update}" onchange="submit()" converter="SelectItemToEntityConverter"> |
| | | <f:selectItem itemLabel="Choose one ..." itemValue="#{null}"/> |
| | | <f:selectItems value="#{groupView.groups}" var="group" itemValue="#{group}" itemLabel="#{group.name}"/> |
| | | </h:selectOneMenu> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:outputLabel value="Employees:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{groupView.userList}" var="person"> |
| | | <li> |
| | | <strong>Name:</strong><h:outputText value="#{person.name}"/><br/> |
| | | <strong>Email:</strong><h:outputText value="#{person.email.address}"/> |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | </p> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
New file |
| | |
| | | .classpath |
| | | .project |
| | | .tern-project |
| | | .settings |
| | | target |
New file |
| | |
| | | -- MySQL dump 10.14 Distrib 5.5.52-MariaDB, for Linux (x86_64) |
| | | -- |
| | | -- Host: services Database: todo |
| | | -- ------------------------------------------------------ |
| | | -- Server version 5.5.52-MariaDB |
| | | |
| | | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
| | | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
| | | /*!40101 SET NAMES utf8 */; |
| | | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; |
| | | /*!40103 SET TIME_ZONE='+00:00' */; |
| | | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; |
| | | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
| | | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
| | | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
| | | |
| | | -- |
| | | -- Table structure for table `Email` |
| | | -- |
| | | |
| | | USE todo; |
| | | |
| | | DROP TABLE IF EXISTS `Email`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `Email` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `address` varchar(255) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `Email` |
| | | -- |
| | | |
| | | LOCK TABLES `Email` WRITE; |
| | | /*!40000 ALTER TABLE `Email` DISABLE KEYS */; |
| | | INSERT INTO `Email` VALUES (1,'development@example.com'),(2,'admin@example.com'),(3,'sales@example.com'),(4,'research@example.com'),(5,'ceo@example.com'),(6,'problems@example.com'),(7,'help-desk@example.com'),(8,'hr@example.com'),(9,'supplies@example.com'); |
| | | /*!40000 ALTER TABLE `Email` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | |
| | | -- |
| | | -- Table structure for table `User` |
| | | -- |
| | | |
| | | DROP TABLE IF EXISTS `User`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `User` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(255) DEFAULT NULL, |
| | | `emailID` bigint(20) DEFAULT NULL, |
| | | `groupID` bigint(20) DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | KEY `FK4ac5lo10mt8w444x6qyag7noi` (`emailID`), |
| | | KEY `FKqw2hxxa638ygi29htecfitk9j` (`groupID`), |
| | | CONSTRAINT `FKqw2hxxa638ygi29htecfitk9j` FOREIGN KEY (`groupID`) REFERENCES `UserGroup` (`id`), |
| | | CONSTRAINT `FK4ac5lo10mt8w444x6qyag7noi` FOREIGN KEY (`emailID`) REFERENCES `Email` (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `User` |
| | | -- |
| | | |
| | | LOCK TABLES `User` WRITE; |
| | | /*!40000 ALTER TABLE `User` DISABLE KEYS */; |
| | | INSERT INTO `User` (`id`,`name`,`emailID`,`groupID`) VALUES (1,'William',1,1),(2,'Rose',2,1),(3,'Pat',3,1),(4,'Rodney',4,2),(5,'Kim',5,2),(6,'Tom',6,2),(7,'Matt',7,3),(8,'George',8,3),(9,'Jean',9,3); |
| | | /*!40000 ALTER TABLE `User` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | |
| | | -- |
| | | -- Table structure for table `UserGroup` |
| | | -- |
| | | |
| | | DROP TABLE IF EXISTS `UserGroup`; |
| | | /*!40101 SET @saved_cs_client = @@character_set_client */; |
| | | /*!40101 SET character_set_client = utf8 */; |
| | | CREATE TABLE `UserGroup` ( |
| | | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(255) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; |
| | | /*!40101 SET character_set_client = @saved_cs_client */; |
| | | |
| | | -- |
| | | -- Dumping data for table `UserGroup` |
| | | -- |
| | | |
| | | LOCK TABLES `UserGroup` WRITE; |
| | | /*!40000 ALTER TABLE `UserGroup` DISABLE KEYS */; |
| | | INSERT INTO `UserGroup` VALUES (1,'dev'),(2,'qa'),(3,'stage'); |
| | | /*!40000 ALTER TABLE `UserGroup` ENABLE KEYS */; |
| | | UNLOCK TABLES; |
| | | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; |
| | | |
| | | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; |
| | | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; |
| | | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; |
| | | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
| | | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
| | | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
| | | |
| | | -- Dump completed on 2017-10-06 8:57:43 |
New file |
| | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | <artifactId>entity-relationships-solution</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Configure Relationships web app Project</name> |
| | | <description>This is the entity relationships project.</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for typesafe |
| | | criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | | <artifactId>junit</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.arquillian.junit</groupId> |
| | | <artifactId>arquillian-junit-container</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.arquillian.protocol</groupId> |
| | | <artifactId>arquillian-protocol-servlet</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <!-- Need to explicitly reference this version, or else there will be an |
| | | exception due to a bug in Arquilian --> |
| | | <dependency> |
| | | <groupId>org.wildfly.arquillian</groupId> |
| | | <artifactId>wildfly-arquillian-common</artifactId> |
| | | <version>2.0.0.Final</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>entity-relationships</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | <profiles> |
| | | <profile> |
| | | <!-- This profile skips all tests, though you can tune it to run just |
| | | unit tests based on a custom pattern --> |
| | | <!-- Separate profiles are provided for running all tests, including Arquillian |
| | | tests that execute in the specified container --> |
| | | <!-- Use this profile if you just want to build a WAR file without running |
| | | any unit tests --> |
| | | <!-- Run like this: mvn clean package -Pdefault --> |
| | | <id>default</id> |
| | | <build> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <version>${version.surefire.plugin}</version> |
| | | <configuration> |
| | | <skip>true</skip> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | </profile> |
| | | <profile> |
| | | <!-- An optional Arquillian testing profile that executes tests in a remote |
| | | JBoss EAP instance --> |
| | | <!-- Run with: mvn clean test -Parq-wildfly-remote or, simply run: mvn |
| | | test --> |
| | | <!-- To make it easy to run tests from within JBDS, this profile is set |
| | | as active by default --> |
| | | <id>arq-wildfly-remote</id> |
| | | <activation> |
| | | <activeByDefault>true</activeByDefault> |
| | | </activation> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.wildfly.arquillian</groupId> |
| | | <artifactId>wildfly-arquillian-container-remote</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | </profile> |
| | | </profiles> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.ejb; |
| | | |
| | | import java.util.logging.Logger; |
| | | |
| | | import javax.enterprise.inject.Produces; |
| | | import javax.enterprise.inject.spi.InjectionPoint; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.PersistenceContext; |
| | | |
| | | public class Resources { |
| | | |
| | | @Produces |
| | | @PersistenceContext |
| | | private EntityManager em; |
| | | |
| | | @Produces |
| | | public Logger produceLog(InjectionPoint injectionPoint) { |
| | | return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ejb; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | import javax.ejb.Stateless; |
| | | import javax.inject.Inject; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.TypedQuery; |
| | | |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @Stateless |
| | | public class UserBean { |
| | | |
| | | @Inject |
| | | private EntityManager em; |
| | | |
| | | public Set<UserGroup> getAllUserGroups(){ |
| | | TypedQuery<UserGroup> query = em.createQuery("SELECT g FROM UserGroup g JOIN FETCH g.users" , UserGroup.class); |
| | | |
| | | return new HashSet<UserGroup>(query.getResultList()); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.OneToOne; |
| | | |
| | | @Entity |
| | | public class Email { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String address; |
| | | |
| | | @OneToOne(mappedBy="email") |
| | | private User user; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public User getUser() { |
| | | return user; |
| | | } |
| | | |
| | | public void setUser(User user) { |
| | | this.user = user; |
| | | } |
| | | |
| | | public String getAddress() { |
| | | return address; |
| | | } |
| | | |
| | | public void setAddress(String address) { |
| | | this.address = address; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "Email [id=" + id + "]"; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Email other = (Email) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.FetchType; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.JoinColumn; |
| | | import javax.persistence.ManyToOne; |
| | | import javax.persistence.OneToOne; |
| | | |
| | | @Entity |
| | | public class User { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | @ManyToOne |
| | | @JoinColumn(name="groupID") |
| | | private UserGroup userGroup; |
| | | |
| | | @OneToOne |
| | | @JoinColumn(name="emailID") |
| | | private Email email; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public UserGroup getDepartment() { |
| | | return userGroup; |
| | | } |
| | | |
| | | public void setDepartment(UserGroup userGroup) { |
| | | this.userGroup = userGroup; |
| | | } |
| | | |
| | | public Email getEmail() { |
| | | return email; |
| | | } |
| | | |
| | | public void setEmail(Email email) { |
| | | this.email = email; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | User other = (User) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "User [id=" + id + ", name=" + name + ", group=" + userGroup + ", email=" + email + "]"; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import java.util.Set; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.FetchType; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.OneToMany; |
| | | |
| | | @Entity |
| | | public class UserGroup { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | @OneToMany(mappedBy="userGroup", fetch=FetchType.LAZY) |
| | | private Set<User> users; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Set<User> getUsers() { |
| | | return users; |
| | | } |
| | | |
| | | public void setUsers(Set<User> users) { |
| | | this.users = users; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | UserGroup other = (UserGroup) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "UserGroup [id=" + id + ", name=" + name + "]"; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.logging.Logger; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.ejb.Stateless; |
| | | import javax.faces.bean.RequestScoped; |
| | | import javax.faces.event.ValueChangeEvent; |
| | | import javax.inject.Inject; |
| | | import javax.inject.Named; |
| | | |
| | | import com.redhat.training.ejb.UserBean; |
| | | import com.redhat.training.model.User; |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @Named("groupView") |
| | | @Stateless |
| | | @RequestScoped |
| | | public class GroupViewBean { |
| | | |
| | | private Set<UserGroup> groups; |
| | | |
| | | private UserGroup currentGroup; |
| | | |
| | | private Set<User> users; |
| | | |
| | | @Inject |
| | | private Logger log; |
| | | |
| | | @Inject |
| | | UserBean peopleBean; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | log.info("INIT!!!"); |
| | | groups = peopleBean.getAllUserGroups(); |
| | | |
| | | } |
| | | |
| | | public void update(ValueChangeEvent event) { |
| | | |
| | | UserGroup group = (UserGroup) event.getNewValue(); |
| | | users = new HashSet<User>(group.getUsers()); |
| | | |
| | | } |
| | | |
| | | public Set<UserGroup> getGroups() { |
| | | return groups; |
| | | } |
| | | |
| | | public void setGroups(Set<UserGroup> userGroups) { |
| | | this.groups = userGroups; |
| | | } |
| | | |
| | | public Set<User> getUsers() { |
| | | return users; |
| | | } |
| | | |
| | | public void setUsers(Set<User> users) { |
| | | this.users = users; |
| | | } |
| | | |
| | | public UserGroup getCurrentGroup() { |
| | | return currentGroup; |
| | | } |
| | | |
| | | public void setCurrentGroup(UserGroup currentGroup) { |
| | | this.currentGroup = currentGroup; |
| | | } |
| | | |
| | | public List<User> getUserList(){ |
| | | if(users != null) { |
| | | return new ArrayList<User>(users); |
| | | }else { |
| | | return new ArrayList<User>(); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import java.util.Set; |
| | | import java.util.function.Predicate; |
| | | |
| | | import javax.faces.component.UIComponent; |
| | | import javax.faces.component.UISelectItems; |
| | | import javax.faces.context.FacesContext; |
| | | import javax.faces.convert.Converter; |
| | | import javax.faces.convert.FacesConverter; |
| | | |
| | | import com.redhat.training.model.UserGroup; |
| | | |
| | | @FacesConverter(value = "SelectItemToEntityConverter") |
| | | public class SelectItemConverter implements Converter { |
| | | |
| | | @Override |
| | | public Object getAsObject(FacesContext ctx, UIComponent comp, String value) { |
| | | Object o = null; |
| | | if (!(value == null || value.isEmpty())) { |
| | | o = this.getSelectedItemAsEntity(comp, value); |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | @Override |
| | | public String getAsString(FacesContext ctx, UIComponent comp, Object value) { |
| | | String s = ""; |
| | | if (value != null) { |
| | | s = ((UserGroup) value).getId().toString(); |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | private UserGroup getSelectedItemAsEntity(UIComponent comp, String value) { |
| | | UserGroup item = null; |
| | | |
| | | Set<UserGroup> selectItems = null; |
| | | for (UIComponent uic : comp.getChildren()) { |
| | | if (uic instanceof UISelectItems) { |
| | | Long itemId = Long.valueOf(value); |
| | | selectItems = (Set<UserGroup>) ((UISelectItems) uic).getValue(); |
| | | |
| | | if (itemId != null && selectItems != null && !selectItems.isEmpty()) { |
| | | Predicate<UserGroup> predicate = i -> i.getId().equals(itemId); |
| | | item = selectItems.stream().filter(predicate).findFirst().orElse(null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item; |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="People" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="update" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Group View web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Group View web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Group View web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Select a Group:" for="group" /> |
| | | <h:selectOneMenu id="group" value="#{groupView.currentGroup}" valueChangeListener="#{groupView.update}" onchange="submit()" converter="SelectItemToEntityConverter"> |
| | | <f:selectItem itemLabel="Choose one ..." itemValue="#{null}"/> |
| | | <f:selectItems value="#{groupView.groups}" var="group" itemValue="#{group}" itemLabel="#{group.name}"/> |
| | | </h:selectOneMenu> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:outputLabel value="Employees:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{groupView.userList}" var="person"> |
| | | <li> |
| | | <strong>Name:</strong><h:outputText value="#{person.name}"/><br/> |
| | | <strong>Email:</strong><h:outputText value="#{person.email.address}"/> |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | </p> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |