Skip to content

Commit fd4478c

Browse files
authored
Merge pull request #247 from maximiliani/109-multipleFAIR_DOs
API for creating interconnected FAIR-DOs (a FAIR-DO graph) in a single request
2 parents 857d912 + 8b2ae49 commit fd4478c

File tree

12 files changed

+2963
-740
lines changed

12 files changed

+2963
-740
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,8 @@ $RECYCLE.BIN/
135135
**/*.properties
136136
!/config/application-default.properties
137137
!/config/application-docker.properties
138-
##############
138+
##############
139+
140+
test_prefix_data/
141+
config/*.bin
142+
config/*.pem

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ repositories {
4848
}
4949

5050
ext {
51-
springDocVersion = '2.8.4'
51+
springDocVersion = '2.8.9'
5252
}
5353

5454
dependencies {
@@ -89,7 +89,7 @@ dependencies {
8989
implementation("net.handle:handle-client:9.3.1")
9090

9191
testImplementation(platform('org.junit:junit-bom:5.11.4'))
92-
testImplementation('org.junit.jupiter:junit-jupiter')
92+
testImplementation('org.junit.jupiter:junit-jupiter')
9393
testImplementation('org.junit.jupiter:junit-jupiter-params')
9494

9595
testImplementation("org.springframework:spring-test")
@@ -154,7 +154,7 @@ test {
154154
println "Tests will have verbose output"
155155
testLogging {
156156
// tests are never "up-to-date", always print everything
157-
outputs.upToDateWhen {false}
157+
outputs.upToDateWhen { false }
158158
// show stdio when tests are running
159159
showStandardStreams = true
160160
// for junit5

config/application-default.properties

Lines changed: 73 additions & 85 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
1-
package edu.kit.datamanager.pit.common;
1+
/*
2+
* Copyright (c) 2024 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
import org.springframework.web.server.ResponseStatusException;
4-
import org.springframework.http.HttpStatus;
17+
package edu.kit.datamanager.pit.common;
518

619
import edu.kit.datamanager.pit.domain.PIDRecord;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.web.server.ResponseStatusException;
722

823
/**
924
* Indicates that a PID was given which could not be resolved to answer the
1025
* request properly.
1126
*/
1227
public class RecordValidationException extends ResponseStatusException {
1328

14-
private static final String VALIDATION_OF_RECORD = "Validation of record ";
15-
private static final long serialVersionUID = 1L;
16-
private static final HttpStatus HTTP_STATUS = HttpStatus.BAD_REQUEST;
29+
private static final String VALIDATION_OF_RECORD = "Validation of record ";
30+
private static final long serialVersionUID = 1L;
31+
private static final HttpStatus HTTP_STATUS = HttpStatus.BAD_REQUEST;
1732

18-
// For cases in which the PID record shold be appended to the error response.
19-
private final transient PIDRecord pidRecord;
33+
// For cases in which the PID record should be appended to the error response.
34+
private final transient PIDRecord pidRecord;
2035

21-
public RecordValidationException(PIDRecord pidRecord) {
22-
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed.");
23-
this.pidRecord = pidRecord;
24-
}
36+
public RecordValidationException(PIDRecord pidRecord) {
37+
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed.");
38+
this.pidRecord = pidRecord;
39+
}
2540

26-
public RecordValidationException(PIDRecord pidRecord, String reason) {
27-
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason);
28-
this.pidRecord = pidRecord;
29-
}
41+
public RecordValidationException(PIDRecord pidRecord, String reason) {
42+
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason);
43+
this.pidRecord = pidRecord;
44+
}
3045

31-
public RecordValidationException(PIDRecord pidRecord, String reason, Exception e) {
32-
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason, e);
33-
this.pidRecord = pidRecord;
34-
}
46+
public RecordValidationException(PIDRecord pidRecord, String reason, Exception e) {
47+
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason, e);
48+
this.pidRecord = pidRecord;
49+
}
3550

36-
public PIDRecord getPidRecord() {
37-
return pidRecord;
38-
}
51+
public PIDRecord getPidRecord() {
52+
return pidRecord;
53+
}
3954
}

src/main/java/edu/kit/datamanager/pit/domain/PIDRecord.java

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
/*
2+
* Copyright (c) 2025 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package edu.kit.datamanager.pit.domain;
218

319
import com.fasterxml.jackson.annotation.JsonIgnore;
4-
520
import edu.kit.datamanager.entities.EtagSupport;
621
import edu.kit.datamanager.pit.pidsystem.impl.local.PidDatabaseObject;
722

8-
import java.util.ArrayList;
9-
import java.util.Collection;
10-
import java.util.HashMap;
11-
import java.util.List;
12-
import java.util.Map;
23+
import java.util.*;
1324
import java.util.stream.Collectors;
14-
import java.util.Set;
1525

1626
/**
1727
* The internal representation for a PID record, offering methods to manipulate
@@ -21,7 +31,7 @@
2131
* communication or representation for the outside. In contrast, this is the
2232
* internal representation offering methods for manipulation.
2333
*/
24-
public class PIDRecord implements EtagSupport {
34+
public class PIDRecord implements EtagSupport, Cloneable {
2535

2636
private String pid = "";
2737

@@ -30,11 +40,12 @@ public class PIDRecord implements EtagSupport {
3040
/**
3141
* Creates an empty record without PID.
3242
*/
33-
public PIDRecord() {}
43+
public PIDRecord() {
44+
}
3445

3546
/**
3647
* Creates a record with the same content as the given representation.
37-
*
48+
*
3849
* @param dbo the given record representation.
3950
*/
4051
public PIDRecord(PidDatabaseObject dbo) {
@@ -53,7 +64,7 @@ public PIDRecord(SimplePidRecord rec) {
5364

5465
/**
5566
* Convenience setter / builder method.
56-
*
67+
*
5768
* @param pid the pid to set in this object.
5869
* @return this object (builder method).
5970
*/
@@ -74,6 +85,15 @@ public Map<String, List<PIDRecordEntry>> getEntries() {
7485
return entries;
7586
}
7687

88+
/**
89+
* Sets the entries of this record.
90+
*
91+
* @param entries the entries to set.
92+
*/
93+
public void setEntries(Map<String, List<PIDRecordEntry>> entries) {
94+
this.entries = entries;
95+
}
96+
7797
@JsonIgnore
7898
public Set<SimplePair> getSimpleEntries() {
7999
return this.entries
@@ -85,20 +105,16 @@ public Set<SimplePair> getSimpleEntries() {
85105
.collect(Collectors.toSet());
86106
}
87107

88-
public void setEntries(Map<String, List<PIDRecordEntry>> entries) {
89-
this.entries = entries;
90-
}
91-
92108
public void addEntry(String propertyIdentifier, String propertyValue) {
93109
this.addEntry(propertyIdentifier, "", propertyValue);
94110
}
95111

96112
/**
97113
* Adds a new key-name-value triplet.
98-
*
114+
*
99115
* @param propertyIdentifier the key/type PID.
100-
* @param propertyName the human-readable name for the given key/type.
101-
* @param propertyValue the value to this key/type.
116+
* @param propertyName the human-readable name for the given key/type.
117+
* @param propertyValue the value to this key/type.
102118
*/
103119
public void addEntry(String propertyIdentifier, String propertyName, String propertyValue) {
104120
if (propertyIdentifier.isEmpty()) {
@@ -110,22 +126,22 @@ public void addEntry(String propertyIdentifier, String propertyName, String prop
110126
entry.setValue(propertyValue);
111127

112128
this.entries
113-
.computeIfAbsent(propertyIdentifier, key -> new ArrayList<>())
114-
.add(entry);
129+
.computeIfAbsent(propertyIdentifier, key -> new ArrayList<>())
130+
.add(entry);
115131
}
116132

117133
/**
118134
* Sets the name for a given key/type in all available pairs.
119-
*
135+
*
120136
* @param propertyIdentifier the key/type.
121-
* @param name the new name.
137+
* @param name the new name.
122138
*/
123139
@JsonIgnore
124140
public void setPropertyName(String propertyIdentifier, String name) {
125141
List<PIDRecordEntry> propertyEntries = this.entries.get(propertyIdentifier);
126142
if (propertyEntries == null) {
127143
throw new IllegalArgumentException(
128-
"Property identifier not listed in this record: " + propertyIdentifier);
144+
"Property identifier not listed in this record: " + propertyIdentifier);
129145
}
130146
for (PIDRecordEntry entry : propertyEntries) {
131147
entry.setName(name);
@@ -135,7 +151,7 @@ public void setPropertyName(String propertyIdentifier, String name) {
135151
/**
136152
* Check if there is a pair or triplet containing the given property (key/type)
137153
* is availeble in this record.
138-
*
154+
*
139155
* @param propertyIdentifier the key/type to search for.
140156
* @return true, if the property/key/type is present.
141157
*/
@@ -158,7 +174,7 @@ public void removeAllValuesOf(String attribute) {
158174

159175
/**
160176
* Get all properties contained in this record.
161-
*
177+
*
162178
* @return al contained properties.
163179
*/
164180
@JsonIgnore
@@ -180,7 +196,7 @@ public String getPropertyValue(String propertyIdentifier) {
180196

181197
/**
182198
* Get all values of a given property.
183-
*
199+
*
184200
* @param propertyIdentifier the given property identifier.
185201
* @return all values of the given property.
186202
*/
@@ -194,7 +210,7 @@ public String[] getPropertyValues(String propertyIdentifier) {
194210
for (PIDRecordEntry e : entry) {
195211
values.add(e.getValue());
196212
}
197-
return values.toArray(new String[] {});
213+
return values.toArray(new String[]{});
198214
}
199215

200216
@Override
@@ -215,9 +231,15 @@ public int hashCode() {
215231
*/
216232
@Override
217233
public boolean equals(Object obj) {
218-
if (this == obj) {return true;}
219-
if (obj == null) {return false;}
220-
if (getClass() != obj.getClass()) {return false;}
234+
if (this == obj) {
235+
return true;
236+
}
237+
if (obj == null) {
238+
return false;
239+
}
240+
if (getClass() != obj.getClass()) {
241+
return false;
242+
}
221243

222244
PIDRecord other = (PIDRecord) obj;
223245
boolean isThisPidEmpty = pid == null || pid.isBlank();
@@ -240,13 +262,32 @@ public String toString() {
240262

241263
/**
242264
* Calculates an etag for a record.
243-
*
265+
*
244266
* @return an etag, which is independent of any order or duplicates in the
245-
* entries.
267+
* entries.
246268
*/
247269
@JsonIgnore
248270
@Override
249271
public String getEtag() {
250272
return Integer.toString(this.hashCode());
251273
}
274+
275+
@Override
276+
public PIDRecord clone() {
277+
try {
278+
PIDRecord clone = (PIDRecord) super.clone();
279+
clone.pid = this.pid;
280+
clone.entries = new HashMap<>();
281+
for (Map.Entry<String, List<PIDRecordEntry>> entry : this.entries.entrySet()) {
282+
List<PIDRecordEntry> entryList = new ArrayList<>();
283+
for (PIDRecordEntry e : entry.getValue()) {
284+
entryList.add(e.clone());
285+
}
286+
clone.entries.put(entry.getKey(), entryList);
287+
}
288+
return clone;
289+
} catch (CloneNotSupportedException e) {
290+
throw new AssertionError();
291+
}
292+
}
252293
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
/*
2+
* Copyright (c) 2025 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package edu.kit.datamanager.pit.domain;
218

319
import lombok.Data;
420

521
@Data
6-
public class PIDRecordEntry {
22+
public class PIDRecordEntry implements Cloneable {
723
private String key;
824
private String name;
925
private String value;
26+
27+
@Override
28+
public PIDRecordEntry clone() {
29+
try {
30+
return (PIDRecordEntry) super.clone();
31+
} catch (CloneNotSupportedException e) {
32+
throw new AssertionError();
33+
}
34+
}
1035
}

0 commit comments

Comments
 (0)