Sun, 10 May 2020 10:58:31 +0200
adds data model for projects and versions
1.1 --- a/setup/postgres/psql_create_tables.sql Sun May 10 10:11:37 2020 +0200 1.2 +++ b/setup/postgres/psql_create_tables.sql Sun May 10 10:58:31 2020 +0200 1.3 @@ -1,9 +1,34 @@ 1.4 -- This script creates the module management tables 1.5 -- 1.6 1.7 -create table lpitcore_user ( 1.8 +create table lpit_user ( 1.9 userid serial primary key, 1.10 username varchar(50) not null unique, 1.11 + mail varchar(50), 1.12 lastname varchar(50), 1.13 givenname varchar(50) 1.14 ); 1.15 + 1.16 +create table lpit_project ( 1.17 + id serial primary key, 1.18 + name varchar(20) not null unique, 1.19 + description varchar(200), 1.20 + repoUrl varchar(50), 1.21 + owner integer references lpit_user(userid) 1.22 +); 1.23 + 1.24 +create type version_status as enum ( 1.25 + 'Future', 1.26 + 'Unreleased', 1.27 + 'Released', 1.28 + 'LTS', 1.29 + 'Deprecated' 1.30 +); 1.31 + 1.32 +create table lpit_version ( 1.33 + id serial primary key, 1.34 + project integer not null references lpit_project(id), 1.35 + name varchar(20) not null, 1.36 + ordinal integer not null default 0, 1.37 + status version_status not null default 'Future' 1.38 +);
2.1 --- a/setup/postgres/psql_default_data.sql Sun May 10 10:11:37 2020 +0200 2.2 +++ b/setup/postgres/psql_default_data.sql Sun May 10 10:58:31 2020 +0200 2.3 @@ -2,4 +2,5 @@ 2.4 * Some default data. 2.5 */ 2.6 2.7 -insert into lpitcore_user (userid, username) values (-1, 'Anonymous'); 2.8 +insert into lpit_user (userid, username) 2.9 +values (-1, 'Anonymous');
3.1 --- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGUserDao.java Sun May 10 10:11:37 2020 +0200 3.2 +++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGUserDao.java Sun May 10 10:58:31 2020 +0200 3.3 @@ -41,8 +41,7 @@ 3.4 3.5 @Override 3.6 protected User mapColumns(ResultSet result) throws SQLException { 3.7 - final var user = new User(); 3.8 - user.setUserID(result.getInt("userid")); 3.9 + final var user = new User(result.getInt("userid")); 3.10 user.setUsername(result.getString("username")); 3.11 user.setGivenname(result.getString("givenname")); 3.12 user.setLastname(result.getString("lastname")); 3.13 @@ -51,6 +50,6 @@ 3.14 3.15 @Override 3.16 protected PreparedStatement listQuery(Connection conn) throws SQLException { 3.17 - return conn.prepareStatement("select * from lpitcore_user where userid >= 0 order by username"); 3.18 + return conn.prepareStatement("select * from lpit_user where userid >= 0 order by username"); 3.19 } 3.20 }
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/main/java/de/uapcore/lightpit/entities/Project.java Sun May 10 10:58:31 2020 +0200 4.3 @@ -0,0 +1,73 @@ 4.4 +package de.uapcore.lightpit.entities; 4.5 + 4.6 +import java.util.ArrayList; 4.7 +import java.util.List; 4.8 +import java.util.Objects; 4.9 + 4.10 +public class Project { 4.11 + 4.12 + private final int id; 4.13 + private String name; 4.14 + private String description; 4.15 + private String repoUrl; 4.16 + private User owner; 4.17 + 4.18 + private final List<Version> versions = new ArrayList<>(); 4.19 + 4.20 + public Project(int id) { 4.21 + this.id = id; 4.22 + } 4.23 + 4.24 + public int getId() { 4.25 + return id; 4.26 + } 4.27 + 4.28 + public String getName() { 4.29 + return name; 4.30 + } 4.31 + 4.32 + public void setName(String name) { 4.33 + this.name = name; 4.34 + } 4.35 + 4.36 + public String getDescription() { 4.37 + return description; 4.38 + } 4.39 + 4.40 + public void setDescription(String description) { 4.41 + this.description = description; 4.42 + } 4.43 + 4.44 + public String getRepoUrl() { 4.45 + return repoUrl; 4.46 + } 4.47 + 4.48 + public void setRepoUrl(String repoUrl) { 4.49 + this.repoUrl = repoUrl; 4.50 + } 4.51 + 4.52 + public User getOwner() { 4.53 + return owner; 4.54 + } 4.55 + 4.56 + public void setOwner(User owner) { 4.57 + this.owner = owner; 4.58 + } 4.59 + 4.60 + public List<Version> getVersions() { 4.61 + return versions; 4.62 + } 4.63 + 4.64 + @Override 4.65 + public boolean equals(Object o) { 4.66 + if (this == o) return true; 4.67 + if (o == null || getClass() != o.getClass()) return false; 4.68 + Project project = (Project) o; 4.69 + return id == project.id; 4.70 + } 4.71 + 4.72 + @Override 4.73 + public int hashCode() { 4.74 + return Objects.hash(id); 4.75 + } 4.76 +}
5.1 --- a/src/main/java/de/uapcore/lightpit/entities/User.java Sun May 10 10:11:37 2020 +0200 5.2 +++ b/src/main/java/de/uapcore/lightpit/entities/User.java Sun May 10 10:58:31 2020 +0200 5.3 @@ -28,23 +28,26 @@ 5.4 */ 5.5 package de.uapcore.lightpit.entities; 5.6 5.7 +import java.util.Objects; 5.8 + 5.9 public final class User { 5.10 5.11 public static final int ANONYMOUS_USERID = -1; 5.12 5.13 - private int userID; 5.14 + private final int userID; 5.15 private String username; 5.16 + private String mail; 5.17 private String givenname; 5.18 private String lastname; 5.19 5.20 + public User(int userID) { 5.21 + this.userID = userID; 5.22 + } 5.23 + 5.24 public int getUserID() { 5.25 return userID; 5.26 } 5.27 5.28 - public void setUserID(int userID) { 5.29 - this.userID = userID; 5.30 - } 5.31 - 5.32 public String getUsername() { 5.33 return username; 5.34 } 5.35 @@ -53,6 +56,14 @@ 5.36 this.username = username; 5.37 } 5.38 5.39 + public String getMail() { 5.40 + return mail; 5.41 + } 5.42 + 5.43 + public void setMail(String mail) { 5.44 + this.mail = mail; 5.45 + } 5.46 + 5.47 public String getGivenname() { 5.48 return givenname; 5.49 } 5.50 @@ -70,21 +81,15 @@ 5.51 } 5.52 5.53 @Override 5.54 - public int hashCode() { 5.55 - int hash = 3; 5.56 - hash = 41 * hash + this.userID; 5.57 - return hash; 5.58 + public boolean equals(Object o) { 5.59 + if (this == o) return true; 5.60 + if (o == null || getClass() != o.getClass()) return false; 5.61 + User user = (User) o; 5.62 + return userID == user.userID; 5.63 } 5.64 5.65 @Override 5.66 - public boolean equals(Object obj) { 5.67 - if (this == obj) { 5.68 - return true; 5.69 - } 5.70 - if (obj == null || getClass() != obj.getClass()) { 5.71 - return false; 5.72 - } else { 5.73 - return this.userID == ((User) obj).userID; 5.74 - } 5.75 + public int hashCode() { 5.76 + return Objects.hash(userID); 5.77 } 5.78 }
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/main/java/de/uapcore/lightpit/entities/Version.java Sun May 10 10:58:31 2020 +0200 6.3 @@ -0,0 +1,69 @@ 6.4 +package de.uapcore.lightpit.entities; 6.5 + 6.6 +import java.util.Objects; 6.7 + 6.8 +public class Version implements Comparable<Version> { 6.9 + 6.10 + private final int id; 6.11 + private String name; 6.12 + /** 6.13 + * If we do not want versions to be ordered lexicographically we may specify an order. 6.14 + */ 6.15 + private int ordinal; 6.16 + private VersionStatus status; 6.17 + 6.18 + public Version(int id) { 6.19 + this.id = id; 6.20 + } 6.21 + 6.22 + public int getId() { 6.23 + return id; 6.24 + } 6.25 + 6.26 + public String getName() { 6.27 + return name; 6.28 + } 6.29 + 6.30 + public void setName(String name) { 6.31 + this.name = name; 6.32 + } 6.33 + 6.34 + public int getOrdinal() { 6.35 + return ordinal; 6.36 + } 6.37 + 6.38 + public void setOrdinal(int ordinal) { 6.39 + this.ordinal = ordinal; 6.40 + } 6.41 + 6.42 + public VersionStatus getStatus() { 6.43 + return status; 6.44 + } 6.45 + 6.46 + public void setStatus(VersionStatus status) { 6.47 + this.status = status; 6.48 + } 6.49 + 6.50 + @Override 6.51 + public boolean equals(Object o) { 6.52 + if (this == o) return true; 6.53 + if (o == null || getClass() != o.getClass()) return false; 6.54 + Version version = (Version) o; 6.55 + return id == version.id; 6.56 + } 6.57 + 6.58 + @Override 6.59 + public int hashCode() { 6.60 + return Objects.hash(id); 6.61 + } 6.62 + 6.63 + @Override 6.64 + public int compareTo(Version version) { 6.65 + int ord = Integer.compare(this.ordinal, version.ordinal); 6.66 + if (ord == 0) { 6.67 + return this.name.compareToIgnoreCase(version.name); 6.68 + } else { 6.69 + return ord; 6.70 + } 6.71 + } 6.72 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/src/main/java/de/uapcore/lightpit/entities/VersionStatus.java Sun May 10 10:58:31 2020 +0200 7.3 @@ -0,0 +1,9 @@ 7.4 +package de.uapcore.lightpit.entities; 7.5 + 7.6 +public enum VersionStatus { 7.7 + Future, 7.8 + Unreleased, 7.9 + Released, 7.10 + LTS, 7.11 + Deprecated 7.12 +}