From 4c07bc2b908eb75975b6797178d3371704b7bab7 Mon Sep 17 00:00:00 2001 From: kre6513 Date: Thu, 10 Sep 2020 15:01:04 +0200 Subject: [PATCH] doublicated controller and data from original ClubhelperBackend. --- pom.xml | 5 + .../controller/AttendanceController.java | 11 +- .../model/controller/ContactController.java | 29 +- .../model/controller/GroupContoller.java | 4 +- .../model/controller/PersonController.java | 4 +- .../kreth/clubhelper/model/dao/AdressDao.java | 4 +- .../clubhelper/model/dao/AttendanceDao.java | 5 +- .../clubhelper/model/dao/ClubhelperDao.java | 14 + .../model/dao/DeletedEntriesDao.java | 7 + .../kreth/clubhelper/model/dao/GroupDao.java | 4 +- .../kreth/clubhelper/model/dao/PersonDao.java | 3 +- .../clubhelper/model/data/Attendance.java | 87 +++--- .../clubhelper/model/data/BaseEntity.java | 12 +- .../kreth/clubhelper/model/data/Contact.java | 155 +++++----- .../clubhelper/model/data/DeletedEntry.java | 83 +++--- .../kreth/clubhelper/model/data/GroupDef.java | 3 - .../kreth/clubhelper/model/data/Person.java | 4 - .../kreth/clubhelper/model/data/Relative.java | 196 ++++++------ .../aspects/AbstractLoggerAspect.java | 99 ++++++ .../aspects/ControllerLoggerAspect.java | 56 ++++ .../aspects/DeletedStorageAspect.java | 66 ++++ .../controller/AdressController.java | 27 ++ .../controller/AttendanceController.java | 63 ++++ .../controller/ContactController.java | 19 ++ .../controller/DeletedEntriesController.java | 26 ++ .../controller/GroupController.java | 19 ++ .../controller/HomeController.java | 49 +++ .../controller/PersonController.java | 104 +++++++ .../controller/RelativeController.java | 27 ++ .../controller/StartpassController.java | 27 ++ .../controller/abstr/AbstractController.java | 144 +++++++++ .../controller/abstr/ClubController.java | 101 +++++++ .../controller/abstr/package-info.java | 5 + .../clubhelperbackend/utils/BoolUtils.java | 11 + .../clubhelperbackend/utils/EmailUtils.java | 18 ++ .../utils/ThreadPoolErrors.java | 52 ++++ .../clubhelperbackend/utils/TimeProvider.java | 7 + .../utils/TimeProviderImpl.java | 15 + src/main/resources/schema.sql | 123 ++++---- src/main/resources/schema_postgres.sql | 282 ++++++++++++++++++ 40 files changed, 1612 insertions(+), 358 deletions(-) create mode 100644 src/main/java/de/kreth/clubhelper/model/dao/ClubhelperDao.java create mode 100644 src/main/java/de/kreth/clubhelper/model/dao/DeletedEntriesDao.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/aspects/AbstractLoggerAspect.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/aspects/ControllerLoggerAspect.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/aspects/DeletedStorageAspect.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/AdressController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/AttendanceController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/ContactController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/DeletedEntriesController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/GroupController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/HomeController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/PersonController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/RelativeController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/StartpassController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/abstr/AbstractController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/abstr/ClubController.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/controller/abstr/package-info.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/utils/BoolUtils.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/utils/EmailUtils.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/utils/ThreadPoolErrors.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/utils/TimeProvider.java create mode 100644 src/main/java/de/kreth/clubhelperbackend/utils/TimeProviderImpl.java create mode 100644 src/main/resources/schema_postgres.sql diff --git a/pom.xml b/pom.xml index df0e935..528dc1c 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,11 @@ h2 test + + com.googlecode.libphonenumber + libphonenumber + 8.11.0 + diff --git a/src/main/java/de/kreth/clubhelper/model/controller/AttendanceController.java b/src/main/java/de/kreth/clubhelper/model/controller/AttendanceController.java index 0237287..6c93db5 100644 --- a/src/main/java/de/kreth/clubhelper/model/controller/AttendanceController.java +++ b/src/main/java/de/kreth/clubhelper/model/controller/AttendanceController.java @@ -4,9 +4,12 @@ import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.format.annotation.DateTimeFormat.ISO; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -30,9 +33,9 @@ public class AttendanceController @Autowired private PersonDao personDao; - @PostMapping(value = "/on") + @GetMapping(value = "/on") @ResponseBody - public List getAttendencesOn(@RequestBody(required = false) Date date) + public List getAttendencesOn(@RequestBody @DateTimeFormat(iso=ISO.DATE) Date date) { if (date == null) { date = new Date(); @@ -42,7 +45,7 @@ public class AttendanceController @PostMapping(value = "/for/{id}") @ResponseBody - public Attendance post(@PathVariable("id") Integer id) + public Attendance post(@PathVariable("id") Long id) { Attendance att = new Attendance(); att.setOnDate(new Date()); @@ -52,7 +55,7 @@ public class AttendanceController } @DeleteMapping("/{id}") - public Attendance delete(@PathVariable("id") int personId, @RequestBody(required = true) Date onDate) { + public Attendance delete(@PathVariable("id") Long personId, @RequestBody(required = true) Date onDate) { Person person = personDao.findById(personId).orElseThrow(() -> new RuntimeException("Person not found by id=" + personId)); Attendance attendance = attendanceDao.findByPersonAndOnDate(person, onDate); attendanceDao.delete(attendance); diff --git a/src/main/java/de/kreth/clubhelper/model/controller/ContactController.java b/src/main/java/de/kreth/clubhelper/model/controller/ContactController.java index 7a00f23..f9ff59c 100644 --- a/src/main/java/de/kreth/clubhelper/model/controller/ContactController.java +++ b/src/main/java/de/kreth/clubhelper/model/controller/ContactController.java @@ -15,18 +15,19 @@ import de.kreth.clubhelper.model.data.Person; @Controller @RequestMapping("/contact") @PreAuthorize("isAuthenticated()") -public class ContactController { - - @Autowired - private ContactDao contactDao; - - public List getByParent(Person person) { - return contactDao.findByPerson(person); - } - - public void delete(Contact c) { - c.setDeleted(new Date()); - contactDao.save(c); - } - +public class ContactController +{ + @Autowired + private ContactDao contactDao; + + public List getByParent(Person person) + { + return contactDao.findByPerson(person); + } + + public void delete(Contact c) + { + c.setDeleted(new Date()); + contactDao.save(c); + } } diff --git a/src/main/java/de/kreth/clubhelper/model/controller/GroupContoller.java b/src/main/java/de/kreth/clubhelper/model/controller/GroupContoller.java index a357486..ca0af57 100644 --- a/src/main/java/de/kreth/clubhelper/model/controller/GroupContoller.java +++ b/src/main/java/de/kreth/clubhelper/model/controller/GroupContoller.java @@ -34,12 +34,12 @@ public class GroupContoller } @GetMapping("/{id}") - public GroupDef getById(@PathVariable("id") int id) { + public GroupDef getById(@PathVariable("id") long id) { Supplier supplier = () -> createNotFoundForId(id); return groupDao.findById(id).orElseThrow(supplier); } - private HttpClientErrorException createNotFoundForId(Integer id) + private HttpClientErrorException createNotFoundForId(long id) { HttpHeaders headers = new HttpHeaders(); byte[] body = new byte[0]; diff --git a/src/main/java/de/kreth/clubhelper/model/controller/PersonController.java b/src/main/java/de/kreth/clubhelper/model/controller/PersonController.java index 60894fb..5e8ce06 100644 --- a/src/main/java/de/kreth/clubhelper/model/controller/PersonController.java +++ b/src/main/java/de/kreth/clubhelper/model/controller/PersonController.java @@ -41,13 +41,13 @@ public class PersonController } @GetMapping(value = "/{id}") - public @ResponseBody Optional getById(@PathVariable("id") final int id) + public @ResponseBody Optional getById(@PathVariable("id") final long id) { return personDao.findById(id); } @DeleteMapping(value = "/{id}") - public @ResponseBody Person delete(@PathVariable("id") final int id) + public @ResponseBody Person delete(@PathVariable("id") final long id) { Optional optional = personDao.findById(id); if (optional.isPresent()) { diff --git a/src/main/java/de/kreth/clubhelper/model/dao/AdressDao.java b/src/main/java/de/kreth/clubhelper/model/dao/AdressDao.java index 5fdb1c7..b105c73 100644 --- a/src/main/java/de/kreth/clubhelper/model/dao/AdressDao.java +++ b/src/main/java/de/kreth/clubhelper/model/dao/AdressDao.java @@ -2,12 +2,10 @@ package de.kreth.clubhelper.model.dao; import java.util.List; -import org.springframework.data.repository.CrudRepository; - import de.kreth.clubhelper.model.data.Adress; import de.kreth.clubhelper.model.data.Person; -public interface AdressDao extends CrudRepository { +public interface AdressDao extends ClubhelperDao { List findByPerson(Person person); diff --git a/src/main/java/de/kreth/clubhelper/model/dao/AttendanceDao.java b/src/main/java/de/kreth/clubhelper/model/dao/AttendanceDao.java index 334403d..d972a63 100644 --- a/src/main/java/de/kreth/clubhelper/model/dao/AttendanceDao.java +++ b/src/main/java/de/kreth/clubhelper/model/dao/AttendanceDao.java @@ -3,16 +3,15 @@ package de.kreth.clubhelper.model.dao; import java.util.Date; import java.util.List; -import org.springframework.data.repository.CrudRepository; - import de.kreth.clubhelper.model.data.Attendance; import de.kreth.clubhelper.model.data.Person; -public interface AttendanceDao extends CrudRepository { +public interface AttendanceDao extends ClubhelperDao { List findByOnDate(Date onDate); List findByPerson(Person person); Attendance findByPersonAndOnDate(Person person, Date onDate); + } diff --git a/src/main/java/de/kreth/clubhelper/model/dao/ClubhelperDao.java b/src/main/java/de/kreth/clubhelper/model/dao/ClubhelperDao.java new file mode 100644 index 0000000..450cf2f --- /dev/null +++ b/src/main/java/de/kreth/clubhelper/model/dao/ClubhelperDao.java @@ -0,0 +1,14 @@ +package de.kreth.clubhelper.model.dao; + +import java.util.Date; +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + + +public interface ClubhelperDao extends CrudRepository +{ + List findByPersonId(long personId); + + List findByChangedGreaterThan(Date date); +} diff --git a/src/main/java/de/kreth/clubhelper/model/dao/DeletedEntriesDao.java b/src/main/java/de/kreth/clubhelper/model/dao/DeletedEntriesDao.java new file mode 100644 index 0000000..591c3bf --- /dev/null +++ b/src/main/java/de/kreth/clubhelper/model/dao/DeletedEntriesDao.java @@ -0,0 +1,7 @@ +package de.kreth.clubhelper.model.dao; + +import de.kreth.clubhelper.model.data.DeletedEntry; + +public interface DeletedEntriesDao extends ClubhelperDao +{ +} diff --git a/src/main/java/de/kreth/clubhelper/model/dao/GroupDao.java b/src/main/java/de/kreth/clubhelper/model/dao/GroupDao.java index e72cb56..6c9c9fa 100644 --- a/src/main/java/de/kreth/clubhelper/model/dao/GroupDao.java +++ b/src/main/java/de/kreth/clubhelper/model/dao/GroupDao.java @@ -1,9 +1,7 @@ package de.kreth.clubhelper.model.dao; -import org.springframework.data.repository.CrudRepository; - import de.kreth.clubhelper.model.data.GroupDef; -public interface GroupDao extends CrudRepository { +public interface GroupDao extends ClubhelperDao { } diff --git a/src/main/java/de/kreth/clubhelper/model/dao/PersonDao.java b/src/main/java/de/kreth/clubhelper/model/dao/PersonDao.java index 0c7cf47..e5866d3 100644 --- a/src/main/java/de/kreth/clubhelper/model/dao/PersonDao.java +++ b/src/main/java/de/kreth/clubhelper/model/dao/PersonDao.java @@ -1,11 +1,10 @@ package de.kreth.clubhelper.model.dao; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import de.kreth.clubhelper.model.data.Person; @Repository -public interface PersonDao extends CrudRepository { +public interface PersonDao extends ClubhelperDao { } diff --git a/src/main/java/de/kreth/clubhelper/model/data/Attendance.java b/src/main/java/de/kreth/clubhelper/model/data/Attendance.java index f5fa03b..4c7b45c 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/Attendance.java +++ b/src/main/java/de/kreth/clubhelper/model/data/Attendance.java @@ -15,58 +15,61 @@ import javax.persistence.TemporalType; /** * The persistent class for the attendance database table. - * */ @Entity @Table(name = "attendance") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @NamedQuery(name = "Attendance.findAll", query = "SELECT a FROM Attendance a") -public class Attendance extends BaseEntity implements Serializable { +public class Attendance extends BaseEntity implements Serializable +{ + private static final long serialVersionUID = 2385033161272078335L; + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "on_date") + private Date onDate; + // bi-directional many-to-one association to Person + @ManyToOne + private Person person; - private static final long serialVersionUID = 2385033161272078335L; + public Date getOnDate() + { + return new Date(this.onDate.getTime()); + } - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "on_date") - private Date onDate; + public Person getPerson() + { + return person; + } - // bi-directional many-to-one association to Person - @ManyToOne - private Person person; + public void setPerson(Person person) + { + this.person = person; + } - public Date getOnDate() { - return new Date(this.onDate.getTime()); - } + public void setOnDate(Date onDate) + { + this.onDate = onDate; + } - public Person getPerson() { - return person; - } + @Override + public int hashCode() + { + final int prime = 103; + int result = super.hashCode(); + result = prime * result; + return result; + } - public void setPerson(Person person) { - this.person = person; - } - - public void setOnDate(Date onDate) { - this.onDate = onDate; - } - - @Override - public int hashCode() { - final int prime = 103; - int result = super.hashCode(); - result = prime * result; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - return super.equals(obj); - } - - @Override - public String toString() { - return "Attendance [person=" + person + ", onDate=" + onDate + "]"; - } + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + return super.equals(obj); + } + @Override + public String toString() + { + return "Attendance [person=" + person + ", onDate=" + onDate + "]"; + } } diff --git a/src/main/java/de/kreth/clubhelper/model/data/BaseEntity.java b/src/main/java/de/kreth/clubhelper/model/data/BaseEntity.java index e9a4e52..4ce1846 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/BaseEntity.java +++ b/src/main/java/de/kreth/clubhelper/model/data/BaseEntity.java @@ -14,7 +14,7 @@ public abstract class BaseEntity implements EntityAccessor { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; + private long id; @Temporal(TemporalType.TIMESTAMP) private Date changed; @Temporal(TemporalType.TIMESTAMP) @@ -63,13 +63,17 @@ public abstract class BaseEntity implements EntityAccessor this.deleted = new Date(deleted.getTime()); } + public boolean isDeleted() { + return getDeleted() != null; + } + @Override - public Integer getId() + public Long getId() { return id; } - public void setId(int id) + public void setId(long id) { this.id = id; } @@ -88,7 +92,7 @@ public abstract class BaseEntity implements EntityAccessor result = prime * result + ((changed == null) ? 0 : changed.hashCode()); result = prime * result + ((created == null) ? 0 : created.hashCode()); result = prime * result + ((deleted == null) ? 0 : deleted.hashCode()); - result = prime * result + id; + result = (int) (prime * result + id); return result; } diff --git a/src/main/java/de/kreth/clubhelper/model/data/Contact.java b/src/main/java/de/kreth/clubhelper/model/data/Contact.java index bf0da58..c6a5f60 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/Contact.java +++ b/src/main/java/de/kreth/clubhelper/model/data/Contact.java @@ -6,87 +6,92 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToOne; -import javax.persistence.NamedQuery; import javax.persistence.Table; /** * The persistent class for the contact database table. - * */ @Entity @Table(name = "contact") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name = "Contact.findAll", query = "SELECT c FROM Contact c WHERE c.deleted is not null") -public class Contact extends BaseEntity implements Serializable { - - private static final long serialVersionUID = -7631864028095077913L; - - public static enum Type { - PHONE("Telefon"), - MOBILE("Mobile"), - EMAIL("Email"); - - private final String name; - - private Type(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - - private String type; - - private String value; - - // bi-directional many-to-one association to Person - @ManyToOne - private Person person; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public Person getPerson() { - return person; - } - - public void setPerson(Person person) { - this.person = person; - } - - @Override - public int hashCode() { - final int prime = 37; - int result = super.hashCode(); - result = prime * result; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - return super.equals(obj); - } - - @Override - public String toString() { - return "Contact [type=" + type + ", value=" + value + "]"; - } - +public class Contact extends BaseEntity implements Serializable +{ + private static final long serialVersionUID = -7631864028095077913L; + + public enum Type + { + PHONE("Telefon"), + MOBILE("Mobile"), + EMAIL("Email"); + private final String name; + + private Type(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + } + + private String type; + private String value; + // bi-directional many-to-one association to Person + @ManyToOne + private Person person; + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public Person getPerson() + { + return person; + } + + public void setPerson(Person person) + { + this.person = person; + } + + @Override + public int hashCode() + { + final int prime = 37; + int result = super.hashCode(); + result = prime * result; + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + return super.equals(obj); + } + + @Override + public String toString() + { + return "Contact [type=" + type + ", value=" + value + "]"; + } } diff --git a/src/main/java/de/kreth/clubhelper/model/data/DeletedEntry.java b/src/main/java/de/kreth/clubhelper/model/data/DeletedEntry.java index 496e29b..df754f4 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/DeletedEntry.java +++ b/src/main/java/de/kreth/clubhelper/model/data/DeletedEntry.java @@ -5,60 +5,61 @@ import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -import javax.persistence.NamedQuery; import javax.persistence.Table; /** * The persistent class for the deleted_entries database table. - * */ @Entity @Table(name = "deleted_entries") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name = "DeletedEntry.findAll", query = "SELECT d FROM DeletedEntry d") -public class DeletedEntry extends BaseEntity implements Serializable { +public class DeletedEntry extends BaseEntity implements Serializable +{ + private static final long serialVersionUID = -4271189592258131845L; + private long entryId; + private String tablename; - private static final long serialVersionUID = -4271189592258131845L; + public long getEntryId() + { + return entryId; + } - private int entryId; + public void setEntryId(long entryId) + { + this.entryId = entryId; + } - private String tablename; + public String getTablename() + { + return tablename; + } - public int getEntryId() { - return entryId; - } + public void setTablename(String tablename) + { + this.tablename = tablename; + } - public void setEntryId(int entryId) { - this.entryId = entryId; - } + @Override + public int hashCode() + { + final int prime = 47; + int result = super.hashCode(); + result = (int) (prime * result + entryId); + result = prime * result + ((tablename == null) ? 0 : tablename.hashCode()); + return result; + } - public String getTablename() { - return tablename; - } - - public void setTablename(String tablename) { - this.tablename = tablename; - } - - @Override - public int hashCode() { - final int prime = 47; - int result = super.hashCode(); - result = prime * result + entryId; - result = prime * result + ((tablename == null) ? 0 : tablename.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - return super.equals(obj); - } - - @Override - public String toString() { - return "DeletedEntry [entryId=" + entryId + ", tablename=" + tablename + "]"; - } + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + return super.equals(obj); + } + @Override + public String toString() + { + return "DeletedEntry [entryId=" + entryId + ", tablename=" + tablename + "]"; + } } diff --git a/src/main/java/de/kreth/clubhelper/model/data/GroupDef.java b/src/main/java/de/kreth/clubhelper/model/data/GroupDef.java index 669e4e4..fee3b88 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/GroupDef.java +++ b/src/main/java/de/kreth/clubhelper/model/data/GroupDef.java @@ -5,7 +5,6 @@ import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -import javax.persistence.NamedQuery; import javax.persistence.Table; /** @@ -14,11 +13,9 @@ import javax.persistence.Table; @Entity @Table(name = "groupdef") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name = GroupDef.QUERY_FINDALL, query = "SELECT g FROM GroupDef g") public class GroupDef extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; - public final static String QUERY_FINDALL = "GroupDef.findAll"; private String name; diff --git a/src/main/java/de/kreth/clubhelper/model/data/Person.java b/src/main/java/de/kreth/clubhelper/model/data/Person.java index 138f4ed..4f711bb 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/Person.java +++ b/src/main/java/de/kreth/clubhelper/model/data/Person.java @@ -11,7 +11,6 @@ import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; -import javax.persistence.NamedQuery; import javax.persistence.Table; /** @@ -21,9 +20,6 @@ import javax.persistence.Table; @Entity @Table(name = "person") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name = Person.QUERY_FINDALL, query = "SELECT p FROM Person p WHERE p.deleted is null") -@NamedQuery(name = Person.QUERY_FINDLOGIN, query = "FROM Person WHERE username = :username AND password = :password AND deleted is" - + " null") public class Person extends BaseEntity implements Serializable { public static final String SESSION_LOGIN = "SESSION_LOGIN_USER"; diff --git a/src/main/java/de/kreth/clubhelper/model/data/Relative.java b/src/main/java/de/kreth/clubhelper/model/data/Relative.java index c779575..1f37cc9 100644 --- a/src/main/java/de/kreth/clubhelper/model/data/Relative.java +++ b/src/main/java/de/kreth/clubhelper/model/data/Relative.java @@ -13,96 +13,118 @@ import javax.persistence.Table; /** * The persistent class for the relative database table. - * */ @Entity @Table(name = "relative") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @NamedQuery(name = Relative.QUERY_FINDALL, query = "SELECT r FROM Relative r") -public class Relative extends BaseEntity implements Serializable { - - public static final String QUERY_FINDALL = "Relative.findAll"; - - @Column(name = "TO_PERSON1_RELATION") - private String toPerson1Relation; - - @Column(name = "TO_PERSON2_RELATION") - private String toPerson2Relation; - - // bi-directional many-to-one association to Person - @ManyToOne - @JoinColumn(name = "person1") - private Person person1Bean; - - // bi-directional many-to-one association to Person - @ManyToOne - @JoinColumn(name = "person2") - private Person person2Bean; - - public String getToPerson1Relation() { - return toPerson1Relation; - } - - public void setToPerson1Relation(String toPerson1Relation) { - this.toPerson1Relation = toPerson1Relation; - } - - public String getToPerson2Relation() { - return toPerson2Relation; - } - - public void setToPerson2Relation(String toPerson2Relation) { - this.toPerson2Relation = toPerson2Relation; - } - - public Person getPerson1Bean() { - return person1Bean; - } - - public void setPerson1Bean(Person person1Bean) { - this.person1Bean = person1Bean; - } - - public Person getPerson2Bean() { - return person2Bean; - } - - public void setPerson2Bean(Person person2Bean) { - this.person2Bean = person2Bean; - } - - public Relation getRelationTo(Person person) { - if (person == null) { - return null; - } - if (person.equals(person1Bean)) { - return new Relation(person2Bean, toPerson2Relation); - } else if (person.equals(person2Bean)) { - return new Relation(person1Bean, toPerson1Relation); - } else { - return null; - } - } - - @Override - public int hashCode() { - final int prime = 73; - int result = super.hashCode(); - result = prime * result; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - return super.equals(obj); - } - - @Override - public String toString() { - return "Relative [person1Bean=" + person1Bean + ", toPerson2Relation=" + toPerson2Relation + ", person2Bean=" - + person2Bean + "]"; - } - +public class Relative extends BaseEntity implements Serializable +{ + public static final String QUERY_FINDALL = "Relative.findAll"; + @Column(name = "TO_PERSON1_RELATION") + private String toPerson1Relation; + @Column(name = "TO_PERSON2_RELATION") + private String toPerson2Relation; + // bi-directional many-to-one association to Person + @ManyToOne + @JoinColumn(name = "person1") + private Person person1Bean; + // bi-directional many-to-one association to Person + @ManyToOne + @JoinColumn(name = "person2") + private Person person2Bean; + + public Relative() + { + } + + public Relative(long id, String toPerson1Relation, String toPerson2Relation, Person person1Bean, Person person2Bean) + { + super(); + setId(id); + this.toPerson1Relation = toPerson1Relation; + this.toPerson2Relation = toPerson2Relation; + this.person1Bean = person1Bean; + this.person2Bean = person2Bean; + } + + + public String getToPerson1Relation() + { + return toPerson1Relation; + } + + public void setToPerson1Relation(String toPerson1Relation) + { + this.toPerson1Relation = toPerson1Relation; + } + + public String getToPerson2Relation() + { + return toPerson2Relation; + } + + public void setToPerson2Relation(String toPerson2Relation) + { + this.toPerson2Relation = toPerson2Relation; + } + + public Person getPerson1Bean() + { + return person1Bean; + } + + public void setPerson1Bean(Person person1Bean) + { + this.person1Bean = person1Bean; + } + + public Person getPerson2Bean() + { + return person2Bean; + } + + public void setPerson2Bean(Person person2Bean) + { + this.person2Bean = person2Bean; + } + + public Relation getRelationTo(Person person) + { + if (person == null) { + return null; + } + if (person.equals(person1Bean)) { + return new Relation(person2Bean, toPerson2Relation); + } + else if (person.equals(person2Bean)) { + return new Relation(person1Bean, toPerson1Relation); + } + else { + return null; + } + } + + @Override + public int hashCode() + { + final int prime = 73; + int result = super.hashCode(); + result = prime * result; + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + return super.equals(obj); + } + + @Override + public String toString() + { + return "Relative [person1Bean=" + person1Bean + ", toPerson2Relation=" + toPerson2Relation + ", person2Bean=" + person2Bean + "]"; + } } diff --git a/src/main/java/de/kreth/clubhelperbackend/aspects/AbstractLoggerAspect.java b/src/main/java/de/kreth/clubhelperbackend/aspects/AbstractLoggerAspect.java new file mode 100644 index 0000000..907c34c --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/aspects/AbstractLoggerAspect.java @@ -0,0 +1,99 @@ +package de.kreth.clubhelperbackend.aspects; + +import org.aspectj.lang.JoinPoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AbstractLoggerAspect { + + protected Logger logger = LoggerFactory.getLogger(getClass()); + + public enum LogLevel { + WARN, DEBUG, INFO; + + boolean enabled(Logger logger) { + switch (this) { + case WARN : + return logger.isWarnEnabled(); + case DEBUG : + return logger.isDebugEnabled(); + case INFO : + return logger.isInfoEnabled(); + + default : + return true; + } + } + } + + protected void log(LogLevel level, JoinPoint joinPoint) { + log(level, joinPoint, null); + } + + protected void log(LogLevel level, JoinPoint joinPoint, Object result) { + + if (level.enabled(logger)) { + + StringBuffer msg = generateLogMessage(joinPoint); + Exception exception = null; + + if (result != null) { + if (result instanceof Exception) { + exception = (Exception) result; + } else { + msg.append(" ==> ").append(result); + } + } + + switch (level) { + case WARN : + if (exception == null) { + logger.warn(msg.toString()); + } else { + logger.warn(msg.toString(), exception); + } + break; + case DEBUG : + if (exception == null) { + logger.debug(msg.toString()); + } else { + logger.debug(msg.toString(), exception); + } + break; + case INFO : + if (exception == null) { + logger.info(msg.toString()); + } else { + logger.info(msg.toString(), exception); + } + break; + default : + if (exception == null) { + logger.trace(msg.toString()); + } else { + logger.trace(msg.toString(), exception); + } + } + } + } + + protected StringBuffer generateLogMessage(JoinPoint joinPoint) { + StringBuffer logMessage = new StringBuffer(); + logMessage.append(joinPoint.getTarget().getClass().getName()); + logMessage.append("."); + logMessage.append(joinPoint.getSignature().getName()); + logMessage.append("("); + // append args + Object[] args = joinPoint.getArgs(); + for (int i = 0; i < args.length; i++) { + logMessage.append(args[i]).append(","); + } + if (args.length > 0) { + logMessage.deleteCharAt(logMessage.length() - 1); + } + + logMessage.append(")"); + return logMessage; + } + +} \ No newline at end of file diff --git a/src/main/java/de/kreth/clubhelperbackend/aspects/ControllerLoggerAspect.java b/src/main/java/de/kreth/clubhelperbackend/aspects/ControllerLoggerAspect.java new file mode 100644 index 0000000..a5cb2d0 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/aspects/ControllerLoggerAspect.java @@ -0,0 +1,56 @@ +package de.kreth.clubhelperbackend.aspects; + +import static de.kreth.clubhelperbackend.aspects.AbstractLoggerAspect.LogLevel.DEBUG; +import static de.kreth.clubhelperbackend.aspects.AbstractLoggerAspect.LogLevel.INFO; +import static de.kreth.clubhelperbackend.aspects.AbstractLoggerAspect.LogLevel.WARN; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +@Component +@Aspect +public class ControllerLoggerAspect extends AbstractLoggerAspect { + + @Pointcut("execution (public * de.kreth.clubhelperbackend.controller..*.delete(..))") + private void deleteItem() { + } + + @Pointcut("execution (public * de.kreth.clubhelperbackend.controller..*(..))") + private void callAny() { + } + + @Pointcut("callAny() && (!deleteItem())") + private void invocation() { + } + + @Before("invocation()") + public void logDao(JoinPoint joinPoint) throws Throwable { + log(INFO, joinPoint); + } + + @AfterThrowing(pointcut = "invocation()", throwing = "ex") + public void logCall(JoinPoint joinPoint, Exception ex) throws Throwable { + logger.error(generateLogMessage(joinPoint).toString(), ex); + } + + @AfterReturning(pointcut = "invocation()", returning = "result") + public void logCall(JoinPoint joinPoint, Object result) throws Throwable { + log(DEBUG, joinPoint, result); + } + + @AfterReturning(pointcut = "deleteItem()", returning = "result") + public void logDeleteSuccess(JoinPoint joinPoint, Object result) + throws Throwable { + log(WARN, joinPoint, result); + } + + @Before("deleteItem()") + public void logDeleteInvocation(JoinPoint joinPoint) throws Throwable { + log(DEBUG, joinPoint); + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/aspects/DeletedStorageAspect.java b/src/main/java/de/kreth/clubhelperbackend/aspects/DeletedStorageAspect.java new file mode 100644 index 0000000..01feed0 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/aspects/DeletedStorageAspect.java @@ -0,0 +1,66 @@ +package de.kreth.clubhelperbackend.aspects; + +import java.lang.reflect.Modifier; +import java.util.Date; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import de.kreth.clubhelper.model.dao.DeletedEntriesDao; +import de.kreth.clubhelper.model.data.BaseEntity; +import de.kreth.clubhelper.model.data.DeletedEntry; +import de.kreth.clubhelperbackend.utils.TimeProvider; + +@Aspect +@Component +public class DeletedStorageAspect { + + private Logger logger = LoggerFactory.getLogger(getClass()); + private DeletedEntriesDao deletedEntriesDao; + private TimeProvider time; + + @Autowired + public void setTime(TimeProvider time) { + this.time = time; + } + + @Autowired + public DeletedStorageAspect(DeletedEntriesDao deletedEntriesDao) { + super(); + this.deletedEntriesDao = deletedEntriesDao; + } + + @Pointcut("execution (public * de.kreth.clubhelperbackend.controller.abstr.AbstractController.delete(..))") + private void invocation() { + } + + @AfterReturning(pointcut = "invocation()", returning = "deleted") + public void storeDeleted(JoinPoint joinPoint, BaseEntity deleted) { + + logger.debug("Deleted: " + deleted); + Class class1 = deleted.getClass(); + + while (!class1.getSuperclass().equals(Object.class) && !Modifier.isAbstract(class1.getSuperclass().getModifiers())) + class1 = class1.getSuperclass(); + + String tableName = class1.getSimpleName(); + long id = deleted.getId(); + Date now = time.getNow(); + + DeletedEntry entry = new DeletedEntry(); + entry.setTablename(tableName); + entry.setEntryId(id); + entry.setChanged(now); + entry.setCreated(now); + logger.info("Inserted Deleteentry: {}", entry); + deletedEntriesDao.save(entry); + } + + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/AdressController.java b/src/main/java/de/kreth/clubhelperbackend/controller/AdressController.java new file mode 100644 index 0000000..5a4da4e --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/AdressController.java @@ -0,0 +1,27 @@ +package de.kreth.clubhelperbackend.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.Adress; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/adress") +public class AdressController extends AbstractController { + + @Autowired + public AdressController() { + super(Adress.class); + } + + @Override + public List getByParentId(long id) { + return new ArrayList(); + } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/AttendanceController.java b/src/main/java/de/kreth/clubhelperbackend/controller/AttendanceController.java new file mode 100644 index 0000000..c1bc5a1 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/AttendanceController.java @@ -0,0 +1,63 @@ +package de.kreth.clubhelperbackend.controller; + +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.format.annotation.DateTimeFormat.ISO; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.dao.AttendanceDao; +import de.kreth.clubhelper.model.dao.PersonDao; +import de.kreth.clubhelper.model.data.Attendance; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/attendance") +public class AttendanceController extends AbstractController { + + @Autowired + private PersonDao personDao; + + public AttendanceController() { + super(Attendance.class); + } + + @RequestMapping(value = "/on", method = RequestMethod.POST, produces = "application/json") + + public List postListAttendencesOn(@RequestBody(required=false) Date date) + throws SQLException { + + if(date == null) { + date = new Date(); + } + AttendanceDao tmpDao = (AttendanceDao)dao; + + return tmpDao.findByOnDate(date); + } + + @RequestMapping(value = "/on/{date}", method = RequestMethod.GET, produces = "application/json") + + public List getAttendencesOn(@PathVariable("date") @DateTimeFormat(iso=ISO.DATE) Date date) + throws SQLException { + + AttendanceDao tmpDao = (AttendanceDao)dao; + + return tmpDao.findByOnDate(date); + } + + @RequestMapping(value = "/for/{id}", method = RequestMethod.POST, produces = "application/json") + + public Attendance post(@PathVariable("id") Long id) { + Attendance att = new Attendance(); + att.setPerson(personDao.findById(id).get()); + att.setOnDate(new Date()); + return post(att); + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/ContactController.java b/src/main/java/de/kreth/clubhelperbackend/controller/ContactController.java new file mode 100644 index 0000000..9e657fa --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/ContactController.java @@ -0,0 +1,19 @@ +package de.kreth.clubhelperbackend.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.Contact; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/contact") +public class ContactController extends AbstractController { + + @Autowired + public ContactController() { + super(Contact.class); + } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/DeletedEntriesController.java b/src/main/java/de/kreth/clubhelperbackend/controller/DeletedEntriesController.java new file mode 100644 index 0000000..86fdd38 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/DeletedEntriesController.java @@ -0,0 +1,26 @@ +package de.kreth.clubhelperbackend.controller; + +import java.util.Collections; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.DeletedEntry; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/deletedentries") +public class DeletedEntriesController extends AbstractController { + + @Autowired + public DeletedEntriesController() { + super(DeletedEntry.class); + } + + @Override + public List getByParentId(long id) { + return Collections.emptyList(); + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/GroupController.java b/src/main/java/de/kreth/clubhelperbackend/controller/GroupController.java new file mode 100644 index 0000000..937219a --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/GroupController.java @@ -0,0 +1,19 @@ +package de.kreth.clubhelperbackend.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.GroupDef; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/group") +public class GroupController extends AbstractController { + + @Autowired() + public GroupController() { + super(GroupDef.class); + } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/HomeController.java b/src/main/java/de/kreth/clubhelperbackend/controller/HomeController.java new file mode 100644 index 0000000..8616d2b --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/HomeController.java @@ -0,0 +1,49 @@ +package de.kreth.clubhelperbackend.controller; + +import java.text.DateFormat; +import java.util.Date; +import java.util.Locale; + +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Handles requests for the application home page. + */ +@RestController +@RequestMapping("/") +public class HomeController { + + private static final Logger logger = LoggerFactory.getLogger(HomeController.class); + + /** + * Simply selects the home view to render by returning its name. + * + * @param response + * response Object for redirection. + * @param device + * device Type to decide redirection target. + * @param locale + * locale for language + * @param model + * model to set response data + * @return Name of View + */ + @GetMapping(value = "/") + public String home(HttpServletResponse response, Locale locale) { + + logger.info("Welcome home! The client locale is {}.", locale); + Date date = new Date(); + DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); + + String formattedDate = dateFormat.format(date); + + return "This is Clubhelper Backend at " + formattedDate; + } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/PersonController.java b/src/main/java/de/kreth/clubhelperbackend/controller/PersonController.java new file mode 100644 index 0000000..f894e3a --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/PersonController.java @@ -0,0 +1,104 @@ +package de.kreth.clubhelperbackend.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.Adress; +import de.kreth.clubhelper.model.data.Contact; +import de.kreth.clubhelper.model.data.Person; +import de.kreth.clubhelper.model.data.Relative; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; +import de.kreth.clubhelperbackend.controller.abstr.ClubController; + +@RestController +@RequestMapping("/person") +public class PersonController extends AbstractController { + + @Autowired + private ClubController contactController; + @Autowired + private ClubController relativeController; + @Autowired + private ClubController adressController; + + public PersonController() { + super(Person.class); + } + +// private static ClubhelperDao doCast(PersonDao dao) { +// Object anonymous = dao; +// return (ClubhelperDao) anonymous; +// } + + @Override + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "application/json") + public ResponseEntity delete(@PathVariable("id") final long id) { + + for (Contact c : contactController.getByParentId(id)) { + contactController.delete(c.getId()); + } + for (Adress a : adressController.getByParentId(id)) { + adressController.delete(a.getId()); + } + for (Relative r : relativeController.getByParentId(id)) { + relativeController.delete(r.getId()); + } + + return super.delete(id); + } + + /** + * Delivers list with one Person with id. + */ + @Override + public List getByParentId(long id) { + List all = new ArrayList(); + all.add(getById(id)); + return all; + } + + /** + * + * @author markus + * + */ + public class PersonRelative extends Relative { + + private static final long serialVersionUID = 4828690343464403867L; + private Person toPerson; + private String relation; + + public PersonRelative(Relative r) { + super(r.getId(), + r.getToPerson2Relation(), r.getToPerson1Relation(), r.getPerson1Bean(), r.getPerson2Bean()); + setChanged(r.getChanged()); + setCreated(r.getCreated()); + toPerson = r.getPerson1Bean(); + relation = r.getToPerson1Relation(); + } + + public Person getToPerson() { + return toPerson; + } + + public String getRelation() { + return relation; + } + + @Override + public String toString() { + StringBuilder bld = new StringBuilder(); + bld.append(relation).append(" ").append(toPerson.getId()) + .append(": ").append(toPerson.getPrename()).append(" ") + .append(toPerson.getSurname()); + return bld.toString(); + } + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/RelativeController.java b/src/main/java/de/kreth/clubhelperbackend/controller/RelativeController.java new file mode 100644 index 0000000..f4520bd --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/RelativeController.java @@ -0,0 +1,27 @@ +package de.kreth.clubhelperbackend.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.Relative; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/relative") +public class RelativeController extends AbstractController { + + @Autowired + public RelativeController() { + super(Relative.class); + } +// +// @Override +// @RequestMapping(value = "/for/{id}", method = RequestMethod.GET) +// public List getByParentId(@PathVariable("id") long id) { +// StringBuilder whereClause = new StringBuilder("person1="); +// whereClause.append(id).append(" OR person2=").append(id); +// return dao.getByWhere(whereClause.toString()); +// } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/StartpassController.java b/src/main/java/de/kreth/clubhelperbackend/controller/StartpassController.java new file mode 100644 index 0000000..bedef28 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/StartpassController.java @@ -0,0 +1,27 @@ +package de.kreth.clubhelperbackend.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.kreth.clubhelper.model.data.Startpass; +import de.kreth.clubhelperbackend.controller.abstr.AbstractController; + +@RestController +@RequestMapping("/startpass") +public class StartpassController extends AbstractController { + + @Autowired + public StartpassController() { + super(Startpass.class); + } + + @Override +// @RequestMapping(value = "/for/{id}", method = RequestMethod.GET, produces = "application/json") + public List getByParentId(@PathVariable("id") long id) { + return dao.findByPersonId(id); + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/abstr/AbstractController.java b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/AbstractController.java new file mode 100644 index 0000000..dbcc37a --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/AbstractController.java @@ -0,0 +1,144 @@ +package de.kreth.clubhelperbackend.controller.abstr; + +import static de.kreth.clubhelperbackend.utils.BoolUtils.not; +import static java.time.temporal.ChronoUnit.MINUTES; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import de.kreth.clubhelper.model.dao.ClubhelperDao; +import de.kreth.clubhelper.model.data.BaseEntity; + +/** + * Default Controller implementing all functionality for all {@link Data} types. + * + * @param + * Data type + */ + +//@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'STAFF')") +public abstract class AbstractController + implements + ClubController { + + @Autowired + protected ClubhelperDao dao; + private Class elementClass; + + public AbstractController(Class element) { + super(); + this.elementClass = element; + } + + @Override + @GetMapping(value = "/{id}", produces = "application/json") + public T getById(@PathVariable("id") long id) { + return dao.findById(id).orElseThrow(() -> new IllegalArgumentException(elementClass.getName() + " with id=" + id + " not found")); + } + + protected List iterableToList(Iterable in) { + List result = new ArrayList<>(); + in.forEach(result::add); + return result; + } + + @Override + @GetMapping(value = {"/", + ""}, produces = "application/json") + public List getAll() { + Iterable findAll = dao.findAll(); + List result = new ArrayList<>(); + findAll.forEach(result::add); + return result; + } + + @Override + @GetMapping(value = "/for/{id}", produces = "application/json") + public List getByParentId(@PathVariable("id") long id) { + return dao.findByPersonId(id); + } + + @Override + @GetMapping(value = "/changed/{changed}", produces = "application/json") + public List getChangedSince(@PathVariable("changed") long changed) { + return dao.findByChangedGreaterThan(new Date(changed)); + } + + @Override + @PutMapping(value = "/{id}", produces = "application/json") + public T put(@PathVariable("id") long id, @RequestBody T toUpdate) { + + Date now = new Date(); + Date created = toUpdate.getCreated(); + Date changed = null; + + if (toUpdate.getChanged() != null) { + changed = toUpdate.getChanged(); + long minutes = MINUTES.between(created.toInstant(), changed.toInstant()); + if (minutes < 1) { + toUpdate.setChanged(now); + } + } else { + toUpdate.setChanged(now); + } + + dao.save(toUpdate); + return toUpdate; + } + + @Override + @DeleteMapping(value = "/{id}", produces = "application/json") + public ResponseEntity delete(@PathVariable("id") long id) { + T byId = getById(id); + if (not(byId.isDeleted())) { + dao.delete(byId); + } + return ResponseEntity.ok(getById(id)); + } + + @Override + @PostMapping(value = "/", produces = "application/json") + public T post(@RequestBody T toCreate) { + return post(-1L, toCreate); + } + + @Override + @PostMapping(value = "/{id}", produces = "application/json") + public T post(@PathVariable("id") Long id, @RequestBody T toCreate) { + if (id == null) { + id = -1L; + } + toCreate.setId(id); + Date now = new Date(); + + toCreate.setChanged(now); + + if (toCreate.getCreated() == null + || toCreate.getCreated().getTime() == 0) { + toCreate.setCreated(now); + } + + if (toCreate.getId() < 0) { + return dao.save(toCreate); + } else { + T byId = getById(toCreate.getId()); + if (byId != null) { + toCreate.setDeleted(null); + return dao.save(toCreate); + } else { + return dao.save(toCreate); + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/abstr/ClubController.java b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/ClubController.java new file mode 100644 index 0000000..634a97c --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/ClubController.java @@ -0,0 +1,101 @@ +package de.kreth.clubhelperbackend.controller.abstr; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; + +public interface ClubController { + + /* + * ************* REST Methoden ************ + */ + + /** + * Rest: PUT - Change object (update) + *

+ * Mapping: /{id} + * + * @param id + * Id of updated object + * @param toUpdate + * Object with updated data. + * @return updated object + */ + T put(@PathVariable("id") long id, @RequestBody T toUpdate); + + /** + * Rest: POST - Create Object without Id. + * + * @param toCreate + * object with data to insert. + * @return created and corrected object + */ + T post(@RequestBody T toCreate); + + /** + * Rest: POST - Create Object with or without Id. + * + * @param id + * -1 for new Id + * @param toCreate + * Object to create. + * @return created object with updated id and dates. + */ + T post(@PathVariable("id") Long id, @RequestBody T toCreate); + + /** + * Rest: GET - return object + *

+ * Mapping: /{id} + * + * @param id + * id to find object for. + * @return Object for matching id + */ + T getById(@PathVariable("id") long id); + + /** + * Rest: GET - return List of all objects + *

+ * Mapping: / + * + * @return List of all Objects - sorted if configured. + */ + List getAll(); + + /** + * Rest: GET - return List of object having the (parent object) id as + * property.
+ * Which property is meant is implementation dependant. Most likely its + * personId + *

+ * Mapping: /for/{id} + * + * @param id + * Id matching all objects property. + * @return List of object with certain property matching id. + */ + List getByParentId(@PathVariable("id") long id); + + /** + * Rest: DELETE - deletes object with the Id. + *

+ * Mapping: /{id} + * + * @param id + * Id of the object to delete. + * @return deleted object. + */ + ResponseEntity delete(@PathVariable("id") long id); + + /** + * + * @param changed + * date of last change included + * @return list of objects changed since changed date. + */ + List getChangedSince(long changed); + +} \ No newline at end of file diff --git a/src/main/java/de/kreth/clubhelperbackend/controller/abstr/package-info.java b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/package-info.java new file mode 100644 index 0000000..bf3166b --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/controller/abstr/package-info.java @@ -0,0 +1,5 @@ +/** + * @author markus + * + */ +package de.kreth.clubhelperbackend.controller.abstr; \ No newline at end of file diff --git a/src/main/java/de/kreth/clubhelperbackend/utils/BoolUtils.java b/src/main/java/de/kreth/clubhelperbackend/utils/BoolUtils.java new file mode 100644 index 0000000..6ace581 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/utils/BoolUtils.java @@ -0,0 +1,11 @@ +package de.kreth.clubhelperbackend.utils; + +public class BoolUtils { + private BoolUtils() { + // Static Methods only. + } + + public static final boolean not(boolean value) { + return !value; + } +} diff --git a/src/main/java/de/kreth/clubhelperbackend/utils/EmailUtils.java b/src/main/java/de/kreth/clubhelperbackend/utils/EmailUtils.java new file mode 100644 index 0000000..cf73882 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/utils/EmailUtils.java @@ -0,0 +1,18 @@ +package de.kreth.clubhelperbackend.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class EmailUtils { + + private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + + private static final Pattern pattern = Pattern.compile(EMAIL_PATTERN); + + public static boolean isValidEmailadress(String email) { + Matcher matcher = pattern.matcher(email); + return matcher.matches(); + } + +} diff --git a/src/main/java/de/kreth/clubhelperbackend/utils/ThreadPoolErrors.java b/src/main/java/de/kreth/clubhelperbackend/utils/ThreadPoolErrors.java new file mode 100644 index 0000000..0b11e60 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/utils/ThreadPoolErrors.java @@ -0,0 +1,52 @@ +package de.kreth.clubhelperbackend.utils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class ThreadPoolErrors extends ThreadPoolExecutor { + + public final List exceptions = Collections + .synchronizedList(new ArrayList<>()); + + public ThreadPoolErrors(int threadCount) { + super(Math.min(3, threadCount), // core threads + threadCount, // max threads + 30, // timeout + TimeUnit.SECONDS, // timeout units + new LinkedBlockingQueue() // work queue + ); + } + + protected void afterExecute(Runnable r, Throwable t) { + super.afterExecute(r, t); + if (t != null) { + exceptions.add(t); + } + } + + public Throwable myAwaitTermination() { + + while (isRunningWithoutException()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + shutdownNow(); + return e; + } + } + if (exceptions.isEmpty() == false) { + return exceptions.get(0); + } + return null; + } + + private boolean isRunningWithoutException() { + return isTerminated() == false && getActiveCount() > 0 + && exceptions.isEmpty(); + } + +} \ No newline at end of file diff --git a/src/main/java/de/kreth/clubhelperbackend/utils/TimeProvider.java b/src/main/java/de/kreth/clubhelperbackend/utils/TimeProvider.java new file mode 100644 index 0000000..69dd8b3 --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/utils/TimeProvider.java @@ -0,0 +1,7 @@ +package de.kreth.clubhelperbackend.utils; + +import java.util.Date; + +public interface TimeProvider { + Date getNow(); +} diff --git a/src/main/java/de/kreth/clubhelperbackend/utils/TimeProviderImpl.java b/src/main/java/de/kreth/clubhelperbackend/utils/TimeProviderImpl.java new file mode 100644 index 0000000..248730c --- /dev/null +++ b/src/main/java/de/kreth/clubhelperbackend/utils/TimeProviderImpl.java @@ -0,0 +1,15 @@ +package de.kreth.clubhelperbackend.utils; + +import java.util.Date; + +import org.springframework.stereotype.Component; + +@Component +public class TimeProviderImpl implements TimeProvider { + + @Override + public Date getNow() { + return new Date(); + } + +} diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 43df90d..bb4b7c8 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -7,13 +7,12 @@ -- -- DROP TABLE IF EXISTS groupdef; CREATE TABLE groupdef ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, name varchar(255) NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY groupname_UNIQUE (name) + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT groupname_UNIQUE UNIQUE (name) ); -- @@ -21,17 +20,16 @@ CREATE TABLE groupdef ( -- -- DROP TABLE IF EXISTS person; CREATE TABLE person ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, prename varchar(255) NOT NULL, surname varchar(255) DEFAULT NULL, - birth datetime DEFAULT NULL, + birth timestamp DEFAULT NULL, gender smallint DEFAULT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, username varchar(255) DEFAULT NULL, - password varchar(255) DEFAULT NULL, - PRIMARY KEY (id) + password varchar(255) DEFAULT NULL ); @@ -41,14 +39,13 @@ CREATE TABLE person ( -- DROP TABLE IF EXISTS contact; CREATE TABLE contact ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, type varchar(255) NOT NULL, value varchar(255) DEFAULT NULL, person_id int NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, CONSTRAINT contact_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) ON DELETE RESTRICT ON UPDATE RESTRICT ); @@ -64,8 +61,8 @@ CREATE TABLE clubevent ( organizerDisplayName varchar(150) DEFAULT NULL, caption varchar(150) DEFAULT NULL, description varchar(500) DEFAULT NULL, - start datetime DEFAULT NULL, - end datetime DEFAULT NULL, + start timestamp DEFAULT NULL, + ende timestamp DEFAULT NULL, allDay smallint DEFAULT NULL, deleted smallint NOT NULL DEFAULT 0, PRIMARY KEY (id) @@ -76,16 +73,15 @@ CREATE TABLE clubevent ( -- -- DROP TABLE IF EXISTS pflichten; CREATE TABLE pflichten ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, name varchar(45) NOT NULL, - fixed tinyint DEFAULT NULL, + fixed smallint DEFAULT NULL, ordered int NOT NULL, comment varchar(500) DEFAULT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY name_UNIQUE (name) + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT name_UNIQUE UNIQUE (name) ); -- @@ -93,16 +89,15 @@ CREATE TABLE pflichten ( -- -- DROP TABLE IF EXISTS adress; CREATE TABLE adress ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, adress1 varchar(255) DEFAULT NULL, adress2 varchar(255) DEFAULT NULL, plz varchar(255) DEFAULT NULL, city varchar(255) DEFAULT NULL, person_id int NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, CONSTRAINT adress_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) ); @@ -111,16 +106,15 @@ CREATE TABLE adress ( -- -- DROP TABLE IF EXISTS altersgruppe; CREATE TABLE altersgruppe ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, event_id varchar(250) NOT NULL, pflicht_id int DEFAULT NULL, bezeichnung varchar(100) NOT NULL, start int DEFAULT NULL, - end varchar(45) DEFAULT NULL, + ende varchar(45) DEFAULT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, CONSTRAINT fk_altersgruppe_event FOREIGN KEY (event_id) REFERENCES clubevent (id), CONSTRAINT fk_altersgruppe_pflicht FOREIGN KEY (pflicht_id) REFERENCES pflichten (id) ); @@ -130,14 +124,13 @@ CREATE TABLE altersgruppe ( -- -- DROP TABLE IF EXISTS attendance; CREATE TABLE attendance ( - id int NOT NULL AUTO_INCREMENT, - on_date datetime DEFAULT NULL, + id SERIAL PRIMARY KEY, + on_date timestamp DEFAULT NULL, person_id int NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY UNIQUE_person_id_on_date (person_id,on_date), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT UNIQUE_person_id_on_date UNIQUE (person_id,on_date), CONSTRAINT attendance_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) ); @@ -173,13 +166,12 @@ CREATE TABLE clubevent_has_person ( -- DROP TABLE IF EXISTS deleted_entries; CREATE TABLE deleted_entries ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, tablename varchar(25) NOT NULL, entryId int NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id) + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL ); -- @@ -188,10 +180,9 @@ CREATE TABLE deleted_entries ( -- DROP TABLE IF EXISTS event_has_altersgruppe; CREATE TABLE event_has_altersgruppe ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, event_id varchar(250) NOT NULL, altersgruppe_id int NOT NULL, - PRIMARY KEY (id), CONSTRAINT fk_event_has_altersgruppe_altersgruppe FOREIGN KEY (altersgruppe_id) REFERENCES altersgruppe (id), CONSTRAINT fk_event_has_altersgruppe_event FOREIGN KEY (event_id) REFERENCES clubevent (id) ); @@ -202,11 +193,10 @@ CREATE TABLE event_has_altersgruppe ( -- DROP TABLE IF EXISTS notes; CREATE TABLE notes ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, person_id int NOT NULL, notekey varchar(25) DEFAULT NULL, notetext varchar(2000) DEFAULT NULL, - PRIMARY KEY (id), CONSTRAINT fk_notes_person FOREIGN KEY (person_id) REFERENCES person (id) ); @@ -216,14 +206,13 @@ CREATE TABLE notes ( -- DROP TABLE IF EXISTS persongroup; CREATE TABLE persongroup ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, person_id int NOT NULL, group_id int NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY unique_person_group (person_id,group_id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT unique_person_group UNIQUE (person_id,group_id), CONSTRAINT persongroup_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id), CONSTRAINT persongroup_ibfk_2 FOREIGN KEY (group_id) REFERENCES groupdef (id) ); @@ -234,15 +223,14 @@ CREATE TABLE persongroup ( -- DROP TABLE IF EXISTS relative; CREATE TABLE relative ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, person1 int NOT NULL, person2 int NOT NULL, TO_PERSON1_RELATION varchar(255) DEFAULT NULL, TO_PERSON2_RELATION varchar(255) DEFAULT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, CONSTRAINT relative_ibfk_1 FOREIGN KEY (person1) REFERENCES person (id), CONSTRAINT relative_ibfk_2 FOREIGN KEY (person2) REFERENCES person (id) ); @@ -253,14 +241,13 @@ CREATE TABLE relative ( -- DROP TABLE IF EXISTS startpaesse; CREATE TABLE startpaesse ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, person_id int NOT NULL, startpass_nr varchar(25) NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY startpass_nr (startpass_nr), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT startpass_nr UNIQUE (startpass_nr), CONSTRAINT startpaesse_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) ); @@ -270,16 +257,15 @@ CREATE TABLE startpaesse ( -- DROP TABLE IF EXISTS startpass_startrechte; CREATE TABLE startpass_startrechte ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, startpass_id int NOT NULL, verein_name varchar(100) NOT NULL, fachgebiet varchar(25) NOT NULL, - startrecht_beginn datetime NOT NULL, - startrecht_ende datetime NOT NULL, + startrecht_beginn timestamp NOT NULL, + startrecht_ende timestamp NOT NULL, changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, - created datetime DEFAULT CURRENT_TIMESTAMP, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id), + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, CONSTRAINT startpass_startrechte_ibfk_1 FOREIGN KEY (startpass_id) REFERENCES startpaesse (id) ); @@ -288,10 +274,9 @@ CREATE TABLE startpass_startrechte ( -- -- DROP TABLE IF EXISTS version; CREATE TABLE version ( - id int NOT NULL AUTO_INCREMENT, + id SERIAL PRIMARY KEY, version int NOT NULL, - deleted datetime DEFAULT NULL, - PRIMARY KEY (id) + deleted timestamp DEFAULT NULL ); -- Dump completed diff --git a/src/main/resources/schema_postgres.sql b/src/main/resources/schema_postgres.sql new file mode 100644 index 0000000..bb4b7c8 --- /dev/null +++ b/src/main/resources/schema_postgres.sql @@ -0,0 +1,282 @@ +-- MySQL dump 10.13 Distrib 8.0.20, for Win64 (x86_64) +-- +-- ------------------------------------------------------ + +-- +-- Table structure for table groupdef +-- +-- DROP TABLE IF EXISTS groupdef; +CREATE TABLE groupdef ( + id SERIAL PRIMARY KEY, + name varchar(255) NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT groupname_UNIQUE UNIQUE (name) +); + +-- +-- Table structure for table person +-- +-- DROP TABLE IF EXISTS person; +CREATE TABLE person ( + id SERIAL PRIMARY KEY, + prename varchar(255) NOT NULL, + surname varchar(255) DEFAULT NULL, + birth timestamp DEFAULT NULL, + gender smallint DEFAULT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + username varchar(255) DEFAULT NULL, + password varchar(255) DEFAULT NULL +); + + +-- +-- Table structure for table `contact` +-- + +-- DROP TABLE IF EXISTS contact; +CREATE TABLE contact ( + id SERIAL PRIMARY KEY, + type varchar(255) NOT NULL, + value varchar(255) DEFAULT NULL, + person_id int NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT contact_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) ON DELETE RESTRICT ON UPDATE RESTRICT +); + +-- +-- Table structure for table clubevent +-- + +-- DROP TABLE IF EXISTS clubevent; +CREATE TABLE clubevent ( + id varchar(250) NOT NULL, + location varchar(255) DEFAULT NULL, + ICALUID varchar(150) DEFAULT NULL, + organizerDisplayName varchar(150) DEFAULT NULL, + caption varchar(150) DEFAULT NULL, + description varchar(500) DEFAULT NULL, + start timestamp DEFAULT NULL, + ende timestamp DEFAULT NULL, + allDay smallint DEFAULT NULL, + deleted smallint NOT NULL DEFAULT 0, + PRIMARY KEY (id) +); + +-- +-- Table structure for table pflichten +-- +-- DROP TABLE IF EXISTS pflichten; +CREATE TABLE pflichten ( + id SERIAL PRIMARY KEY, + name varchar(45) NOT NULL, + fixed smallint DEFAULT NULL, + ordered int NOT NULL, + comment varchar(500) DEFAULT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT name_UNIQUE UNIQUE (name) +); + +-- +-- Table structure for table adress +-- +-- DROP TABLE IF EXISTS adress; +CREATE TABLE adress ( + id SERIAL PRIMARY KEY, + adress1 varchar(255) DEFAULT NULL, + adress2 varchar(255) DEFAULT NULL, + plz varchar(255) DEFAULT NULL, + city varchar(255) DEFAULT NULL, + person_id int NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT adress_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) +); + +-- +-- Table structure for table altersgruppe +-- +-- DROP TABLE IF EXISTS altersgruppe; +CREATE TABLE altersgruppe ( + id SERIAL PRIMARY KEY, + event_id varchar(250) NOT NULL, + pflicht_id int DEFAULT NULL, + bezeichnung varchar(100) NOT NULL, + start int DEFAULT NULL, + ende varchar(45) DEFAULT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT fk_altersgruppe_event FOREIGN KEY (event_id) REFERENCES clubevent (id), + CONSTRAINT fk_altersgruppe_pflicht FOREIGN KEY (pflicht_id) REFERENCES pflichten (id) +); + +-- +-- Table structure for table attendance +-- +-- DROP TABLE IF EXISTS attendance; +CREATE TABLE attendance ( + id SERIAL PRIMARY KEY, + on_date timestamp DEFAULT NULL, + person_id int NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT UNIQUE_person_id_on_date UNIQUE (person_id,on_date), + CONSTRAINT attendance_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) +); + +-- +-- Table structure for table clubevent_addon +-- + +-- DROP TABLE IF EXISTS clubevent_addon; +CREATE TABLE clubevent_addon ( + id varchar(250) NOT NULL, + competition_type varchar(45) NOT NULL, + PRIMARY KEY (id), + CONSTRAINT fk_event_addon_id FOREIGN KEY (id) REFERENCES clubevent (id) +); + +-- +-- Table structure for table clubevent_has_person +-- + +-- DROP TABLE IF EXISTS clubevent_has_person; +CREATE TABLE clubevent_has_person ( + clubevent_id varchar(250) NOT NULL, + person_id int NOT NULL, + comment varchar(250) NOT NULL, + PRIMARY KEY (clubevent_id,person_id), + CONSTRAINT fk_clubevent_has_person_clubevent1 FOREIGN KEY (clubevent_id) REFERENCES clubevent (id), + CONSTRAINT fk_clubevent_has_person_person1 FOREIGN KEY (person_id) REFERENCES person (id) +); + +-- +-- Table structure for table deleted_entries +-- + +-- DROP TABLE IF EXISTS deleted_entries; +CREATE TABLE deleted_entries ( + id SERIAL PRIMARY KEY, + tablename varchar(25) NOT NULL, + entryId int NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL +); + +-- +-- Table structure for table event_has_altersgruppe +-- + +-- DROP TABLE IF EXISTS event_has_altersgruppe; +CREATE TABLE event_has_altersgruppe ( + id SERIAL PRIMARY KEY, + event_id varchar(250) NOT NULL, + altersgruppe_id int NOT NULL, + CONSTRAINT fk_event_has_altersgruppe_altersgruppe FOREIGN KEY (altersgruppe_id) REFERENCES altersgruppe (id), + CONSTRAINT fk_event_has_altersgruppe_event FOREIGN KEY (event_id) REFERENCES clubevent (id) +); + +-- +-- Table structure for table notes +-- + +-- DROP TABLE IF EXISTS notes; +CREATE TABLE notes ( + id SERIAL PRIMARY KEY, + person_id int NOT NULL, + notekey varchar(25) DEFAULT NULL, + notetext varchar(2000) DEFAULT NULL, + CONSTRAINT fk_notes_person FOREIGN KEY (person_id) REFERENCES person (id) +); + +-- +-- Table structure for table persongroup +-- + +-- DROP TABLE IF EXISTS persongroup; +CREATE TABLE persongroup ( + id SERIAL PRIMARY KEY, + person_id int NOT NULL, + group_id int NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT unique_person_group UNIQUE (person_id,group_id), + CONSTRAINT persongroup_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id), + CONSTRAINT persongroup_ibfk_2 FOREIGN KEY (group_id) REFERENCES groupdef (id) +); + +-- +-- Table structure for table relative +-- + +-- DROP TABLE IF EXISTS relative; +CREATE TABLE relative ( + id SERIAL PRIMARY KEY, + person1 int NOT NULL, + person2 int NOT NULL, + TO_PERSON1_RELATION varchar(255) DEFAULT NULL, + TO_PERSON2_RELATION varchar(255) DEFAULT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT relative_ibfk_1 FOREIGN KEY (person1) REFERENCES person (id), + CONSTRAINT relative_ibfk_2 FOREIGN KEY (person2) REFERENCES person (id) +); + +-- +-- Table structure for table startpaesse +-- + +-- DROP TABLE IF EXISTS startpaesse; +CREATE TABLE startpaesse ( + id SERIAL PRIMARY KEY, + person_id int NOT NULL, + startpass_nr varchar(25) NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT startpass_nr UNIQUE (startpass_nr), + CONSTRAINT startpaesse_ibfk_1 FOREIGN KEY (person_id) REFERENCES person (id) +); + +-- +-- Table structure for table startpass_startrechte +-- + +-- DROP TABLE IF EXISTS startpass_startrechte; +CREATE TABLE startpass_startrechte ( + id SERIAL PRIMARY KEY, + startpass_id int NOT NULL, + verein_name varchar(100) NOT NULL, + fachgebiet varchar(25) NOT NULL, + startrecht_beginn timestamp NOT NULL, + startrecht_ende timestamp NOT NULL, + changed timestamp NULL DEFAULT CURRENT_TIMESTAMP, + created timestamp DEFAULT CURRENT_TIMESTAMP, + deleted timestamp DEFAULT NULL, + CONSTRAINT startpass_startrechte_ibfk_1 FOREIGN KEY (startpass_id) REFERENCES startpaesse (id) +); + +-- +-- Table structure for table version +-- +-- DROP TABLE IF EXISTS version; +CREATE TABLE version ( + id SERIAL PRIMARY KEY, + version int NOT NULL, + deleted timestamp DEFAULT NULL +); + +-- Dump completed