adds data model for projects and versions

Sun, 10 May 2020 10:58:31 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 10 May 2020 10:58:31 +0200
changeset 37
fecda0f466e6
parent 36
0f4f8f255c32
child 38
cf85ef18f231

adds data model for projects and versions

setup/postgres/psql_create_tables.sql file | annotate | diff | comparison | revisions
setup/postgres/psql_default_data.sql file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/dao/postgres/PGUserDao.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/entities/Project.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/entities/User.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/entities/Version.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/entities/VersionStatus.java file | annotate | diff | comparison | revisions
--- a/setup/postgres/psql_create_tables.sql	Sun May 10 10:11:37 2020 +0200
+++ b/setup/postgres/psql_create_tables.sql	Sun May 10 10:58:31 2020 +0200
@@ -1,9 +1,34 @@
 -- This script creates the module management tables
 --
 
-create table lpitcore_user (
+create table lpit_user (
     userid          serial          primary key,
     username        varchar(50)     not null unique,
+    mail            varchar(50),
     lastname        varchar(50),
     givenname       varchar(50)
 );
+
+create table lpit_project (
+    id              serial          primary key,
+    name            varchar(20)     not null unique,
+    description     varchar(200),
+    repoUrl         varchar(50),
+    owner           integer         references lpit_user(userid)
+);
+
+create type version_status as enum (
+    'Future',
+    'Unreleased',
+    'Released',
+    'LTS',
+    'Deprecated'
+);
+
+create table lpit_version (
+    id              serial          primary key,
+    project         integer         not null references lpit_project(id),
+    name            varchar(20)     not null,
+    ordinal         integer         not null default 0,
+    status          version_status  not null default 'Future'
+);
--- a/setup/postgres/psql_default_data.sql	Sun May 10 10:11:37 2020 +0200
+++ b/setup/postgres/psql_default_data.sql	Sun May 10 10:58:31 2020 +0200
@@ -2,4 +2,5 @@
  * Some default data.
  */
 
-insert into lpitcore_user (userid, username) values (-1, 'Anonymous');
+insert into lpit_user (userid, username)
+values (-1, 'Anonymous');
--- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGUserDao.java	Sun May 10 10:11:37 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGUserDao.java	Sun May 10 10:58:31 2020 +0200
@@ -41,8 +41,7 @@
 
     @Override
     protected User mapColumns(ResultSet result) throws SQLException {
-        final var user = new User();
-        user.setUserID(result.getInt("userid"));
+        final var user = new User(result.getInt("userid"));
         user.setUsername(result.getString("username"));
         user.setGivenname(result.getString("givenname"));
         user.setLastname(result.getString("lastname"));
@@ -51,6 +50,6 @@
 
     @Override
     protected PreparedStatement listQuery(Connection conn) throws SQLException {
-        return conn.prepareStatement("select * from lpitcore_user where userid >= 0 order by username");
+        return conn.prepareStatement("select * from lpit_user where userid >= 0 order by username");
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/uapcore/lightpit/entities/Project.java	Sun May 10 10:58:31 2020 +0200
@@ -0,0 +1,73 @@
+package de.uapcore.lightpit.entities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class Project {
+
+    private final int id;
+    private String name;
+    private String description;
+    private String repoUrl;
+    private User owner;
+
+    private final List<Version> versions = new ArrayList<>();
+
+    public Project(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getRepoUrl() {
+        return repoUrl;
+    }
+
+    public void setRepoUrl(String repoUrl) {
+        this.repoUrl = repoUrl;
+    }
+
+    public User getOwner() {
+        return owner;
+    }
+
+    public void setOwner(User owner) {
+        this.owner = owner;
+    }
+
+    public List<Version> getVersions() {
+        return versions;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        Project project = (Project) o;
+        return id == project.id;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id);
+    }
+}
--- a/src/main/java/de/uapcore/lightpit/entities/User.java	Sun May 10 10:11:37 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/entities/User.java	Sun May 10 10:58:31 2020 +0200
@@ -28,23 +28,26 @@
  */
 package de.uapcore.lightpit.entities;
 
+import java.util.Objects;
+
 public final class User {
 
     public static final int ANONYMOUS_USERID = -1;
 
-    private int userID;
+    private final int userID;
     private String username;
+    private String mail;
     private String givenname;
     private String lastname;
 
+    public User(int userID) {
+        this.userID = userID;
+    }
+
     public int getUserID() {
         return userID;
     }
 
-    public void setUserID(int userID) {
-        this.userID = userID;
-    }
-
     public String getUsername() {
         return username;
     }
@@ -53,6 +56,14 @@
         this.username = username;
     }
 
+    public String getMail() {
+        return mail;
+    }
+
+    public void setMail(String mail) {
+        this.mail = mail;
+    }
+
     public String getGivenname() {
         return givenname;
     }
@@ -70,21 +81,15 @@
     }
 
     @Override
-    public int hashCode() {
-        int hash = 3;
-        hash = 41 * hash + this.userID;
-        return hash;
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        User user = (User) o;
+        return userID == user.userID;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        } else {
-            return this.userID == ((User) obj).userID;
-        }
+    public int hashCode() {
+        return Objects.hash(userID);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/uapcore/lightpit/entities/Version.java	Sun May 10 10:58:31 2020 +0200
@@ -0,0 +1,69 @@
+package de.uapcore.lightpit.entities;
+
+import java.util.Objects;
+
+public class Version implements Comparable<Version> {
+
+    private final int id;
+    private String name;
+    /**
+     * If we do not want versions to be ordered lexicographically we may specify an order.
+     */
+    private int ordinal;
+    private VersionStatus status;
+
+    public Version(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getOrdinal() {
+        return ordinal;
+    }
+
+    public void setOrdinal(int ordinal) {
+        this.ordinal = ordinal;
+    }
+
+    public VersionStatus getStatus() {
+        return status;
+    }
+
+    public void setStatus(VersionStatus status) {
+        this.status = status;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        Version version = (Version) o;
+        return id == version.id;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id);
+    }
+
+    @Override
+    public int compareTo(Version version) {
+        int ord = Integer.compare(this.ordinal, version.ordinal);
+        if (ord == 0) {
+            return this.name.compareToIgnoreCase(version.name);
+        } else {
+            return ord;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/uapcore/lightpit/entities/VersionStatus.java	Sun May 10 10:58:31 2020 +0200
@@ -0,0 +1,9 @@
+package de.uapcore.lightpit.entities;
+
+public enum VersionStatus {
+    Future,
+    Unreleased,
+    Released,
+    LTS,
+    Deprecated
+}

mercurial