From aeb71e94a3081f1c1e282da7a879b7c3e5e82eff Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Tue, 27 Mar 2018 01:46:48 +0200 Subject: [PATCH] [1.1.1+1.3.1] model + dao(-stubs) + Material Listener. --- .../java/dst/ass1/jpa/dao/impl/CourseDAO.java | 25 +++ .../ass1/jpa/dao/impl/CoursePlatformDAO.java | 13 ++ .../dst/ass1/jpa/dao/impl/DAOFactory.java | 44 ++-- .../dst/ass1/jpa/dao/impl/EnrollmentDAO.java | 13 ++ .../dst/ass1/jpa/dao/impl/GenericDAO.java | 24 +++ .../dst/ass1/jpa/dao/impl/LecturerDAO.java | 21 ++ .../java/dst/ass1/jpa/dao/impl/LessonDAO.java | 14 ++ .../dst/ass1/jpa/dao/impl/MaterialDAO.java | 13 ++ .../ass1/jpa/dao/impl/MaterialServerDAO.java | 21 ++ .../dst/ass1/jpa/dao/impl/MembershipDAO.java | 13 ++ .../dst/ass1/jpa/dao/impl/MetadataDAO.java | 13 ++ .../dst/ass1/jpa/dao/impl/ParticipantDAO.java | 18 ++ .../ass1/jpa/listener/MaterialListener.java | 29 +++ .../java/dst/ass1/jpa/model/impl/Address.java | 48 +++++ .../java/dst/ass1/jpa/model/impl/Course.java | 197 ++++++++++++++++++ .../ass1/jpa/model/impl/CoursePlatform.java | 71 +++++++ .../dst/ass1/jpa/model/impl/Enrollment.java | 57 +++++ .../ass1/jpa/model/impl/EnrollmentKey.java | 42 ++++ .../dst/ass1/jpa/model/impl/Lecturer.java | 58 ++++++ .../java/dst/ass1/jpa/model/impl/Lesson.java | 155 ++++++++++++++ .../dst/ass1/jpa/model/impl/Material.java | 97 +++++++++ .../ass1/jpa/model/impl/MaterialServer.java | 86 ++++++++ .../dst/ass1/jpa/model/impl/Membership.java | 78 +++++++ .../dst/ass1/jpa/model/impl/Metadata.java | 45 ++++ .../dst/ass1/jpa/model/impl/ModelFactory.java | 39 ++-- .../dst/ass1/jpa/model/impl/Participant.java | 103 +++++++++ .../java/dst/ass1/jpa/model/impl/Person.java | 53 +++++ .../src/main/resources/META-INF/Material.xml | 32 ++- 28 files changed, 1360 insertions(+), 62 deletions(-) create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CourseDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CoursePlatformDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/EnrollmentDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/GenericDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LecturerDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LessonDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MembershipDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MetadataDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/ParticipantDAO.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/listener/MaterialListener.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Address.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Course.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/CoursePlatform.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Enrollment.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/EnrollmentKey.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lecturer.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lesson.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Material.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/MaterialServer.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Membership.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Metadata.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Participant.java create mode 100644 ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Person.java diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CourseDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CourseDAO.java new file mode 100644 index 0000000..d2a2e18 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CourseDAO.java @@ -0,0 +1,25 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.ICourseDAO; +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.impl.Course; + +import javax.persistence.EntityManager; +import java.util.Collection; +import java.util.Date; + +public class CourseDAO extends GenericDAO implements ICourseDAO { + public CourseDAO(EntityManager em) { + super(em, Course.class); + } + + @Override + public Collection findOngoingAndFreeCoursesForPlatform(String platformName) { + return null; + } + + @Override + public Collection findNonCancelledCoursesBetweenStartAndEnd(Date start, Date end) { + return null; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CoursePlatformDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CoursePlatformDAO.java new file mode 100644 index 0000000..d947d6e --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/CoursePlatformDAO.java @@ -0,0 +1,13 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.ICoursePlatformDAO; +import dst.ass1.jpa.model.ICoursePlatform; +import dst.ass1.jpa.model.impl.CoursePlatform; + +import javax.persistence.EntityManager; + +public class CoursePlatformDAO extends GenericDAO implements ICoursePlatformDAO { + public CoursePlatformDAO(EntityManager em) { + super(em, CoursePlatform.class); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/DAOFactory.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/DAOFactory.java index 9c7ad55..86744d9 100644 --- a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/DAOFactory.java +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/DAOFactory.java @@ -1,18 +1,8 @@ package dst.ass1.jpa.dao.impl; -import javax.persistence.EntityManager; +import dst.ass1.jpa.dao.*; -import dst.ass1.jpa.dao.ICourseDAO; -import dst.ass1.jpa.dao.ICoursePlatformDAO; -import dst.ass1.jpa.dao.IDAOFactory; -import dst.ass1.jpa.dao.IEnrollmentDAO; -import dst.ass1.jpa.dao.ILecturerDAO; -import dst.ass1.jpa.dao.ILessonDAO; -import dst.ass1.jpa.dao.IMaterialDAO; -import dst.ass1.jpa.dao.IMaterialServerDAO; -import dst.ass1.jpa.dao.IMembershipDAO; -import dst.ass1.jpa.dao.IMetadataDAO; -import dst.ass1.jpa.dao.IParticipantDAO; +import javax.persistence.EntityManager; public class DAOFactory implements IDAOFactory { @@ -30,61 +20,51 @@ public class DAOFactory implements IDAOFactory { @Override public IMembershipDAO createMembershipDAO() { - // TODO - return null; + return new MembershipDAO(em); } @Override public IParticipantDAO createParticipantDAO() { - // TODO - return null; + return new ParticipantDAO(em); } @Override public ILessonDAO createLessonDAO() { - // TODO - return null; + return new LessonDAO(em); } @Override public ILecturerDAO createLecturerDAO() { - // TODO - return null; + return new LecturerDAO(em); } @Override public IEnrollmentDAO createEnrollmentDAO() { - // TODO - return null; + return new EnrollmentDAO(em); } @Override public ICourseDAO createCourseDAO() { - // TODO - return null; + return new CourseDAO(em); } @Override public IMaterialDAO createMaterialDAO() { - // TODO - return null; + return new MaterialDAO(em); } @Override public IMaterialServerDAO createMaterialServerDAO() { - // TODO - return null; + return new MaterialServerDAO(em); } @Override public IMetadataDAO createMetadataDAO() { - // TODO - return null; + return new MetadataDAO(em); } @Override public ICoursePlatformDAO createCoursePlatformDAO() { - // TODO - return null; + return new CoursePlatformDAO(em); } } diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/EnrollmentDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/EnrollmentDAO.java new file mode 100644 index 0000000..a5de8f4 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/EnrollmentDAO.java @@ -0,0 +1,13 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IEnrollmentDAO; +import dst.ass1.jpa.model.IEnrollment; +import dst.ass1.jpa.model.impl.Enrollment; + +import javax.persistence.EntityManager; + +public class EnrollmentDAO extends GenericDAO implements IEnrollmentDAO { + public EnrollmentDAO(EntityManager em) { + super(em, Enrollment.class); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/GenericDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/GenericDAO.java new file mode 100644 index 0000000..0272e27 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/GenericDAO.java @@ -0,0 +1,24 @@ +package dst.ass1.jpa.dao.impl; + +import javax.persistence.EntityManager; +import java.util.List; + +public class GenericDAO implements dst.ass1.jpa.dao.GenericDAO { + private final EntityManager em; + private final Class c; + + protected GenericDAO(EntityManager em, Class c) { + this.em = em; + this.c = c; + } + + @Override + public T findById(Long id) { + return em.find(c, id); + } + + @Override + public List findAll() { + return em.createQuery("from " + c.getName()).getResultList(); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LecturerDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LecturerDAO.java new file mode 100644 index 0000000..8db0297 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LecturerDAO.java @@ -0,0 +1,21 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.ILecturerDAO; +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.ILecturer; +import dst.ass1.jpa.model.ILesson; +import dst.ass1.jpa.model.impl.Lecturer; + +import javax.persistence.EntityManager; +import java.util.Map; + +public class LecturerDAO extends GenericDAO implements ILecturerDAO { + public LecturerDAO(EntityManager em) { + super(em, Lecturer.class); + } + + @Override + public Map findUpcomingLessonForLecturersOfCourse(ICourse course) { + return null; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LessonDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LessonDAO.java new file mode 100644 index 0000000..d5a3a52 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/LessonDAO.java @@ -0,0 +1,14 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.ILessonDAO; +import dst.ass1.jpa.model.ILesson; +import dst.ass1.jpa.model.impl.Lesson; + +import javax.persistence.EntityManager; + +public class LessonDAO extends GenericDAO implements ILessonDAO { + public LessonDAO(EntityManager em) { + super(em, Lesson.class); + } + +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialDAO.java new file mode 100644 index 0000000..7b947c7 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialDAO.java @@ -0,0 +1,13 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IMaterialDAO; +import dst.ass1.jpa.model.IMaterial; +import dst.ass1.jpa.model.impl.Material; + +import javax.persistence.EntityManager; + +public class MaterialDAO extends GenericDAO implements IMaterialDAO { + public MaterialDAO(EntityManager em) { + super(em, Material.class); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java new file mode 100644 index 0000000..d1ff753 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java @@ -0,0 +1,21 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IMaterialServerDAO; +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.IMaterialServer; +import dst.ass1.jpa.model.impl.MaterialServer; + +import javax.persistence.EntityManager; +import java.util.Collection; + +public class MaterialServerDAO extends GenericDAO implements IMaterialServerDAO { + public MaterialServerDAO(EntityManager em) { + super(em, MaterialServer.class); + } + + @Override + public Collection findMaterialServersForCourse(ICourse course) { + return null; + } + +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MembershipDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MembershipDAO.java new file mode 100644 index 0000000..0a7aa2a --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MembershipDAO.java @@ -0,0 +1,13 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IMembershipDAO; +import dst.ass1.jpa.model.IMembership; +import dst.ass1.jpa.model.impl.Membership; + +import javax.persistence.EntityManager; + +public class MembershipDAO extends GenericDAO implements IMembershipDAO { + public MembershipDAO(EntityManager em) { + super(em, Membership.class); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MetadataDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MetadataDAO.java new file mode 100644 index 0000000..839e37a --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MetadataDAO.java @@ -0,0 +1,13 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IMetadataDAO; +import dst.ass1.jpa.model.IMetadata; +import dst.ass1.jpa.model.impl.Metadata; + +import javax.persistence.EntityManager; + +public class MetadataDAO extends GenericDAO implements IMetadataDAO { + public MetadataDAO(EntityManager em) { + super(em, Metadata.class); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/ParticipantDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/ParticipantDAO.java new file mode 100644 index 0000000..428b9a0 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/ParticipantDAO.java @@ -0,0 +1,18 @@ +package dst.ass1.jpa.dao.impl; + +import dst.ass1.jpa.dao.IParticipantDAO; +import dst.ass1.jpa.model.IParticipant; +import dst.ass1.jpa.model.impl.Participant; + +import javax.persistence.EntityManager; + +public class ParticipantDAO extends GenericDAO implements IParticipantDAO { + public ParticipantDAO(EntityManager em) { + super(em, Participant.class); + } + + @Override + public IParticipant findByEmail(String email) { + return null; + } +} \ No newline at end of file diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/listener/MaterialListener.java b/ass1-jpa/src/main/java/dst/ass1/jpa/listener/MaterialListener.java new file mode 100644 index 0000000..60001a6 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/listener/MaterialListener.java @@ -0,0 +1,29 @@ +package dst.ass1.jpa.listener; + +import dst.ass1.jpa.model.impl.Material; + +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import java.util.Date; + +public class MaterialListener { + + @PrePersist + public void set_dates(Object obj) { + System.out.println("MaterialListener: UpdateDates (PrePersist)"); + if (obj instanceof Material) { + Material material = (Material) obj; + Date date = new Date(); + material.setUploaded(date); + material.setLastUpdate(date); + } + } + + @PreUpdate + public void update_dates(Object obj) { + System.out.println("MaterialListener: SetLastUpdate (PreUpdate)"); + if (obj instanceof Material) { + ((Material) obj).setLastUpdate(new Date()); + } + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Address.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Address.java new file mode 100644 index 0000000..6f1abf5 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Address.java @@ -0,0 +1,48 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IAddress; + +import javax.persistence.Column; +import javax.persistence.Embeddable; + +@Embeddable +public class Address implements IAddress { + @Column + private String street; + + @Column + private String city; + + @Column + private String zipCode; + + @Override + public String getStreet() { + return street; + } + + @Override + public void setStreet(String street) { + this.street = street; + } + + @Override + public String getCity() { + return city; + } + + @Override + public void setCity(String city) { + this.city = city; + } + + @Override + public String getZipCode() { + return zipCode; + } + + @Override + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Course.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Course.java new file mode 100644 index 0000000..1af4755 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Course.java @@ -0,0 +1,197 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.*; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +@Entity +@Table(name = Constants.T_COURSE) +public class Course implements ICourse { + @Id + @GeneratedValue + private Long id; + + @Column + private String name; + + @Column + private Integer capacity; + + @Column + private Boolean premium; + + @Column + private BigDecimal cost; + + @Column + private CourseStatus status; + + @Column + private Date start; + + @Column + private Date end; + + // , optional = false? + @ManyToOne(targetEntity = CoursePlatform.class) + private ICoursePlatform coursePlatform; + + // , optional = false? + @ManyToOne(targetEntity = Lecturer.class) + private ILecturer lecturer; + + @OneToMany(targetEntity = Lesson.class) + private Collection lessons = new ArrayList<>(); + + @OneToOne(targetEntity = Metadata.class, optional = false, cascade = CascadeType.ALL) + private IMetadata metadata; + + @OneToMany(targetEntity = Enrollment.class) + private Collection enrollments = new ArrayList<>(); + + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Integer getCapacity() { + return capacity; + } + + @Override + public void setCapacity(Integer capacity) { + this.capacity = capacity; + } + + @Override + public Boolean getPremium() { + return premium; + } + + @Override + public void setPremium(Boolean premium) { + this.premium = premium; + } + + @Override + public BigDecimal getCost() { + return cost; + } + + @Override + public void setCost(BigDecimal cost) { + this.cost = cost; + } + + @Override + public CourseStatus getStatus() { + return status; + } + + @Override + public void setStatus(CourseStatus status) { + this.status = status; + } + + @Override + public Date getStart() { + return start; + } + + @Override + public void setStart(Date start) { + this.start = start; + } + + @Override + public Date getEnd() { + return end; + } + + @Override + public void setEnd(Date end) { + this.end = end; + } + + @Override + public ICoursePlatform getCoursePlatform() { + return coursePlatform; + } + + @Override + public void setCoursePlatform(ICoursePlatform coursePlatform) { + this.coursePlatform = coursePlatform; + } + + @Override + public ILecturer getLecturer() { + return lecturer; + } + + @Override + public void setLecturer(ILecturer lecturer) { + this.lecturer = lecturer; + } + + @Override + public Collection getLessons() { + return lessons; + } + + @Override + public void setLessons(Collection lessons) { + this.lessons = lessons; + } + + @Override + public void addLesson(ILesson lesson) { + this.lessons.add(lesson); + } + + @Override + public IMetadata getMetadata() { + return metadata; + } + + @Override + public void setMetadata(IMetadata metadata) { + this.metadata = metadata; + } + + @Override + public Collection getEnrollments() { + return enrollments; + } + + @Override + public void setEnrollments(Collection enrollments) { + this.enrollments = enrollments; + } + + @Override + public void addEnrollment(IEnrollment enrollment) { + this.enrollments.add(enrollment); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/CoursePlatform.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/CoursePlatform.java new file mode 100644 index 0000000..572fd0c --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/CoursePlatform.java @@ -0,0 +1,71 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ICoursePlatform; +import dst.ass1.jpa.model.IMaterialServer; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; + +@Entity +@Table(name = Constants.T_COURSEPLATFORM) +public class CoursePlatform implements ICoursePlatform { + @Id + @GeneratedValue + private Long id; + + @Column(unique = true) + private String name; + + @Column + private String url; + + @OneToMany(targetEntity = MaterialServer.class) + private Collection materialServers = new ArrayList<>(); + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public void setUrl(String url) { + this.url = url; + } + + @Override + public Collection getMaterialServers() { + return materialServers; + } + + @Override + public void setMaterialServers(Collection materialServers) { + this.materialServers = materialServers; + } + + @Override + public void addMaterialServer(IMaterialServer materialServer) { + this.materialServers.add(materialServer); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Enrollment.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Enrollment.java new file mode 100644 index 0000000..2cc8b5c --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Enrollment.java @@ -0,0 +1,57 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IEnrollment; +import dst.ass1.jpa.model.IEnrollmentKey; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Table; +import java.util.Date; + +@Entity +@Table(name = Constants.T_ENROLLMENT) +public class Enrollment implements IEnrollment { + @EmbeddedId + private EnrollmentKey id; + + @Column + private Date date; + + @Column + private Boolean paid; + + + @Override + public IEnrollmentKey getId() { + return id; + } + + @Override + public void setId(IEnrollmentKey id) { + if (id instanceof EnrollmentKey) { + this.id = (EnrollmentKey) id; + } + } + + @Override + public Date getEnrolledAt() { + return date; + } + + @Override + public void setEnrolledAt(Date date) { + this.date = date; + } + + @Override + public Boolean getPaid() { + return paid; + } + + @Override + public void setPaid(Boolean paid) { + this.paid = paid; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/EnrollmentKey.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/EnrollmentKey.java new file mode 100644 index 0000000..dbe6aea --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/EnrollmentKey.java @@ -0,0 +1,42 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.IEnrollmentKey; +import dst.ass1.jpa.model.IParticipant; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.Embeddable; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import java.io.Serializable; + +@Embeddable +public class EnrollmentKey implements IEnrollmentKey, Serializable { + @ManyToOne(targetEntity = Participant.class, optional = false) + @JoinColumn(name = Constants.I_PARTICIPANT) + private IParticipant participant; + + @ManyToOne(targetEntity = Course.class, optional = false) + @JoinColumn(name = Constants.I_COURSE) + private ICourse course; + + @Override + public IParticipant getParticipant() { + return participant; + } + + @Override + public void setParticipant(IParticipant participant) { + this.participant = participant; + } + + @Override + public ICourse getCourse() { + return course; + } + + @Override + public void setCourse(ICourse course) { + this.course = course; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lecturer.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lecturer.java new file mode 100644 index 0000000..9d7f565 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lecturer.java @@ -0,0 +1,58 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.ILecturer; +import dst.ass1.jpa.model.ILesson; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; + +@Entity +@Table(name = Constants.T_LECTURER) +public class Lecturer extends Person implements ILecturer { + @OneToMany(targetEntity = Course.class) + private Collection courses = new ArrayList<>(); + + @ManyToMany(targetEntity = Lesson.class) + @JoinTable(name = Constants.J_LECTURER_LESSON, + joinColumns = { + @JoinColumn(name = Constants.I_LECTURER) + }, + inverseJoinColumns = { + @JoinColumn(name = Constants.I_LESSON) + }) + private Collection lessons = new ArrayList<>(); + + + @Override + public Collection getCourses() { + return courses; + } + + @Override + public void setCourses(Collection courses) { + this.courses = courses; + } + + @Override + public void addCourse(ICourse course) { + this.courses.add(course); + } + + @Override + public Collection getLessons() { + return lessons; + } + + @Override + public void setLessons(Collection lessons) { + this.lessons = lessons; + } + + @Override + public void addLesson(ILesson lesson) { + this.lessons.add(lesson); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lesson.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lesson.java new file mode 100644 index 0000000..181fded --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Lesson.java @@ -0,0 +1,155 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ICourse; +import dst.ass1.jpa.model.ILecturer; +import dst.ass1.jpa.model.ILesson; +import dst.ass1.jpa.model.IMaterial; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +@Entity +@Table(name = Constants.T_LESSON) +public class Lesson implements ILesson { + @Id + @GeneratedValue + private Long id; + + @Column + private String description; + + @Column + private Date start; + + @Column + private Date end; + + @ManyToOne(targetEntity = Course.class) + private ICourse course; + + @ManyToMany(targetEntity = Lecturer.class, mappedBy = Constants.M_LECTURER_LESSONS) + private Collection lecturers = new ArrayList<>(); + + @ManyToMany(targetEntity = Lesson.class) + @JoinTable(name = Constants.J_LESSONS_REQUIRED) + private Collection requiredLessons = new ArrayList<>(); + + @ManyToMany(targetEntity = Lesson.class, mappedBy = Constants.M_LESSON_REQUIRED) + private Collection requiredLessonsBy = new ArrayList<>(); + + @OneToMany(targetEntity = Material.class, mappedBy = Constants.M_MATERIAL_LESSON) + private Collection materials = new ArrayList<>(); + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public Date getStart() { + return start; + } + + @Override + public void setStart(Date start) { + this.start = start; + } + + @Override + public Date getEnd() { + return end; + } + + @Override + public void setEnd(Date end) { + this.end = end; + } + + @Override + public ICourse getCourse() { + return course; + } + + @Override + public void setCourse(ICourse course) { + this.course = course; + } + + @Override + public Collection getLecturers() { + return lecturers; + } + + @Override + public void setLecturers(Collection lecturers) { + this.lecturers = lecturers; + } + + @Override + public void addLecturer(ILecturer lecturer) { + this.lecturers.add(lecturer); + } + + @Override + public Collection getRequiredLessons() { + return requiredLessons; + } + + @Override + public void setRequiredLessons(Collection requiredLessons) { + this.requiredLessons = requiredLessons; + } + + @Override + public void addRequiredLesson(ILesson lesson) { + this.requiredLessons.add(lesson); + } + + @Override + public Collection getRequiredByLessons() { + return requiredLessonsBy; + } + + @Override + public void setRequiredByLessons(Collection requiredByLessons) { + this.requiredLessonsBy = requiredByLessons; + } + + @Override + public void addRequiredByLesson(ILesson lesson) { + this.requiredLessonsBy.add(lesson); + } + + @Override + public Collection getMaterials() { + return materials; + } + + @Override + public void setMaterials(Collection materials) { + this.materials = materials; + } + + @Override + public void addMaterial(IMaterial material) { + this.materials.add(material); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Material.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Material.java new file mode 100644 index 0000000..92ab11b --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Material.java @@ -0,0 +1,97 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ILesson; +import dst.ass1.jpa.model.IMaterial; +import dst.ass1.jpa.model.IMaterialServer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +//@Entity +//@Table(name = Constants.T_MATERIAL) +public class Material implements IMaterial { + // EXTERNAL! -> xml. + private Long id; + private String urn; + private String type; + private Date uploaded; + private Date lastUpdate; + private ILesson lesson; + private Collection materialServers = new ArrayList<>(); + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getUrn() { + return urn; + } + + @Override + public void setUrn(String urn) { + this.urn = urn; + } + + @Override + public String getType() { + return type; + } + + @Override + public void setType(String type) { + this.type = type; + } + + @Override + public Date getUploaded() { + return uploaded; + } + + @Override + public void setUploaded(Date uploaded) { + this.uploaded = uploaded; + } + + @Override + public Date getLastUpdate() { + return lastUpdate; + } + + @Override + public void setLastUpdate(Date lastUpdate) { + this.lastUpdate = lastUpdate; + } + + @Override + public ILesson getLesson() { + return lesson; + } + + @Override + public void setLesson(ILesson lesson) { + this.lesson = lesson; + } + + @Override + public Collection getMaterialServers() { + return materialServers; + } + + @Override + public void setMaterialServers(Collection materialServers) { + this.materialServers = materialServers; + } + + @Override + public void addMaterialServer(IMaterialServer materialServer) { + this.materialServers.add(materialServer); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/MaterialServer.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/MaterialServer.java new file mode 100644 index 0000000..308c971 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/MaterialServer.java @@ -0,0 +1,86 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IMaterial; +import dst.ass1.jpa.model.IMaterialServer; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +@Entity +@Table(name = Constants.T_MATERIALSERVER) +public class MaterialServer implements IMaterialServer { + @Id + @GeneratedValue + private Long id; + + @Column(unique = true) + private String name; + + @Column + private Date lastMaintenance; + + @Column + private Date nextMaintenance; + + @ManyToMany(targetEntity = Material.class) + @JoinTable(name = Constants.J_MATERIALSERVER_MATERIAL) + private Collection materials = new ArrayList<>(); + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Date getLastMaintenance() { + return lastMaintenance; + } + + @Override + public void setLastMaintenance(Date lastMaintenance) { + this.lastMaintenance = lastMaintenance; + } + + @Override + public Date getNextMaintenance() { + return nextMaintenance; + } + + @Override + public void setNextMaintenance(Date nextMaintenance) { + this.nextMaintenance = nextMaintenance; + } + + @Override + public Collection getMaterials() { + return materials; + } + + @Override + public void setMaterials(Collection materials) { + this.materials = materials; + } + + @Override + public void addMaterial(IMaterial material) { + this.materials.add(material); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Membership.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Membership.java new file mode 100644 index 0000000..12a6d11 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Membership.java @@ -0,0 +1,78 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.ICoursePlatform; +import dst.ass1.jpa.model.IMembership; +import dst.ass1.jpa.model.IParticipant; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; + +@Entity +@Table(name = Constants.T_MEMBERSHIP) +public class Membership implements IMembership { + @Id + @GeneratedValue + private Long id; + + @Column + private Boolean premium; + + @Column + private Double discount; + + @ManyToOne(targetEntity = CoursePlatform.class, optional = false) + private ICoursePlatform coursePlatform; + + @ManyToOne(targetEntity = Participant.class) + private IParticipant participant; + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public Boolean getPremium() { + return premium; + } + + @Override + public void setPremium(Boolean premium) { + this.premium = premium; + } + + @Override + public Double getDiscount() { + return discount; + } + + @Override + public void setDiscount(Double discount) { + this.discount = discount; + } + + @Override + public ICoursePlatform getCoursePlatform() { + return coursePlatform; + } + + @Override + public void setCoursePlatform(ICoursePlatform coursePlatform) { + this.coursePlatform = coursePlatform; + } + + @Override + public IParticipant getParticipant() { + return participant; + } + + @Override + public void setParticipant(IParticipant participant) { + this.participant = participant; + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Metadata.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Metadata.java new file mode 100644 index 0000000..482ae43 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Metadata.java @@ -0,0 +1,45 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IMetadata; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; + +@Entity +@Table(name = Constants.T_METADATA) +public class Metadata implements IMetadata { + @Id + @GeneratedValue + private Long id; + + @ElementCollection + private Map data = new HashMap<>(); + + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public Map getData() { + return data; + } + + @Override + public void setData(Map data) { + this.data = data; + } + + @Override + public void putData(String key, String value) { + this.data.put(key, value); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/ModelFactory.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/ModelFactory.java index 704d71b..8b30796 100644 --- a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/ModelFactory.java +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/ModelFactory.java @@ -21,79 +21,66 @@ public class ModelFactory implements IModelFactory { @Override public IAddress createAddress() { - // TODO - return null; + return new Address(); } @Override public ICourse createCourse() { - // TODO - return null; + return new Course(); } @Override public ICoursePlatform createCoursePlatform() { - // TODO - return null; + return new CoursePlatform(); } @Override public IEnrollment createEnrollment() { - // TODO - return null; + return new Enrollment(); } @Override public IEnrollmentKey createEnrollmentKey() { - // TODO - return null; + return new EnrollmentKey(); } @Override public ILecturer createLecturer() { - // TODO - return null; + return new Lecturer(); } @Override public ILesson createLesson() { - // TODO - return null; + return new Lesson(); } @Override public IMaterial createMaterial() { - // TODO - return null; + return new Material(); } @Override public IMaterialServer createMaterialServer() { - // TODO - return null; + return new MaterialServer(); } @Override public IMembership createMembership() { - // TODO - return null; + return new Membership(); } @Override public IMetadata createMetadata() { - // TODO - return null; + return new Metadata(); } @Override public IModelFactory createModelFactory() { - // TODO - return null; + return new ModelFactory(); } @Override public IParticipant createParticipant() { - // TODO - return null; + return new Participant(); } } diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Participant.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Participant.java new file mode 100644 index 0000000..64786ce --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Participant.java @@ -0,0 +1,103 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IEnrollment; +import dst.ass1.jpa.model.IMembership; +import dst.ass1.jpa.model.IParticipant; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; + +@Entity +@Table(name = Constants.T_PARTICIPANT, uniqueConstraints = {@UniqueConstraint(columnNames = {Constants.M_PARTICIPANT_ACCOUNT, Constants.M_PARTICIPANT_BANK_CODE})}) +public class Participant extends Person implements IParticipant { + @Column(nullable = false, unique = true) + private String email; + + @Column(name = Constants.M_PERSON_PASSWORD, columnDefinition = "VARBINARY(20)") + private byte[] password; + + @Column + private String accountNo; + + @Column + private String bankCode; + + @OneToMany(targetEntity = Enrollment.class) + private Collection enrollments = new ArrayList<>(); + + @OneToMany(targetEntity = Membership.class) + private Collection memberships = new ArrayList<>(); + + + @Override + public String getEmail() { + return email; + } + + @Override + public void setEmail(String email) { + this.email = email; + } + + @Override + public byte[] getPassword() { + return password; + } + + @Override + public void setPassword(byte[] password) { + this.password = password; + } + + @Override + public String getAccountNo() { + return accountNo; + } + + @Override + public void setAccountNo(String accountNo) { + this.accountNo = accountNo; + } + + @Override + public String getBankCode() { + return bankCode; + } + + @Override + public void setBankCode(String bankCode) { + this.bankCode = bankCode; + } + + @Override + public Collection getEnrollments() { + return enrollments; + } + + @Override + public void setEnrollments(Collection enrollments) { + this.enrollments = enrollments; + } + + @Override + public void addEnrollment(IEnrollment enrollment) { + this.enrollments.add(enrollment); + } + + @Override + public Collection getMemberships() { + return memberships; + } + + @Override + public void setMemberships(Collection memberships) { + this.memberships = memberships; + } + + @Override + public void addMembership(IMembership membership) { + this.memberships.add(membership); + } +} diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Person.java b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Person.java new file mode 100644 index 0000000..00e6786 --- /dev/null +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/model/impl/Person.java @@ -0,0 +1,53 @@ +package dst.ass1.jpa.model.impl; + +import dst.ass1.jpa.model.IAddress; +import dst.ass1.jpa.model.IPerson; +import dst.ass1.jpa.util.Constants; + +import javax.persistence.*; + +@MappedSuperclass +@Table(name = Constants.T_PERSON) +public class Person implements IPerson { + @Id + @GeneratedValue + private Long id; + + @Column + private String name; + + @Embedded + private Address address; + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public IAddress getAddress() { + return address; + } + + @Override + public void setAddress(IAddress address) { + if (address instanceof Address) { + this.address = (Address) address; + } + } +} diff --git a/ass1-jpa/src/main/resources/META-INF/Material.xml b/ass1-jpa/src/main/resources/META-INF/Material.xml index 1291bec..0c6db87 100644 --- a/ass1-jpa/src/main/resources/META-INF/Material.xml +++ b/ass1-jpa/src/main/resources/META-INF/Material.xml @@ -1,9 +1,33 @@ - - - + Mappings for Material + + + + + + + + + + + + + + DATE + + + DATE + + + + + + + -- 2.43.0