Compare commits

...

5 Commits

Author SHA1 Message Date
Nils Gerstner 173489a29a signIn madness
7 years ago
nils f6b2adce48 User and Course Entities
7 years ago
Nils Gerstner 9edbf0231a coursesBean jsf
7 years ago
Nils Gerstner ad6d3083de jpa course + diverse ändringar
7 years ago
nils e0cd6f12fc add Course entity and jpa persist
7 years ago

6
.gitignore vendored

@ -1,8 +1,4 @@
.idea/*
target/*
<<<<<<< HEAD
=======
*.war
>>>>>>> 21f7771889fbd331d8067aeaacba276c2ab841e7
target/RotanaReg.war
com.rotanareg.skolan.iml
target/RotanaReg.war

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
</configuration>
</facet>
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="" />
<datasource-mapping>
<factory-entry name="school" />
</datasource-mapping>
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: javax:javaee-api:7.0" level="project" />
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.5.0" level="project" />
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.jpa:2.6.4" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:javax.persistence:2.1.1" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.asm:2.6.4" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.antlr:2.6.4" level="project" />
<orderEntry type="library" name="Maven: org.glassfish:javax.json:1.0.4" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:2.6.4" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.core:2.6.4" level="project" />
<orderEntry type="library" name="Maven: postgresql:postgresql:8.1-404.jdbc3" level="project" />
<orderEntry type="library" name="Maven: org.primefaces:primefaces:6.0" level="project" />
</component>
</module>

Binary file not shown.

@ -0,0 +1,16 @@
F<EFBFBD>r att skapa connection poolen och resursen jdbc/school,
k<EFBFBD>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

@ -36,22 +36,26 @@
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.6.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.1-404.jdbc3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>
</dependencies>

@ -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;
}
}

@ -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;
}
}

@ -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<AttendanceDomain> getAttendances() {
return aService.getAttendances();
}
/*
public List<CourseDomain> 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;
}
}

@ -0,0 +1,76 @@
package com.rotanareg.skolan;
import javax.ejb.EJB;
import com.rotanareg.skolan.domains.Course;
import com.rotanareg.skolan.coursePersist.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.List;
@ManagedBean
@RequestScoped
public class CoursesBean {
private Long id;
private String name;
private String description;
private String courseNr;
@EJB
CourseService courseService;
public String addCourse(){
if (getId()==null)
courseService.addCourse(new Course(name, description, courseNr));
else
courseService.updateCourse(new Course(getId(),getName(),getDescription(),getCourseNr()));
setId(null);
setName("");
setDescription("");
setCourseNr("");
return "course";
}
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 getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCourseNr() {
return courseNr;
}
public void setCourseNr(String courseNr) {
this.courseNr = courseNr;
}
public CourseService getCourses() {
return courseService;
}
public void setCourseService(CourseService courseService) {
this.courseService = courseService;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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<AttendanceDomain> getAttendances();
/*
public List<CourseDomain> getCoursesNameContain(String filter);
*/
}

@ -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<AttendanceDomain> 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<CourseEntity> courseEntityList = em.createNamedQuery("selectAllCourses").getResultList();
/*
List<AttendanceEntity> courseRecords = query.getResultList();
System.out.println("course Size " + courseRecords.size());
*/
List<AttendanceEntity> l = em.createNamedQuery("selectAll").getResultList();
return l.stream().
map(a -> new AttendanceDomain(a.getId(), a.getDate(), a.isHasAttended())).
collect(Collectors.toList());
}
/*
@Override
public List<CourseDomain> getCoursesNameContain(String filter) {
List<Course> l = em.createNamedQuery("selectSome").setParameter("filt", filter).getResultList();
return l.stream().
map(p -> new CourseDomain(p.getId(), p.getName(), p.getCode())).
collect(Collectors.toList());
}
*/
}

@ -1,28 +0,0 @@
package com.rotanareg.skolan.course;
import java.io.Serializable;
public final class Course implements Serializable {
private static final long serialVersionUID = 1L;
private final long id;
private final String name;
private final String description;
public Course (long id, String name, String description){
this.id = id;
this.name = name;
this.description = description;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}

@ -1,35 +0,0 @@
package com.rotanareg.skolan.course;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
@Named
@ViewScoped
public class CourseDetails implements Serializable{
private static final long serialVersionUID = 1L;
@Inject
private CourseService courseService;
private long courseId;
private Course course;
public long getCourseId() {
return courseId;
}
public void setCourseId(long courseId) {
this.courseId = courseId;
}
public void onload() {
course = courseService.getCourse(courseId);
}
//public course getCourse() {
// return course;
//}
}

@ -1,7 +0,0 @@
package com.rotanareg.skolan.course;
import java.util.List;
public interface CourseService {
List<Course> getMostStudiedCourses ();
Course getCourse (long id);
}

@ -1,36 +0,0 @@
package com.rotanareg.skolan.course;
import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ApplicationScoped
public class CourseServiceImpl implements CourseService {
private final Map<Long, Course> courses;
private final List<Course> mostStudiedCourses;
public CourseServiceImpl (){
Map<Long, Course> map = new HashMap<>();
map.put(1L, new Course(1L,"Design och konstruktion av grafiska gränssnitt","Kursen innehåller en genomgång av standardklasserna i ett välutvecklat grafiskt bibliotek, en översikt över vilka riktlinjer som krävs för att skapa lättanvända gränssnitt samt metoder för att iterativt utveckla och förbättra ett gränssnitt. Kursen ger praktisk erfarenhet i implementering samt användbarhet genom ett grupprojekt som ger en fördjupning av delmomentet kring grafiska komponenter från kursen Objektorienterad programvaruutveckling. Projektets mål är att utveckla en applikation för en specifik användargrupp och att genom att låta dessa testa programmet iterativt förbättra det."));
map.put(2L, new Course(2L," Objektorienterad programmering","Grundläggande begrepp i objektorienterad programutveckling. Vad som skiljer det objektorienterade synsättet från andra synsätt.I kursen används programspråket Java. Momenten så som objekt och klass, datainkapsling,konstruktorer, metoder, instansvariabler, klassvariabler behandals men även modularisering av program, användning av dokumentation för standardbibliotek, användning av standardklasser för datasamlingar samt kodningsstandard, namnsättning och kommentering. Testning av program också ingår i kursen och det behandlas även arv, dynamisk bindning och polymorfism, abstrakta klasser och gränssnitt, grafiska användargränssnitt, händelser och lyssnare."));
map.put(3L, new Course(3L,"Datastrukturer","Abstrakta datatyper. Enkel komplexitetsanalys. Vanliga datastrukturer som fält, listor, träd och hashtabeller samt hur dessa kan användas för att implementera abstrakta datatyper som köer, prioritetsköer, lexika och grafer. Standardalgoritmer för dessa datastrukturer och deras resurskrav. Iteratorer. Sorteringsalgoritmer. Standardbibliotek för datastrukturer och algoritmer."));
courses =Collections.unmodifiableMap(map);
mostStudiedCourses = Collections.unmodifiableList(new ArrayList<>(courses.values()));
}
@Override
public List<Course> getMostStudiedCourses() {
return mostStudiedCourses;
}
@Override
public Course getCourse (long id) {
return courses.get(id);
}
}

@ -1,26 +0,0 @@
package com.rotanareg.skolan.course;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
@Named
@RequestScoped
public class MostStudiedCourses {
@Inject
private com.rotanareg.skolan.course.CourseService courseService;
private List<Course> courses;
@PostConstruct
public void initialize() {
courses = courseService.getMostStudiedCourses ();
}
public List<Course> getCourses() {
return courses;
}
}

@ -0,0 +1,97 @@
package com.rotanareg.skolan.coursePersist;
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="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 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@Column(length = 10000)
private String description;
private String courseNr;
@OneToMany(mappedBy="course")
private List<CourseUserAssociation> persons;
public CourseEntity() {
}
public CourseEntity(String name, String description, String courseNr) {
this.name = name;
this.description = description;
this.courseNr = courseNr;
}
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 getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCourseNr() {
return courseNr;
}
public void setCourseNr(String courseNr) {
this.courseNr = courseNr;
}
public List<CourseUserAssociation> 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);
}
}
}

@ -0,0 +1,18 @@
package com.rotanareg.skolan.coursePersist;
import com.rotanareg.skolan.domains.Course;
import javax.ejb.Local;
import java.util.List;
@Local
public interface CourseService {
void addCourse(Course course);
void updateCourse(Course course);
void removeCourse(Long id);
Course getCourse(Long id);
List<Course> getCourses();
public List<Course> getCoursesContaining(String filter);
}

@ -0,0 +1,78 @@
package com.rotanareg.skolan.coursePersist;
import com.rotanareg.skolan.domains.Course;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
import java.util.stream.Collectors;
@Stateless
public class CourseServiceImpl implements CourseService{
@PersistenceContext
EntityManager em;
@Override
public void addCourse(Course course) {
CourseEntity c = new CourseEntity(course.getName(),course.getDescription(),course.getCourseNr());
em.persist(c);
}
@Override
public void updateCourse(Course course) {
CourseEntity c = em.find(CourseEntity.class,course.getId());
c.setName(course.getName());
c.setDescription(course.getDescription());
c.setCourseNr(course.getCourseNr());
em.merge(c);
}
@Override
public void removeCourse(Long id) {
CourseEntity c = em.find(CourseEntity.class, id);
em.remove(c);
}
@Override
public Course getCourse(Long id) {
CourseEntity c = em.find(CourseEntity.class,id);
Course cd = new Course(c.getId(),c.getName(),c.getDescription(),c.getCourseNr());
return cd;
}
@Override
public List<Course> getCourses() {
List<CourseEntity> 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!",
"E1234A");
em.persist(a);
CourseEntity b = new CourseEntity("Svenska",
"Utbildningen är individualiserad och innan antagning sker en intestning. Du kan delta i utbildningen även om du inte har avslutat din Svenska för invandrare, SFI. Korta vägen pågår i 25 veckor och därutöver ingår 5 veckors praktik. Utbildningen utförs av Folkuniversitetet i Umeå i samarbete med Umeå universitet. Det finns möjlighet till individuell förlängning.",
"Sv234B");
em.persist(b);
CourseEntity c = new CourseEntity("allmän datakunskap",
"Kom igång och lär dig data från början. Folkuniversitetet är en erfaren data- och IT-utbildare. Vi har kurser för både nybörjare och erfarna dataanvändare, för juniorer såväl som seniorer och inom både allmän datakunskap och enskilda datorprogram.",
"DK234C");
em.persist(c);
}
return courseEntityList.stream().
map(c->new Course(c.getId(),c.getName(),c.getDescription(),c.getCourseNr())).
collect(Collectors.toList());
}
@Override
public List<Course> getCoursesContaining(String filter) {
List<CourseEntity> courseEntityList = em.createNamedQuery("selectSomeCourses").setParameter("filt",filter).getResultList();
return courseEntityList.stream().
map(c->new Course(c.getId(),c.getName(),c.getDescription(),c.getCourseNr())).
collect(Collectors.toList());
}
}

@ -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;
}
}

@ -0,0 +1,83 @@
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.
*/
public class Course {
private long id;
private String name;
private String description;
private String courseNr;
private List<CourseUserAssociation> persons;
public Course(String name, String description, String courseNr){
this.name = name;
this.description = description;
this.courseNr = courseNr;
}
public Course(long id, String name, String description, String courseNr){
this.id = id;
this.name = name;
this.description = description;
this.courseNr = courseNr;
}
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 getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCourseNr() {
return courseNr;
}
public void setCourseNr(String courseNr) {
this.courseNr = courseNr;
}
public List<CourseUserAssociation> getPersons() {
return persons;
}
public void setPersons(List<CourseUserAssociation> persons) {
this.persons = persons;
}
@Override
public String toString(){
final StringBuilder sbc = new StringBuilder("CourseEntity{");
sbc.append("id=").append(id);
sbc.append(", courseCode='").append(courseNr).append('\'');
sbc.append(", courseTitle='").append(name).append('\'');
sbc.append(", description='").append(description).append('\'');
sbc.append('}');
return sbc.toString();
}
}

@ -0,0 +1,81 @@
package com.rotanareg.skolan.domains;
import com.rotanareg.skolan.Role;
/**
* Created by Nils Gerstner on 8/20/17.
*/
public class User {
private long id;
private String name;
private String lastName;
private Role role;
private String passWord;
public User(String name, String lastName, Role role){
this.name = name;
this.lastName = lastName;
this.role = role;
this.passWord = null;
}
public User(long id, String name, String lastName, Role role, String passWord){
this.id = id;
this.name = name;
this.lastName = lastName;
this.role = role;
this.passWord = passWord;
}
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 void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getPassWord() {
return passWord;
}
@Override
public String toString(){
StringBuilder sbc = new StringBuilder("User{");
sbc.append("id=").append(id);
sbc.append(", name='").append(name).append('\'');
sbc.append(", lastName='").append(lastName).append('\'');
sbc.append(", role='").append(role.toString()).append('\'');
sbc.append('}');
return sbc.toString();
}
}

@ -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;
}
}

@ -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;
}
}

@ -1,20 +0,0 @@
package com.rotanareg.skolan.user;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
public class EmailAddressValidator implements ConstraintValidator<ValidEmailAddress, String> {
@Override
public void initialize(ValidEmailAddress constraintAnnotation) {
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return value == null || value.equals("") || value.contains("@");
}
}

@ -1,28 +0,0 @@
package com.rotanareg.skolan.user;
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;
}
}

@ -1,45 +0,0 @@
package com.rotanareg.skolan.user;
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();
}
}

@ -1,33 +0,0 @@
package com.rotanareg.skolan.user;
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."));
}
}
}

@ -1,42 +0,0 @@
package com.rotanareg.skolan.user;
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);
}
}

@ -1,102 +0,0 @@
package com.rotanareg.skolan.user;
import com.rotanareg.skolan.Role;
import java.util.ArrayList;
import java.util.Date;
import java.io.Serializable;
import java.util.List;
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String username;
private String password;
private String firstName;
private String lastName;
private String emailAddress;
private String phoneNumber;
private Date birthDate;
private Role role;
private List<Role> 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
}
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 String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String 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<Role> getRolesList() {
return rolesList;
}
}

@ -1,30 +0,0 @@
package com.rotanareg.skolan.user;
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);
}
}

@ -1,54 +0,0 @@
package com.rotanareg.skolan.user;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
@Named
@SessionScoped // Marko jobbar på
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())) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Skriv in ditt användarnamn och password"));
return "failure";
}
currentUser = user;
return "success";
}
public void signOut() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
//return "index?faces-redirect =true";
}
public String save(User user) {
userService.saveUser(user);
currentUser = user;
return "index";
}
}

@ -1,9 +0,0 @@
package com.rotanareg.skolan.user;
public interface UserService {
// get information om användare
User getUser(String username);
// spara information om användare
void saveUser(User user);
}

@ -1,23 +0,0 @@
package com.rotanareg.skolan.user;
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<String, User> users = new ConcurrentHashMap<>();
@Override
public User getUser(String username) {
return users.get(username);
}
@Override
public void saveUser(User user) {
users.put(user.getUsername(), user);
}
}

@ -1,20 +0,0 @@
package com.rotanareg.skolan.user;
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<? extends Payload>[] payload() default {};
}

@ -0,0 +1,104 @@
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;
@Entity
@Table(name = "Person")
@NamedQueries({
@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 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Enumerated(EnumType.STRING)
private Role role;
private String name;
private String lastName;
private String passWord;
@OneToMany(mappedBy = "person")
private List<CourseUserAssociation> courses;
public UserEntity() {
}
public UserEntity(String name, String lastName, Role role, String passWord) {
this.name = name;
this.lastName = lastName;
this.role = role;
this.passWord = passWord;
}
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 void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getPassWord() {
return passWord;
}
public List<CourseUserAssociation> 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);
}
}
}

@ -0,0 +1,18 @@
package com.rotanareg.skolan.userPersist;
import com.rotanareg.skolan.domains.User;
import javax.ejb.Local;
import java.util.List;
@Local
public interface UserService {
void addUser(User user);
void updateUser(User user);
void removeUser(Long id);
User getUser(Long id);
List<User> getUsers();
public List<User> getUserContaining(String filter);
}

@ -0,0 +1,72 @@
package com.rotanareg.skolan.userPersist;
import com.rotanareg.skolan.Role;
import com.rotanareg.skolan.domains.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
import java.util.stream.Collectors;
@Stateless
public class UserServiceImpl implements UserService{
@PersistenceContext
EntityManager em;
@Override
public void addUser(User user) {
UserEntity u = new UserEntity(user.getName(),user.getLastName(),user.getRole(),user.getPassWord());
em.persist(u);
}
@Override
public void updateUser(User user) {
UserEntity u = em.find(UserEntity.class,user.getId());
u.setName(user.getName());
u.setLastName(user.getLastName());
u.setRole(user.getRole());
em.merge(u);
}
@Override
public void removeUser(Long id) {
UserEntity u = em.find(UserEntity.class, id);
em.remove(u);
}
@Override
public User getUser(Long id) {
UserEntity u = em.find(UserEntity.class, id);
User ud = new User(u.getId(),u.getName(),u.getLastName(),u.getRole(),u.getPassWord());
return ud;
}
@Override
public List<User> getUsers() {
List<UserEntity> userEntityList = em.createNamedQuery("selectAllUsers").getResultList();
if (userEntityList.isEmpty()){
UserEntity a = new UserEntity("Nils","Gerstner",Role.STUDENT,"1234");
em.persist(a);
UserEntity b = new UserEntity("Jasna","Nilsson-Milkic",Role.STUDENT,"1234");
em.persist(b);
UserEntity c = new UserEntity("Moustafa", "Almehyo",Role.TEACHER,"1234");
em.persist(c);
UserEntity d = new UserEntity("Marko","Seppänen",Role.ADMIN,"1234");
em.persist(d);
}
return userEntityList.stream().
map(u->new User(u.getId(),u.getName(),u.getLastName(),u.getRole(),u.getPassWord())).collect(Collectors.toList());
}
@Override
public List<User> getUserContaining(String filter) {
List<UserEntity> 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())).
collect(Collectors.toList());
}
}

@ -5,9 +5,9 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="nameDB" transaction-type="JTA"> <!--same name as in emf definition-->
<persistence-unit name="school" transaction-type="JTA"> <!--same name as in emf definition-->
<jta-data-source>jdbc/person</jta-data-source> <!--This resource has to be added to GlassFish-->
<jta-data-source>jdbc/school</jta-data-source> <!--This resource has to be added to GlassFish-->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
@ -16,4 +16,4 @@
</properties>
</persistence-unit>
</persistence>
</persistence>

@ -1,7 +1,22 @@
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<display-name>index.xhtml</display-name>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/pupil1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>index.xhtml</display-name>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>

@ -12,21 +12,19 @@
<ui:define name="panel-top">
<section>
<h:outputLink value="user_detail.xhtml">Registrera nya användare</h:outputLink>
<p> </p>
<h:outputLink value="create_course.xhtml">Registrera nya kurser</h:outputLink>
<h:outputLink value="index.xhtml">Logga ut</h:outputLink>
</section>
</ui:define>
<ui:define name="panel-main">
<section>
<h1>här kommer mer</h1>
<ui:define name="panel-main">
<section>
<h1>Admin</h1>
</section>
</ui:define>
<h:outputLink value="user_detail.xhtml">Registrera nya användare</h:outputLink>
</section>
</ui:define>
</ui:composition>
</html>
</html>

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</html>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
@ -8,17 +8,17 @@
<ui:composition template="templates/template_page.xhtml">
<f:metadata>
<f:viewParam name ="courseId" value="#{courseDetails.courseId}"/>
<f:viewParam name="courseId" value="#{courseDetails.courseId}"/>
<f:viewAction action="#{courseDetails.onload}"/>
</f:metadata>
<ui:param name="pageTitle" value="Course Details"/>
<ui:define name="panel-main">
<section class="course_details">
<h:form>
<h1>#{courseDetails.course.name}</h1>
<p>#{courseDetails.course.description}</p>
</h:form>
<ui:define name="panel-main">
<section class="course_details">
<h:form>
<h1>#{courseDetails.course.name}</h1>
<p>#{courseDetails.course.description}</p>
</h:form>
</section>
</ui:define>
</ui:composition>

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</html>

@ -0,0 +1,28 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://xmlns.jcp.org/jsf/composite">
<h:form>
<p id="login_form">
<label class="text_grey">Login:</label><br/>
<br/>
<h:outputLabel>Användarnamn123:</h:outputLabel><br/>
<h:inputText id="username" value="#{contactInformation.foreName}"/><br/>
<br/>
<h:outputLabel>Lösenord:</h:outputLabel><br/>
<h:inputText id="password" value="#{contactInformation.city}"/><br/>
<br/>
<h:commandButton action="#{contactInformation.save}" value="Login"/>
</p>
</h:form>
</ui:composition>

@ -7,11 +7,11 @@
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/templates/template_page.xhtml">
<ui:param name="pageTitle" value="Index sidan"/>
<ui:param name="pageTitle" value="Första sidan"/>
<ui:define name="panel-main">
<section class = "bild">
<h:graphicImage library="skola" name="/images/testBild2.jpg"/>
<section class="bild">
<h:graphicImage library="skola" name="/images/testBild2.jpg"/>
</section>
</ui:define>

@ -8,38 +8,33 @@
<ui:composition template="/templates/template_page.xhtml">
<ui:param name="pageTitle" value="Sign In"/>
<ui:define name="panel-top">
<section>
<ui:fragment rendered="#{not userManager.signedIn}">
<ui:fragment rendered="#{loggedIn.id == null}">
<h1>Logga in</h1>
<p>Skriv ditt användarnamn</p>
</ui:fragment>
<ui:fragment rendered="#{userManager.signedIn}">
<ui:fragment rendered="#{loggedIn.id != null}">
<h:form>
<h1>Välkommen, #{userManager.currentUser.firstName}!</h1>
<h1>Välkommen, #{userBean.users.getUser(loggedIn.id).name}!</h1>
<p>Du är redan inloggad.
Vill du<h:commandLink action="#{userManager.signOut}">logga ut</h:commandLink>?</p>
Vill du<h:commandLink action="#{signIn.logout}">logga ut</h:commandLink>?</p>
</h:form>
</ui:fragment>
</section>
</ui:define>
<ui:define name="panel-main">
<ui:fragment rendered="#{not userManager.signedIn}">
<ui:fragment rendered="#{loggedIn.id == null}">
<section>
<h:messages styleClass="validation-messages"/>
<h:form>
<h:panelGrid columns="2" styleClass="form-grid" columnClasses="form-column-label,form-column-input">
<h:outputLabel for="username">Användarnamn</h:outputLabel>
<h:inputText id="username" value="#{signIn.username}" size="20"/>
<h:inputText id="username" value="#{signIn.username}"/>
<h:outputLabel for="password">Password</h:outputLabel>
<h:inputSecret id="password" value="#{signIn.password}" size="20"/>
<h:inputSecret id="password" value="#{signIn.password}"/> <!--anroppar user bean-->
<h:outputText value=""/>
<h:commandButton value="Submit" action="#{signIn.submit}"/> <!--anroppar usermanager-->

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="templates/template_page.xhtml">
<ui:param name="pageTitle" value="Admin sidan"/>
<ui:define name="panel-top">
<section>
<h:outputLink value="index.xhtml">Logga ut</h:outputLink>
</section>
</ui:define>
<ui:define name="panel-main">
<section>
<h1>Statistik</h1>
--marko jobbar på statistik-biten...---
<br/>
<h:link styleClass="menuItem" value="stats_test.xhtml" outcome="stats_test"/>
</section>
</ui:define>
</ui:composition>
</html>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:form id="form1">
<h:panelGrid columns="3">
<h:panelGrid columns="2" style="vertical-align: top">
<h:outputText value='Enter name'/>
<h:inputText value='#{attendanceBean.date}'/>
<h:outputText value='Enter code'/>
<h:inputText value='#{attendanceBean.hasAttended}'/>
<h:commandButton action="#{attendanceBean.addAttendance}" value="#{attendanceBean.submitButton}"/>
<h:inputHidden value="#{attendanceBean.id}"/>
</h:panelGrid>
<h:panelGrid columns="1" style="vertical-align: top">
<h:outputText value="Unfilterd List"/>
<h:dataTable id="tbl1" value="#{attendanceBean.attendances}" var="aBean">
<h:column >
<f:facet name="header">Id</f:facet>
<h:outputText id="id" value="#{aBean.id}"/>
</h:column>
<h:column >
<f:facet name="header">Datum</f:facet>
<h:outputText value="#{aBean.date}"/>
</h:column>
<h:column >
<f:facet name="header">Närvaro</f:facet>
<h:outputText value="#{aBean.hasAttended}"/>
</h:column>
</h:dataTable>
</h:panelGrid>
<h:panelGrid columns="1" style="vertical-align:text-top">
</h:panelGrid>
</h:panelGrid>
</h:form>
</f:view>
</html>

@ -1,34 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="templates/template_page.xhtml">
<ui:composition template="templates/template_page.xhtml">
<ui:param name="pageTitle" value="Student sidan"/>
<ui:define name="panel-top">
<section>
<!-- <h:outputLink value="index.xhtml">Logga ut</h:outputLink> måste redict på rätt sätt-->
<h:outputLink value="index.xhtml">Logga ut</h:outputLink>
</section>
</ui:define>
<ui:define name="panel-main">
<section>
<h1>Mest lästa kurser</h1>
<h:form>
<ui:repeat value="#{mostStudiedCourses.courses}" var="course">
<ui:param name="course" value="#{course}"/>
<ui:define name="course-description">
</ui:define>
</ui:repeat>
</h:form>
</section>
<ui:define name="panel-main">
<h:dataTable value="#{userBean.users.users}" var="myUser">
<h:column>
#{myUser.name} #{myUser.role}
</h:column>
</h:dataTable>
<section>
<h:dataTable value="#{coursesBean.courses.courses}" var="myCourse">
<h:column>
<h1>#{myCourse.name}</h1>
#{myCourse.description}
</h:column>
</h:dataTable>
</section>
</ui:define>
</ui:composition>
</ui:composition>
</html>

@ -10,10 +10,16 @@
<ui:param name="pageTitle" value="Lärare sidan"/>
<ui:define name="panel-top">
<section>
<h:outputLink value="index.xhtml">Logga ut</h:outputLink>
</section>
</ui:define>
<ui:define name="panel-main">
<section>
<h1>Lärare</h1>
<h2>Bla bla bla</h2>
</section>
</ui:define>
</ui:composition>

@ -0,0 +1,28 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://xmlns.jcp.org/jsf/composite">
<h:form id="loginForm">
<label class="text_grey" value="Login"/>
<h:outputLabel value="Användarnamn: "/>
<h:inputText id="username"
value="#{loginBean.username}"
required="true"
requiredMessage="du måste ange ditt namn!!!"/>
<br/>
<h:outputLabel value="Lösenord: "/>
<h:inputSecret id="password"
value="#{loginBean.password}"
required="true"
requiredMessage="mata in ditt lösenord"/>
<br/>
<br/>
<h:commandButton action="#{loginBean.login}" value="Login"/>
</h:form>
</ui:composition>

@ -9,7 +9,7 @@
<ui:composition>
<footer>
<h:form>
<h:outputText value="Skolan 2017"/>
<h:outputText value="2017 Rotana Reg Skolan"/>
</h:form>
</footer>
</ui:composition>

@ -26,6 +26,8 @@
<h:link styleClass="menuItem" value="Student" outcome="student"/>
<span class="text_grey"> | </span>
<h:link styleClass="menuItem" value="Teacher" outcome="teacher"/>
<span class="text_grey"> | </span>
<h:link styleClass="menuItem" value="Stats" outcome="stats"/>
</nav>
<ui:insert name = "panel-top">

Loading…
Cancel
Save