Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4.0.0
with:
repository: icatproject-contrib/icat-ansible
ref: no-icat-install
path: icat-ansible
- name: Install Ansible
run: pip install -r icat-ansible/requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

General installation instructions are at https://icatproject.org/installation/component

Specific installation instructions are at https://repo.icatproject.org/site/icat/server/6.0.1/installation.html
Specific installation instructions are at https://repo.icatproject.org/site/icat/server/7.0.0/installation.html

All documentation on the icat.server may be found at https://repo.icatproject.org/site/icat/server/6.0.1
All documentation on the icat.server may be found at https://repo.icatproject.org/site/icat/server/7.0.0
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.icatproject</groupId>
<artifactId>icat.server</artifactId>
<version>6.2.1-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ICAT Server</name>
<description>A metadata catalogue to support Large Facility experimental data,
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/org/icatproject/core/entity/Investigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Investigation extends EntityBaseBean implements Serializable {
private Date releaseDate;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation")
private List<Sample> samples = new ArrayList<>();
private List<InvestigationSample> samples = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation")
private List<Shift> shifts = new ArrayList<>();
Expand Down Expand Up @@ -184,7 +184,7 @@ public Date getReleaseDate() {
return this.releaseDate;
}

public List<Sample> getSamples() {
public List<InvestigationSample> getSamples() {
return samples;
}

Expand Down Expand Up @@ -284,7 +284,7 @@ public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}

public void setSamples(List<Sample> samples) {
public void setSamples(List<InvestigationSample> samples) {
this.samples = samples;
}

Expand Down Expand Up @@ -383,11 +383,6 @@ public static Map<String, Relationship[]> getDocumentFields() throws IcatExcepti
Relationship[] parameterTypeRelationships = {
EntityInfoHandler.getRelationshipsByName(Investigation.class).get("parameters"),
EntityInfoHandler.getRelationshipsByName(InvestigationParameter.class).get("type") };
Relationship[] sampleRelationships = {
EntityInfoHandler.getRelationshipsByName(Investigation.class).get("samples") };
Relationship[] sampleTypeRelationships = {
EntityInfoHandler.getRelationshipsByName(Investigation.class).get("samples"),
EntityInfoHandler.getRelationshipsByName(Sample.class).get("type") };
documentFields.put("name", null);
documentFields.put("visitId", null);
documentFields.put("title", null);
Expand All @@ -411,9 +406,6 @@ public static Map<String, Relationship[]> getDocumentFields() throws IcatExcepti
documentFields.put("InvestigationParameter stringValue", parameterRelationships);
documentFields.put("InvestigationParameter numericValue", parameterRelationships);
documentFields.put("InvestigationParameter dateTimeValue", parameterRelationships);
documentFields.put("Sample sample.id", sampleRelationships);
documentFields.put("Sample sample.name", sampleRelationships);
documentFields.put("Sample type.name", sampleTypeRelationships);
}
return documentFields;
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/org/icatproject/core/entity/InvestigationSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.icatproject.core.entity;

import java.io.Serializable;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Comment("Represents a many-to-many relationship between an investigation and a sample that has been used in that investigation")
@SuppressWarnings("serial")
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "INVESTIGATION_ID", "SAMPLE_ID" }) })
public class InvestigationSample extends EntityBaseBean implements Serializable {

@JoinColumn(nullable = false, name = "INVESTIGATION_ID")
@ManyToOne(fetch = FetchType.LAZY)
private Investigation investigation;

@JoinColumn(nullable = false, name = "SAMPLE_ID")
@ManyToOne(fetch = FetchType.LAZY)
private Sample sample;

public Investigation getInvestigation() {
return this.investigation;
}

public Sample getSample() {
return this.sample;
}

public void setInvestigation(Investigation investigation) {
this.investigation = investigation;
}

public void setSample(Sample sample) {
this.sample = sample;
}
}
26 changes: 10 additions & 16 deletions src/main/java/org/icatproject/core/entity/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
import org.icatproject.core.IcatException;
import org.icatproject.core.manager.search.SearchApi;

@Comment("A sample to be used in an investigation")
@Comment("A sample to be used in one or more investigations")
@SuppressWarnings("serial")
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "INVESTIGATION_ID", "NAME" }) })
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "PID" }) })
public class Sample extends EntityBaseBean implements Serializable {

@Comment("A persistent identifier attributed to this sample")
@Column(nullable = false, name = "PID")
private String pid;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "sample")
private List<Dataset> datasets = new ArrayList<>();

@JoinColumn(nullable = false, name = "INVESTIGATION_ID")
@ManyToOne(fetch = FetchType.LAZY)
private Investigation investigation;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "sample")
private List<InvestigationSample> investigationSamples = new ArrayList<>();

@Column(nullable = false, name = "NAME")
@Column(nullable = false)
private String name;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "sample")
Expand Down Expand Up @@ -67,8 +67,8 @@ public List<Dataset> getDatasets() {
return this.datasets;
}

public Investigation getInvestigation() {
return this.investigation;
public List<InvestigationSample> getInvestigationSamples() {
return this.investigationSamples;
}

public String getName() {
Expand All @@ -83,8 +83,8 @@ public void setDatasets(List<Dataset> datasets) {
this.datasets = datasets;
}

public void setInvestigation(Investigation investigation) {
this.investigation = investigation;
public void setInvestigationSamples(List<InvestigationSample> investigationSamples) {
this.investigationSamples = investigationSamples;
}

public void setName(String name) {
Expand All @@ -107,12 +107,6 @@ public void setType(SampleType type) {
public void getDoc(EntityManager entityManager, JsonGenerator gen) throws IcatException {
SearchApi.encodeString(gen, "sample.name", name);
SearchApi.encodeLong(gen, "sample.id", id);
if (investigation != null) {
// Investigation is not nullable, but it is possible to pass Samples without their Investigation
// relationship populated when creating Datasets, where this field is not needed anyway - so guard against
// null pointers
SearchApi.encodeLong(gen, "sample.investigation.id", investigation.id);
}
if (type != null) {
if (type.getName() == null) {
type = entityManager.find(type.getClass(), type.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.icatproject.core.entity.InvestigationGroup;
import org.icatproject.core.entity.InvestigationInstrument;
import org.icatproject.core.entity.InvestigationParameter;
import org.icatproject.core.entity.InvestigationSample;
import org.icatproject.core.entity.InvestigationType;
import org.icatproject.core.entity.InvestigationUser;
import org.icatproject.core.entity.Job;
Expand Down Expand Up @@ -223,8 +224,8 @@ public String toString() {
Publication.class, RelatedDatafile.class, SampleParameter.class, Shift.class, Study.class,
DataPublicationType.class, DataPublication.class, Subject.class, DataPublicationDate.class, DataPublicationUser.class,
Affiliation.class, RelatedItem.class, FundingReference.class, DataPublicationFunding.class,
InvestigationFunding.class, InvestigationUser.class, InvestigationGroup.class, StudyInvestigation.class,
InvestigationInstrument.class, InstrumentScientist.class, DatasetInstrument.class,
InvestigationFunding.class, InvestigationUser.class, InvestigationGroup.class, InvestigationSample.class,
StudyInvestigation.class, InvestigationInstrument.class, InstrumentScientist.class, DatasetInstrument.class,
InvestigationFacilityCycle.class);

// All entities, plus the abstract classes Parameter and EntityBaseBean
Expand Down
23 changes: 12 additions & 11 deletions src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,59 @@

<class>org.icatproject.core.entity.Affiliation</class>
<class>org.icatproject.core.entity.Application</class>
<class>org.icatproject.core.entity.DataCollection</class>
<class>org.icatproject.core.entity.DataCollectionDatafile</class>
<class>org.icatproject.core.entity.DataCollectionDataset</class>
<class>org.icatproject.core.entity.DataCollectionInvestigation</class>
<class>org.icatproject.core.entity.DataCollection</class>
<class>org.icatproject.core.entity.DataCollectionParameter</class>
<class>org.icatproject.core.entity.DatafileFormat</class>
<class>org.icatproject.core.entity.Datafile</class>
<class>org.icatproject.core.entity.DatafileParameter</class>
<class>org.icatproject.core.entity.DataPublication</class>
<class>org.icatproject.core.entity.DataPublicationDate</class>
<class>org.icatproject.core.entity.DataPublicationFunding</class>
<class>org.icatproject.core.entity.DataPublication</class>
<class>org.icatproject.core.entity.DataPublicationType</class>
<class>org.icatproject.core.entity.DataPublicationUser</class>
<class>org.icatproject.core.entity.DatasetInstrument</class>
<class>org.icatproject.core.entity.Datafile</class>
<class>org.icatproject.core.entity.DatafileFormat</class>
<class>org.icatproject.core.entity.DatafileParameter</class>
<class>org.icatproject.core.entity.Dataset</class>
<class>org.icatproject.core.entity.DatasetInstrument</class>
<class>org.icatproject.core.entity.DatasetParameter</class>
<class>org.icatproject.core.entity.DatasetTechnique</class>
<class>org.icatproject.core.entity.DatasetType</class>
<class>org.icatproject.core.entity.FacilityCycle</class>
<class>org.icatproject.core.entity.Facility</class>
<class>org.icatproject.core.entity.FacilityCycle</class>
<class>org.icatproject.core.entity.FundingReference</class>
<class>org.icatproject.core.entity.Grouping</class>
<class>org.icatproject.core.entity.Instrument</class>
<class>org.icatproject.core.entity.InstrumentScientist</class>
<class>org.icatproject.core.entity.Investigation</class>
<class>org.icatproject.core.entity.InvestigationFacilityCycle</class>
<class>org.icatproject.core.entity.InvestigationFunding</class>
<class>org.icatproject.core.entity.InvestigationGroup</class>
<class>org.icatproject.core.entity.InvestigationInstrument</class>
<class>org.icatproject.core.entity.Investigation</class>
<class>org.icatproject.core.entity.InvestigationParameter</class>
<class>org.icatproject.core.entity.InvestigationSample</class>
<class>org.icatproject.core.entity.InvestigationType</class>
<class>org.icatproject.core.entity.InvestigationUser</class>
<class>org.icatproject.core.entity.Job</class>
<class>org.icatproject.core.entity.Keyword</class>
<class>org.icatproject.core.entity.Parameter</class>
<class>org.icatproject.core.entity.ParameterType</class>
<class>org.icatproject.core.entity.PermissibleStringValue</class>
<class>org.icatproject.core.entity.Publication</class>
<class>org.icatproject.core.entity.PublicStep</class>
<class>org.icatproject.core.entity.Publication</class>
<class>org.icatproject.core.entity.RelatedDatafile</class>
<class>org.icatproject.core.entity.RelatedItem</class>
<class>org.icatproject.core.entity.Rule</class>
<class>org.icatproject.core.entity.Sample</class>
<class>org.icatproject.core.entity.SampleParameter</class>
<class>org.icatproject.core.entity.SampleType</class>
<class>org.icatproject.core.entity.Shift</class>
<class>org.icatproject.core.entity.StudyInvestigation</class>
<class>org.icatproject.core.entity.Study</class>
<class>org.icatproject.core.entity.StudyInvestigation</class>
<class>org.icatproject.core.entity.Subject</class>
<class>org.icatproject.core.entity.Technique</class>
<class>org.icatproject.core.entity.UserGroup</class>
<class>org.icatproject.core.entity.User</class>
<class>org.icatproject.core.entity.UserGroup</class>
<exclude-unlisted-classes />

<properties>
Expand Down
69 changes: 69 additions & 0 deletions src/main/scripts/upgrade_mysql_7_0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- Add table and constraints for InvestigationSamples

CREATE TABLE INVESTIGATIONSAMPLE (
ID BIGINT NOT NULL AUTO_INCREMENT,
CREATE_ID VARCHAR(255) NOT NULL,
CREATE_TIME DATETIME NOT NULL,
MOD_ID VARCHAR(255) NOT NULL,
MOD_TIME DATETIME NOT NULL,
INVESTIGATION_ID BIGINT NOT NULL,
SAMPLE_ID BIGINT NOT NULL,
PRIMARY KEY (ID)
);

ALTER TABLE INVESTIGATIONSAMPLE ADD CONSTRAINT FK_INVESTIGATIONSAMPLE_INVESTIGATION_ID FOREIGN KEY (INVESTIGATION_ID) REFERENCES INVESTIGATION (ID);
ALTER TABLE INVESTIGATIONSAMPLE ADD CONSTRAINT FK_INVESTIGATIONSAMPLE_SAMPLE_ID FOREIGN KEY (SAMPLE_ID) REFERENCES SAMPLE (ID);
ALTER TABLE INVESTIGATIONSAMPLE ADD CONSTRAINT UNQ_INVESTIGATIONSAMPLE_0 UNIQUE (INVESTIGATION_ID, SAMPLE_ID);

-- Set the PID field of existing Samples

DELIMITER //

CREATE PROCEDURE SET_SAMPLES_PID()
BEGIN
UPDATE SAMPLE SET PID = CONCAT('_local:', LPAD(ID, 8, '0')), MOD_ID = 'schema_upgrade', MOD_TIME = NOW() WHERE PID IS NULL;
END; //

DELIMITER ;

CALL SET_SAMPLES_PID();

DROP PROCEDURE SET_SAMPLES_PID;

-- Move existing Sample/Investigation relations over to the new table

DELIMITER //

CREATE PROCEDURE MOVE_SAMPLE_INVESTIGATION_RELATIONS()
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE _invid BIGINT;
DECLARE _id BIGINT;
DECLARE cur CURSOR FOR SELECT INVESTIGATION_ID, ID FROM SAMPLE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;

OPEN cur;
sampleLoop: LOOP
FETCH cur INTO _invid, _id;
IF done THEN
LEAVE sampleLoop;
END IF;

INSERT INTO INVESTIGATIONSAMPLE (CREATE_ID, CREATE_TIME, MOD_ID, MOD_TIME, INVESTIGATION_ID, SAMPLE_ID) VALUES ('schema_upgrade', NOW(), 'schema_upgrade', NOW(), _invid, _id);
END LOOP sampleLoop;
CLOSE cur;
END; //

DELIMITER ;

CALL MOVE_SAMPLE_INVESTIGATION_RELATIONS();

DROP PROCEDURE MOVE_SAMPLE_INVESTIGATION_RELATIONS;

-- Alter the Sample table

ALTER TABLE SAMPLE MODIFY PID VARCHAR(255) NOT NULL;
ALTER TABLE SAMPLE DROP CONSTRAINT FK_SAMPLE_INVESTIGATION_ID;
ALTER TABLE SAMPLE DROP CONSTRAINT UNQ_SAMPLE_0;
ALTER TABLE SAMPLE ADD CONSTRAINT UNQ_SAMPLE_0 UNIQUE (PID);
ALTER TABLE SAMPLE DROP COLUMN INVESTIGATION_ID;
Loading