Skip to content
Snippets Groups Projects
Commit b0fa3909 authored by buczekp's avatar buczekp
Browse files

[LMS-2363] rename deletion and related names in DB + necessary changes in Java...

[LMS-2363] rename deletion and related names in DB + necessary changes in Java (but no renaming of method names, classes or javadocs)

SVN: 22059
parent aa77de78
No related branches found
No related tags found
No related merge requests found
Showing
with 1218 additions and 20 deletions
...@@ -23,6 +23,6 @@ public class ExperimentProjectSpaceCodeRecord ...@@ -23,6 +23,6 @@ public class ExperimentProjectSpaceCodeRecord
public Long dbin_id; public Long dbin_id;
public Long inva_id; public Long del_id;
} }
...@@ -49,7 +49,7 @@ public interface ISecondaryEntityListingQuery extends TransactionQuery ...@@ -49,7 +49,7 @@ public interface ISecondaryEntityListingQuery extends TransactionQuery
* *
* @param experimentId The id of the experiment to get the code for. * @param experimentId The id of the experiment to get the code for.
*/ */
@Select("select e.code as e_code, e.perm_id as e_permid, e.inva_id as inva_id, et.code as et_code, " @Select("select e.code as e_code, e.perm_id as e_permid, e.del_id as del_id, et.code as et_code, "
+ "p.code as p_code, p.id as p_id, g.code as spc_code, g.dbin_id as dbin_id from experiments e " + "p.code as p_code, p.id as p_id, g.code as spc_code, g.dbin_id as dbin_id from experiments e "
+ "join experiment_types et on e.exty_id=et.id join projects p on e.proj_id=p.id " + "join experiment_types et on e.exty_id=et.id join projects p on e.proj_id=p.id "
+ "join spaces g on p.space_id=g.id where e.id=?{1}") + "join spaces g on p.space_id=g.id where e.id=?{1}")
...@@ -63,7 +63,7 @@ public interface ISecondaryEntityListingQuery extends TransactionQuery ...@@ -63,7 +63,7 @@ public interface ISecondaryEntityListingQuery extends TransactionQuery
/** /**
* Returns the samples for the given ids. * Returns the samples for the given ids.
*/ */
@Select(sql = "select s.id as id, s.perm_id as perm_id, s.code as s_code, s.inva_id as inva_id, " @Select(sql = "select s.id as id, s.perm_id as perm_id, s.code as s_code, s.del_id as del_id, "
+ " st.code as st_code, g.code as spc_code, c.code as c_code" + " st.code as st_code, g.code as spc_code, c.code as c_code"
+ " from samples s join sample_types st on s.saty_id=st.id" + " from samples s join sample_types st on s.saty_id=st.id"
+ " join spaces g on s.space_id=g.id " + " join spaces g on s.space_id=g.id "
......
...@@ -34,7 +34,7 @@ public class SampleReferenceRecord ...@@ -34,7 +34,7 @@ public class SampleReferenceRecord
public String s_code; public String s_code;
/** invalidation id */ /** invalidation id */
public Long inva_id; public Long del_id;
/** sample type code */ /** sample type code */
public String st_code; public String st_code;
......
...@@ -114,7 +114,7 @@ public class SecondaryEntityDAO ...@@ -114,7 +114,7 @@ public class SecondaryEntityDAO
experiment.setPermId(record.e_permid); experiment.setPermId(record.e_permid);
experiment.setIdentifier(new ExperimentIdentifier(null, space.getCode(), record.p_code, experiment.setIdentifier(new ExperimentIdentifier(null, space.getCode(), record.p_code,
record.e_code).toString()); record.e_code).toString());
experiment.setInvalidation(createInvalidation(record.inva_id)); experiment.setInvalidation(createInvalidation(record.del_id));
final Project project = new Project(); final Project project = new Project();
project.setId(record.p_id); project.setId(record.p_id);
project.setCode(record.p_code); project.setCode(record.p_code);
...@@ -199,7 +199,7 @@ public class SecondaryEntityDAO ...@@ -199,7 +199,7 @@ public class SecondaryEntityDAO
sample.setId(record.id); sample.setId(record.id);
sample.setCode(IdentifierHelper.convertCode(record.s_code, record.c_code)); sample.setCode(IdentifierHelper.convertCode(record.s_code, record.c_code));
sample.setSampleType(createSampleType(record.st_code, databaseInstance)); sample.setSampleType(createSampleType(record.st_code, databaseInstance));
sample.setInvalidation(createInvalidation(record.inva_id)); sample.setInvalidation(createInvalidation(record.del_id));
sample.setSpace(tryCreateGroup(record.spc_code, databaseInstance)); sample.setSpace(tryCreateGroup(record.spc_code, databaseInstance));
sample.setDatabaseInstance(tryGetDatabaseInstance(record.spc_code, databaseInstance)); sample.setDatabaseInstance(tryGetDatabaseInstance(record.spc_code, databaseInstance));
sample.setPermId(record.perm_id); sample.setPermId(record.perm_id);
......
...@@ -657,7 +657,7 @@ public class DatasetLister extends AbstractLister implements IDatasetLister ...@@ -657,7 +657,7 @@ public class DatasetLister extends AbstractLister implements IDatasetLister
// NOTE: this just marks the data set as invalid without loading any details // NOTE: this just marks the data set as invalid without loading any details
private void enrichWithInvalidation(final ExternalData dataSet, DatasetRecord row) private void enrichWithInvalidation(final ExternalData dataSet, DatasetRecord row)
{ {
if (row.inva_id != null) if (row.del_id != null)
{ {
final Invalidation invalidation = new Invalidation(); final Invalidation invalidation = new Invalidation();
dataSet.setInvalidation(invalidation); dataSet.setInvalidation(invalidation);
......
...@@ -39,7 +39,7 @@ public class DatasetRecord extends CodeRecord ...@@ -39,7 +39,7 @@ public class DatasetRecord extends CodeRecord
public Long ctnr_id; public Long ctnr_id;
public Long inva_id; public Long del_id;
// ---- from external_data table // ---- from external_data table
// ---- can be NULL in case of container(virtual) data sets // ---- can be NULL in case of container(virtual) data sets
......
...@@ -59,7 +59,7 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ ...@@ -59,7 +59,7 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ
static final String SELECT_FROM_SAMPLES_S = static final String SELECT_FROM_SAMPLES_S =
" SELECT s.id, s.perm_id, s.code, s.expe_id, s.space_id, s.saty_id, s.dbin_id, " " SELECT s.id, s.perm_id, s.code, s.expe_id, s.space_id, s.saty_id, s.dbin_id, "
+ " s.registration_timestamp, s.modification_timestamp, s.pers_id_registerer, " + " s.registration_timestamp, s.modification_timestamp, s.pers_id_registerer, "
+ " s.inva_id, s.samp_id_part_of " + " s.del_id, s.samp_id_part_of "
+ " FROM samples s"; + " FROM samples s";
/** /**
......
...@@ -619,7 +619,7 @@ final class SampleListingWorker extends AbstractLister ...@@ -619,7 +619,7 @@ final class SampleListingWorker extends AbstractLister
// NOTE: this just marks the sample as invalid without loading any details // NOTE: this just marks the sample as invalid without loading any details
private void enrichWithInvalidation(final Sample sample, SampleRecord row) private void enrichWithInvalidation(final Sample sample, SampleRecord row)
{ {
if (row.inva_id != null) if (row.del_id != null)
{ {
final Invalidation invalidation = new Invalidation(); final Invalidation invalidation = new Invalidation();
sample.setInvalidation(invalidation); sample.setInvalidation(invalidation);
......
...@@ -17,7 +17,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.common.CodeRecord; ...@@ -17,7 +17,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.common.CodeRecord;
// REGISTRATION_TIMESTAMP TIME_STAMP_DFL NOT NULL DEFAULT CURRENT_TIMESTAMP, // REGISTRATION_TIMESTAMP TIME_STAMP_DFL NOT NULL DEFAULT CURRENT_TIMESTAMP,
// MODIFICATION_TIMESTAMP TIME_STAMP DEFAULT CURRENT_TIMESTAMP, // MODIFICATION_TIMESTAMP TIME_STAMP DEFAULT CURRENT_TIMESTAMP,
// PERS_ID_REGISTERER TECH_ID NOT NULL, // PERS_ID_REGISTERER TECH_ID NOT NULL,
// INVA_ID TECH_ID, // del_id TECH_ID,
// DBIN_ID TECH_ID, // DBIN_ID TECH_ID,
// SPACE_ID TECH_ID, // SPACE_ID TECH_ID,
// SAMP_ID_PART_OF TECH_ID); // SAMP_ID_PART_OF TECH_ID);
...@@ -40,7 +40,7 @@ public class SampleRecord extends CodeRecord ...@@ -40,7 +40,7 @@ public class SampleRecord extends CodeRecord
public long pers_id_registerer; public long pers_id_registerer;
public Long inva_id; public Long del_id;
public long saty_id; public long saty_id;
} }
...@@ -24,7 +24,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db; ...@@ -24,7 +24,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
public final class DatabaseVersionHolder public final class DatabaseVersionHolder
{ {
/** Current version of the database. */ /** Current version of the database. */
private static final String DATABASE_VERSION = "074"; // S110 private static final String DATABASE_VERSION = "075"; // S111
private DatabaseVersionHolder() private DatabaseVersionHolder()
{ {
......
...@@ -120,7 +120,7 @@ public final class ColumnNames ...@@ -120,7 +120,7 @@ public final class ColumnNames
public static final String ID_COLUMN = "id"; public static final String ID_COLUMN = "id";
public static final String INVALIDATION_COLUMN = "inva_id"; public static final String INVALIDATION_COLUMN = "del_id";
public static final String IS_COMPLETE_COLUMN = "is_complete"; public static final String IS_COMPLETE_COLUMN = "is_complete";
......
...@@ -21,10 +21,10 @@ package ch.systemsx.cisd.openbis.generic.shared.dto; ...@@ -21,10 +21,10 @@ package ch.systemsx.cisd.openbis.generic.shared.dto;
* <p> * <p>
* These names reflect the ones that could be found in the database. * These names reflect the ones that could be found in the database.
* </p> * </p>
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
public enum EventType public enum EventType
{ {
DELETION, INVALIDATION, MOVEMENT; DELETION, MOVEMENT;
} }
...@@ -41,7 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder; ...@@ -41,7 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder;
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
@Entity @Entity
@Table(name = TableNames.INVALIDATION_TABLE) @Table(name = TableNames.INVALIDATIONS_TABLE)
public class InvalidationPE extends HibernateAbstractRegistrationHolder implements IIdHolder, public class InvalidationPE extends HibernateAbstractRegistrationHolder implements IIdHolder,
Serializable Serializable
{ {
......
...@@ -74,7 +74,7 @@ public final class SequenceNames ...@@ -74,7 +74,7 @@ public final class SequenceNames
public static final String SCRIPT_SEQUENCE = "SCRIPT_ID_SEQ"; public static final String SCRIPT_SEQUENCE = "SCRIPT_ID_SEQ";
public static final String INVALIDATION_SEQUENCE = "INVALIDATION_ID_SEQ"; public static final String INVALIDATION_SEQUENCE = "DELETION_ID_SEQ";
public static final String LOCATOR_TYPE_SEQUENCE = "LOCATOR_TYPE_ID_SEQ"; public static final String LOCATOR_TYPE_SEQUENCE = "LOCATOR_TYPE_ID_SEQ";
......
...@@ -72,7 +72,7 @@ public final class TableNames ...@@ -72,7 +72,7 @@ public final class TableNames
public static final String SPACES_TABLE = "spaces"; public static final String SPACES_TABLE = "spaces";
public static final String INVALIDATION_TABLE = "invalidations"; public static final String INVALIDATIONS_TABLE = "deletions";
public static final String LOCATOR_TYPES_TABLE = "locator_types"; public static final String LOCATOR_TYPES_TABLE = "locator_types";
......
----------------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table DATABASE_INSTANCES
----------------------------------------------------------------------------
INSERT INTO database_instances(
id
, code
, uuid
, is_original_source)
VALUES ( nextval('DATABASE_INSTANCE_ID_SEQ')
, 'SYSTEM_DEFAULT'
, 'SYSTEM_DEFAULT'
, 'T');
----------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table PERSONS
-----------------------------------------------------------------------
insert into persons
(id
,first_name
,last_name
,user_id
,email
,dbin_id)
values
(nextval('PERSON_ID_SEQ')
,''
,'System User'
,'system'
,''
,(select id from database_instances where code = 'SYSTEM_DEFAULT') );
-----------------------------------------------------------------------------------
-- Purpose: Create Controlled Vocabulary STORAGE_FORMAT
-----------------------------------------------------------------------------------
insert into controlled_vocabularies
( id
, code
, is_internal_namespace
, description
, pers_id_registerer
, is_managed_internally
, dbin_id)
values (nextval('CONTROLLED_VOCABULARY_ID_SEQ')
, 'STORAGE_FORMAT'
, true
, 'The on-disk storage format of a data set'
, (select id from persons where user_id ='system')
, true
, (select id from database_instances where code = 'SYSTEM_DEFAULT'));
-----------------------------------------------------------------------------------
-- Purpose: Create Controlled Vocabulary Terms for STORAGE_FORMAT
-----------------------------------------------------------------------------------
insert into controlled_vocabulary_terms
( id
, code
, covo_id
, pers_id_registerer
, ordinal )
values (nextval('CVTE_ID_SEQ')
, 'PROPRIETARY'
, (select id from controlled_vocabularies where code = 'STORAGE_FORMAT' and is_internal_namespace = true)
, (select id from persons where user_id ='system')
, 1);
insert into controlled_vocabulary_terms
( id
, code
, covo_id
, pers_id_registerer
, ordinal)
values (nextval('CVTE_ID_SEQ')
, 'BDS_DIRECTORY'
, (select id from controlled_vocabularies where code = 'STORAGE_FORMAT' and is_internal_namespace = true)
, (select id from persons where user_id ='system')
, 2);
------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table DATA_TYPES
------------------------------------------------------------------
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'VARCHAR'
,'Short text'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'MULTILINE_VARCHAR'
,'Long text'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'INTEGER'
,'Integer number'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'REAL'
,'Real number, i.e. an inexact, variable-precision numeric type'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'BOOLEAN'
,'True or False'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'TIMESTAMP'
,'Both date and time. Format: yyyy-mm-dd hh:mm:ss'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'CONTROLLEDVOCABULARY'
,'Controlled Vocabulary'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'MATERIAL'
,'Reference to a material'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'HYPERLINK'
,'Address of a web page'
);
insert into data_types
(id
,code
,description)
values
(nextval('DATA_TYPE_ID_SEQ')
,'XML'
,'XML document'
);
----------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table PROPERTY_TYPES
-----------------------------------------------------------------------
insert into property_types
(id
,code
,description
,label
,daty_id
,pers_id_registerer
,dbin_id)
values
(nextval('PROPERTY_TYPE_ID_SEQ')
,'DESCRIPTION'
,'A Description'
,'Description'
,(select id from data_types where code ='VARCHAR')
,(select id from persons where user_id ='system')
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
--------------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table DATA_SET_TYPES
--------------------------------------------------------------------------
insert into data_set_types
(id
,code
,description
,dbin_id)
values
(nextval('DATA_SET_TYPE_ID_SEQ')
,'UNKNOWN'
,'Unknown'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
-------------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table FILE_FORMAT_TYPES
-------------------------------------------------------------------------
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'HDF5'
,'Hierarchical Data Format File, version 5'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'PROPRIETARY'
,'Proprietary Format File'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'SRF'
,'Sequence Read Format File'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'TIFF'
,'TIFF File'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'TSV'
,'Tab Separated Values File'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into file_format_types
(id
,code
,description
,dbin_id)
values
(nextval('FILE_FORMAT_TYPE_ID_SEQ')
,'XML'
,'XML File'
,(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
---------------------------------------------------------------------
-- Purpose: Insert an initial data set into the table LOCATOR_TYPES
---------------------------------------------------------------------
insert into locator_types
(id
,code
,description)
values
(nextval('LOCATOR_TYPE_ID_SEQ')
,'RELATIVE_LOCATION'
,'Relative Location'
);
---------------------------------------------------------------------
-- Purpose: Insert an initial data into table RELATIONSHIP_TYPES
---------------------------------------------------------------------
insert into relationship_types
(id,
code,
label,
parent_label,
child_label,
description,
pers_id_registerer,
is_managed_internally,
is_internal_namespace,
dbin_id)
values
(
nextval('RELATIONSHIP_TYPE_ID_SEQ'),
'PARENT_CHILD',
'Parent - Child',
'Parent',
'Child',
'Parent - Child relationship',
(select id from persons where user_id ='system'),
'T',
'T',
(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
insert into relationship_types
(id,
code,
label,
parent_label,
child_label,
description,
pers_id_registerer,
is_managed_internally,
is_internal_namespace,
dbin_id)
values
(
nextval('RELATIONSHIP_TYPE_ID_SEQ'),
'PLATE_CONTROL_LAYOUT',
'Plate - Control Layout',
'Plate',
'Control Layout',
'Plate - Control Layout relationship',
(select id from persons where user_id ='system'),
'T',
'T',
(select id from database_instances where code = 'SYSTEM_DEFAULT')
);
This diff is collapsed.
-- Creating domains
CREATE DOMAIN AUTHORIZATION_ROLE AS VARCHAR(40) CHECK (VALUE IN ('ADMIN', 'POWER_USER', 'USER', 'OBSERVER', 'ETL_SERVER'));
CREATE DOMAIN BOOLEAN_CHAR AS BOOLEAN DEFAULT FALSE;
CREATE DOMAIN BOOLEAN_CHAR_OR_UNKNOWN AS CHAR(1) DEFAULT 'U' CHECK (VALUE IN ('F', 'T', 'U'));
CREATE DOMAIN CODE AS VARCHAR(60);
CREATE DOMAIN COLUMN_LABEL AS VARCHAR(128);
CREATE DOMAIN DATA_STORE_SERVICE_KIND AS VARCHAR(40) CHECK (VALUE IN ('PROCESSING', 'QUERIES'));
CREATE DOMAIN DATA_STORE_SERVICE_REPORTING_PLUGIN_TYPE AS VARCHAR(40) CHECK (VALUE IN ('TABLE_MODEL', 'DSS_LINK'));
CREATE DOMAIN EVENT_TYPE AS VARCHAR(40) CHECK (VALUE IN ('DELETION', 'MOVEMENT'));
CREATE DOMAIN FILE AS BYTEA;
CREATE DOMAIN FILE_NAME AS VARCHAR(100);
CREATE DOMAIN TEXT_VALUE AS TEXT;
CREATE DOMAIN OBJECT_NAME AS VARCHAR(50);
CREATE DOMAIN REAL_VALUE AS REAL;
CREATE DOMAIN TECH_ID AS BIGINT;
CREATE DOMAIN TIME_STAMP AS TIMESTAMP WITH TIME ZONE;
CREATE DOMAIN TIME_STAMP_DFL AS TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
CREATE DOMAIN USER_ID AS VARCHAR(50);
CREATE DOMAIN TITLE_100 AS VARCHAR(100);
CREATE DOMAIN GRID_EXPRESSION AS VARCHAR(2000);
CREATE DOMAIN GRID_ID AS VARCHAR(200);
CREATE DOMAIN ORDINAL_INT AS BIGINT CHECK (VALUE > 0);
CREATE DOMAIN DESCRIPTION_2000 AS VARCHAR(2000);
CREATE DOMAIN ARCHIVING_STATUS AS VARCHAR(100) CHECK (VALUE IN ('LOCKED', 'AVAILABLE', 'ARCHIVED', 'ARCHIVE_PENDING', 'UNARCHIVE_PENDING', 'BACKUP_PENDING'));
CREATE DOMAIN QUERY_TYPE AS VARCHAR(40) CHECK (VALUE IN ('GENERIC', 'EXPERIMENT', 'SAMPLE', 'DATA_SET', 'MATERIAL'));
CREATE DOMAIN ENTITY_KIND AS VARCHAR(40) CHECK (VALUE IN ('SAMPLE', 'EXPERIMENT', 'DATA_SET', 'MATERIAL'));
CREATE DOMAIN SCRIPT_TYPE AS VARCHAR(40) CHECK (VALUE IN ('DYNAMIC_PROPERTY', 'MANAGED_PROPERTY'));
\ No newline at end of file
-- Creating Functions
------------------------------------------------------------------------------------
-- Purpose: Create function RENAME_SEQUENCE() that is required for renaming the sequences belonging to tables
------------------------------------------------------------------------------------
CREATE FUNCTION RENAME_SEQUENCE(OLD_NAME VARCHAR, NEW_NAME VARCHAR) RETURNS INTEGER AS $$
DECLARE
CURR_SEQ_VAL INTEGER;
BEGIN
SELECT INTO CURR_SEQ_VAL NEXTVAL(OLD_NAME);
EXECUTE 'CREATE SEQUENCE ' || NEW_NAME || ' START WITH ' || CURR_SEQ_VAL;
EXECUTE 'DROP SEQUENCE ' || OLD_NAME;
RETURN CURR_SEQ_VAL;
END;
$$ LANGUAGE 'plpgsql';
------------------------------------------------------------------------------------
-- Purpose: Create trigger CONTROLLED_VOCABULARY_CHECK
------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION CONTROLLED_VOCABULARY_CHECK() RETURNS trigger AS $$
DECLARE
v_code CODE;
BEGIN
select code into v_code from data_types where id = NEW.daty_id;
-- Check if the data is of type "CONTROLLEDVOCABULARY"
if v_code = 'CONTROLLEDVOCABULARY' then
if NEW.covo_id IS NULL then
RAISE EXCEPTION 'Insert/Update of Property Type (Code: %) failed, as its Data Type is CONTROLLEDVOCABULARY, but it is not linked to a Controlled Vocabulary.', NEW.code;
end if;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER CONTROLLED_VOCABULARY_CHECK BEFORE INSERT OR UPDATE ON PROPERTY_TYPES
FOR EACH ROW EXECUTE PROCEDURE CONTROLLED_VOCABULARY_CHECK();
------------------------------------------------------------------------------------
-- Purpose: Create trigger EXTERNAL_DATA_STORAGE_FORMAT_CHECK
------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION EXTERNAL_DATA_STORAGE_FORMAT_CHECK() RETURNS trigger AS $$
DECLARE
v_covo_code CODE;
data_code CODE;
BEGIN
select code into v_covo_code from controlled_vocabularies
where is_internal_namespace = true and
id = (select covo_id from controlled_vocabulary_terms where id = NEW.cvte_id_stor_fmt);
-- Check if the data storage format is a term of the controlled vocabulary "STORAGE_FORMAT"
if v_covo_code != 'STORAGE_FORMAT' then
select code into data_code from data where id = NEW.data_id;
RAISE EXCEPTION 'Insert/Update of Data (Code: %) failed, as its Storage Format is %, but is required to be STORAGE_FORMAT.', data_code, v_covo_code;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER EXTERNAL_DATA_STORAGE_FORMAT_CHECK BEFORE INSERT OR UPDATE ON EXTERNAL_DATA
FOR EACH ROW EXECUTE PROCEDURE EXTERNAL_DATA_STORAGE_FORMAT_CHECK();
------------------------------------------------------------------------------------
-- Purpose: Create triggers for checking sample code uniqueness
------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION SAMPLE_CODE_UNIQUENESS_CHECK() RETURNS trigger AS $$
DECLARE
counter INTEGER;
BEGIN
LOCK TABLE samples IN EXCLUSIVE MODE;
IF (NEW.samp_id_part_of is NULL) THEN
IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and dbin_id = NEW.dbin_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code already exists.', NEW.code;
END IF;
ELSIF (NEW.space_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and space_id = NEW.space_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample with the same code already exists.', NEW.code;
END IF;
END IF;
ELSE
IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and dbin_id = NEW.dbin_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code and being the part of the same container already exists.', NEW.code;
END IF;
ELSIF (NEW.space_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and space_id = NEW.space_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample with the same code and being the part of the same container already exists.', NEW.code;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER SAMPLE_CODE_UNIQUENESS_CHECK BEFORE INSERT OR UPDATE ON SAMPLES
FOR EACH ROW EXECUTE PROCEDURE SAMPLE_CODE_UNIQUENESS_CHECK();
CREATE OR REPLACE FUNCTION SAMPLE_SUBCODE_UNIQUENESS_CHECK() RETURNS trigger AS $$
DECLARE
counter INTEGER;
unique_subcode BOOLEAN_CHAR;
BEGIN
LOCK TABLE samples IN EXCLUSIVE MODE;
SELECT is_subcode_unique into unique_subcode FROM sample_types WHERE id = NEW.saty_id;
IF (unique_subcode) THEN
IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and saty_id = NEW.saty_id and dbin_id = NEW.dbin_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample of the same type with the same subcode already exists.', NEW.code;
END IF;
ELSIF (NEW.space_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and saty_id = NEW.saty_id and space_id = NEW.space_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample of the same type with the same subcode already exists.', NEW.code;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER SAMPLE_SUBCODE_UNIQUENESS_CHECK BEFORE INSERT OR UPDATE ON SAMPLES
FOR EACH ROW EXECUTE PROCEDURE SAMPLE_SUBCODE_UNIQUENESS_CHECK();
------------------------------------------------------------------------------------
-- Purpose: Create trigger MATERIAL/SAMPLE/EXPERIMENT/DATA_SET _PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK
-- It checks that if material property value is assigned to the entity,
-- then the material type is equal to the one described by property type.
------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION MATERIAL_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK() RETURNS trigger AS $$
DECLARE
v_type_id CODE;
v_type_id_prop CODE;
BEGIN
if NEW.mate_prop_id IS NOT NULL then
-- find material type id of the property type
select pt.maty_prop_id into v_type_id_prop
from material_type_property_types etpt, property_types pt
where NEW.mtpt_id = etpt.id AND etpt.prty_id = pt.id;
if v_type_id_prop IS NOT NULL then
-- find material type id of the material which consists the entity's property value
select entity.maty_id into v_type_id
from materials entity
where NEW.mate_prop_id = entity.id;
if v_type_id != v_type_id_prop then
RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).',
NEW.mate_prop_id, v_type_id, v_type_id_prop;
end if;
end if;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER MATERIAL_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK BEFORE INSERT OR UPDATE ON material_properties
FOR EACH ROW EXECUTE PROCEDURE MATERIAL_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK();
CREATE OR REPLACE FUNCTION SAMPLE_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK() RETURNS trigger AS $$
DECLARE
v_type_id CODE;
v_type_id_prop CODE;
BEGIN
if NEW.mate_prop_id IS NOT NULL then
-- find material type id of the property type
select pt.maty_prop_id into v_type_id_prop
from sample_type_property_types etpt, property_types pt
where NEW.stpt_id = etpt.id AND etpt.prty_id = pt.id;
if v_type_id_prop IS NOT NULL then
-- find material type id of the material which consists the entity's property value
select entity.maty_id into v_type_id
from materials entity
where NEW.mate_prop_id = entity.id;
if v_type_id != v_type_id_prop then
RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).',
NEW.mate_prop_id, v_type_id, v_type_id_prop;
end if;
end if;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER SAMPLE_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK BEFORE INSERT OR UPDATE ON sample_properties
FOR EACH ROW EXECUTE PROCEDURE SAMPLE_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK();
CREATE OR REPLACE FUNCTION EXPERIMENT_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK() RETURNS trigger AS $$
DECLARE
v_type_id CODE;
v_type_id_prop CODE;
BEGIN
if NEW.mate_prop_id IS NOT NULL then
-- find material type id of the property type
select pt.maty_prop_id into v_type_id_prop
from experiment_type_property_types etpt, property_types pt
where NEW.etpt_id = etpt.id AND etpt.prty_id = pt.id;
if v_type_id_prop IS NOT NULL then
-- find material type id of the material which consists the entity's property value
select entity.maty_id into v_type_id
from materials entity
where NEW.mate_prop_id = entity.id;
if v_type_id != v_type_id_prop then
RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).',
NEW.mate_prop_id, v_type_id, v_type_id_prop;
end if;
end if;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER EXPERIMENT_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK BEFORE INSERT OR UPDATE ON experiment_properties
FOR EACH ROW EXECUTE PROCEDURE EXPERIMENT_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK();
-- data set
CREATE OR REPLACE FUNCTION DATA_SET_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK() RETURNS trigger AS $$
DECLARE
v_type_id CODE;
v_type_id_prop CODE;
BEGIN
if NEW.mate_prop_id IS NOT NULL then
-- find material type id of the property type
select pt.maty_prop_id into v_type_id_prop
from data_set_type_property_types dstpt, property_types pt
where NEW.dstpt_id = dstpt.id AND dstpt.prty_id = pt.id;
if v_type_id_prop IS NOT NULL then
-- find material type id of the material which consists the entity's property value
select entity.maty_id into v_type_id
from materials entity
where NEW.mate_prop_id = entity.id;
if v_type_id != v_type_id_prop then
RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).',
NEW.mate_prop_id, v_type_id, v_type_id_prop;
end if;
end if;
end if;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER DATA_SET_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK BEFORE INSERT OR UPDATE ON data_set_properties
FOR EACH ROW EXECUTE PROCEDURE DATA_SET_PROPERTY_WITH_MATERIAL_DATA_TYPE_CHECK();
\ No newline at end of file
-- Granting SELECT privilege to group OPENBIS_READONLY
GRANT SELECT ON SEQUENCE attachment_content_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE attachment_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE code_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE controlled_vocabulary_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE cvte_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_set_property_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_set_relationship_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_set_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_store_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE DATA_STORE_SERVICES_ID_SEQ TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE data_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE database_instance_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE dstpt_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE etpt_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE event_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE experiment_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE experiment_property_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE experiment_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE file_format_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE space_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE deletion_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE locator_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE material_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE material_property_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE material_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE mtpt_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE perm_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE person_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE project_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE property_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE role_assignment_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE sample_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE sample_property_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE sample_type_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE stpt_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE authorization_group_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE filter_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON SEQUENCE query_id_seq TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE attachment_contents TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE attachments TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE controlled_vocabularies TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE controlled_vocabulary_terms TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_set_properties TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_set_relationships TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_set_type_property_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_set_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_stores TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE data_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE DATA_STORE_SERVICES TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE DATA_STORE_SERVICE_DATA_SET_TYPES TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE database_instances TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE database_version_logs TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE events TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE experiment_properties TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE experiment_type_property_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE experiment_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE experiments TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE external_data TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE file_format_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE spaces TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE invalidations TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE locator_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE material_properties TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE material_type_property_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE material_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE materials TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE persons TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE projects TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE property_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE role_assignments TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE sample_properties TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE sample_type_property_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE sample_types TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE samples TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE authorization_groups TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE authorization_group_persons TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE filters TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE queries TO GROUP OPENBIS_READONLY;
GRANT SELECT ON TABLE scripts TO GROUP OPENBIS_READONLY;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment