diff --git a/dbrepo-metadata-db/setup-schema.sql b/dbrepo-metadata-db/setup-schema.sql index c418a3f4227e51b40e3785a22e2daadd3895fab4..a24971600a29e3ab0371454f759b16ad99807adf 100644 --- a/dbrepo-metadata-db/setup-schema.sql +++ b/dbrepo-metadata-db/setup-schema.sql @@ -1,560 +1,560 @@ - BEGIN; - - CREATE TABLE IF NOT EXISTS `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 `mdb_images` - ( - id bigint NOT NULL AUTO_INCREMENT, - name character varying(255) NOT NULL, - version character varying(255) NOT NULL, - default_port integer NOT NULL, - dialect character varying(255) NOT NULL, - driver_class character varying(255) NOT NULL, - jdbc_method character varying(255) NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - last_modified timestamp, - PRIMARY KEY (id), - UNIQUE (name, version) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_images_date` - ( - id bigint NOT NULL AUTO_INCREMENT, - iid bigint NOT NULL, - database_format character varying(255) NOT NULL, - unix_format character varying(255) NOT NULL, - example character varying(255) NOT NULL, - has_time boolean NOT NULL, - created_at timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (id), - FOREIGN KEY (iid) REFERENCES mdb_images (id), - UNIQUE (database_format, unix_format, example) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `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 default 3306, - ui_host character varying(255) NOT NULL default host, - ui_port integer NOT NULL default port, - ui_additional_flags text, - sidecar_host character varying(255) NOT NULL, - sidecar_port integer NOT NULL default 3305, - image_id bigint NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - last_modified timestamp, - privileged_username character varying(255) NOT NULL, - privileged_password character varying(255) NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (image_id) REFERENCES mdb_images (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_data` - ( - ID bigint NOT NULL AUTO_INCREMENT, - PROVENANCE text, - FileEncoding text, - FileType character varying(100), - Version text, - Seperator text, - PRIMARY KEY (ID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_licenses` - ( - identifier character varying(255) NOT NULL, - uri text NOT NULL, - PRIMARY KEY (identifier), - UNIQUE (uri(200)) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_databases` - ( - id bigint NOT NULL AUTO_INCREMENT, - cid bigint NOT NULL, - name character varying(255) NOT NULL, - internal_name character varying(255) NOT NULL, - exchange_name character varying(255) NOT NULL, - description text, - engine character varying(20), - 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 (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 `mdb_databases_subjects` - ( - dbid BIGINT NOT NULL, - subjects character varying(255) NOT NULL, - PRIMARY KEY (dbid, subjects) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_tables` - ( - ID bigint NOT NULL AUTO_INCREMENT, - tDBID bigint NOT NULL, - internal_name character varying(255) NOT NULL, - queue_name character varying(255) NOT NULL, - routing_key character varying(255) NOT NULL, - tName VARCHAR(50), - tDescription TEXT, - NumCols INTEGER, - NumRows INTEGER, - `separator` CHAR(1), - quote CHAR(1), - element_null VARCHAR(50), - skip_lines BIGINT, - element_true VARCHAR(50), - element_false VARCHAR(50), - Version TEXT, - created timestamp NOT NULL DEFAULT NOW(), - versioned boolean not null default true, - 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 (created_by) REFERENCES mdb_users (id), - FOREIGN KEY (owned_by) REFERENCES mdb_users (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns` - ( - ID bigint NOT NULL AUTO_INCREMENT, - tID bigint NOT NULL, - dfID bigint, - cName VARCHAR(100), - internal_name VARCHAR(100) NOT NULL, - alias VARCHAR(100), - Datatype ENUM ('CHAR','VARCHAR','BINARY','VARBINARY','TINYBLOB','TINYTEXT','TEXT','BLOB','MEDIUMTEXT','MEDIUMBLOB','LONGTEXT','LONGBLOB','ENUM','SET','BIT','TINYINT','BOOL','SMALLINT','MEDIUMINT','INT','BIGINT','FLOAT','DOUBLE','DECIMAL','DATE','DATETIME','TIMESTAMP','TIME','YEAR'), - length INT NULL, - ordinal_position INTEGER NOT NULL, - is_primary_key BOOLEAN NOT NULL, - index_length INT NULL, - size INT, - d INT, - auto_generated BOOLEAN DEFAULT false, - is_null_allowed BOOLEAN NOT NULL DEFAULT true, - created timestamp NOT NULL DEFAULT NOW(), - last_modified timestamp, - FOREIGN KEY (tID) REFERENCES mdb_tables (ID), - PRIMARY KEY (ID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_enums` - ( - id bigint NOT NULL AUTO_INCREMENT, - column_id bigint NOT NULL, - value CHARACTER VARYING(255) NOT NULL, - FOREIGN KEY (column_id) REFERENCES mdb_columns (ID), - PRIMARY KEY (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_sets` - ( - id bigint NOT NULL AUTO_INCREMENT, - column_id bigint NOT NULL, - value CHARACTER VARYING(255) NOT NULL, - FOREIGN KEY (column_id) REFERENCES mdb_columns (ID), - PRIMARY KEY (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_nom` - ( - tID bigint, - cID bigint, - maxlength INTEGER, - last_modified timestamp, - created timestamp NOT NULL DEFAULT NOW(), - FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), - PRIMARY KEY (tID, cID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_num` - ( - tID bigint, - cID bigint, - SIunit TEXT, - MaxVal NUMERIC, - MinVal NUMERIC, - Mean NUMERIC, - Median NUMERIC, - Sd Numeric, +BEGIN; + +CREATE TABLE IF NOT EXISTS `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 `mdb_images` +( + id bigint NOT NULL AUTO_INCREMENT, + name character varying(255) NOT NULL, + version character varying(255) NOT NULL, + default_port integer NOT NULL, + dialect character varying(255) NOT NULL, + driver_class character varying(255) NOT NULL, + jdbc_method character varying(255) NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + last_modified timestamp, + PRIMARY KEY (id), + UNIQUE (name, version) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_images_date` +( + id bigint NOT NULL AUTO_INCREMENT, + iid bigint NOT NULL, + database_format character varying(255) NOT NULL, + unix_format character varying(255) NOT NULL, + example character varying(255) NOT NULL, + has_time boolean NOT NULL, + created_at timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (id), + FOREIGN KEY (iid) REFERENCES mdb_images (id), + UNIQUE (database_format, unix_format, example) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `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 default 3306, + ui_host character varying(255) NOT NULL default host, + ui_port integer NOT NULL default port, + ui_additional_flags text, + sidecar_host character varying(255) NOT NULL, + sidecar_port integer NOT NULL default 3305, + image_id bigint NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + last_modified timestamp, + privileged_username character varying(255) NOT NULL, + privileged_password character varying(255) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (image_id) REFERENCES mdb_images (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_data` +( + ID bigint NOT NULL AUTO_INCREMENT, + PROVENANCE text, + FileEncoding text, + FileType character varying(100), + Version text, + Seperator text, + PRIMARY KEY (ID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_licenses` +( + identifier character varying(255) NOT NULL, + uri text NOT NULL, + PRIMARY KEY (identifier), + UNIQUE (uri(200)) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_databases` +( + id bigint NOT NULL AUTO_INCREMENT, + cid bigint NOT NULL, + name character varying(255) NOT NULL, + internal_name character varying(255) NOT NULL, + exchange_name character varying(255) NOT NULL, + description text, + engine character varying(20), + 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 (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 `mdb_databases_subjects` +( + dbid BIGINT NOT NULL, + subjects character varying(255) NOT NULL, + PRIMARY KEY (dbid, subjects) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_tables` +( + ID bigint NOT NULL AUTO_INCREMENT, + tDBID bigint NOT NULL, + internal_name character varying(255) NOT NULL, + queue_name character varying(255) NOT NULL, + routing_key character varying(255) NOT NULL, + tName VARCHAR(50), + tDescription TEXT, + NumCols INTEGER, + NumRows INTEGER, + `separator` CHAR(1), + quote CHAR(1), + element_null VARCHAR(50), + skip_lines BIGINT, + element_true VARCHAR(50), + element_false VARCHAR(50), + Version TEXT, + created timestamp NOT NULL DEFAULT NOW(), + versioned boolean not null default true, + 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 (created_by) REFERENCES mdb_users (id), + FOREIGN KEY (owned_by) REFERENCES mdb_users (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns` +( + ID bigint NOT NULL AUTO_INCREMENT, + tID bigint NOT NULL, + dfID bigint, + cName VARCHAR(100), + internal_name VARCHAR(100) NOT NULL, + alias VARCHAR(100), + Datatype ENUM ('char','varchar','binary','varbinary','tinyblob','tinytext','text','blob','mediumtext','mediumblob','longtext','longblob','enum','set','bit','tinyint','bool','smallint','mediumint','int','bigint','float','double','decimal','date','datetime','timestamp','time','year'), + length INT NULL, + ordinal_position INTEGER NOT NULL, + is_primary_key BOOLEAN NOT NULL, + index_length INT NULL, + size INT, + d INT, + auto_generated BOOLEAN DEFAULT false, + is_null_allowed BOOLEAN NOT NULL DEFAULT true, + created timestamp NOT NULL DEFAULT NOW(), + last_modified timestamp, + FOREIGN KEY (tID) REFERENCES mdb_tables (ID), + PRIMARY KEY (ID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_enums` +( + id bigint NOT NULL AUTO_INCREMENT, + column_id bigint NOT NULL, + value CHARACTER VARYING(255) NOT NULL, + FOREIGN KEY (column_id) REFERENCES mdb_columns (ID), + PRIMARY KEY (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_sets` +( + id bigint NOT NULL AUTO_INCREMENT, + column_id bigint NOT NULL, + value CHARACTER VARYING(255) NOT NULL, + FOREIGN KEY (column_id) REFERENCES mdb_columns (ID), + PRIMARY KEY (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_nom` +( + tID bigint, + cID bigint, + maxlength INTEGER, + last_modified timestamp, + created timestamp NOT NULL DEFAULT NOW(), + FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), + PRIMARY KEY (tID, cID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_num` +( + tID bigint, + cID bigint, + SIunit TEXT, + MaxVal NUMERIC, + MinVal NUMERIC, + Mean NUMERIC, + Median NUMERIC, + Sd Numeric, -- Histogram INTEGER[], - last_modified timestamp, - created timestamp NOT NULL DEFAULT NOW(), - FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), - PRIMARY KEY (tID, cID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_cat` - ( - tID bigint, - cID bigint, - num_cat INTEGER, + last_modified timestamp, + created timestamp NOT NULL DEFAULT NOW(), + FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), + PRIMARY KEY (tID, cID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_cat` +( + tID bigint, + cID bigint, + num_cat INTEGER, -- cat_array TEXT[], - last_modified timestamp, - created timestamp NOT NULL DEFAULT NOW(), - FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), - PRIMARY KEY (tID, cID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_constraints_foreign_key` - ( - fkid BIGINT NOT NULL AUTO_INCREMENT, - tid BIGINT NOT NULL, - rtid BIGINT NOT NULL, - on_update VARCHAR(50) NULL, - on_delete VARCHAR(50) NULL, - position INT NULL, - PRIMARY KEY (fkid), - FOREIGN KEY (tid) REFERENCES mdb_tables (id), - FOREIGN KEY (rtid) REFERENCES mdb_tables (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_constraints_foreign_key_reference` - ( - id BIGINT NOT NULL AUTO_INCREMENT, - fkid BIGINT NOT NULL, - cid BIGINT NOT NULL, - rcid BIGINT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (fkid) REFERENCES mdb_constraints_foreign_key (fkid) ON UPDATE CASCADE, - FOREIGN KEY (cid) REFERENCES mdb_columns (id), - FOREIGN KEY (rcid) REFERENCES mdb_columns (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_constraints_unique` - ( - uid BIGINT NOT NULL AUTO_INCREMENT, - tid BIGINT NOT NULL, - position INT NULL, - PRIMARY KEY (uid), - FOREIGN KEY (tid) REFERENCES mdb_tables (id) - ); - - CREATE TABLE IF NOT EXISTS `mdb_constraints_unique_columns` - ( - id BIGINT NOT NULL AUTO_INCREMENT, - uid BIGINT NOT NULL, - cid BIGINT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (uid) REFERENCES mdb_constraints_unique (uid), - FOREIGN KEY (cid) REFERENCES mdb_columns (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_constraints_checks` - ( - id BIGINT NOT NULL AUTO_INCREMENT, - tid BIGINT NOT NULL, - checks VARCHAR(255) NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (tid) REFERENCES mdb_tables (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_concepts` - ( - id bigint NOT NULL AUTO_INCREMENT, - uri text not null, - name VARCHAR(255) null, - description TEXT null, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (id), - UNIQUE (uri(200)) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_units` - ( - id bigint NOT NULL AUTO_INCREMENT, - uri text not null, - name VARCHAR(255) null, - description TEXT null, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (id), - UNIQUE (uri(200)) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_concepts` - ( - id bigint NOT NULL, - cID bigint NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (id), - FOREIGN KEY (cID) REFERENCES mdb_columns (ID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_columns_units` - ( - id bigint NOT NULL, - cID bigint NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (id), - FOREIGN KEY (cID) REFERENCES mdb_columns (ID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_view` - ( - id bigint NOT NULL AUTO_INCREMENT, - vdbid bigint NOT NULL, - vName VARCHAR(255) NOT NULL, - internal_name VARCHAR(255) NOT NULL, - Query TEXT NOT NULL, - query_hash VARCHAR(255) NOT NULL, - Public BOOLEAN NOT NULL, - NumCols INTEGER, - NumRows INTEGER, - InitialView BOOLEAN NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - last_modified timestamp, - created_by character varying(36) NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (vdbid) REFERENCES mdb_databases (id), - FOREIGN KEY (created_by) REFERENCES mdb_users (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_banner_messages` - ( - id bigint NOT NULL AUTO_INCREMENT, - type ENUM ('ERROR', 'WARNING', 'INFO') NOT NULL default 'INFO', - message TEXT NOT NULL, - link TEXT NULL, - link_text VARCHAR(255) NULL, - display_start timestamp NULL, - display_end timestamp NULL, - PRIMARY KEY (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_ontologies` - ( - id bigint NOT NULL AUTO_INCREMENT, - prefix VARCHAR(8) NOT NULL, - uri TEXT NOT NULL, - uri_pattern TEXT, - sparql_endpoint TEXT NULL, - last_modified timestamp, - created timestamp NOT NULL DEFAULT NOW(), - UNIQUE (prefix), - UNIQUE (uri(200)), - PRIMARY KEY (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_view_columns` - ( - id BIGINT NOT NULL AUTO_INCREMENT, - cid BIGINT NOT NULL, - vid BIGINT NOT NULL, - position INTEGER NULL, - PRIMARY KEY (id), - FOREIGN KEY (vid) REFERENCES mdb_view (id), - FOREIGN KEY (cid) REFERENCES mdb_columns (ID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifiers` - ( - id bigint NOT NULL AUTO_INCREMENT, - dbid bigint, - qid bigint, - vid bigint, - publisher VARCHAR(255) NOT NULL, - language VARCHAR(2), - visibility ENUM ('SELF', 'EVERYONE') NOT NULL default 'EVERYONE', - publication_year INTEGER NOT NULL, - publication_month INTEGER, - publication_day INTEGER, - identifier_type ENUM ('DATABASE', 'SUBSET', 'VIEW') NOT NULL, - query TEXT, - query_normalized TEXT, - query_hash VARCHAR(255), - execution timestamp, - result_hash VARCHAR(255), - result_number bigint, - doi VARCHAR(255), - created timestamp NOT NULL DEFAULT NOW(), - 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), - FOREIGN KEY (created_by) REFERENCES mdb_users (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifier_licenses` - ( - pid bigint NOT NULL, - license_id VARCHAR(255) NOT NULL, - PRIMARY KEY (pid, license_id), - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id), - FOREIGN KEY (license_id) REFERENCES mdb_licenses (identifier) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifier_titles` - ( - id bigint NOT NULL AUTO_INCREMENT, - pid bigint NOT NULL, - title text NOT NULL, - title_type ENUM ('ALTERNATIVE_TITLE', 'SUBTITLE', 'TRANSLATED_TITLE', 'OTHER'), - language VARCHAR(2), - PRIMARY KEY (id), - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifier_funders` - ( - id bigint NOT NULL AUTO_INCREMENT, - pid bigint NOT NULL, - funder_name VARCHAR(255) NOT NULL, - funder_identifier TEXT, - funder_identifier_type ENUM ('CROSSREF_FUNDER_ID', 'GRID', 'ISNI', 'ROR', 'OTHER'), - scheme_uri text, - award_number VARCHAR(255), - award_title text, - language VARCHAR(255), - PRIMARY KEY (id), - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifier_descriptions` - ( - id bigint NOT NULL AUTO_INCREMENT, - pid bigint NOT NULL, - description text NOT NULL, - description_type ENUM ('ABSTRACT', 'METHODS', 'SERIES_INFORMATION', 'TABLE_OF_CONTENTS', 'TECHNICAL_INFO', 'OTHER'), - language VARCHAR(2), - PRIMARY KEY (id), - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_related_identifiers` - ( - id bigint NOT NULL AUTO_INCREMENT, - pid bigint NOT NULL, - value varchar(255) NOT NULL, - type varchar(255), - relation varchar(255), - PRIMARY KEY (id), /* must be a single id from persistent identifier concept */ - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id), - UNIQUE (pid, value) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_identifier_creators` - ( - id bigint NOT NULL AUTO_INCREMENT, - pid bigint NOT NULL, - given_names text, - family_name text, - creator_name VARCHAR(255) NOT NULL, - name_type ENUM ('PERSONAL', 'ORGANIZATIONAL') default 'PERSONAL', - name_identifier text, - name_identifier_scheme ENUM ('ROR', 'GRID', 'ISNI', 'ORCID'), - name_identifier_scheme_uri text, - affiliation VARCHAR(255), - affiliation_identifier text, - affiliation_identifier_scheme ENUM ('ROR', 'GRID', 'ISNI'), - affiliation_identifier_scheme_uri text, - PRIMARY KEY (id), - FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_feed` - ( - fDBID bigint, - fID bigint, - 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 (fUserId) REFERENCES mdb_users (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_update` - ( - uUserID character varying(255) NOT NULL, - uDBID bigint NOT NULL, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (uUserID, uDBID), - FOREIGN KEY (uDBID) REFERENCES mdb_databases (id) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_access` - ( - aUserID character varying(255) NOT NULL, - aDBID bigint REFERENCES mdb_databases (id), - attime TIMESTAMP, - download BOOLEAN, - created timestamp NOT NULL DEFAULT NOW(), - PRIMARY KEY (aUserID, aDBID) - ) WITH SYSTEM VERSIONING; - - CREATE TABLE IF NOT EXISTS `mdb_have_access` - ( - 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), - FOREIGN KEY (user_id) REFERENCES mdb_users (id) - ) WITH SYSTEM VERSIONING; - - COMMIT; - BEGIN; - - INSERT INTO `mdb_licenses` (identifier, uri) - VALUES ('MIT', 'https://opensource.org/licenses/MIT'), - ('GPL-3.0-only', 'https://www.gnu.org/licenses/gpl-3.0-standalone.html'), - ('BSD-3-Clause', 'https://opensource.org/licenses/BSD-3-Clause'), - ('BSD-4-Clause', 'http://directory.fsf.org/wiki/License:BSD_4Clause'), - ('Apache-2.0', 'https://opensource.org/licenses/Apache-2.0'), - ('CC0-1.0', 'https://creativecommons.org/publicdomain/zero/1.0/legalcode'), - ('CC-BY-4.0', 'https://creativecommons.org/licenses/by/4.0/legalcode'); - - INSERT INTO `mdb_images` (name, version, default_port, dialect, driver_class, jdbc_method) - VALUES ('mariadb', '11.1.3', 3306, 'org.hibernate.dialect.MariaDBDialect', 'org.mariadb.jdbc.Driver', 'mariadb'); - - INSERT INTO `mdb_images_date` (iid, database_format, unix_format, example, has_time) - VALUES (1, '%Y-%c-%d %H:%i:%S.%f', 'yyyy-MM-dd HH:mm:ss.SSSSSS', '2022-01-30 13:44:25.499', true), - (1, '%Y-%c-%d %H:%i:%S', 'yyyy-MM-dd HH:mm:ss', '2022-01-30 13:44:25', true), - (1, '%Y-%c-%d', 'yyyy-MM-dd', '2022-01-30', false), - (1, '%H:%i:%S', 'HH:mm:ss', '13:44:25', true); - - INSERT INTO `mdb_ontologies` (prefix, uri, uri_pattern, sparql_endpoint) - VALUES ('om', 'http://www.ontology-of-units-of-measure.org/resource/om-2/', - 'http://www.ontology-of-units-of-measure.org/resource/om-2/.*', null), - ('wd', 'http://www.wikidata.org/', 'http://www.wikidata.org/entity/.*', 'https://query.wikidata.org/sparql'), - ('mo', 'http://purl.org/ontology/mo/', 'http://purl.org/ontology/mo/.*', null), - ('dc', 'http://purl.org/dc/elements/1.1/', null, null), - ('xsd', 'http://www.w3.org/2001/XMLSchema#', null, null), - ('tl', 'http://purl.org/NET/c4dm/timeline.owl#', null, null), - ('foaf', 'http://xmlns.com/foaf/0.1/', null, null), - ('schema', 'http://schema.org/', null, null), - ('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', null, null), - ('rdfs', 'http://www.w3.org/2000/01/rdf-schema#', null, null), - ('owl', 'http://www.w3.org/2002/07/owl#', null, null), - ('prov', 'http://www.w3.org/ns/prov#', null, null), - ('db', 'http://dbpedia.org', 'http://dbpedia.org/ontology/.*', 'http://dbpedia.org/sparql'); - COMMIT; + last_modified timestamp, + created timestamp NOT NULL DEFAULT NOW(), + FOREIGN KEY (tID, cID) REFERENCES mdb_columns (tID, ID), + PRIMARY KEY (tID, cID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_constraints_foreign_key` +( + fkid BIGINT NOT NULL AUTO_INCREMENT, + tid BIGINT NOT NULL, + rtid BIGINT NOT NULL, + on_update VARCHAR(50) NULL, + on_delete VARCHAR(50) NULL, + position INT NULL, + PRIMARY KEY (fkid), + FOREIGN KEY (tid) REFERENCES mdb_tables (id), + FOREIGN KEY (rtid) REFERENCES mdb_tables (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_constraints_foreign_key_reference` +( + id BIGINT NOT NULL AUTO_INCREMENT, + fkid BIGINT NOT NULL, + cid BIGINT NOT NULL, + rcid BIGINT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (fkid) REFERENCES mdb_constraints_foreign_key (fkid) ON UPDATE CASCADE, + FOREIGN KEY (cid) REFERENCES mdb_columns (id), + FOREIGN KEY (rcid) REFERENCES mdb_columns (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_constraints_unique` +( + uid BIGINT NOT NULL AUTO_INCREMENT, + tid BIGINT NOT NULL, + position INT NULL, + PRIMARY KEY (uid), + FOREIGN KEY (tid) REFERENCES mdb_tables (id) +); + +CREATE TABLE IF NOT EXISTS `mdb_constraints_unique_columns` +( + id BIGINT NOT NULL AUTO_INCREMENT, + uid BIGINT NOT NULL, + cid BIGINT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (uid) REFERENCES mdb_constraints_unique (uid), + FOREIGN KEY (cid) REFERENCES mdb_columns (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_constraints_checks` +( + id BIGINT NOT NULL AUTO_INCREMENT, + tid BIGINT NOT NULL, + checks VARCHAR(255) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (tid) REFERENCES mdb_tables (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_concepts` +( + id bigint NOT NULL AUTO_INCREMENT, + uri text not null, + name VARCHAR(255) null, + description TEXT null, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (id), + UNIQUE (uri(200)) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_units` +( + id bigint NOT NULL AUTO_INCREMENT, + uri text not null, + name VARCHAR(255) null, + description TEXT null, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (id), + UNIQUE (uri(200)) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_concepts` +( + id bigint NOT NULL, + cID bigint NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (id), + FOREIGN KEY (cID) REFERENCES mdb_columns (ID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_columns_units` +( + id bigint NOT NULL, + cID bigint NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (id), + FOREIGN KEY (cID) REFERENCES mdb_columns (ID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_view` +( + id bigint NOT NULL AUTO_INCREMENT, + vdbid bigint NOT NULL, + vName VARCHAR(255) NOT NULL, + internal_name VARCHAR(255) NOT NULL, + Query TEXT NOT NULL, + query_hash VARCHAR(255) NOT NULL, + Public BOOLEAN NOT NULL, + NumCols INTEGER, + NumRows INTEGER, + InitialView BOOLEAN NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + last_modified timestamp, + created_by character varying(36) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (vdbid) REFERENCES mdb_databases (id), + FOREIGN KEY (created_by) REFERENCES mdb_users (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_banner_messages` +( + id bigint NOT NULL AUTO_INCREMENT, + type ENUM ('error', 'warning', 'info') NOT NULL default 'info', + message TEXT NOT NULL, + link TEXT NULL, + link_text VARCHAR(255) NULL, + display_start timestamp NULL, + display_end timestamp NULL, + PRIMARY KEY (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_ontologies` +( + id bigint NOT NULL AUTO_INCREMENT, + prefix VARCHAR(8) NOT NULL, + uri TEXT NOT NULL, + uri_pattern TEXT, + sparql_endpoint TEXT NULL, + last_modified timestamp, + created timestamp NOT NULL DEFAULT NOW(), + UNIQUE (prefix), + UNIQUE (uri(200)), + PRIMARY KEY (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_view_columns` +( + id BIGINT NOT NULL AUTO_INCREMENT, + cid BIGINT NOT NULL, + vid BIGINT NOT NULL, + position INTEGER NULL, + PRIMARY KEY (id), + FOREIGN KEY (vid) REFERENCES mdb_view (id), + FOREIGN KEY (cid) REFERENCES mdb_columns (ID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifiers` +( + id bigint NOT NULL AUTO_INCREMENT, + dbid bigint, + qid bigint, + vid bigint, + publisher VARCHAR(255) NOT NULL, + language VARCHAR(2), + visibility ENUM ('self', 'everyone') NOT NULL default 'everyone', + publication_year INTEGER NOT NULL, + publication_month INTEGER, + publication_day INTEGER, + identifier_type ENUM ('database', 'subset', 'view') NOT NULL, + query TEXT, + query_normalized TEXT, + query_hash VARCHAR(255), + execution timestamp, + result_hash VARCHAR(255), + result_number bigint, + doi VARCHAR(255), + created timestamp NOT NULL DEFAULT NOW(), + 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), + FOREIGN KEY (created_by) REFERENCES mdb_users (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifier_licenses` +( + pid bigint NOT NULL, + license_id VARCHAR(255) NOT NULL, + PRIMARY KEY (pid, license_id), + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id), + FOREIGN KEY (license_id) REFERENCES mdb_licenses (identifier) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifier_titles` +( + id bigint NOT NULL AUTO_INCREMENT, + pid bigint NOT NULL, + title text NOT NULL, + title_type ENUM ('alternative_title', 'subtitle', 'translated_title', 'other'), + language VARCHAR(2), + PRIMARY KEY (id), + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifier_funders` +( + id bigint NOT NULL AUTO_INCREMENT, + pid bigint NOT NULL, + funder_name VARCHAR(255) NOT NULL, + funder_identifier TEXT, + funder_identifier_type ENUM ('crossref_funder_id', 'grid', 'isni', 'ror', 'other'), + scheme_uri text, + award_number VARCHAR(255), + award_title text, + language VARCHAR(255), + PRIMARY KEY (id), + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifier_descriptions` +( + id bigint NOT NULL AUTO_INCREMENT, + pid bigint NOT NULL, + description text NOT NULL, + description_type ENUM ('abstract', 'methods', 'series_information', 'table_of_contents', 'technical_info', 'other'), + language VARCHAR(2), + PRIMARY KEY (id), + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_related_identifiers` +( + id bigint NOT NULL AUTO_INCREMENT, + pid bigint NOT NULL, + value varchar(255) NOT NULL, + type varchar(255), + relation varchar(255), + PRIMARY KEY (id), /* must be a single id from persistent identifier concept */ + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id), + UNIQUE (pid, value) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_identifier_creators` +( + id bigint NOT NULL AUTO_INCREMENT, + pid bigint NOT NULL, + given_names text, + family_name text, + creator_name VARCHAR(255) NOT NULL, + name_type ENUM ('personal', 'organizational') default 'personal', + name_identifier text, + name_identifier_scheme ENUM ('ror', 'grid', 'isni', 'orcid'), + name_identifier_scheme_uri text, + affiliation VARCHAR(255), + affiliation_identifier text, + affiliation_identifier_scheme ENUM ('ror', 'grid', 'isni'), + affiliation_identifier_scheme_uri text, + PRIMARY KEY (id), + FOREIGN KEY (pid) REFERENCES mdb_identifiers (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_feed` +( + fDBID bigint, + fID bigint, + 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 (fUserId) REFERENCES mdb_users (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_update` +( + uUserID character varying(255) NOT NULL, + uDBID bigint NOT NULL, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (uUserID, uDBID), + FOREIGN KEY (uDBID) REFERENCES mdb_databases (id) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_access` +( + aUserID character varying(255) NOT NULL, + aDBID bigint REFERENCES mdb_databases (id), + attime TIMESTAMP, + download BOOLEAN, + created timestamp NOT NULL DEFAULT NOW(), + PRIMARY KEY (aUserID, aDBID) +) WITH SYSTEM VERSIONING; + +CREATE TABLE IF NOT EXISTS `mdb_have_access` +( + 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), + FOREIGN KEY (user_id) REFERENCES mdb_users (id) +) WITH SYSTEM VERSIONING; + +COMMIT; +BEGIN; + +INSERT INTO `mdb_licenses` (identifier, uri) +VALUES ('MIT', 'https://opensource.org/licenses/MIT'), + ('GPL-3.0-only', 'https://www.gnu.org/licenses/gpl-3.0-standalone.html'), + ('BSD-3-Clause', 'https://opensource.org/licenses/BSD-3-Clause'), + ('BSD-4-Clause', 'http://directory.fsf.org/wiki/License:BSD_4Clause'), + ('Apache-2.0', 'https://opensource.org/licenses/Apache-2.0'), + ('CC0-1.0', 'https://creativecommons.org/publicdomain/zero/1.0/legalcode'), + ('CC-BY-4.0', 'https://creativecommons.org/licenses/by/4.0/legalcode'); + +INSERT INTO `mdb_images` (name, version, default_port, dialect, driver_class, jdbc_method) +VALUES ('mariadb', '11.1.3', 3306, 'org.hibernate.dialect.MariaDBDialect', 'org.mariadb.jdbc.Driver', 'mariadb'); + +INSERT INTO `mdb_images_date` (iid, database_format, unix_format, example, has_time) +VALUES (1, '%Y-%c-%d %H:%i:%S.%f', 'yyyy-MM-dd HH:mm:ss.SSSSSS', '2022-01-30 13:44:25.499', true), + (1, '%Y-%c-%d %H:%i:%S', 'yyyy-MM-dd HH:mm:ss', '2022-01-30 13:44:25', true), + (1, '%Y-%c-%d', 'yyyy-MM-dd', '2022-01-30', false), + (1, '%H:%i:%S', 'HH:mm:ss', '13:44:25', true); + +INSERT INTO `mdb_ontologies` (prefix, uri, uri_pattern, sparql_endpoint) +VALUES ('om', 'http://www.ontology-of-units-of-measure.org/resource/om-2/', + 'http://www.ontology-of-units-of-measure.org/resource/om-2/.*', null), + ('wd', 'http://www.wikidata.org/', 'http://www.wikidata.org/entity/.*', 'https://query.wikidata.org/sparql'), + ('mo', 'http://purl.org/ontology/mo/', 'http://purl.org/ontology/mo/.*', null), + ('dc', 'http://purl.org/dc/elements/1.1/', null, null), + ('xsd', 'http://www.w3.org/2001/XMLSchema#', null, null), + ('tl', 'http://purl.org/NET/c4dm/timeline.owl#', null, null), + ('foaf', 'http://xmlns.com/foaf/0.1/', null, null), + ('schema', 'http://schema.org/', null, null), + ('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', null, null), + ('rdfs', 'http://www.w3.org/2000/01/rdf-schema#', null, null), + ('owl', 'http://www.w3.org/2002/07/owl#', null, null), + ('prov', 'http://www.w3.org/ns/prov#', null, null), + ('db', 'http://dbpedia.org', 'http://dbpedia.org/ontology/.*', 'http://dbpedia.org/sparql'); +COMMIT; diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/AccessTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/AccessTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..80aa0686280085f2710c419b3d150d927588eb9e --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/AccessTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.database.AccessType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class AccessTypeConverter implements AttributeConverter<AccessType, String> { + + @Override + public String convertToDatabaseColumn(AccessType accessType) { + return accessType.name() + .toLowerCase(); + } + + @Override + public AccessType convertToEntityAttribute(String accessType) { + return AccessType.valueOf(accessType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierAffiliationIdentifierSchemeTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierAffiliationIdentifierSchemeTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..ba8a0a43fb6c3fe5a99a7704cd3f3e8620fff0c5 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierAffiliationIdentifierSchemeTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.AffiliationIdentifierSchemeType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierAffiliationIdentifierSchemeTypeConverter implements AttributeConverter<AffiliationIdentifierSchemeType, String> { + + @Override + public String convertToDatabaseColumn(AffiliationIdentifierSchemeType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public AffiliationIdentifierSchemeType convertToEntityAttribute(String columnType) { + return AffiliationIdentifierSchemeType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierDescriptionTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierDescriptionTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..767733862d7423e2c7747200c967b4315f28db62 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierDescriptionTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.DescriptionType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierDescriptionTypeConverter implements AttributeConverter<DescriptionType, String> { + + @Override + public String convertToDatabaseColumn(DescriptionType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public DescriptionType convertToEntityAttribute(String columnType) { + return DescriptionType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierFunderTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierFunderTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..48d4200b2078df0e1d837338107a8469aedd42ce --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierFunderTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.IdentifierFunderType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierFunderTypeConverter implements AttributeConverter<IdentifierFunderType, String> { + + @Override + public String convertToDatabaseColumn(IdentifierFunderType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public IdentifierFunderType convertToEntityAttribute(String columnType) { + return IdentifierFunderType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierIdentifierTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierIdentifierTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..f44a393663facd7a31a61fb301a6b5c716e32bd6 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierIdentifierTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.IdentifierType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierIdentifierTypeConverter implements AttributeConverter<IdentifierType, String> { + + @Override + public String convertToDatabaseColumn(IdentifierType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public IdentifierType convertToEntityAttribute(String columnType) { + return IdentifierType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameIdentifierSchemeTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameIdentifierSchemeTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..365177d783b118983a2e18c7c7078c5b7735787c --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameIdentifierSchemeTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.NameIdentifierSchemeType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierNameIdentifierSchemeTypeConverter implements AttributeConverter<NameIdentifierSchemeType, String> { + + @Override + public String convertToDatabaseColumn(NameIdentifierSchemeType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public NameIdentifierSchemeType convertToEntityAttribute(String columnType) { + return NameIdentifierSchemeType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..8eb9fc7afe423a232610d8272e2c0b5b9e7757b8 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierNameTypeConverter.java @@ -0,0 +1,21 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.NameType; +import at.tuwien.entities.identifier.RelatedType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierNameTypeConverter implements AttributeConverter<NameType, String> { + + @Override + public String convertToDatabaseColumn(NameType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public NameType convertToEntityAttribute(String columnType) { + return NameType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierRelatedTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierRelatedTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..1fef4cb8b26aeea62c0e3a65a674f79175680f1d --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierRelatedTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.RelatedType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierRelatedTypeConverter implements AttributeConverter<RelatedType, String> { + + @Override + public String convertToDatabaseColumn(RelatedType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public RelatedType convertToEntityAttribute(String columnType) { + return RelatedType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierVisibilityTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierVisibilityTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..756f73b84768b882b1f1b23caaf8c201f0e4bbc6 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/IdentifierVisibilityTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.identifier.VisibilityType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class IdentifierVisibilityTypeConverter implements AttributeConverter<VisibilityType, String> { + + @Override + public String convertToDatabaseColumn(VisibilityType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public VisibilityType convertToEntityAttribute(String columnType) { + return VisibilityType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/LanguageTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/LanguageTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..5d132af64d375a1cbc62fa11d70eb4444dfb3377 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/LanguageTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.database.LanguageType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class LanguageTypeConverter implements AttributeConverter<LanguageType, String> { + + @Override + public String convertToDatabaseColumn(LanguageType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public LanguageType convertToEntityAttribute(String columnType) { + return LanguageType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/TableColumnTypeConverter.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/TableColumnTypeConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..7be348e8fd754fc5a10f31217b0af10872a4d094 --- /dev/null +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/converters/TableColumnTypeConverter.java @@ -0,0 +1,20 @@ +package at.tuwien.converters; + +import at.tuwien.entities.database.table.columns.TableColumnType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class TableColumnTypeConverter implements AttributeConverter<TableColumnType, String> { + + @Override + public String convertToDatabaseColumn(TableColumnType columnType) { + return columnType.name() + .toLowerCase(); + } + + @Override + public TableColumnType convertToEntityAttribute(String columnType) { + return TableColumnType.valueOf(columnType.toUpperCase()); + } +} diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/AccessType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/AccessType.java index 19a642ff965c7c1b930e67e31fa6b41decb59e67..c14042c070f173d80030148c01f34b8c93e01c4a 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/AccessType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/AccessType.java @@ -4,9 +4,22 @@ import lombok.Getter; import lombok.ToString; @Getter -@ToString public enum AccessType { - READ, - WRITE_OWN, - WRITE_ALL; + + READ("read"), + + WRITE_OWN("write_own"), + + WRITE_ALL("write_all"); + + private String name; + + AccessType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/Database.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/Database.java index 60e5bb57e5b0ab0c20e3c06b1932d7a76772109f..2f01dc84c5e4b2cbf9753662d78ec37fe3c86c6c 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/Database.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/Database.java @@ -107,7 +107,7 @@ public class Database implements Serializable { @OneToOne(fetch = FetchType.LAZY) @JoinColumnsOrFormulas({ @JoinColumnOrFormula(column = @JoinColumn(name = "id", referencedColumnName = "dbid", insertable = false, updatable = false)), - @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "identifier_type", value = "'DATABASE'")) + @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "identifier_type", value = "'database'")) }) private Identifier identifier; diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/DatabaseAccess.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/DatabaseAccess.java index 8492ee757feffab1f0045ccf2bbe004081042bc1..3a1748e385bc5081e3f930a6b759634b158175ec 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/DatabaseAccess.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/DatabaseAccess.java @@ -1,5 +1,6 @@ package at.tuwien.entities.database; +import at.tuwien.converters.AccessTypeConverter; import at.tuwien.entities.user.User; import lombok.*; import org.hibernate.annotations.JdbcTypeCode; @@ -50,8 +51,8 @@ public class DatabaseAccess { }) private Database database; - @Column(nullable = false, name = "access_type", columnDefinition = "enum('READ', 'WRITE_OWN', 'WRITE_ALL')") - @Enumerated(EnumType.STRING) + @Column(nullable = false, name = "access_type", columnDefinition = "enum('read', 'write_own', 'write_all')") + @Convert(converter = AccessTypeConverter.class) private AccessType type; @Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP") diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/View.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/View.java index 569ae61ea7100f246f85da3ac3cabe5f8f4d589f..5961cc7e7cbbddf925bc9e8445d16e369d4a02de 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/View.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/View.java @@ -85,7 +85,7 @@ public class View { @OneToOne(fetch = FetchType.LAZY) @JoinColumnsOrFormulas({ @JoinColumnOrFormula(column = @JoinColumn(name = "id", referencedColumnName = "vid", insertable = false, updatable = false)), - @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "identifier_type", value = "'VIEW'")) + @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "identifier_type", value = "'view'")) }) private Identifier identifier; diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumn.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumn.java index 98c5d5d8895fb4839f539db0331fd23f9bedf7fd..6a0ecd6de983cf09722372e7ba2d369c35edfeea 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumn.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumn.java @@ -1,5 +1,6 @@ package at.tuwien.entities.database.table.columns; +import at.tuwien.converters.TableColumnTypeConverter; import at.tuwien.entities.container.image.ContainerImageDate; import at.tuwien.entities.database.View; import at.tuwien.entities.database.table.Table; @@ -10,6 +11,7 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import jakarta.persistence.*; + import java.time.Instant; import java.util.List; @@ -69,8 +71,8 @@ public class TableColumn implements Comparable<TableColumn> { @Column private String alias; - @Column(name = "datatype", nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "datatype", nullable = false, columnDefinition = "ENUM('char','varchar','binary','varbinary','tinyblob','tinytext','text','blob','mediumtext','mediumblob','longtext','longblob','enum','set','bit','tinyint','bool','smallint','mediumint','int','bigint','float','double','decimal','date','datetime','timestamp','time','year')") + @Convert(converter = TableColumnTypeConverter.class) private TableColumnType columnType; @Column diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumnType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumnType.java index 074620a349fff43977ad585a7e4abe4ad770f39e..cf3bed9a85cdbc8492363454f2c9c077b8c2be27 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumnType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/database/table/columns/TableColumnType.java @@ -4,35 +4,74 @@ import lombok.Getter; import lombok.ToString; @Getter -@ToString public enum TableColumnType { - CHAR, - VARCHAR, - BINARY, - VARBINARY, - TINYBLOB, - TINYTEXT, - TEXT, - BLOB, - MEDIUMTEXT, - MEDIUMBLOB, - LONGTEXT, - LONGBLOB, - ENUM, - SET, - BIT, - TINYINT, - BOOL, - SMALLINT, - MEDIUMINT, - INT, - BIGINT, - FLOAT, - DOUBLE, - DECIMAL, - DATE, - DATETIME, - TIMESTAMP, - TIME, - YEAR; + + CHAR("char"), + + VARCHAR("varchar"), + + BINARY("binary"), + + VARBINARY("varbinary"), + + TINYBLOB("tinyblob"), + + TINYTEXT("tinytext"), + + TEXT("text"), + + BLOB("blob"), + + MEDIUMTEXT("mediumtext"), + + MEDIUMBLOB("mediumblob"), + + LONGTEXT("longtext"), + + LONGBLOB("longblob"), + + ENUM("enum"), + + SET("set"), + + BIT("bit"), + + TINYINT("tinyint"), + + BOOL("bool"), + + SMALLINT("smallint"), + + MEDIUMINT("mediumint"), + + INT("int"), + + BIGINT("bigint"), + + FLOAT("float"), + + DOUBLE("double"), + + DECIMAL("decimal"), + + DATE("date"), + + DATETIME("datetime"), + + TIMESTAMP("timestamp"), + + TIME("time"), + + YEAR("year"); + + private String name; + + TableColumnType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } \ No newline at end of file diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/AffiliationIdentifierSchemeType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/AffiliationIdentifierSchemeType.java index 0d794ff431005a17a34294b19816ea84cc6e3ab6..5c3f62d6e719fd568e502411b6295d0302756428 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/AffiliationIdentifierSchemeType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/AffiliationIdentifierSchemeType.java @@ -5,7 +5,21 @@ import lombok.Getter; @Getter public enum AffiliationIdentifierSchemeType { - ROR, - GRID, - ISNI + + ROR("ror"), + + GRID("grid"), + + ISNI("isni"); + + private String name; + + AffiliationIdentifierSchemeType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Creator.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Creator.java index d3a3e372d0cd110a9fadf6973c8f9197f237407a..4119bba2579b98d1c09451f20335856fa2f032a4 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Creator.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Creator.java @@ -1,5 +1,8 @@ package at.tuwien.entities.identifier; +import at.tuwien.converters.IdentifierAffiliationIdentifierSchemeTypeConverter; +import at.tuwien.converters.IdentifierNameIdentifierSchemeTypeConverter; +import at.tuwien.converters.IdentifierNameTypeConverter; import lombok.*; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -32,15 +35,15 @@ public class Creator { @Column(name = "creator_name", nullable = false) private String creatorName; - @Column(columnDefinition = "enum('PERSONAL', 'ORGANIZATIONAL')") - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('personal', 'organizational')") + @Convert(converter = IdentifierNameTypeConverter.class) private NameType nameType; @Column private String nameIdentifier; - @Column(columnDefinition = "enum('ROR', 'GRID', 'ISNI', 'ORCID')") - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('ror', 'grid', 'isni', 'orcid')") + @Convert(converter = IdentifierNameIdentifierSchemeTypeConverter.class) private NameIdentifierSchemeType nameIdentifierScheme; @Column @@ -52,8 +55,8 @@ public class Creator { @Column private String affiliationIdentifier; - @Column(columnDefinition = "enum('ROR', 'GRID', 'ISNI')") - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('ror', 'grid', 'isni')") + @Convert(converter = IdentifierAffiliationIdentifierSchemeTypeConverter.class) private AffiliationIdentifierSchemeType affiliationIdentifierScheme; private String affiliationIdentifierSchemeUri; diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java index df3ee6fff9b9dc93d0b7526af5d8abe4f698aab5..ef8f0405c18e696b46ae8976532a779aeea29485 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java @@ -1,5 +1,7 @@ package at.tuwien.entities.identifier; +import at.tuwien.converters.IdentifierIdentifierTypeConverter; +import at.tuwien.converters.IdentifierVisibilityTypeConverter; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.LanguageType; import at.tuwien.entities.database.License; @@ -27,11 +29,11 @@ import java.util.UUID; @EntityListeners(AuditingEntityListener.class) @Table(name = "mdb_identifiers") @NamedQueries({ - @NamedQuery(name = "Identifier.findAllDatabaseIdentifiers", query = "select i from Identifier i where i.type = 'DATABASE'"), - @NamedQuery(name = "Identifier.findAllSubsetIdentifiers", query = "select i from Identifier i where i.type = 'SUBSET'"), - @NamedQuery(name = "Identifier.findDatabaseIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.type = 'DATABASE'"), - @NamedQuery(name = "Identifier.findSubsetIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.queryId = ?2 and i.type = 'SUBSET'"), - @NamedQuery(name = "Identifier.findViewIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.viewId = ?2 and i.type = 'VIEW'"), + @NamedQuery(name = "Identifier.findAllDatabaseIdentifiers", query = "select i from Identifier i where i.type = 'database'"), + @NamedQuery(name = "Identifier.findAllSubsetIdentifiers", query = "select i from Identifier i where i.type = 'subset'"), + @NamedQuery(name = "Identifier.findDatabaseIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.type = 'database'"), + @NamedQuery(name = "Identifier.findSubsetIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.queryId = ?2 and i.type = 'subset'"), + @NamedQuery(name = "Identifier.findViewIdentifier", query = "select i from Identifier i where i.databaseId = ?1 and i.viewId = ?2 and i.type = 'view'"), }) public class Identifier implements Serializable { @@ -83,8 +85,8 @@ public class Identifier implements Serializable { ) private List<License> licenses; - @Column(name = "identifier_type", nullable = false, columnDefinition = "enum('SUBSET', 'DATABASE', 'VIEW')") - @Enumerated(EnumType.STRING) + @Column(name = "identifier_type", nullable = false, columnDefinition = "enum('subset', 'database', 'view')") + @Convert(converter = IdentifierIdentifierTypeConverter.class) private IdentifierType type; @Column(columnDefinition = "TEXT") @@ -121,8 +123,8 @@ public class Identifier implements Serializable { @Column private Integer publicationDay; - @Column(nullable = false, columnDefinition = "enum('EVERYONE', 'SELF')") - @Enumerated(EnumType.STRING) + @Column(nullable = false, columnDefinition = "enum('everyone', 'self')") + @Convert(converter = IdentifierVisibilityTypeConverter.class) private VisibilityType visibility; @ToString.Exclude diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierDescription.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierDescription.java index 26b88690637d34cc81b135550ab191c8a108a414..4ead69810942835163fd64f9cce38bd8d50c431a 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierDescription.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierDescription.java @@ -1,5 +1,7 @@ package at.tuwien.entities.identifier; +import at.tuwien.converters.IdentifierDescriptionTypeConverter; +import at.tuwien.converters.LanguageTypeConverter; import at.tuwien.entities.database.LanguageType; import jakarta.persistence.*; import lombok.*; @@ -30,12 +32,12 @@ public class IdentifierDescription implements Serializable { private String description; @Field(name = "description_type") - @Column(columnDefinition = "enum('ABSTRACT', 'METHODS', 'SERIES_INFORMATION', 'TABLE_OF_CONTENTS', 'TECHNICAL_INFO', 'OTHER')") - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('abstract', 'methods', 'series_information', 'table_of_contents', 'technical_info', 'other')") + @Convert(converter = IdentifierDescriptionTypeConverter.class) private DescriptionType descriptionType; - @Column(columnDefinition = "enum('AB','AA','AF','AK','SQ','AM','AR','AN','HY','AS','AV','AE','AY','AZ','BM','BA','EU','BE','BN','BH','BI','BS','BR','BG','MY','CA','KM','CH','CE','NY','ZH','CU','CV','KW','CO','CR','HR','CS','DA','DV','NL','DZ','EN','EO','ET','EE','FO','FJ','FI','FR','FF','GD','GL','LG','KA','DE','KI','EL','KL','GN','GU','HT','HA','HE','HZ','HI','HO','HU','IS','IO','IG','ID','IA','IE','IU','IK','GA','IT','JA','JV','KN','KR','KS','KK','RW','KV','KG','KO','KJ','KU','KY','LO','LA','LV','LB','LI','LN','LT','LU','MK','MG','MS','ML','MT','GV','MI','MR','MH','RO','MN','NA','NV','ND','NG','NE','SE','NO','NB','NN','II','OC','OJ','OR','OM','OS','PI','PA','PS','FA','PL','PT','QU','RM','RN','RU','SM','SG','SA','SC','SR','SN','SD','SI','SK','SL','SO','ST','NR','ES','SU','SW','SS','SV','TL','TY','TG','TA','TT','TE','TH','BO','TI','TO','TS','TN','TR','TK','TW','UG','UK','UR','UZ','VE','VI','VO','WA','CY','FY','WO','XH','YI','YO','ZA','ZU')") - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('ab','aa','af','ak','sq','am','ar','an','hy','as','av','ae','ay','az','bm','ba','eu','be','bn','bh','bi','bs','br','bg','my','ca','km','ch','ce','ny','zh','cu','cv','kw','co','cr','hr','cs','da','dv','nl','dz','en','eo','et','ee','fo','fj','fi','fr','ff','gd','gl','lg','ka','de','ki','el','kl','gn','gu','ht','ha','he','hz','hi','ho','hu','is','io','ig','id','ia','ie','iu','ik','ga','it','ja','jv','kn','kr','ks','kk','rw','kv','kg','ko','kj','ku','ky','lo','la','lv','lb','li','ln','lt','lu','mk','mg','ms','ml','mt','gv','mi','mr','mh','ro','mn','na','nv','nd','ng','ne','se','no','nb','nn','ii','oc','oj','or','om','os','pi','pa','ps','fa','pl','pt','qu','rm','rn','ru','sm','sg','sa','sc','sr','sn','sd','si','sk','sl','so','st','nr','es','su','sw','ss','sv','tl','ty','tg','ta','tt','te','th','bo','ti','to','ts','tn','tr','tk','tw','ug','uk','ur','uz','ve','vi','vo','wa','cy','fy','wo','xh','yi','yo','za','zu')") + @Convert(converter = LanguageTypeConverter.class) private LanguageType language; @ToString.Exclude diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunder.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunder.java index 65a7b9fdc26e686d1a60d7f92e82a955658a4c2c..cdf4b148c66d0487d0b1b9d6ad799e0370a1f9d2 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunder.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunder.java @@ -1,5 +1,6 @@ package at.tuwien.entities.identifier; +import at.tuwien.converters.IdentifierFunderTypeConverter; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.GenericGenerator; @@ -34,8 +35,8 @@ public class IdentifierFunder implements Serializable { private String funderIdentifier; @Field(name = "funder_identifier_type") - @Column(name="funder_identifier_type", columnDefinition = "enum('CROSSREF_FUNDER_ID', 'ROR', 'GND', 'ISNI', 'OTHER')") - @Enumerated(EnumType.STRING) + @Column(name="funder_identifier_type", columnDefinition = "enum('crossref_funder_id', 'ror', 'gnd', 'isni', 'other')") + @Convert(converter = IdentifierFunderTypeConverter.class) private IdentifierFunderType funderIdentifierType; @Field(name = "scheme_uri") diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunderType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunderType.java index ea538dcbfbc062884c19cfc4998e33c114f189d9..12b31112c66820f1e2e65ffe601b15b49cece8d1 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunderType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierFunderType.java @@ -1,9 +1,26 @@ package at.tuwien.entities.identifier; public enum IdentifierFunderType { - CROSSREF_FUNDER_ID, - ROR, - GND, - ISNI, - OTHER + + CROSSREF_FUNDER_ID("crossref_funder_id"), + + ROR("ror"), + + GND("gnd"), + + ISNI("isni"), + + OTHER("other"); + + private String name; + + IdentifierFunderType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + } diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierType.java index 54badf37095af4d28567198b16ca04cdfcd03983..a0d143cff0a1161864b11e9e3a18ea88f5b5fafc 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/IdentifierType.java @@ -1,7 +1,24 @@ package at.tuwien.entities.identifier; +import lombok.Getter; + +@Getter public enum IdentifierType { - DATABASE, - SUBSET, - VIEW; + + DATABASE("database"), + + SUBSET("subset"), + + VIEW("view"); + + private String name; + + IdentifierType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/NameIdentifierSchemeType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/NameIdentifierSchemeType.java index 6a7eb73a12a15cfd7360cfe7e3034349caa0b75f..e5564249cf25afe723978e1e8d672e4f803a5978 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/NameIdentifierSchemeType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/NameIdentifierSchemeType.java @@ -5,8 +5,23 @@ import lombok.Getter; @Getter public enum NameIdentifierSchemeType { - ORCID, - ROR, - ISNI, - GRID + + ORCID("orcid"), + + ROR("ror"), + + ISNI("isni"), + + GRID("grid"); + + private String name; + + NameIdentifierSchemeType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/RelatedIdentifier.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/RelatedIdentifier.java index a2a8a17ff794251ef6fa4c23f2ad089fb1e9b586..69c04c8d175c6bc01e7f006d582dc1eb8c278de9 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/RelatedIdentifier.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/RelatedIdentifier.java @@ -1,5 +1,6 @@ package at.tuwien.entities.identifier; +import at.tuwien.converters.IdentifierRelatedTypeConverter; import lombok.*; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -29,11 +30,11 @@ public class RelatedIdentifier { @Column(nullable = false) private String value; - @Column - @Enumerated(EnumType.STRING) + @Column(columnDefinition = "enum('doi', 'url', 'urn', 'ark', 'arxiv', 'bibcode', 'ean13', 'eissn', 'handle', 'igsn', 'isbn', 'istc', 'lissn', 'lsid', 'pmid', 'purl', 'upc', 'w3id')") + @Convert(converter = IdentifierRelatedTypeConverter.class) private RelatedType type; - @Column + @Column(columnDefinition = "enum('is_cited_by', 'cites', 'is_supplement_to', 'is_supplemented_by', 'is_continued_by', 'continues', 'is_described_by', 'describes', 'has_metadata', 'is_metadata_for', 'has_version', 'is_version_of', 'is_new_version_of', 'is_previous_version_of', 'is_part_of', 'has_part', 'is_published_in', 'is_referenced_by', 'references', 'is_documented_by', 'documents', 'is_compiled_by', 'compiles', 'is_variant_form_of', 'is_original_form_of', 'is_identical_to', 'is_reviewed_by', 'reviews', 'is_derived_from', 'is_source_of', 'is_required_by', 'requires', 'is_obsoleted_by', 'obsoletes')") @Enumerated(EnumType.STRING) private RelationType relation; diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/VisibilityType.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/VisibilityType.java index 3565740c6b2042fd4fdb003e68a19f369710efcf..28efa248347c6c62297ffb668f29bbec81cf9174 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/VisibilityType.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/identifier/VisibilityType.java @@ -4,8 +4,20 @@ import lombok.Getter; import lombok.ToString; @Getter -@ToString public enum VisibilityType { - EVERYONE, - SELF; + + EVERYONE("everyone"), + + SELF("self"); + + private String name; + + VisibilityType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } } \ No newline at end of file diff --git a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/maintenance/BannerMessage.java b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/maintenance/BannerMessage.java index b268e3f5a05ae8f547cd7dc22418b3a3b2bec030..befcec9c73b668e93fc81e1aee53fd6558988aa1 100644 --- a/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/maintenance/BannerMessage.java +++ b/dbrepo-metadata-service/entities/src/main/java/at/tuwien/entities/maintenance/BannerMessage.java @@ -28,7 +28,7 @@ public class BannerMessage { private Long id; @Enumerated(EnumType.STRING) - @Column(nullable = false, columnDefinition = "enum('ERROR','WARNING','INFO')") + @Column(nullable = false, columnDefinition = "enum('error', 'warning', 'info')") private BannerMessageType type; @Column(nullable = false) diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/converters/IdentifierTypeConverterUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/converters/IdentifierTypeConverterUnitTest.java deleted file mode 100644 index 0dae5e2840732b7fad0d723ce8f0d75aa0041ec3..0000000000000000000000000000000000000000 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/converters/IdentifierTypeConverterUnitTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package at.tuwien.converters; - -import at.tuwien.BaseUnitTest; -import at.tuwien.annotations.MockAmqp; -import at.tuwien.annotations.MockOpensearch; -import at.tuwien.api.identifier.IdentifierTypeDto; -import lombok.extern.log4j.Log4j2; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@ExtendWith(SpringExtension.class) -@AutoConfigureMockMvc -@SpringBootTest -@MockAmqp -@MockOpensearch -public class IdentifierTypeConverterUnitTest extends BaseUnitTest { - - @Autowired - private IdentifierTypeConverter identifierTypeConverter; - - @Test - public void convert_succeeds() { - - /* test */ - for (String name : List.of("DATABASE", "SUBSET", "VIEW")) { - final IdentifierTypeDto response = identifierTypeConverter.convert(name); - assertEquals(IdentifierTypeDto.valueOf(name), response); - } - } - - @Test - public void convert_fails() { - - /* test */ - assertThrows(Exception.class, () -> { - identifierTypeConverter.convert("idonotexist"); - }); - } - -} diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/JacksonConfig.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/JacksonConfig.java index c4944a469174ad1962d5c54cc483400dbee12f1d..69777fe635b103c1f3b4380f31ba11bcdc92a878 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/JacksonConfig.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/JacksonConfig.java @@ -3,6 +3,7 @@ package at.tuwien.config; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.cfg.EnumFeature; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import lombok.extern.slf4j.Slf4j; @@ -22,6 +23,7 @@ public class JacksonConfig { objectMapper.registerModule(new Jdk8Module()); objectMapper.registerModule(new JavaTimeModule()); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.configure(EnumFeature.WRITE_ENUMS_TO_LOWERCASE, true); objectMapper.setTimeZone(TimeZone.getTimeZone("UTC")); log.debug("current time is {}", objectMapper.writeValueAsString(new Date())); return objectMapper; diff --git a/dbrepo-mirror-service/services/src/main/java/at/tuwien/config/JacksonConfig.java b/dbrepo-mirror-service/services/src/main/java/at/tuwien/config/JacksonConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..69777fe635b103c1f3b4380f31ba11bcdc92a878 --- /dev/null +++ b/dbrepo-mirror-service/services/src/main/java/at/tuwien/config/JacksonConfig.java @@ -0,0 +1,32 @@ +package at.tuwien.config; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.cfg.EnumFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Date; +import java.util.TimeZone; + +@Slf4j +@Configuration +public class JacksonConfig { + + @Bean + public ObjectMapper objectMapper() throws JsonProcessingException { + final ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new Jdk8Module()); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.configure(EnumFeature.WRITE_ENUMS_TO_LOWERCASE, true); + objectMapper.setTimeZone(TimeZone.getTimeZone("UTC")); + log.debug("current time is {}", objectMapper.writeValueAsString(new Date())); + return objectMapper; + } + +} diff --git a/dbrepo-search-service/app/api/routes.py b/dbrepo-search-service/app/api/routes.py index 695e50e0430c93a2b812a68173d44d08e59afdb6..b212c81d14a01b7656f709d0e27e959fc33cbd5b 100644 --- a/dbrepo-search-service/app/api/routes.py +++ b/dbrepo-search-service/app/api/routes.py @@ -152,10 +152,11 @@ def search(): req_body = request.json logging.debug('search request body: %s', req_body) search_term = req_body.get("search_term") + type = req_body.get("type") t1 = req_body.get("t1") t2 = req_body.get("t2") field = req_body.get("field") value = req_body.get("value") - fieldValuePairs = req_body.get("fieldValuePairs") - response = general_search(search_term, t1, t2, fieldValuePairs) + fieldValuePairs = req_body.get("field_value_pairs") + response = general_search(type, search_term, t1, t2, fieldValuePairs) return response, 200 diff --git a/dbrepo-search-service/app/opensearch_client.py b/dbrepo-search-service/app/opensearch_client.py index 20b5d4bccb42647841c426249ec4a5759bb6cd80..c3d3f575b7a4942c4dda21b9b66383e03b66082f 100644 --- a/dbrepo-search-service/app/opensearch_client.py +++ b/dbrepo-search-service/app/opensearch_client.py @@ -111,7 +111,7 @@ def get_fields_for_index(index): return fields_list -def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): +def general_search(type=None, search_term=None, t1=None, t2=None, fieldValuePairs=None): """ Main method for seaching stuff in the opensearch db @@ -134,6 +134,9 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): "identifier.creators.*.firstname", "identifier.creators.*.lastname", "identifier.creators.*.creator_name", + "column.column_type", + "column.is_null_allowed", + "column.is_primary_key", "funders", "title", "description", @@ -143,9 +146,12 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): "author", "database.*", "internal_name", - "public", + "is_public", ] queries = [] + if type is not None: + logging.debug("search for specific index: %s", type) + index = type if search_term is not None: logging.debug('query has search_term present') text_query = { @@ -171,11 +177,12 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): logging.debug('query has fieldValuePairs present') musts = [] for field, value in fieldValuePairs.items(): - if field == "type" and value in searchable_indices: - logging.debug("search for specific index: %s", value) - index = value - continue if field in field_list: + if field.startswith(index) and "." in field: + new_field = field[field.index(".") + 1:len(field)] + logging.debug( + f"field name {field} starts with index name {index}: flattened field name to {new_field}") + field = new_field musts.append({ "match": { field: {"query": value, "minimum_should_match": "90%"} @@ -195,11 +202,13 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): "description", "title", "type", + "uri", "username", "is_public", "created", "_score", "concept", + "unit", "author", "docID", "creator.*", diff --git a/dbrepo-ui/api/advanced_search.service.js b/dbrepo-ui/api/advanced_search.service.js deleted file mode 100644 index 6cae96ce74be70e16dd7357da13f714250e3d7bc..0000000000000000000000000000000000000000 --- a/dbrepo-ui/api/advanced_search.service.js +++ /dev/null @@ -1,46 +0,0 @@ -import Vue from 'vue' -import axios from 'axios' - -class AdvancedSearchService { - getFields (type) { - return new Promise((resolve, reject) => { - axios.get(`/api/search/${type}/fields`, { headers: { Accept: 'application/json' } }) - .then((response) => { - const jsonResponse = response.data - resolve(jsonResponse) - }) - .catch((error) => { - const { code, message } = error - console.error(`Failed to load ${type} fields`, error) - Vue.$toast.error(`[${code}] Failed to load ${type} fields: ${message}`) - reject(error) - }) - }) - } - - search (searchData) { - // transform values to what the search API expects - const searchTerm = searchData.search_term - delete searchData.search_term - const payload = { - search_term: searchTerm, - fieldValuePairs: { ...searchData } - } - - return new Promise((resolve, reject) => { - axios.post('/api/search', payload, { headers: { Accept: 'application/json' } }) - .then((response) => { - const jsonResponse = response.data - resolve(jsonResponse) - }) - .catch((error) => { - const { code, message } = error - console.error('Failed to load search results', error) - Vue.$toast.error(`[${code}] Failed to load search results: ${message}`) - reject(error) - }) - }) - } -} - -export default new AdvancedSearchService() diff --git a/dbrepo-ui/api/search.service.js b/dbrepo-ui/api/search.service.js index 3cb3724cc2f6b87e77566c3738151529e07280e8..e9dd6ddb7ea52583d18b0960ceccfe3a6c6fe405 100644 --- a/dbrepo-ui/api/search.service.js +++ b/dbrepo-ui/api/search.service.js @@ -1,15 +1,36 @@ import Vue from 'vue' -import store from '@/store' import axios from 'axios' class SearchService { - search (query) { + getFields (type) { return new Promise((resolve, reject) => { - axios.get(`/retrieve/_all/_search?q=${query}*&terminate_after=50`, { headers: { Accept: 'application/json' }, auth: { username: store().state.searchUsername, password: store().state.searchPassword } }) + axios.get(`/api/search/${type}/fields`, { headers: { Accept: 'application/json' } }) .then((response) => { - const hits = response.data.hits.hits - console.debug('response hits', hits) - resolve(hits) + const jsonResponse = response.data + resolve(jsonResponse) + }) + .catch((error) => { + const { code, message } = error + console.error(`Failed to load ${type} fields`, error) + Vue.$toast.error(`[${code}] Failed to load ${type} fields: ${message}`) + reject(error) + }) + }) + } + + search (type, searchTerm, keyValuePairs) { + const payload = { + type, + search_term: searchTerm, + field_value_pairs: { ...keyValuePairs } + } + + return new Promise((resolve, reject) => { + axios.post('/api/search', payload, { headers: { Accept: 'application/json' } }) + .then((response) => { + const { hits } = response.data + console.debug('advanced search response', hits.hits) + resolve(hits.hits) }) .catch((error) => { const { code, message } = error diff --git a/dbrepo-ui/components/dialogs/Semantics.vue b/dbrepo-ui/components/dialogs/Semantics.vue index 951aca68670d3de3d3a895ca92e3a93e6b1cb5f3..fd8535491a929657eaec145540eddb35e9fd79aa 100644 --- a/dbrepo-ui/components/dialogs/Semantics.vue +++ b/dbrepo-ui/components/dialogs/Semantics.vue @@ -192,12 +192,16 @@ export default { this.loadingSave = true TableService.updateColumn(this.database.id, this.tableId, this.column.id, payload) .then(() => { + this.recommendation = null + this.$refs.form.reset() this.$emit('close', { success: true, action: 'assign' }) }) .finally(() => { + this.recommendation = null + this.$refs.form.reset() this.loadingSave = false }) }, @@ -213,20 +217,19 @@ export default { }, isUri (str) { if (!str) { - return true + return false } - return str.match(/https?:\/\//g) + return str.startsWith('http') }, init () { + this.uri = null if (this.column.unit && this.mode === 'unit') { this.uri = this.column.unit.uri return } if (this.column.concept && this.mode === 'concept') { this.uri = this.column.concept.uri - return } - this.uri = null }, submit () { this.$refs.form.validate() diff --git a/dbrepo-ui/layouts/default.vue b/dbrepo-ui/layouts/default.vue index 9a3b21d8e7f1111ea26065b0388a6a786c6debb4..77073f8de84d11a251828d3c593e36c7cd290c57 100644 --- a/dbrepo-ui/layouts/default.vue +++ b/dbrepo-ui/layouts/default.vue @@ -147,7 +147,7 @@ <v-row> <v-col cols="auto"> <v-select - v-model="advancedSearchData.type" + v-model="advancedSearchType" clearable :items="fieldItems" item-text="name" @@ -180,16 +180,27 @@ <!-- Loop through "fields" list --> <template v-if="shouldRenderItem(field)"> <v-col cols="auto"> - <v-checkbox + <v-select v-if="field.type === 'boolean'" v-model="advancedSearchData[generateDynamicVModelKey(field)]" + clearable + :items="booleanItems" + item-text="name" + item-value="value" :label="generateFriendlyName(field)" /> <v-text-field - v-if="field.type === 'keyword' || field.type === 'text' || field.type === 'date'" + v-if="(field.type === 'keyword' && field.attribute_name !== 'column_type') || field.type === 'text' || field.type === 'date'" v-model="advancedSearchData[generateDynamicVModelKey(field)]" type="text" :label="generateFriendlyName(field)" clearable /> + <v-select + v-if="field.type === 'keyword' && field.attribute_name === 'column_type'" + v-model="advancedSearchData[generateDynamicVModelKey(field)]" + :items="columnTypes" + item-value="value" + clearable + :label="generateFriendlyName(field)" /> <v-text-field v-if="field.type === 'integer'" v-model="advancedSearchData[generateDynamicVModelKey(field)]" @@ -203,12 +214,12 @@ </v-container> </v-card-text> <v-card-text> - <v-btn @click="toggleAdvancedSearch"> - Cancel - </v-btn> - <v-btn class="ml-2" color="primary" @click="advancedSearch"> + <v-btn class="mr-2" color="primary" small @click="advancedSearch"> Search </v-btn> + <v-btn small @click="toggleAdvancedSearch"> + Cancel + </v-btn> </v-card-text> </v-card> <v-container> @@ -219,11 +230,12 @@ </template> <script> -import AdvancedSearchService from '@/api/advanced_search.service' +import SearchService from '@/api/search.service' import AuthenticationService from '@/api/authentication.service' import DatabaseService from '@/api/database.service' import EventBus from '@/api/eventBus' import TableService from '@/api/table.service' +import QueryMapper from '@/api/query.mapper' export default { data () { @@ -239,6 +251,10 @@ export default { loadingDatabases: false, search: null, showAdvancedSearch: false, + columnTypes: QueryMapper.mySql8DataTypes().map((datatype) => { + datatype.value = datatype.value.toUpperCase() + return datatype + }), fieldItems: [ { name: 'Database', value: 'database' }, { name: 'Table', value: 'table' }, @@ -249,7 +265,12 @@ export default { { name: 'Unit', value: 'unit' }, { name: 'View', value: 'view' } ], + booleanItems: [ + { name: 'True', value: true }, + { name: 'False', value: false } + ], fieldsResponse: null, + advancedSearchType: null, advancedSearchData: { name: '', internal_name: '', @@ -305,7 +326,7 @@ export default { return this.$store.state.databaseCount }, hideFields () { - const selectedOption = this.advancedSearchData.type + const selectedOption = this.advancedSearchType return { hideNameField: selectedOption === 'identifier', hideInternalNameField: ['identifier', 'user', 'concept', 'unit'].includes(selectedOption) @@ -356,10 +377,10 @@ export default { }) } }, - 'advancedSearchData.type': { + advancedSearchType: { async handler () { - if (this.advancedSearchData.type) { - const promise = await AdvancedSearchService.getFields(this.advancedSearchData.type.toLowerCase()) + if (this.advancedSearchType) { + const promise = await SearchService.getFields(this.advancedSearchType.toLowerCase()) this.fieldsResponse = JSON.parse(JSON.stringify(promise)) console.log('Fields Response: ', this.fieldsResponse) } else { @@ -452,7 +473,7 @@ export default { }) }, retrieve () { - console.info('Performing Normal Search') + console.debug('performing fuzzy search') this.$router.push({ path: '/search', query: { q: this.search } }) }, initEnvironment () { @@ -466,8 +487,6 @@ export default { console.debug('runtime config', this.$config) }, advancedSearch () { - console.info('Performing Advanced Search') - // attach free text value to the provided data if (this.search) { this.advancedSearchData.search_term = this.search } else { @@ -481,7 +500,7 @@ export default { }, isAdvancedSearchEmpty () { return !( - this.advancedSearchData.type || + this.advancedSearchType || this.advancedSearchData.id || this.advancedSearchData.name || this.advancedSearchData.internal_name @@ -531,12 +550,12 @@ export default { // Generates a dynamic v-model; It will be attached to the advancedSearchData object if (!item) { return '' } - return `${this.advancedSearchData.type}.${item.attribute_name}` + return `${this.advancedSearchType}.${item.attribute_name}` }, shouldRenderItem (item) { // Checks if item's attribute_name matches any wanted field // The expected response is of a flattened format, so this method must be modified accordingly if the response is changed - return this.dynamicFieldsMap()[this.advancedSearchData.type].includes(item.attribute_name) + return this.dynamicFieldsMap()[this.advancedSearchType].includes(item.attribute_name) } }, head () { @@ -546,7 +565,8 @@ export default { }, provide () { return { - advancedSearchData: this.advancedSearchData + advancedSearchData: this.advancedSearchData, + advancedSearchType: this.advancedSearchType } } } diff --git a/dbrepo-ui/pages/search/index.vue b/dbrepo-ui/pages/search/index.vue index 20a0e24fcb10d60c8663acf6375957a3053c9369..a62a788c0a26aba19a26a6cf9f6f95551948cd0f 100644 --- a/dbrepo-ui/pages/search/index.vue +++ b/dbrepo-ui/pages/search/index.vue @@ -7,25 +7,25 @@ <v-card v-for="(result, idx) in results" :key="idx" - :to="link(result)" + :to="link(result) && link(result).startsWith('http') ? null : link(result)" + :href="link(result) && link(result).startsWith('http') ? link(result): null" flat tile> <v-divider class="mx-4" /> <v-card-title> - <a :href="link(result)">{{ title(result) }}</a> + <a v-if="link(result)" :href="link(result)">{{ title(result) }}</a> + <span v-else>{{ title(result) }}</span> </v-card-title> <v-card-subtitle class="search-subtitle" v-text="description(result)" /> - <v-card-text class="search-description"> + <v-card-text v-if="tags(result).length > 0" class="search-description"> <div class="search-tags"> - <v-chip v-if="isPublic(result) === true" small color="green" outlined>Public</v-chip> - <v-chip v-if="isPublic(result) === false" small color="red" outlined>Private</v-chip> - <v-chip v-if="isTable(result)" small outlined>Table</v-chip> - <v-chip v-if="isColumn(result)" small outlined>Column</v-chip> - <v-chip v-if="isView(result)" small outlined>View</v-chip> - <v-chip v-if="isIdentifier(result)" small outlined>Identifier</v-chip> - <v-chip v-if="isDatabase(result) || (isIdentifier(result) && result.type === 'DATABASE')" small outlined>Database</v-chip> - <v-chip v-if="isIdentifier(result) && result.type === 'SUBSET'" small outlined>Subset</v-chip> - <v-chip v-if="isIdentifier(result) && result.publicationYear" small outlined>{{ result.publicationYear }}</v-chip> + <v-chip + v-for="(tag, i) in tags(result)" + :key="i" + small + :color="tag.color" + outlined + v-text="tag.text" /> </div> </v-card-text> </v-card> @@ -33,12 +33,11 @@ </template> <script> -import AdvancedSearchService from '@/api/advanced_search.service' import EventBus from '@/api/eventBus' import SearchService from '@/api/search.service' export default { - inject: ['advancedSearchData'], + inject: ['advancedSearchData', 'advancedSearchType'], data () { return { results: [], @@ -89,7 +88,7 @@ export default { }, created () { EventBus.$on('advancedSearchButtonClicked', () => { - this.doAdvancedSearch(this.advancedSearchData) + this.doAdvancedSearch(this.advancedSearchType, this.advancedSearchData) }) }, beforeDestroy () { @@ -97,7 +96,7 @@ export default { }, mounted () { if (Object.keys(this.advancedSearchData).some(key => key !== 'search_term')) { - this.doAdvancedSearch(this.advancedSearchData) + this.doAdvancedSearch(this.advancedSearchType, this.advancedSearchData) } else if (this.query) { this.retrieve(this.query) } @@ -108,7 +107,7 @@ export default { return } this.loading = true - SearchService.search(this.query) + SearchService.search(this.type, this.query, []) .then((hits) => { this.results = hits.map(h => h._source) }) @@ -116,13 +115,11 @@ export default { this.loading = false }) }, - doAdvancedSearch (advancedSearchData) { - console.log('Advanced Search Data:', advancedSearchData) - AdvancedSearchService.search(advancedSearchData) + doAdvancedSearch (advancedSearchType, advancedSearchData) { + console.debug('advanced search type:', advancedSearchType, 'data:', advancedSearchData) + SearchService.search(advancedSearchType, null, advancedSearchData) .then((response) => { - const hits = response.hits.hits - this.results = hits.map(h => h._source) - console.log('Advanced Search Results', this.results) + this.results = response.map(h => h._source) }) .finally(() => { this.loading = false @@ -169,7 +166,16 @@ export default { return false } if ('_class' in item) { - return /at.tuwien.entities.database.table.columns.TableColumn/.test(item._class) + return /at.tuwien.api.database.table.columns.ColumnDto/.test(item._class) + } + return false + }, + isUser (item) { + if (!item) { + return false + } + if ('_class' in item) { + return /at.tuwien.api.user.UserDto/.test(item._class) } return false }, @@ -192,24 +198,20 @@ export default { return false }, isPublic (item) { - if (this.isDatabase(item)) { - return item.isPublic - } else if (this.isTable(item)) { - return item.isPublic - } else if (this.isColumn(item)) { - return item.isPublic - } else if (this.isView(item)) { - return item.isPublic + if (this.isDatabase(item) || this.isTable(item) || this.isColumn(item) || this.isView(item)) { + return item.is_public } else if (this.isIdentifier(item)) { return item.visibility === 'EVERYONE' } - return false + return null }, title (item) { if (this.isDatabase(item) || this.isTable(item) || this.isColumn(item) || this.isView(item) || this.isConcept(item) || this.isUnit(item)) { return item.name } else if (this.isIdentifier(item)) { return item.title + } else if (this.isUser(item)) { + return item.username } return null }, @@ -221,25 +223,53 @@ export default { } else if (this.isView(item)) { return item.query } - return false + return null }, link (item) { if (this.isDatabase(item)) { return `/database/${item.id}` - } - if (this.isTable(item)) { + } else if (this.isTable(item)) { return `/database/${item.databaseId}/table/${item.id}` - } - if (this.isView(item)) { + } else if (this.isView(item)) { return `/database/${item.vdbid}/view/${item.id}` - } - if (this.isColumn(item)) { + } else if (this.isColumn(item)) { return `/database/${item.cdbid}/table/${item.tid}` - } - if (this.isIdentifier(item)) { + } else if (this.isIdentifier(item)) { return `/pid/${item.id}` + } else if (this.isConcept(item) || this.isUnit(item)) { + return item.uri + } + return null + }, + tags (item) { + const tags = [] + if (this.isPublic(item) === true || this.isPublic(item) === false) { + tags.push({ color: this.isPublic(item) ? 'green' : 'red', text: this.isPublic(item) ? 'Public' : 'Private' }) + } + if (this.isDatabase(item)) { + tags.push({ text: 'Database' }) + } else if (this.isTable(item)) { + tags.push({ text: 'Table' }) + } else if (this.isColumn(item)) { + tags.push({ text: 'Column' }) + if ('concept' in item) { + const conceptName = ('name' in item.concept) ? item.concept.name : 'Concept' + tags.push({ color: 'green', text: conceptName }) + } + if ('unit' in item) { + const unitName = ('name' in item.unit) ? item.unit.name : 'Unit' + tags.push({ color: 'green', text: unitName }) + } + } else if (this.isView(item)) { + tags.push({ text: 'View' }) + } else if (this.isIdentifier(item)) { + tags.push({ text: 'Identifier' }) + } else if (this.isUnit(item)) { + tags.push({ text: 'Unit' }) + } else if (this.isConcept(item)) { + tags.push({ text: 'Concept' }) } - return '/' + return tags } } }