Skip to content

Commit 6585fce

Browse files
committed
Fix proper implementation of #326:
- Remove relation from SampleType to Facility - Change uniqueness constraint for SampleType to be pid alone
1 parent 0a71174 commit 6585fce

File tree

8 files changed

+26
-53
lines changed

8 files changed

+26
-53
lines changed

src/main/java/org/icatproject/core/entity/Facility.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ public class Facility extends EntityBaseBean implements Serializable {
6363
@OneToMany(cascade = CascadeType.ALL, mappedBy = "facility")
6464
private List<ParameterType> parameterTypes = new ArrayList<ParameterType>();
6565

66-
@OneToMany(cascade = CascadeType.ALL, mappedBy = "facility")
67-
private List<SampleType> sampleTypes = new ArrayList<SampleType>();
68-
6966
@Comment("A URL associated with this facility")
7067
private String url;
7168

@@ -129,10 +126,6 @@ public List<ParameterType> getParameterTypes() {
129126
return parameterTypes;
130127
}
131128

132-
public List<SampleType> getSampleTypes() {
133-
return sampleTypes;
134-
}
135-
136129
public String getUrl() {
137130
return url;
138131
}
@@ -193,10 +186,6 @@ public void setParameterTypes(List<ParameterType> parameterTypes) {
193186
this.parameterTypes = parameterTypes;
194187
}
195188

196-
public void setSampleTypes(List<SampleType> sampleTypes) {
197-
this.sampleTypes = sampleTypes;
198-
}
199-
200189
public void setUrl(String url) {
201190
this.url = url;
202191
}

src/main/java/org/icatproject/core/entity/SampleType.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@
2525
@Comment("A sample to be used in an investigation")
2626
@SuppressWarnings("serial")
2727
@Entity
28-
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "FACILITY_ID", "NAME",
29-
"PID" }) })
28+
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "PID" }) })
3029
public class SampleType extends EntityBaseBean implements Serializable {
3130

32-
@Comment("The facility which has defined this sample type")
33-
@JoinColumn(name = "FACILITY_ID", nullable = false)
34-
@ManyToOne(fetch = FetchType.LAZY)
35-
private Facility facility;
36-
3731
@Comment("A persistent identifier attributed to this sample type, ideally referring to a vocabulary term")
3832
@Column(name = "PID", nullable = false)
3933
private String pid;
@@ -58,10 +52,6 @@ public class SampleType extends EntityBaseBean implements Serializable {
5852
public SampleType() {
5953
}
6054

61-
public Facility getFacility() {
62-
return facility;
63-
}
64-
6555
public String getPid() {
6656
return pid;
6757
}
@@ -82,10 +72,6 @@ public List<Sample> getSamples() {
8272
return samples;
8373
}
8474

85-
public void setFacility(Facility facility) {
86-
this.facility = facility;
87-
}
88-
8975
public void setPid(String pid) {
9076
this.pid = pid;
9177
}

src/test/java/org/icatproject/core/manager/TestEntityInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void testExportNull() throws Exception {
170170
public void testFields() throws Exception {
171171
testField(
172172
"applications,dataPublicationTypes,dataPublications,datafileFormats,datasetTypes,daysUntilRelease,description,facilityCycles,"
173-
+ "fullName,instruments,investigationTypes,investigations,name,parameterTypes,sampleTypes,url",
173+
+ "fullName,instruments,investigationTypes,investigations,name,parameterTypes,url",
174174
Facility.class);
175175
testField("description,facility,investigations,name", InvestigationType.class);
176176
testField(

src/test/java/org/icatproject/integration/TestRS.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void TestJsoniseBean() throws Exception {
187187
* "2019-03-11T15:58:33.000Z","applications":[],"datafileFormats":[],
188188
* "datasetTypes":[],"daysUntilRelease":90,"facilityCycles":[],"instruments":[],
189189
* "investigationTypes":[],"investigations":[],"name":"Test port facility"
190-
* ,"parameterTypes":[],"sampleTypes":[]}}]>
190+
* ,"parameterTypes":[]}}]>
191191
*/
192192
JsonArray fac_response = search(session, "SELECT f from Facility f WHERE f.name = 'Test port facility'", 1);
193193
collector.checkThat(fac_response.getJsonObject(0).containsKey("Facility"), is(true));
@@ -293,12 +293,11 @@ public void TestJsoniseBean() throws Exception {
293293
collector.checkThat(st_response.getJsonObject(0).containsKey("SampleType"), is(true));
294294

295295
/*
296-
* Expected: <[{"SampleType":{"id":????,"createId":"db/notroot","createTime":
297-
* "2019-03-11T15:58:33.000Z","modId":"db/notroot","modTime":
298-
* "2019-03-11T15:58:33.000Z","molecularFormula":null,"name":"N/A",
299-
* "pid":"st:004","safetyInformation":"N/A","samples":[]}}]>
296+
* Expected: <[{"SampleType":{"id":420,"createId":"db/notroot","createTime":
297+
* "2025-12-17T13:23:13.000Z","modId":"db/notroot","modTime":
298+
* "2025-12-17T13:23:13.000Z","name":"fossil","pid":"st:004","samples":[]}}]>
300299
*/
301-
JsonArray st_null_response = search(session, "SELECT st from SampleType st WHERE st.name = 'N/A'", 1);
300+
JsonArray st_null_response = search(session, "SELECT st from SampleType st WHERE st.name = 'fossil'", 1);
302301
collector.checkThat(st_null_response.getJsonObject(0).containsKey("SampleType"), is(true));
303302
collector.checkThat(st_null_response.getJsonObject(0).getJsonObject("SampleType").getString("pid"), is("st:004"));
304303
collector.checkThat(st_null_response.getJsonObject(0).getJsonObject("SampleType").get("molecularFormula"), is(equalTo(null)));

src/test/java/org/icatproject/integration/TestWS.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private static void create() throws Exception {
104104

105105
SampleType sampleType = new SampleType();
106106
/* FIXME: sampleType.setPid("somepid"); */
107-
sampleType.setFacility(facility);
108107
sampleType.setName("somename");
109108
sampleType.setMolecularFormula("Someformula");
110109
session.create(sampleType);
@@ -1008,7 +1007,6 @@ public void getInvestigationWithVeryManyDatasets() throws Exception {
10081007

10091008
SampleType sampleType = new SampleType();
10101009
/* FIXME: sampleType.setPid("somepid"); */
1011-
sampleType.setFacility(facility);
10121010
sampleType.setName("somename");
10131011
sampleType.setMolecularFormula("Someformula");
10141012
session.create(sampleType);

src/test/java/org/icatproject/integration/WSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void addUserGroupMember(String groupName, String userName) throws Excepti
195195
}
196196

197197
public void clear() throws Exception {
198-
deleteAll(Arrays.asList("Facility", "DataCollection", "Study", "FundingReference", "Technique"));
198+
deleteAll(Arrays.asList("Facility", "DataCollection", "Study", "FundingReference", "Technique", "SampleType"));
199199
}
200200

201201
private void deleteAll(List<String> names) throws IcatException_Exception {

src/test/resources/icat-import-check.port

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ Shift(investigation(facility(name:0), name:1, visitId:2), startDate:3, endDate:4
4040
"Test port facility", "expt1", "zero", 2014-01-01T00:00:00+01:00, 2014-01-01T18:00:00+01:00, "beamtime", "EDDI"
4141
"Test port facility", "expt1", "two", 2014-04-29T14:00:00+02:00, 2014-04-30T18:15:00+02:00, "preparing", null
4242

43-
SampleType(facility(name:0), name:1, molecularFormula:2, safetyInformation:3, pid:4)
44-
"Test port facility", "diamond", "C", "fairly harmless", "st:001"
45-
"Test port facility", "graphite", "C", "bit messy", "st:002"
46-
"Test port facility", "rust", "Fe3O4", "messy", "st:003"
47-
48-
Sample(investigation(facility(name:0), name:1, visitId:2), type(facility(name:0), name:3, molecularFormula:4), name:5, pid:6)
49-
"Test port facility", "expt1", "one", "diamond", "C", "Koh-I-Noor", "sdb:374717"
50-
"Test port facility", "expt1", "one", "rust", "Fe3O4", "Ford\t\"Anglia\"", null
43+
SampleType(name:0, molecularFormula:1, safetyInformation:2, pid:3)
44+
"diamond", "C", "fairly harmless", "st:001"
45+
"graphite", "C", "bit messy", "st:002"
46+
"rust", "Fe3O4", "messy", "st:003"
47+
"fossil", null, null, "st:004"
48+
49+
Sample(investigation(facility(name:0), name:1, visitId:2), type(pid:3), name:4, pid:5)
50+
"Test port facility", "expt1", "one", "st:001", "Koh-I-Noor", "sdb:374717"
51+
"Test port facility", "expt1", "one", "st:003", "Ford\t\"Anglia\"", null
5152

5253
InvestigationParameter(investigation(facility(name:0), name:1, visitId:2), type(facility(name:0), name:3 , units:4),stringValue:5)
5354
"Test port facility", "expt1", "one", "colour" , "name", "green"

src/test/resources/icat.port

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ Shift(investigation(facility(name:0), name:1, visitId:2), startDate:3, endDate:4
4040
"Test port facility", "expt1", "zero", 2014-01-01T00:00:00+01:00, 2014-01-01T18:00:00+01:00, "beamtime", "EDDI"
4141
"Test port facility", "expt1", "two", 2014-04-29T14:00:00+02:00, 2014-04-30T18:15:00+02:00, "preparing", null
4242

43-
SampleType(facility(name:0), name:1, molecularFormula:2, safetyInformation:3, pid:4)
44-
"Test port facility", "diamond", "C", "fairly harmless", "st:001"
45-
"Test port facility", "graphite", "C", "bit messy", "st:002"
46-
"Test port facility", "rust", "Fe3O4", "messy", "st:003"
47-
"Test port facility", "N/A", null, "N/A", "st:004"
48-
49-
Sample(investigation(facility(name:0), name:1, visitId:2), type(facility(name:0), name:3, molecularFormula:4), name:5, pid:6)
50-
"Test port facility", "expt1", "one", "diamond", "C", "Koh-I-Noor", "sdb:374717"
51-
"Test port facility", "expt1", "one", "rust", "Fe3O4", "Ford\t\"Anglia\"", null
43+
SampleType(name:0, molecularFormula:1, safetyInformation:2, pid:3)
44+
"diamond", "C", "fairly harmless", "st:001"
45+
"graphite", "C", "bit messy", "st:002"
46+
"rust", "Fe3O4", "messy", "st:003"
47+
"fossil", null, null, "st:004"
48+
49+
Sample(investigation(facility(name:0), name:1, visitId:2), type(pid:3), name:4, pid:5)
50+
"Test port facility", "expt1", "one", "st:001", "Koh-I-Noor", "sdb:374717"
51+
"Test port facility", "expt1", "one", "st:003", "Ford\t\"Anglia\"", null
5252

5353
InvestigationParameter(investigation(facility(name:0), name:1, visitId:2), type(facility(name:0), name:3 , units:4),stringValue:5)
5454
"Test port facility", "expt1", "one", "colour" , "name", "green"

0 commit comments

Comments
 (0)