diff --git a/com.rotanareg.skolan.iml b/com.rotanareg.skolan.iml index 0ed5a4b..50a4b38 100644 --- a/com.rotanareg.skolan.iml +++ b/com.rotanareg.skolan.iml @@ -15,7 +15,9 @@ - + + + @@ -33,7 +35,6 @@ - @@ -41,5 +42,7 @@ + + \ No newline at end of file diff --git a/docs/JavaEE_Project.pdf b/docs/JavaEE_Project.pdf new file mode 100644 index 0000000..0d1b21a Binary files /dev/null and b/docs/JavaEE_Project.pdf differ diff --git a/docs/jcdb.txt b/docs/jcdb.txt new file mode 100644 index 0000000..198828d --- /dev/null +++ b/docs/jcdb.txt @@ -0,0 +1,16 @@ +F�r att skapa connection poolen och resursen jdbc/school, +k�r f�ljande kommando i asadmin +(OBS: ni m�ste eventuellt anpassa l�senordet...) + +------------------------------------------------------- + + +(Om DB inte igång, skriv: "start-domain" kommando tolken) + +create-jdbc-connection-pool --datasourceclassname org.postgresql.ds.PGSimpleDataSource --restype javax.sql.XADataSource --property portNumber=5432:password=LexiconJava:user=postgres:serverName=localhost:databaseName=school jpa_school_postgresql_pool + + + +create-jdbc-resource --connectionpoolid jpa_school_postgresql_pool jdbc/school + +stop-domain \ No newline at end of file diff --git a/pom.xml b/pom.xml index cdfa35e..de98012 100644 --- a/pom.xml +++ b/pom.xml @@ -36,20 +36,27 @@ javaee-api 7.0 - - - org.primefaces - primefaces - 6.1 - org.eclipse.persistence org.eclipse.persistence.jpa 2.6.4 + + + postgresql + postgresql + 8.1-404.jdbc3 + + + + org.primefaces + primefaces + 6.0 + + - + \ No newline at end of file diff --git a/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociation.java b/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociation.java new file mode 100644 index 0000000..348f753 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociation.java @@ -0,0 +1,73 @@ +package com.rotanareg.skolan.AssociatedPersist; + +import com.rotanareg.skolan.coursePersist.CourseEntity; +import com.rotanareg.skolan.userPersist.UserEntity; + +import javax.persistence.*; + +/** + * Created by Nils Gerstner on 2017-08-31. + */ + +@Entity +@Table(name="COURSE_USER") +@IdClass(CourseUserAssociationId.class) +public class CourseUserAssociation { + + @Id + private long courseId; + @Id + private long personId; + + @Column(name="IS_TEACHER") + private boolean isTeacher; + + @ManyToOne + @PrimaryKeyJoinColumn(name="COURSEID", referencedColumnName = "ID") + private CourseEntity course; + @ManyToOne + @PrimaryKeyJoinColumn(name="PERSONID", referencedColumnName = "ID") + + private UserEntity person; + + public long getCourseId() { + return courseId; + } + + public void setCourseId(Long courseId) { + this.courseId = courseId; + } + + public long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public boolean isTeacher() { + return isTeacher; + } + + public void setTeacher(boolean teacher) { + isTeacher = teacher; + } + + public CourseEntity getCourse() { + return course; + } + + public void setCourse(CourseEntity course) { + this.course = course; + } + + public UserEntity getPerson() { + return person; + } + + public void setPerson(UserEntity person) { + this.person = person; + } +} + diff --git a/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociationId.java b/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociationId.java new file mode 100644 index 0000000..0809eaa --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/AssociatedPersist/CourseUserAssociationId.java @@ -0,0 +1,25 @@ +package com.rotanareg.skolan.AssociatedPersist; + +import java.io.Serializable; + +/** + * Created by Nils Gerstner on 2017-08-31. + */ +public class CourseUserAssociationId implements Serializable { + private long personId; + private long courseId; + + @Override + public int hashCode() { + return (int) (personId + courseId); + } + + @Override + public boolean equals(Object o) { + if (o instanceof CourseUserAssociationId) { + CourseUserAssociationId otherId = (CourseUserAssociationId) o; + return (otherId.personId == this.personId) && (otherId.courseId == this.courseId); + } + return false; + } +} diff --git a/src/main/java/com/rotanareg/skolan/AttendanceBean.java b/src/main/java/com/rotanareg/skolan/AttendanceBean.java new file mode 100644 index 0000000..f1fb8f4 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/AttendanceBean.java @@ -0,0 +1,109 @@ +/****************************** + * JSF - Managed-Bean, hämta info till/från xhtml filen. (Mellan Back och Front -end.) + ******************************/ + +//TODO: inkludera logik + +package com.rotanareg.skolan; + +import com.rotanareg.skolan.attendancePersist.*; +import com.rotanareg.skolan.domains.*; + +import javax.ejb.EJB; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import java.sql.Date; +import java.util.List; + +/** + * Created by Marko K. Seppänen. + */ +@ManagedBean +@RequestScoped +public class AttendanceBean { + private Long id; + // private Course course; +// private User user; + private Date sqlDate; //yyyy-mm-dd + private boolean hasAttended; + + @EJB + AttendanceService aService; + + public String addCourse() { + if (getId() == null) { + aService.addAttendance(new AttendanceDomain(getDate(), isHasAttended())); + }else { + // Update +// aService.updateCourse(new AttendanceDomain(getId(), getDate(), isHasAttended())); + } + + setId(null); + setDate(null); + setHasAttended(false); + return "stats_test"; + } +/* + public String editCourse(Long id) { + CourseDomain courseDomain = courseService.getCourse(id); + setId(courseDomain.getId()); + setName(courseDomain.getName()); + setCode(courseDomain.getCode()); + return "course"; + } + + public String removeCourse(Long id) { + courseService.removeCourse(id); + return "course"; + } +*/ + public List getAttendances() { + return aService.getAttendances(); + } +/* + public List getCoursesFilter() { + if (myFilter == null || myFilter.equals("")) + return courseService.getCourses(); + else + return courseService.getCoursesNameContain(myFilter); + } +*/ + public String getSubmitButton() { + if (id == null) + return "Add"; + else + return "Update"; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getDate() { + return sqlDate; + } + + public void setDate(Date date) { + this.sqlDate = date; + } + + public boolean isHasAttended() { + return hasAttended; + } + + public void setHasAttended(boolean hasAttended) { + this.hasAttended = hasAttended; + } + + public AttendanceService getCourseService() { + return aService; + } + + public void setCourseService(AttendanceService courseService) { + this.aService = courseService; + } +} diff --git a/src/main/java/com/rotanareg/skolan/Role.java b/src/main/java/com/rotanareg/skolan/Role.java index 2601485..070e1ae 100644 --- a/src/main/java/com/rotanareg/skolan/Role.java +++ b/src/main/java/com/rotanareg/skolan/Role.java @@ -10,9 +10,9 @@ public enum Role { public String toString() { switch (this) { case STUDENT: - return "StudentJAS"; + return "Student"; case TEACHER: - return "TeacherJAS"; + return "Teacher"; case ADMIN: return "Admin"; } diff --git a/src/main/java/com/rotanareg/skolan/UserBean.java b/src/main/java/com/rotanareg/skolan/UserBean.java new file mode 100644 index 0000000..4c4e10c --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/UserBean.java @@ -0,0 +1,87 @@ +package com.rotanareg.skolan; + +import java.util.List; + +import com.rotanareg.skolan.domains.User; +import com.rotanareg.skolan.userPersist.*; +import javax.ejb.EJB; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; + + +@ManagedBean +@RequestScoped +public class UserBean { + private Long id; + private String name; + private String lastName; + private Role role; + private String passWord; + @EJB + UserService userService; + + public String addUser(){ + if (getId()==null) + userService.addUser(new User(name,lastName,role)); + else + userService.addUser(new User(getId(),getName(),getLastName(),getRole(),getPassWord())); + + setId(null); + setName(""); + setLastName(""); + setRole(null); + setPassWord(""); + return "user"; + } + + 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 String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } + + public String getPassWord() { + return passWord; + } + + public void setPassWord(String passWord) { + this.passWord = passWord; + } + + public UserService getUserService() { + return userService; + } + + public void setUserService(UserService userService) { + this.userService = userService; + } + public UserService getUsers(){ + return userService; + } +} diff --git a/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceEntity.java b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceEntity.java new file mode 100644 index 0000000..0bf086a --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceEntity.java @@ -0,0 +1,98 @@ +/****************************** + * JPA Entity class defines whose instances can be stored in the database. + * The Entity represents your Data Object Model. + ******************************/ + +package com.rotanareg.skolan.attendancePersist; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +//import java.util.*; +import java.sql.Date; +import java.text.DateFormat.*; +import java.text.*; + +/** + * Created by Marko K. Seppänen. + */ +/*@NamedQueries({ + @NamedQuery(name = "selectAll", query = "SELECT p FROM Course p"), + @NamedQuery(name = "selectSome", query = "SELECT t FROM Course t WHERE LOCATE(:filt,t.name) >0 ") +})*/ +@Entity +@Table(name = "Attendance") +@NamedQueries({ + @NamedQuery(name = "selectAll", query = "SELECT p FROM AttendanceEntity p"), + //@NamedQuery(name = "selectSome", query = "SELECT t FROM AttendanceEntity t WHERE LOCATE(:filt,t.name) >0 ") +}) +public class AttendanceEntity { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + //@NotNull + //private Long courseId; +/* private CourseEntity course; + + //@NotNull + //private Long userId; + private UserEntity user; +*/ + ////@Temporal(TemporalType.DATE) + ////@DateFormat(format = "yyyy-MM-dd") + //@NotNull + private Date sqlDate; //yyyy-mm-dd + private boolean hasAttended; + + public AttendanceEntity() { + } + + public AttendanceEntity(Date date, boolean hasAttended) { + this.sqlDate = date; + this.hasAttended = hasAttended; + } + + /* public AttendanceEntity(CourseEntity course, UserEntity user, Date sqlDate, boolean hasAttended) { + this.course = course; + this.user = user; + this.sqlDate = sqlDate; + this.hasAttended = hasAttended; + } +*/ + public Long getId() { + return id; + } + +/* public CourseEntity getCourse() { + return course; + } + + public void setCourse(CourseEntity course) { + this.course = course; + } + + public UserEntity getUser() { + return user; + } + + public void setUser(UserEntity user) { + this.user = user; + } +*/ + public Date getDate() { + return sqlDate; + } + + public void setDate(Date date) { + this.sqlDate = date; + } + + public boolean isHasAttended() { + return hasAttended; + } + + public void setHasAttended(boolean hasAttended) { + this.hasAttended = hasAttended; + } +} diff --git a/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceService.java b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceService.java new file mode 100644 index 0000000..d4ed292 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceService.java @@ -0,0 +1,35 @@ +/****************************** + * EJB - Interface för våran tjänst ("kontrakt" för varje EJB att följa om den vill stödja tjänsten för Attendance) + ******************************/ + +package com.rotanareg.skolan.attendancePersist; + +import com.rotanareg.skolan.domains.*; + +import javax.ejb.Local; +import java.util.List; + +/** + * Created by Marko K. Seppänen. + */ +@Local +public interface AttendanceService { + + // (C)reate / add. + void addAttendance(AttendanceDomain attendance); +/* + // (R)ead / get. + AttendanceDomain getAttendance(Long id); + + // (U)pdate. + void updateAttendance(AttendanceDomain attendance); + + // (D)elete. + void deleteAttendance(Long id); +*/ + + List getAttendances(); +/* + public List getCoursesNameContain(String filter); + */ +} diff --git a/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceServiceImpl.java b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceServiceImpl.java new file mode 100644 index 0000000..b05b446 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/attendancePersist/AttendanceServiceImpl.java @@ -0,0 +1,92 @@ +/****************************** + * EJB - Enterprise bean (EJB), som stödjer tjänsten AttendanceService. + ******************************/ + +package com.rotanareg.skolan.attendancePersist; + +import com.rotanareg.skolan.domains.*; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.sql.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by Marko K. Seppänen. + */ +@Stateless +public class AttendanceServiceImpl implements AttendanceService { + @PersistenceContext + EntityManager em; + + // (C)reate / add. + @Override + public void addAttendance(AttendanceDomain ad){ + AttendanceEntity dom = new AttendanceEntity(ad.getDate(), ad.isHasAttended()); // Create the Data Object Model + em.persist(dom); + } + + // (R)ead / get. +/* @Override + public AttendanceDomain getAttendance(Long id){ + Course c = em.find(Course.class, id); + return new CourseDomain(c.getId(), c.getName(), c.getCode()); + } + + // (U)pdate. + @Override + public void updateAttendance(AttendanceDomain attendance){ + Course c = em.find(Course.class, course.getId()); + c.setName(course.getName()); + c.setCode(course.getCode()); + em.merge(c); + + } + + // (D)elete. + @Override + public void deleteAttendance(Long id){ + Course c = em.find(Course.class, id); + em.remove(c); + } +*/ + + @Override + public List getAttendances() { + /*Query query = em.createQuery("select a from Course a where a.code = :lname and a.name = :fname", Course.class); + query.setParameter("lname", "Karlsson"); + query.setParameter("fname", "Kalle"); + */ + /*Query query = em.createQuery("select a from Attendance a where a.code = :lname and a.name = :fname", AttendanceEntity.class); + query.setParameter("lname", "Karlsson"); + query.setParameter("fname", "Kalle"); + */ + //List courseEntityList = em.createNamedQuery("selectAllCourses").getResultList(); + + /* + List courseRecords = query.getResultList(); + System.out.println("course Size " + courseRecords.size()); + */ + + List l = em.createNamedQuery("selectAll").getResultList(); + + return l.stream(). + map(a -> new AttendanceDomain(a.getId(), a.getDate(), a.isHasAttended())). + collect(Collectors.toList()); + } +/* + @Override + public List getCoursesNameContain(String filter) { + + List l = em.createNamedQuery("selectSome").setParameter("filt", filter).getResultList(); + + return l.stream(). + map(p -> new CourseDomain(p.getId(), p.getName(), p.getCode())). + collect(Collectors.toList()); + + } +*/ +} diff --git a/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java b/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java index 2f0df3b..3e3c188 100644 --- a/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java +++ b/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java @@ -1,23 +1,21 @@ package com.rotanareg.skolan.coursePersist; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; - - -/** - * Created by Solidbeans on 2017-03-20. - */ +import com.rotanareg.skolan.AssociatedPersist.CourseUserAssociation; +import com.rotanareg.skolan.Role; +import com.rotanareg.skolan.userPersist.UserEntity; + +import javax.persistence.*; + +import java.util.ArrayList; +import java.util.List; + + + @Entity @Table(name = "Course") @NamedQueries({ - @NamedQuery(name="selectAll",query="SELECT c FROM CourseEntity c"), - @NamedQuery(name="selectSome",query="SELECT t FROM CourseEntity t WHERE LOCATE(:filt,t.name) >0 ") + @NamedQuery(name="selectAllCourses",query="SELECT c FROM CourseEntity c"), + @NamedQuery(name="selectSomeCourses",query="SELECT t FROM CourseEntity t WHERE LOCATE(:filt,t.name) >0 ") }) public class CourseEntity { @@ -30,6 +28,9 @@ public class CourseEntity { private String description; private String courseNr; + @OneToMany(mappedBy="course") + private List persons; + public CourseEntity() { } @@ -70,4 +71,27 @@ public class CourseEntity { public void setCourseNr(String courseNr) { this.courseNr = courseNr; } + + public List getPersons() { + return persons; + } + public void addPerson (UserEntity person, boolean isTeacher) { + CourseUserAssociation courseUserAssociation = new CourseUserAssociation(); + if (person.getRole() == Role.ADMIN) { + System.out.println("Nor TEACHER or STUDENT; not added!"); + } else { + if (isTeacher && person.getRole() == Role.TEACHER) + courseUserAssociation.setTeacher(true); + else if (!isTeacher && person.getRole() != Role.STUDENT) + courseUserAssociation.setTeacher(false); + courseUserAssociation.setPerson(person); + courseUserAssociation.setCourse(this); + courseUserAssociation.setPersonId(person.getId()); + courseUserAssociation.setCourseId(this.getId()); + if (this.persons == null) + this.persons = new ArrayList<>(); + this.persons.add(courseUserAssociation); + } + } + } diff --git a/src/main/java/com/rotanareg/skolan/coursePersist/CourseService.java b/src/main/java/com/rotanareg/skolan/coursePersist/CourseService.java index 279a498..a455277 100644 --- a/src/main/java/com/rotanareg/skolan/coursePersist/CourseService.java +++ b/src/main/java/com/rotanareg/skolan/coursePersist/CourseService.java @@ -1,12 +1,11 @@ package com.rotanareg.skolan.coursePersist; -import java.util.List; -import javax.ejb.Local; import com.rotanareg.skolan.domains.Course; -/** - * Created by Solidbeans on 2017-03-20. - */ +import javax.ejb.Local; +import java.util.List; + + @Local public interface CourseService { diff --git a/src/main/java/com/rotanareg/skolan/coursePersist/CourseServiceImpl.java b/src/main/java/com/rotanareg/skolan/coursePersist/CourseServiceImpl.java index 2cbf259..a6fffd8 100644 --- a/src/main/java/com/rotanareg/skolan/coursePersist/CourseServiceImpl.java +++ b/src/main/java/com/rotanareg/skolan/coursePersist/CourseServiceImpl.java @@ -8,9 +8,6 @@ import javax.persistence.PersistenceContext; import java.util.List; import java.util.stream.Collectors; -/** - * Created by Solidbeans on 2017-03-20. - */ @Stateless public class CourseServiceImpl implements CourseService{ @@ -49,7 +46,7 @@ public class CourseServiceImpl implements CourseService{ @Override public List getCourses() { - List courseEntityList = em.createNamedQuery("selectAll").getResultList(); + List courseEntityList = em.createNamedQuery("selectAllCourses").getResultList(); if (courseEntityList.isEmpty()){ CourseEntity a = new CourseEntity("Engelska", "Du som behärskar engelska kommer långt. Engelska är ett världsspråk och antalet engelsktalande människor i världen ökar ständigt. Men engelska är inte bara samtal. Det är också litteratur att läsa och texter att skriva. Välkommen till oss när du vill förbättra din engelska!", @@ -71,7 +68,7 @@ public class CourseServiceImpl implements CourseService{ @Override public List getCoursesContaining(String filter) { - List courseEntityList = em.createNamedQuery("selectSome").setParameter("filt",filter).getResultList(); + List courseEntityList = em.createNamedQuery("selectSomeCourses").setParameter("filt",filter).getResultList(); return courseEntityList.stream(). map(c->new Course(c.getId(),c.getName(),c.getDescription(),c.getCourseNr())). diff --git a/src/main/java/com/rotanareg/skolan/domains/AttendanceDomain.java b/src/main/java/com/rotanareg/skolan/domains/AttendanceDomain.java new file mode 100644 index 0000000..025f2ea --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/domains/AttendanceDomain.java @@ -0,0 +1,80 @@ +/****************************** + * POJO - Mellanskikt mellan AttendanceBean (vanlig böna) och EJB (Enterprise-böna), samt JPA (transformerings-klass). + * Inkapslings-klass (hjälp-klass) för att underlätta transporten av data mellan objekt. + ******************************/ + +package com.rotanareg.skolan.domains; + +import java.sql.Date; + +/** + * Created by Marko K. Seppänen. + */ +public class AttendanceDomain { + private Long id; +// private Course course; +// private User user; + private Date sqlDate; //yyyy-mm-dd + private boolean hasAttended; + + public AttendanceDomain(Date date, boolean hasAttended) { + this.sqlDate = date; + this.hasAttended = hasAttended; + } + + public AttendanceDomain(Long id, Date date, boolean hasAttended) { + this.id = id; + this.sqlDate = date; + this.hasAttended = hasAttended; + } + + /* public AttendanceDomain(Long id, Course course, User user, Date date, boolean hasAttended) { + this.id = id; + this.courseId = courseId; + this.userId = userId; + this.sqlDate = date; + this.hasAttended = hasAttended; + } +*/ + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + +/* public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +*/ + public Date getDate() { + return sqlDate; + } + + public void setDate(Date date) { + this.sqlDate = sqlDate; + } + + public boolean isHasAttended() { + return hasAttended; + } + + public void setHasAttended(boolean hasAttended) { + this.hasAttended = hasAttended; + } + +} diff --git a/src/main/java/com/rotanareg/skolan/domains/Course.java b/src/main/java/com/rotanareg/skolan/domains/Course.java index 2c577d0..23ef40c 100644 --- a/src/main/java/com/rotanareg/skolan/domains/Course.java +++ b/src/main/java/com/rotanareg/skolan/domains/Course.java @@ -1,5 +1,11 @@ package com.rotanareg.skolan.domains; +import com.rotanareg.skolan.AssociatedPersist.CourseUserAssociation; +import com.rotanareg.skolan.userPersist.UserEntity; + +import java.util.ArrayList; +import java.util.List; + /** * Created by Nils Gerstner on 8/20/17. */ @@ -9,6 +15,7 @@ public class Course { private String name; private String description; private String courseNr; + private List persons; public Course(String name, String description, String courseNr){ this.name = name; @@ -55,6 +62,14 @@ public class Course { this.courseNr = courseNr; } + public List getPersons() { + return persons; + } + + public void setPersons(List persons) { + this.persons = persons; + } + @Override public String toString(){ final StringBuilder sbc = new StringBuilder("CourseEntity{"); diff --git a/src/main/java/com/rotanareg/skolan/signIn/LoggedIn.java b/src/main/java/com/rotanareg/skolan/signIn/LoggedIn.java new file mode 100644 index 0000000..7fae19a --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/signIn/LoggedIn.java @@ -0,0 +1,26 @@ +package com.rotanareg.skolan.signIn; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; +import java.io.Serializable; + +/** + * Created by Nils Gerstner on 2017-09-01. + */ + +@Named +@SessionScoped +public class LoggedIn implements Serializable { + private Long id = null; + + public LoggedIn() { + } + + public LoggedIn(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } +} diff --git a/src/main/java/com/rotanareg/skolan/signIn/SignIn.java b/src/main/java/com/rotanareg/skolan/signIn/SignIn.java new file mode 100644 index 0000000..847db06 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/signIn/SignIn.java @@ -0,0 +1,49 @@ +package com.rotanareg.skolan.signIn; + +import javax.ejb.EJB; +import javax.enterprise.context.*; +import javax.inject.*; + +import com.rotanareg.skolan.userPersist.UserService; + +@Named +@RequestScoped +public class SignIn { + + @Inject + private LoggedIn loggedIn; + + @EJB + private UserService us; + + private String username; + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void submit() { + if (us.getUserContaining(username).get(0).getPassWord().equals(password)){ + this.loggedIn = new LoggedIn(us.getUserContaining(username).get(0).getId()); + } + } + + public boolean loggedIn(){ + if (loggedIn != null) + return true; + return false; + } + + public void logout(){ + this.loggedIn = null; + } +} diff --git a/src/main/java/com/rotanareg/skolan/user/DateB.java b/src/main/java/com/rotanareg/skolan/user/DateB.java deleted file mode 100644 index 81628bf..0000000 --- a/src/main/java/com/rotanareg/skolan/user/DateB.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.rotanareg.skolan.user; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - - - -public class DateB { - - public static Date date(String s) { - SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - try { - return dateFormat.parse(s); - } catch (ParseException e) { - e.printStackTrace(); - } - return null; - } -} - diff --git a/src/main/java/com/rotanareg/skolan/user/admin/admindomain/AdminDomain.java b/src/main/java/com/rotanareg/skolan/user/admin/admindomain/AdminDomain.java deleted file mode 100644 index ef27539..0000000 --- a/src/main/java/com/rotanareg/skolan/user/admin/admindomain/AdminDomain.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.admin.admindomain; - -public class AdminDomain { -} diff --git a/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminService.java b/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminService.java deleted file mode 100644 index 9c01b9d..0000000 --- a/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.admin.adminejb; - -public class AdminService { -} diff --git a/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminServiceImpl.java b/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminServiceImpl.java deleted file mode 100644 index 5ff00e7..0000000 --- a/src/main/java/com/rotanareg/skolan/user/admin/adminejb/AdminServiceImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.admin.adminejb; - -public class AdminServiceImpl { -} diff --git a/src/main/java/com/rotanareg/skolan/user/admin/adminjpa/Admin.java b/src/main/java/com/rotanareg/skolan/user/admin/adminjpa/Admin.java deleted file mode 100644 index ada60f2..0000000 --- a/src/main/java/com/rotanareg/skolan/user/admin/adminjpa/Admin.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.admin.adminjpa; - -public class Admin { -} diff --git a/src/main/java/com/rotanareg/skolan/user/admin/adminjsf/AdminBean.java b/src/main/java/com/rotanareg/skolan/user/admin/adminjsf/AdminBean.java deleted file mode 100644 index 78b5556..0000000 --- a/src/main/java/com/rotanareg/skolan/user/admin/adminjsf/AdminBean.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.admin.adminjsf; - -public class AdminBean { -} diff --git a/src/main/java/com/rotanareg/skolan/user/student/studentdomain/StudentDomain.java b/src/main/java/com/rotanareg/skolan/user/student/studentdomain/StudentDomain.java deleted file mode 100644 index b769e07..0000000 --- a/src/main/java/com/rotanareg/skolan/user/student/studentdomain/StudentDomain.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.student.studentdomain; - -public class StudentDomain { -} diff --git a/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentService.java b/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentService.java deleted file mode 100644 index 95a5ea1..0000000 --- a/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.student.studentejb; - -public class StudentService { -} diff --git a/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentServiceImpl.java b/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentServiceImpl.java deleted file mode 100644 index 7849f7c..0000000 --- a/src/main/java/com/rotanareg/skolan/user/student/studentejb/StudentServiceImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.student.studentejb; - -public class StudentServiceImpl { -} diff --git a/src/main/java/com/rotanareg/skolan/user/student/studentjpa/Student.java b/src/main/java/com/rotanareg/skolan/user/student/studentjpa/Student.java deleted file mode 100644 index 6f17e71..0000000 --- a/src/main/java/com/rotanareg/skolan/user/student/studentjpa/Student.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.student.studentjpa; - -public class Student { -} diff --git a/src/main/java/com/rotanareg/skolan/user/student/studentjsf/StudentBean.java b/src/main/java/com/rotanareg/skolan/user/student/studentjsf/StudentBean.java deleted file mode 100644 index 35747ec..0000000 --- a/src/main/java/com/rotanareg/skolan/user/student/studentjsf/StudentBean.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.rotanareg.skolan.user.student.studentjsf; - -public class StudentBean { - -} diff --git a/src/main/java/com/rotanareg/skolan/user/teacher/teacherdomain/TeacherDomain.java b/src/main/java/com/rotanareg/skolan/user/teacher/teacherdomain/TeacherDomain.java deleted file mode 100644 index f5b9a3f..0000000 --- a/src/main/java/com/rotanareg/skolan/user/teacher/teacherdomain/TeacherDomain.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.teacher.teacherdomain; - -public class TeacherDomain { -} diff --git a/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeacherServiceImpl.java b/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeacherServiceImpl.java deleted file mode 100644 index 50dac17..0000000 --- a/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeacherServiceImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.teacher.teacherejb; - -public class TeacherServiceImpl { -} diff --git a/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeaherService.java b/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeaherService.java deleted file mode 100644 index dff970c..0000000 --- a/src/main/java/com/rotanareg/skolan/user/teacher/teacherejb/TeaherService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.teacher.teacherejb; - -public class TeaherService { -} diff --git a/src/main/java/com/rotanareg/skolan/user/teacher/teacherjpa/Teacher.java b/src/main/java/com/rotanareg/skolan/user/teacher/teacherjpa/Teacher.java deleted file mode 100644 index e1121ac..0000000 --- a/src/main/java/com/rotanareg/skolan/user/teacher/teacherjpa/Teacher.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.teacher.teacherjpa; - -public class Teacher { -} diff --git a/src/main/java/com/rotanareg/skolan/user/teacher/teacherjsf/TeacherBean.java b/src/main/java/com/rotanareg/skolan/user/teacher/teacherjsf/TeacherBean.java deleted file mode 100644 index b01aa0a..0000000 --- a/src/main/java/com/rotanareg/skolan/user/teacher/teacherjsf/TeacherBean.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rotanareg.skolan.user.teacher.teacherjsf; - -public class TeacherBean { -} diff --git a/src/main/java/com/rotanareg/skolan/userManager/EmailAddressValidator.java b/src/main/java/com/rotanareg/skolan/userManager/EmailAddressValidator.java deleted file mode 100644 index 4b001b1..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/EmailAddressValidator.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -public class EmailAddressValidator implements ConstraintValidator { - - @Override - public void initialize(ValidEmailAddress constraintAnnotation) { - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext context) { - return value == null || value.equals("") || value.contains("@"); - } -} - - - - diff --git a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumber.java b/src/main/java/com/rotanareg/skolan/userManager/PhoneNumber.java deleted file mode 100644 index 1276f3e..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumber.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import java.io.Serializable; - -public class PhoneNumber implements Serializable { - - private static final long serialVersionUID = 1L; - - private String countryCode; - private String subscriberNumber; - - public String getCountryCode() { - return countryCode; - } - - public void setCountryCode(String countryCode) { - this.countryCode = countryCode; - } - - - public String getSubscriberNumber() { - return subscriberNumber; - } - - public void setSubscriberNumber(String subscriberNumber) { - this.subscriberNumber = subscriberNumber; - } -} diff --git a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberConverter.java b/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberConverter.java deleted file mode 100644 index 577c0ab..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberConverter.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import java.util.regex.Pattern; - -@FacesConverter(forClass = PhoneNumber.class) -public class PhoneNumberConverter implements Converter { - - private static final Pattern PHONE_NUMBER_PATTERN = Pattern.compile("[0-8]{2}-[0-8]{3}-[0-8]{3}"); - - @Override - public Object getAsObject(FacesContext context, UIComponent component, String value) { - if (value == null || value.equals("")) { - return null; - } - - if (!PHONE_NUMBER_PATTERN.matcher(value).matches()) { - throw new ConverterException( - new FacesMessage("Fyll i det rätta formen på telefonummer: 00-000-000.")); - } - - PhoneNumber phoneNumber = new PhoneNumber(); - phoneNumber.setCountryCode(value.substring(0, 2)); - phoneNumber.setSubscriberNumber(value.substring(3)); - - return phoneNumber; - } - - @Override - public String getAsString(FacesContext context, UIComponent component, Object value) { - if (value == null) { - return null; - } - - PhoneNumber phoneNumber = (PhoneNumber) value; - - return phoneNumber.getCountryCode() + "-" + phoneNumber.getSubscriberNumber(); - } -} - diff --git a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberValidator.java b/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberValidator.java deleted file mode 100644 index 2120eaf..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/PhoneNumberValidator.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.validator.FacesValidator; -import javax.faces.validator.Validator; -import javax.faces.validator.ValidatorException; - - -@FacesValidator("com.rotanareg.skolan.user.PhoneNumber") -public class PhoneNumberValidator implements Validator { - - @Override - public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { - PhoneNumber phoneNumber = (PhoneNumber) value; - - - - if (phoneNumber != null) { - checkCountryCode(phoneNumber.getCountryCode()); - - } - } - - private void checkCountryCode(String countryCode) { - int firstDigit = Character.digit(countryCode.charAt(0), 10); - if (firstDigit == 0 || firstDigit == 1) { - throw new ValidatorException( - new FacesMessage("Första siffran i ditt tfn får inte vara 0 or 1.")); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/rotanareg/skolan/userManager/SignIn.java b/src/main/java/com/rotanareg/skolan/userManager/SignIn.java deleted file mode 100644 index 3fccb61..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/SignIn.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.rotanareg.skolan.userManager; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.inject.Named; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - -@Named -@RequestScoped -public class SignIn { - - @Inject - private UserManager userManager; - - @Pattern(regexp = "[A-Za-z0-9]{2,20}", message = "Användarnamnet skall innehålla bara bokstäver och siffror samt vara långt mellan 2 och 20 tecken.") - private String username; - - @Size(min = 8, message = "Ditt password måste innehålla minst 8 tecken.") - private String password; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String submit() { - return userManager.signIn(username, password); - } -} diff --git a/src/main/java/com/rotanareg/skolan/userManager/User.java b/src/main/java/com/rotanareg/skolan/userManager/User.java deleted file mode 100644 index 3d87108..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/User.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import com.rotanareg.skolan.Role; - -import javax.validation.constraints.Past; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - - -public class User implements Serializable { - - private static final long serialVersionUID = 1L; - - private Role role; - private List rolesList; - - public User() { - rolesList = new ArrayList(); - rolesList.add(Role.STUDENT); - rolesList.add(Role.TEACHER); - rolesList.add(Role.ADMIN); - role = Role.STUDENT; // set the first role as default - } - - @Pattern(regexp = "[A-Za-z0-9]{2,20}", message = "Skriv in ditt användarnamn mellan 2 och 20 tecken långt, innehållande bokstäver och siffror") - private String username; - - @Size(min = 8, message = "Ditt pasword måste innehålla minst 8 tecken") - private String password; - - @Size(min = 1, max = 30, message = "Skriv in ditt Förnamn mellan 1 och 30 tecken långt.") - private String firstName; - - @Size(min = 1, max = 30, message = "Skriv in ditt Efternamn mellan 1 och 30 tecken långt.") - private String lastName; - - @ValidEmailAddress - private String emailAddress; - - private PhoneNumber phoneNumber; - - @Past(message = "Ditt födelsedatum måste vara i dåtid .") - private Date birthDate; - - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - - this.lastName = lastName; - } - - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public PhoneNumber getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(PhoneNumber phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public Date getBirthDate() { - return birthDate; - } - - public void setBirthDate(Date birthDate) { - this.birthDate = birthDate; - } - - public Role getRole() { - return role; - } - - public void setRole(Role role) { - this.role = role; - } - - public List getRolesList() { - return rolesList; - } - -} - - diff --git a/src/main/java/com/rotanareg/skolan/userManager/UserDetail.java b/src/main/java/com/rotanareg/skolan/userManager/UserDetail.java deleted file mode 100644 index 807f288..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/UserDetail.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.rotanareg.skolan.userManager; - - -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; -@Named -@ViewScoped -public class UserDetail implements Serializable { - private static final long serialVersionUID = 1L; - - @Inject - private UserManager userManager; - - private User user; - - public User getUser() { - return user; - } - - public void onload() { - user = userManager.isSignedIn() ? userManager.getCurrentUser() : new User(); - } - - public String submit() { - return userManager.save(user); - } - -} diff --git a/src/main/java/com/rotanareg/skolan/userManager/UserManager.java b/src/main/java/com/rotanareg/skolan/userManager/UserManager.java deleted file mode 100644 index b2ad538..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/UserManager.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import com.rotanareg.skolan.Role; - -import javax.enterprise.context.SessionScoped; -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; - -@Named -@SessionScoped -public class UserManager implements Serializable { - - private static final long serialVersionUID = 1L; - - @Inject - private UserService userService; - - private User currentUser; - - public boolean isSignedIn() { - return currentUser != null; - } - - public User getCurrentUser() { - return currentUser; - } - - public String signIn(String username, String password) { - User user = userService.getUser(username); - if (user == null || !password.equals(user.getPassword())) { - return "signIn"; - } - currentUser = user; - - switch (user.getRole()) { - case STUDENT: - return "student"; // xhtml-page to redirect to when signed in - case TEACHER: - return "teacher"; // xhtml-page to redirect to when signed in - case ADMIN: - return "admin"; // xhtml-page to redirect to when signed in - } - return ""; // should never happen, but redirects to the default xhtml-page - } - - public void signOut() { - FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); - } - - public String save(User user) { - userService.saveUser(user); - currentUser = user; - - return "index"; - } -} - - diff --git a/src/main/java/com/rotanareg/skolan/userManager/UserService.java b/src/main/java/com/rotanareg/skolan/userManager/UserService.java deleted file mode 100644 index f07deea..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/UserService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.rotanareg.skolan.userManager; - -public interface UserService { - // get information om användare - User getUser(String username); - - // spara information om användare - void saveUser(User user); -} diff --git a/src/main/java/com/rotanareg/skolan/userManager/UserServiceImpl.java b/src/main/java/com/rotanareg/skolan/userManager/UserServiceImpl.java deleted file mode 100644 index 27840ff..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/UserServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import javax.enterprise.context.ApplicationScoped; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@ApplicationScoped // skall stored i databas -public class UserServiceImpl implements UserService { - - - private final Map users = new ConcurrentHashMap<>(); - - @Override - public User getUser(String username) { - return users.get(username); - } - - @Override - public void saveUser(User user) { - users.put(user.getUsername(), user); - } -} - diff --git a/src/main/java/com/rotanareg/skolan/userManager/ValidEmailAddress.java b/src/main/java/com/rotanareg/skolan/userManager/ValidEmailAddress.java deleted file mode 100644 index 994871c..0000000 --- a/src/main/java/com/rotanareg/skolan/userManager/ValidEmailAddress.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.rotanareg.skolan.userManager; - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Constraint(validatedBy = EmailAddressValidator.class) -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface ValidEmailAddress { - - String message() default "Skriv din rätta e-mail adressen."; - - Class[] groups() default {}; - - Class[] payload() default {}; -} diff --git a/src/main/java/com/rotanareg/skolan/userPersist/UserEntity.java b/src/main/java/com/rotanareg/skolan/userPersist/UserEntity.java index 1e4d956..ca8db8e 100644 --- a/src/main/java/com/rotanareg/skolan/userPersist/UserEntity.java +++ b/src/main/java/com/rotanareg/skolan/userPersist/UserEntity.java @@ -1,16 +1,19 @@ package com.rotanareg.skolan.userPersist; import javax.persistence.*; +import com.rotanareg.skolan.AssociatedPersist.CourseUserAssociation; import com.rotanareg.skolan.Role; +import com.rotanareg.skolan.coursePersist.CourseEntity; + +import java.util.ArrayList; +import java.util.List; + -/** - * Created by Solidbeans on 2017-03-20. - */ @Entity @Table(name = "Person") @NamedQueries({ - @NamedQuery(name="selectAll",query="SELECT u FROM UserEntity u"), - @NamedQuery(name="selectSome",query="SELECT t FROM UserEntity t WHERE LOCATE(:filt,t.name) >0 ") + @NamedQuery(name="selectAllUsers",query="SELECT u FROM UserEntity u"), + @NamedQuery(name="selectSomeUsers",query="SELECT t FROM UserEntity t WHERE LOCATE(:filt,t.name) >0 ") }) public class UserEntity { @@ -23,6 +26,9 @@ public class UserEntity { private String lastName; private String passWord; + @OneToMany(mappedBy = "person") + private List courses; + public UserEntity() { } @@ -72,4 +78,27 @@ public class UserEntity { public String getPassWord() { return passWord; } + + public List getCourses() { + return courses; + } + + public void addCourse (CourseEntity course, boolean isTeacher) { + CourseUserAssociation courseUserAssociation = new CourseUserAssociation(); + if (this.getRole() == Role.ADMIN) { + System.out.println("Nor TEACHER or STUDENT; not added!"); + } else { + if (isTeacher && this.getRole() == Role.TEACHER) + courseUserAssociation.setTeacher(true); + else if (!isTeacher && this.getRole() != Role.STUDENT) + courseUserAssociation.setTeacher(false); + courseUserAssociation.setPerson(this); + courseUserAssociation.setCourse(course); + courseUserAssociation.setPersonId(this.getId()); + courseUserAssociation.setCourseId(course.getId()); + if (this.courses == null) + this.courses = new ArrayList<>(); + this.courses.add(courseUserAssociation); + } + } } diff --git a/src/main/java/com/rotanareg/skolan/userPersist/UserService.java b/src/main/java/com/rotanareg/skolan/userPersist/UserService.java index 413dc98..d39e2d5 100644 --- a/src/main/java/com/rotanareg/skolan/userPersist/UserService.java +++ b/src/main/java/com/rotanareg/skolan/userPersist/UserService.java @@ -5,9 +5,7 @@ import com.rotanareg.skolan.domains.User; import javax.ejb.Local; import java.util.List; -/** - * Created by Solidbeans on 2017-03-20. - */ + @Local public interface UserService { @@ -15,6 +13,6 @@ public interface UserService { void updateUser(User user); void removeUser(Long id); User getUser(Long id); - List getUser(); + List getUsers(); public List getUserContaining(String filter); } diff --git a/src/main/java/com/rotanareg/skolan/userPersist/UserServiceImpl.java b/src/main/java/com/rotanareg/skolan/userPersist/UserServiceImpl.java index c225e36..b4aa0ce 100644 --- a/src/main/java/com/rotanareg/skolan/userPersist/UserServiceImpl.java +++ b/src/main/java/com/rotanareg/skolan/userPersist/UserServiceImpl.java @@ -9,9 +9,7 @@ import javax.persistence.PersistenceContext; import java.util.List; import java.util.stream.Collectors; -/** - * Created by Solidbeans on 2017-03-20. - */ + @Stateless public class UserServiceImpl implements UserService{ @@ -47,8 +45,8 @@ public class UserServiceImpl implements UserService{ return ud; } @Override - public List getUser() { - List userEntityList = em.createNamedQuery("selectAll").getResultList(); + public List getUsers() { + List userEntityList = em.createNamedQuery("selectAllUsers").getResultList(); if (userEntityList.isEmpty()){ UserEntity a = new UserEntity("Nils","Gerstner",Role.STUDENT,"1234"); em.persist(a); @@ -65,7 +63,7 @@ public class UserServiceImpl implements UserService{ @Override public List getUserContaining(String filter) { - List userEntityList = em.createNamedQuery("selectSome").setParameter("filt",filter).getResultList(); + List userEntityList = em.createNamedQuery("selectSomeUsers").setParameter("filt",filter).getResultList(); return userEntityList.stream(). map(c->new User(c.getId(),c.getName(),c.getLastName(),c.getRole(),c.getPassWord())). diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 9808c80..6c98409 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -3,13 +3,17 @@ - - jdbc/school + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + + + + jdbc/school false + + - \ No newline at end of file + diff --git a/src/main/webapp/WEB-INF/faces-config.xml b/src/main/webapp/WEB-INF/faces-config.xml index c2df863..eccae5c 100644 --- a/src/main/webapp/WEB-INF/faces-config.xml +++ b/src/main/webapp/WEB-INF/faces-config.xml @@ -1,7 +1,22 @@ - + + index.xhtml + /index.xhtml + + success + /pupil1.xhtml + + + + index.xhtml + /index.xhtml + + failure + /index.xhtml + + \ No newline at end of file diff --git a/src/main/webapp/admin.xhtml b/src/main/webapp/admin.xhtml index 7754f1f..aced9d6 100644 --- a/src/main/webapp/admin.xhtml +++ b/src/main/webapp/admin.xhtml @@ -1,24 +1,30 @@ - + + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" + xmlns:f="http://xmlns.jcp.org/jsf/core"> + + - - - + +
- - + Logga ut
+
+

Admin

+ Registrera nya användare
-
+ + diff --git a/src/main/webapp/course.xhtml b/src/main/webapp/course.xhtml deleted file mode 100644 index b64e7be..0000000 --- a/src/main/webapp/course.xhtml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/src/main/webapp/course_detail.xhtml b/src/main/webapp/course_detail.xhtml deleted file mode 100644 index 1d70762..0000000 --- a/src/main/webapp/course_detail.xhtml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - -
- -

#{course.name}

-

-
-
-
-
- diff --git a/src/main/webapp/course_details.xhtml b/src/main/webapp/course_details.xhtml index 6183246..1f2df28 100644 --- a/src/main/webapp/course_details.xhtml +++ b/src/main/webapp/course_details.xhtml @@ -1,6 +1,6 @@ - + - - + + - -
- -

#{course.name}

-

#{course.description}

-
+ +
+ +

#{courseDetails.course.name}

+

#{courseDetails.course.description}

+
diff --git a/src/main/webapp/create_course.xhtml b/src/main/webapp/create_course.xhtml deleted file mode 100644 index da2073e..0000000 --- a/src/main/webapp/create_course.xhtml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - -
- -

Ny kurs panel top

- -
-
- - -
- -

Kurs kod

-

Kurs namn

-

Kurs deskription

-

Ansvarig lärare

-
-
-
- -
- \ No newline at end of file diff --git a/src/main/webapp/inc/inc_form_login.xhtml b/src/main/webapp/inc/inc_form_login.xhtml new file mode 100644 index 0000000..ca41c04 --- /dev/null +++ b/src/main/webapp/inc/inc_form_login.xhtml @@ -0,0 +1,28 @@ + + +

+
+ +
+ + Användarnamn123:
+
+ +
+ + Lösenord:
+
+ +
+ + +

+
+ +
+ diff --git a/src/main/webapp/index.xhtml b/src/main/webapp/index.xhtml index 3bd85b3..0c73128 100644 --- a/src/main/webapp/index.xhtml +++ b/src/main/webapp/index.xhtml @@ -1,27 +1,19 @@ - + + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" + xmlns:f="http://xmlns.jcp.org/jsf/core"> - - - - -
- -

Logga in

- -
-
+ +
- - +
- diff --git a/src/main/webapp/resources/skolan/css/style.css b/src/main/webapp/resources/skolan/css/style.css deleted file mode 100644 index 00c43bb..0000000 --- a/src/main/webapp/resources/skolan/css/style.css +++ /dev/null @@ -1,83 +0,0 @@ -html { - margin: 0; - padding: 0; - font-family: Tahoma, sans-serif; -} - -body { - margin: 0; - padding: 0; -} - -h1, h2, h3, h4, h5, h6 { - margin: 0 0 8px 0; - padding: 0; -} - -p { - margin: 8px 0 0 0; - padding: 0; -} - -input, button,select { - font-family: Tahoma, sans-serif; - font-size: 100%; -} - -body > header { - padding: 16px; - clear: both; - text-align: center; - font-size: 200%; -} - -body > header > h1 { - margin: 0; -} - -body > section , body > form > section{ - margin: 8px 20%; - padding: 18px; - overflow: hidden; -.bild -background-image: url("testBild2.jpg"); - background-repeat: no-repeat; - background-size: cover; - background-position: 100%; -} - -body > footer { - padding: 8px; - clear: both; - font-size: 13px; - text-align: center; -} - -body > footer > p { - margin: 0; -} -.student-table { - width: 100%; -} - -.student-header { - padding: 4px; - text-align: left; - font-weight: bold; -} - -.student-col-name { - padding: 4px; - text-align: left; -} - -.student-col-courseCode, .student-col-courseName, .student-col-teacherName { - padding: 4px; - text-align: right; -} - -.student-footer { - padding: 4px; - font-weight: bold; - text-align: right; -} \ No newline at end of file diff --git a/src/main/webapp/resources/skolan/images/testBild2.jpg b/src/main/webapp/resources/skolan/images/testBild2.jpg deleted file mode 100644 index c622c86..0000000 Binary files a/src/main/webapp/resources/skolan/images/testBild2.jpg and /dev/null differ diff --git a/src/main/webapp/resources/skolan/theme/blueheven.css b/src/main/webapp/resources/skolan/theme/blueheven.css deleted file mode 100644 index d0da4e4..0000000 --- a/src/main/webapp/resources/skolan/theme/blueheven.css +++ /dev/null @@ -1,62 +0,0 @@ -body { - background-color: rgba(118, 203, 224, 0.1); -} - -a:link, a:visited { - color: #8d52a0; -} - -a:hover, a:active { - color: #76cbe0; -} - -input, select { - background-color: #ffffff; - color: #000000; - border: 1px solid #396280; - padding: 4px; -} -option { - background-color: white; - color: black; -} -input[readonly] { - color: #808080; -} - -input[type="submit"], input[type="button"] { - border-radius: 4px; - padding: 4px 12px; -} - -body > header { - background-color: #2badca; - color: white; -} - -body > section, body > form > section { - background-color: rgba(114, 207, 179, 0.38); - color: black; -} - -body > footer { - background-color: #2badca; - color: #e5e5e5; -} -.student-header { - background-color: #2a17f1; - color: white; -} - -.student-row-odd { - background-color: #e0e0e0; -} - -.student-row-even { - background-color: #f0f0f0; -} - -.student-footer { - background-color: #2a17f1; - color: white; -} \ No newline at end of file diff --git a/src/main/webapp/signIn.xhtml b/src/main/webapp/signIn.xhtml index a787040..ded119e 100644 --- a/src/main/webapp/signIn.xhtml +++ b/src/main/webapp/signIn.xhtml @@ -1,41 +1,48 @@ - + - - + +
- - -

- - + +

Logga in

+

Skriv ditt användarnamn

+
+ + + +

Välkommen, #{userBean.users.getUser(loggedIn.id).name}!

+

Du är redan inloggad. + Vill dulogga ut?

+
+
- -
- - - - Användarnamn - - - Password - - - - - - -
+ +
+ + + Användarnamn + + + Password + + + + + + +
- \ No newline at end of file + diff --git a/src/main/webapp/stats.xhtml b/src/main/webapp/stats.xhtml new file mode 100644 index 0000000..22a6c28 --- /dev/null +++ b/src/main/webapp/stats.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + +
+ Logga ut +
+
+ + + +
+

Statistik

+--marko jobbar på statistik-biten...--- +
+ +
+
+
+ + + diff --git a/src/main/webapp/stats_test.xhtml b/src/main/webapp/stats_test.xhtml new file mode 100644 index 0000000..ae656f3 --- /dev/null +++ b/src/main/webapp/stats_test.xhtml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + Id + + + + Datum + + + + Närvaro + + + + + + + + + + diff --git a/src/main/webapp/student.xhtml b/src/main/webapp/student.xhtml index 9533426..ce33f14 100644 --- a/src/main/webapp/student.xhtml +++ b/src/main/webapp/student.xhtml @@ -1,14 +1,26 @@ - + - - - - + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" + xmlns:f="http://xmlns.jcp.org/jsf/core"> + + + +
+ Logga ut +
+
+ + + + + #{myUser.name} #{myUser.role} + +
@@ -16,72 +28,9 @@ #{myCourse.description} - - - - Kurs kod - - - #{line.courseCode.name} - - - - Kurs namn - #{line.courseName.name} - - - Ansvarig lärare - #{line.teacherName} - - - - - - - - -
+
+
- -
- - - - Kurs kod - - - #{line.courseCode.name} - - - - Kurs namn - #{line.courseName.name} - - - Ansvarig lärare - #{line.teacherName} + - - - - - - - - -
-
- - - \ No newline at end of file diff --git a/src/main/webapp/teacher.xhtml b/src/main/webapp/teacher.xhtml index 2b10212..6288645 100644 --- a/src/main/webapp/teacher.xhtml +++ b/src/main/webapp/teacher.xhtml @@ -1,24 +1,27 @@ - + + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" + xmlns:f="http://xmlns.jcp.org/jsf/core"> - - - + + +
-

lärare sidan panel top

- + Logga ut
-
-

lärare sidan panel main

- +

Lärare

+

Bla bla bla

- \ No newline at end of file + + + + diff --git a/src/main/webapp/templates/footer_template.xhtml b/src/main/webapp/templates/footer_template.xhtml deleted file mode 100644 index df389b4..0000000 --- a/src/main/webapp/templates/footer_template.xhtml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - -
-

Skolan 2017

-
-
- diff --git a/src/main/webapp/templates/form_login.xhtml b/src/main/webapp/templates/form_login.xhtml new file mode 100644 index 0000000..3a6f517 --- /dev/null +++ b/src/main/webapp/templates/form_login.xhtml @@ -0,0 +1,28 @@ + + + + + \ No newline at end of file diff --git a/src/main/webapp/templates/header_template.xhtml b/src/main/webapp/templates/header_template.xhtml deleted file mode 100644 index 114cae4..0000000 --- a/src/main/webapp/templates/header_template.xhtml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - -
-

Rotana Reg skola

-
-
- \ No newline at end of file diff --git a/src/main/webapp/templates/page_template.xhtml b/src/main/webapp/templates/page_template.xhtml deleted file mode 100644 index 82c300d..0000000 --- a/src/main/webapp/templates/page_template.xhtml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - RotanaReg Skolan #{pageTitel} - - - - - - - - -
-

Hej

-
-
- - -
-

Main Panel

-

Placeholder text.

-
-
- -
-
- diff --git a/src/main/webapp/templates/template_footer.xhtml b/src/main/webapp/templates/template_footer.xhtml index 328fa4f..ea3372e 100644 --- a/src/main/webapp/templates/template_footer.xhtml +++ b/src/main/webapp/templates/template_footer.xhtml @@ -9,7 +9,7 @@
- +
diff --git a/src/main/webapp/templates/template_page.xhtml b/src/main/webapp/templates/template_page.xhtml index e23331e..c5241eb 100644 --- a/src/main/webapp/templates/template_page.xhtml +++ b/src/main/webapp/templates/template_page.xhtml @@ -26,6 +26,8 @@ | + | + diff --git a/src/main/webapp/templates/top_panel_template.xhtml b/src/main/webapp/templates/top_panel_template.xhtml deleted file mode 100644 index a90fdb3..0000000 --- a/src/main/webapp/templates/top_panel_template.xhtml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/src/main/webapp/user_detail.xhtml b/src/main/webapp/user_detail.xhtml index cbfea45..6e4048b 100644 --- a/src/main/webapp/user_detail.xhtml +++ b/src/main/webapp/user_detail.xhtml @@ -1,17 +1,15 @@ - + - - - + - @@ -19,48 +17,46 @@ Tillbaka - -
- - - Användarnamn - +
+ + + Användarnamn + - Password - + Password + - Förnamn - + Förnamn + - Efternamn - + Efternamn + - E-mail address - + E-mail address + - Telefon nummer - - - - Födelsedatum - - - + Telefon nummer + - - - - + Födelsedatum + + + - - - - -
- + + + + + + + +
+
+
+
- \ No newline at end of file +