Skip to content
Snippets Groups Projects
Commit 9070b341 authored by Martin Weise's avatar Martin Weise
Browse files

Merge branch '363-split-keycloak-database-from-metadata-database' into 'dev'

Resolve "Split Keycloak database from metadata database"

See merge request !189
parents 683d2096 12005dff
No related branches found
No related tags found
5 merge requests!231CI: Remove build for log-service,!228Better error message handling in the frontend,!223Release of version 1.4.0,!191Fixed the DataCite issue of minting new dois,!189Resolve "Split Keycloak database from metadata database"
Showing
with 345 additions and 157 deletions
......@@ -9,6 +9,9 @@ SEARCH_PASSWORD=admin
METADATA_DB=fda
METADATA_USERNAME=root
METADATA_PASSWORD=dbrepo
AUTH_DB=keycloak
AUTH_USERNAME=root
AUTH_PASSWORD=dbrepo
BROKER_ENDPOINT=http://broker-service:15672
BROKER_USERNAME=fda
BROKER_PASSWORD=fda
......
......@@ -36,13 +36,14 @@ WORKDIR /app
COPY ./healthcheck.sh ./healthcheck.sh
ENV METADATA_USERNAME=root
ENV METADATA_PASSWORD=dbrepo
ENV AUTH_DB=keycloak
ENV AUTH_USERNAME=root
ENV AUTH_PASSWORD=dbrepo
ENV KC_DB=mariadb
ENV KC_DB_URL=jdbc:mariadb://metadata-db/fda
ENV KC_DB_USERNAME=${METADATA_USERNAME}
ENV KC_DB_PASSWORD=${METADATA_PASSWORD}
ENV KC_DB_URL=jdbc:mariadb://auth-db/${AUTH_DB}
ENV KC_DB_USERNAME=${AUTH_USERNAME}
ENV KC_DB_PASSWORD=${AUTH_PASSWORD}
ENV KC_HOSTNAME_STRICT_HTTPS=false
ENV KC_HOSTNAME_PATH=/api/auth
ENV KC_HOSTNAME_ADMIN_URL=http://localhost/api/auth
......
BEGIN;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_users`
(
id character varying(36) NOT NULL,
username character varying(255) NOT NULL,
firstname character varying(255),
lastname character varying(255),
email character varying(255) NOT NULL,
orcid character varying(255),
affiliation character varying(255),
mariadb_password character varying(255) NOT NULL,
theme_dark boolean,
PRIMARY KEY (id),
UNIQUE (username),
UNIQUE (email)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_images`
(
id bigint NOT NULL AUTO_INCREMENT,
......@@ -32,13 +48,13 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_images_date`
CREATE TABLE IF NOT EXISTS `fda`.`mdb_containers`
(
id bigint NOT NULL AUTO_INCREMENT,
INTERNAL_NAME character varying(255) NOT NULL,
NAME character varying(255) NOT NULL,
HOST character varying(255) NOT NULL,
PORT integer NOT NULL,
internal_name character varying(255) NOT NULL,
name character varying(255) NOT NULL,
host character varying(255) NOT NULL,
port integer NOT NULL,
image_id bigint NOT NULL,
created timestamp NOT NULL DEFAULT NOW(),
LAST_MODIFIED timestamp,
last_modified timestamp,
privileged_username character varying(255) NOT NULL,
privileged_password character varying(255) NOT NULL,
PRIMARY KEY (id),
......@@ -48,18 +64,18 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_containers`
CREATE TABLE IF NOT EXISTS `fda`.`mdb_data`
(
ID bigint NOT NULL AUTO_INCREMENT,
PROVENANCE TEXT,
FileEncoding TEXT,
FileType VARCHAR(100),
Version TEXT,
Seperator TEXT,
PROVENANCE text,
FileEncoding text,
FileType character varying(100),
Version text,
Seperator text,
PRIMARY KEY (ID)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_licenses`
(
identifier character varying(255) NOT NULL,
uri TEXT NOT NULL,
uri text NOT NULL,
PRIMARY KEY (identifier),
UNIQUE (uri)
) WITH SYSTEM VERSIONING;
......@@ -71,16 +87,19 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_databases`
name character varying(255) NOT NULL,
internal_name character varying(255) NOT NULL,
exchange_name character varying(255) NOT NULL,
description TEXT,
description text,
engine character varying(20),
is_public BOOLEAN NOT NULL DEFAULT TRUE,
created_by character varying(255),
owned_by character varying(255),
contact_person character varying(255),
is_public boolean NOT NULL DEFAULT TRUE,
created_by character varying(36),
owned_by character varying(36),
contact_person character varying(36),
created timestamp NOT NULL DEFAULT NOW(),
last_modified timestamp,
PRIMARY KEY (id),
FOREIGN KEY (cid) REFERENCES mdb_containers (id) /* currently we only support one-to-one */
FOREIGN KEY (cid) REFERENCES mdb_containers (id) /* currently we only support one-to-one */,
FOREIGN KEY (created_by) REFERENCES mdb_users (id),
FOREIGN KEY (owned_by) REFERENCES mdb_users (id),
FOREIGN KEY (contact_person) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_databases_subjects`
......@@ -110,11 +129,13 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_tables`
Version TEXT,
created timestamp NOT NULL DEFAULT NOW(),
versioned boolean not null default true,
created_by character varying(255) NOT NULL,
owned_by character varying(255) NOT NULL,
created_by character varying(36) NOT NULL,
owned_by character varying(36) NOT NULL,
last_modified timestamp,
PRIMARY KEY (ID),
FOREIGN KEY (tDBID) REFERENCES mdb_databases (id)
FOREIGN KEY (tDBID) REFERENCES mdb_databases (id),
FOREIGN KEY (created_by) REFERENCES mdb_users (id),
FOREIGN KEY (owned_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns`
......@@ -159,19 +180,17 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_sets`
CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_nom`
(
cDBID bigint,
tID bigint,
cID bigint,
maxlength INTEGER,
last_modified timestamp,
created timestamp NOT NULL DEFAULT NOW(),
FOREIGN KEY (cDBID, tID, cID) REFERENCES mdb_columns (cDBID, tID, ID),
PRIMARY KEY (cDBID, tID, cID)
FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID),
PRIMARY KEY (tID, cID)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_num`
(
cDBID bigint,
tID bigint,
cID bigint,
SIunit TEXT,
......@@ -183,21 +202,20 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_num`
-- Histogram INTEGER[],
last_modified timestamp,
created timestamp NOT NULL DEFAULT NOW(),
FOREIGN KEY (cDBID, tID, cID) REFERENCES mdb_columns (cDBID, tID, ID),
PRIMARY KEY (cDBID, tID, cID)
FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID),
PRIMARY KEY (tID, cID)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_cat`
(
cDBID bigint,
tID bigint,
cID bigint,
num_cat INTEGER,
-- cat_array TEXT[],
last_modified timestamp,
created timestamp NOT NULL DEFAULT NOW(),
FOREIGN KEY (cDBID, tID, cID) REFERENCES mdb_columns (cDBID, tID, ID),
PRIMARY KEY (cDBID, tID, cID)
FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID),
PRIMARY KEY (tID, cID)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_constraints_foreign_key`
......@@ -260,9 +278,10 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_concepts`
name VARCHAR(255) null,
description TEXT null,
created timestamp NOT NULL DEFAULT NOW(),
created_by character varying(255),
created_by character varying(36) NOT NULL,
PRIMARY KEY (id),
UNIQUE (uri)
UNIQUE (uri),
FOREIGN KEY (created_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_units`
......@@ -272,9 +291,10 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_units`
name VARCHAR(255) null,
description TEXT null,
created timestamp NOT NULL DEFAULT NOW(),
created_by character varying(255),
created_by character varying(36) NOT NULL,
PRIMARY KEY (id),
UNIQUE (uri)
UNIQUE (uri),
FOREIGN KEY (created_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_columns_concepts`
......@@ -309,9 +329,10 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_view`
InitialView BOOLEAN NOT NULL,
created timestamp NOT NULL DEFAULT NOW(),
last_modified timestamp,
created_by character varying(255) NOT NULL,
created_by character varying(36) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (vdbid) REFERENCES mdb_databases (id)
FOREIGN KEY (vdbid) REFERENCES mdb_databases (id),
FOREIGN KEY (created_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_banner_messages`
......@@ -335,10 +356,11 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_ontologies`
sparql_endpoint TEXT NULL,
last_modified timestamp,
created timestamp NOT NULL DEFAULT NOW(),
created_by character varying(255) NULL,
created_by character varying(36) NOT NULL,
UNIQUE (prefix),
UNIQUE (uri),
PRIMARY KEY (id)
PRIMARY KEY (id),
FOREIGN KEY (created_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_view_columns`
......@@ -373,11 +395,12 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_identifiers`
result_number bigint,
doi VARCHAR(255),
created timestamp NOT NULL DEFAULT NOW(),
created_by character varying(255) NOT NULL,
created_by character varying(36) NOT NULL,
last_modified timestamp,
PRIMARY KEY (id), /* must be a single id from persistent identifier concept */
FOREIGN KEY (dbid) REFERENCES mdb_databases (id),
UNIQUE (dbid, qid)
UNIQUE (dbid, qid),
FOREIGN KEY (created_by) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_identifier_licenses`
......@@ -462,11 +485,12 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_feed`
(
fDBID bigint,
fID bigint,
fUserId character varying(255) not null,
fUserId character varying(36) not null,
fDataID bigint REFERENCES mdb_data (ID),
created timestamp NOT NULL DEFAULT NOW(),
PRIMARY KEY (fDBID, fID, fUserId, fDataID),
FOREIGN KEY (fDBID, fID) REFERENCES mdb_tables (tDBID, ID)
FOREIGN KEY (fDBID, fID) REFERENCES mdb_tables (tDBID, ID),
FOREIGN KEY (fUserId) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
CREATE TABLE IF NOT EXISTS `fda`.`mdb_update`
......@@ -490,11 +514,12 @@ CREATE TABLE IF NOT EXISTS `fda`.`mdb_access`
CREATE TABLE IF NOT EXISTS `fda`.`mdb_have_access`
(
user_id character varying(255) NOT NULL,
user_id character varying(36) NOT NULL,
database_id bigint REFERENCES mdb_databases (id),
access_type ENUM ('READ', 'WRITE_OWN', 'WRITE_ALL') NOT NULL,
created timestamp NOT NULL DEFAULT NOW(),
PRIMARY KEY (user_id, database_id)
PRIMARY KEY (user_id, database_id),
FOREIGN KEY (user_id) REFERENCES mdb_users (id)
) WITH SYSTEM VERSIONING;
COMMIT;
......
......@@ -34,8 +34,9 @@ MAINTAINER Martin Weise <martin.weise@tuwien.ac.at>
ENV ADMIN_MAIL="noreply@localhost"
ENV BASE_URL="http://localhost"
ENV GRANT_PRIVILEGES="SELECT, CREATE, CREATE VIEW, CREATE ROUTINE, CREATE TEMPORARY TABLES, LOCK TABLES, INDEX, TRIGGER, INSERT, UPDATE, DELETE"
ENV BROKER_CONSUMERS=2
ENV BROKER_ENDPOINT=http://broker-service:15672
ENV BROKER_ENDPOINT="http://broker-service:15672"
ENV BROKER_USERNAME=fda
ENV CLIENT_ID="dbrepo-client"
ENV DBREPO_CLIENT_SECRET="MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG"
......@@ -54,7 +55,10 @@ ENV REPOSITORY_NAME="Example Repository"
ENV SEARCH_USERNAME=admin
ENV SHARED_FILESYSTEM=/tmp
ENV USER_NETWORK=userdb
ENV WEBSITE=http://localhost
ENV WEBSITE="http://localhost"
ENV KEYCLOAK_HOST="http://authentication-service:8080"
ENV KEYCLOAK_ADMIN=fda
ENV KEYCLOAK_ADMIN_PASSWORD=fda
WORKDIR /app
......
......@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.jackson.Jacksonized;
import java.util.UUID;
@Getter
@Setter
@Builder
......@@ -15,8 +17,8 @@ import lombok.extern.jackson.Jacksonized;
@ToString
public class DatabaseGiveAccessDto {
@NotBlank(message = "username is required")
private String username;
@NotBlank(message = "user id is required")
private UUID userId;
@NotNull(message = "access type is required")
private AccessTypeDto type;
......
package at.tuwien.api.user;
package at.tuwien.api.keycloak;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import java.util.UUID;
@Getter
@Setter
@Builder
......@@ -16,21 +12,15 @@ import java.util.UUID;
@AllArgsConstructor
@Jacksonized
@ToString
public class UserAttributeDto {
public class CredentialDto {
@NotNull
@JsonIgnore
private UUID id;
private CredentialTypeDto type;
@NotNull
@JsonIgnore
@Schema(example = "1ffc7b0e-9aeb-4e8b-b8f1-68f3936155b4")
private UUID userId;
@Schema(example = "theme_dark")
private String name;
@Schema(example = "true")
@Schema(example = "s3cr3t")
private String value;
@Schema(example = "false")
private Boolean temporary;
}
package at.tuwien.api.keycloak;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
@Getter
public enum CredentialTypeDto {
@JsonProperty("password")
PASSWORD("password");
private String name;
CredentialTypeDto(String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
package at.tuwien.api.keycloak;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@ToString
public class TokenDto {
@NotNull
@JsonProperty("access_token")
private String accessToken;
@NotNull
private String scope;
}
package at.tuwien.api.keycloak;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import java.util.List;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@ToString
public class UpdateCredentialsDto {
@NotNull
private List<CredentialDto> credentials;
}
package at.tuwien.api.keycloak;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import java.util.List;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@ToString
public class UserCreateDto {
@NotNull
@Schema(example = "jcarberry", description = "Only contains lowercase characters")
private String username;
@NotNull
@Schema(example = "true")
private Boolean enabled;
@NotNull
@Schema(example = "jcarberry@brown.edu")
private String email;
@NotNull
private List<CredentialDto> credentials;
}
package at.tuwien.api.keycloak;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import java.util.UUID;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@ToString
public class UserDto {
@NotNull
private UUID id;
@NotNull
@Schema(example = "jcarberry", description = "Only contains lowercase characters")
private String username;
@NotNull
@Schema(example = "true")
private Boolean enabled;
@NotNull
@Schema(example = "false")
private Boolean totp;
@NotNull
@JsonProperty("emailVerified")
@Schema(example = "false")
private Boolean emailVerified;
@NotNull
@Schema(example = "jcarberry@brown.edu")
private String email;
@NotNull
@JsonProperty("notBefore")
@Schema(example = "0")
private Long notBefore;
}
package at.tuwien.api.user;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Jacksonized
@ToString
public class UserAttributesDto {
@JsonIgnore
@org.springframework.data.annotation.Transient
@JsonProperty("theme_dark")
@Schema(example = "false")
private Boolean themeDark;
@Field(name = "orcid", type = FieldType.Keyword)
@Schema(example = "https://orcid.org/0000-0002-1825-0097")
private String orcid;
@Field(name = "affiliation", type = FieldType.Keyword)
@Schema(example = "Brown University")
private String affiliation;
@JsonIgnore
@org.springframework.data.annotation.Transient
@Schema(example = "*CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D")
private String mariadbPassword;
}
......@@ -41,9 +41,4 @@ public class UserBriefDto {
@Schema(example = "Carberry")
private String lastname;
@JsonProperty("email_verified")
@Schema(example = "true")
@org.springframework.data.annotation.Transient
private Boolean emailVerified;
}
package at.tuwien.api.user;
import at.tuwien.api.container.ContainerDto;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
......@@ -12,7 +11,6 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.util.List;
import java.util.UUID;
@Getter
......@@ -22,11 +20,13 @@ import java.util.UUID;
@AllArgsConstructor
@Jacksonized
@ToString
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Document(indexName = "user")
public class UserDto {
@Id
@NotNull
@EqualsAndHashCode.Include
@Schema(example = "1ffc7b0e-9aeb-4e8b-b8f1-68f3936155b4")
@Field(name = "id", type = FieldType.Keyword)
private UUID id;
......@@ -40,10 +40,6 @@ public class UserDto {
@Field(name = "name", type = FieldType.Keyword)
private String name;
@Schema(example = "http://orcid.org/0000-0002-1825-0097")
@Field(name = "orcid", type = FieldType.Keyword)
private String orcid;
@JsonProperty("given_name")
@Schema(example = "Josiah")
@Field(name = "firstname", type = FieldType.Keyword)
......@@ -55,30 +51,12 @@ public class UserDto {
private String lastname;
@NotNull
@org.springframework.data.annotation.Transient
private List<UserAttributeDto> attributes;
@NotNull
@org.springframework.data.annotation.Transient
private List<ContainerDto> containers;
@NotNull
@org.springframework.data.annotation.Transient
private List<ContainerDto> databases;
@NotNull
@org.springframework.data.annotation.Transient
private List<ContainerDto> identifiers;
@Field(name = "attributes", includeInParent = true, type = FieldType.Nested)
private UserAttributesDto attributes;
@NotNull
@org.springframework.data.annotation.Transient
@Schema(example = "jcarberry@brown.edu")
private String email;
@NotNull
@JsonProperty("email_verified")
@org.springframework.data.annotation.Transient
@Schema(example = "true")
private Boolean emailVerified;
}
......@@ -63,11 +63,4 @@ public class ContainerImage {
@Column(columnDefinition = "TIMESTAMP")
private Instant lastModified;
@PreRemove
public void preRemove() {
this.containers.forEach(container -> {
container.setImage(null);
});
}
}
......@@ -33,8 +33,8 @@ import java.util.UUID;
@NamedQueries({
@NamedQuery(name = "Database.findReadAccess", query = "select distinct d from Database d join DatabaseAccess a on a.hdbid = d.id and a.huserid = ?1"),
@NamedQuery(name = "Database.findWriteAccess", query = "select distinct d from Database d join DatabaseAccess a on a.hdbid = d.id and a.huserid = ?1 where a.type = 'WRITE_OWN' or a.type = 'WRITE_ALL'"),
@NamedQuery(name = "Database.findConfigureAccess", query = "select distinct d from Database d where d.owner.id = ?1"),
@NamedQuery(name = "Database.findPublicOrMine", query = "select distinct d from Database d where d.id = ?1 and (d.isPublic = true or d.owner.id = ?2)"),
@NamedQuery(name = "Database.findConfigureAccess", query = "select distinct d from Database d where d.ownedBy = ?1"),
@NamedQuery(name = "Database.findPublicOrMine", query = "select distinct d from Database d where d.id = ?1 and (d.isPublic = true or d.ownedBy = ?2)"),
@NamedQuery(name = "Database.findPublic", query = "select distinct d from Database d where d.isPublic = true and d.id = ?1"),
})
@Document(indexName = "database")
......@@ -72,7 +72,6 @@ public class Database implements Serializable {
@Column(nullable = false)
private Long cid;
@ToString.Exclude
@org.springframework.data.annotation.Transient
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumns({
......
package at.tuwien.entities.database;
import at.tuwien.entities.user.User;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.springframework.data.annotation.CreatedDate;
......@@ -32,13 +31,6 @@ public class DatabaseAccess {
@Column(name = "database_id", updatable = false)
private Long hdbid;
@org.springframework.data.annotation.Transient
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.DETACH, CascadeType.MERGE})
@JoinColumns({
@JoinColumn(name = "user_id", referencedColumnName = "ID", updatable = false, insertable = false)
})
private User user;
@Column(nullable = false, name = "access_type", columnDefinition = "enum('READ', 'WRITE_OWN', 'WRITE_ALL')")
@Enumerated(EnumType.STRING)
private AccessType type;
......
......@@ -13,7 +13,7 @@ import jakarta.persistence.*;
@AllArgsConstructor
@NoArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@Table(name = "mdb_licenses", uniqueConstraints = {
@jakarta.persistence.Table(name = "mdb_licenses", uniqueConstraints = {
@UniqueConstraint(columnNames = {"uri"})
})
public class License {
......
......@@ -2,7 +2,6 @@ package at.tuwien.entities.database;
import at.tuwien.entities.database.table.columns.TableColumn;
import at.tuwien.entities.identifier.Identifier;
import at.tuwien.entities.user.User;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.NamedQueries;
......@@ -30,9 +29,9 @@ import java.util.UUID;
@Table(name = "mdb_view")
@NamedQueries({
@NamedQuery(name = "View.findAllPublicByDatabaseId", query = "select v from View v where v.database.id = ?1 and v.isPublic = true"),
@NamedQuery(name = "View.findAllPublicOrMineByDatabaseId", query = "select v from View v where v.database.id = ?1 and (v.isPublic = true or v.creator.username = ?2)"),
@NamedQuery(name = "View.findAllPublicOrMineByDatabaseId", query = "select v from View v where v.database.id = ?1 and (v.isPublic = true or v.createdBy = ?2)"),
@NamedQuery(name = "View.findPublicByDatabaseIdAndId", query = "select v from View v where v.database.id = ?1 and v.id = ?2 and v.isPublic = true"),
@NamedQuery(name = "View.findPublicOrMineByDatabaseIdAndId", query = "select v from View v where v.database.id = ?1 and v.id = ?2 and (v.isPublic = true or v.creator.username = ?3)")
@NamedQuery(name = "View.findPublicOrMineByDatabaseIdAndId", query = "select v from View v where v.database.id = ?1 and v.id = ?2 and (v.isPublic = true or v.createdBy = ?3)")
})
public class View {
......@@ -47,20 +46,11 @@ public class View {
@Column(updatable = false, nullable = false)
private Long vdbid;
@ToString.Exclude
@JdbcTypeCode(java.sql.Types.VARCHAR)
@Field(name = "created_by")
@Column(name = "createdBy", nullable = false, columnDefinition = "VARCHAR(36)")
private UUID createdBy;
@ToString.Exclude
@org.springframework.data.annotation.Transient
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumns({
@JoinColumn(name = "createdBy", referencedColumnName = "ID", insertable = false, updatable = false)
})
private User creator;
@Column(name = "vname", nullable = false)
private String name;
......
......@@ -3,11 +3,11 @@ package at.tuwien.entities.database.table;
import at.tuwien.entities.database.Database;
import at.tuwien.entities.database.table.columns.TableColumn;
import at.tuwien.entities.database.table.constraints.Constraints;
import at.tuwien.entities.user.User;
import lombok.*;
import lombok.extern.log4j.Log4j2;
import net.sf.jsqlparser.statement.select.FromItem;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JdbcTypeCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -16,6 +16,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.*;;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Data
@Entity
......@@ -39,19 +40,13 @@ public class Table {
@Column(updatable = false, nullable = false)
private Long tdbid;
@ToString.Exclude
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "createdBy", referencedColumnName = "ID", nullable = false, columnDefinition = "VARCHAR(36)", updatable = false)
})
private User creator;
@JdbcTypeCode(java.sql.Types.VARCHAR)
@Column(name = "created_by", columnDefinition = "VARCHAR(36)")
private UUID createdBy;
@ToString.Exclude
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "ownedBy", referencedColumnName = "ID", nullable = false, columnDefinition = "VARCHAR(36)", updatable = false)
})
private User owner;
@JdbcTypeCode(java.sql.Types.VARCHAR)
@Column(name = "owned_by", columnDefinition = "VARCHAR(36)")
private UUID ownedBy;
@Column(name = "tname", nullable = false)
private String name;
......@@ -97,11 +92,6 @@ public class Table {
@Column(columnDefinition = "TIMESTAMP")
private Instant lastModified;
@PreRemove
public void preRemove() {
this.creator = null;
}
/**
* KEEP THIS FUNCTION HERE! IT WILL BREAK CODE!
* Custom equality function implementation.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment