From 79d1b6849a5a18df54d36d8cbf0ff69eab20c33e Mon Sep 17 00:00:00 2001 From: Andreas Pfeil Date: Tue, 30 Sep 2025 15:56:46 +0200 Subject: [PATCH 1/4] refactor: rename PIDRecord to PidRecord across the codebase for consistency --- .../edu/kit/datamanager/pit/Application.java | 4 +- .../datamanager/pit/cli/CliTaskBootstrap.java | 4 +- .../pit/common/RecordValidationException.java | 12 +- .../datamanager/pit/domain/Operations.java | 4 +- .../domain/{PIDRecord.java => PidRecord.java} | 586 +++++++++--------- .../pit/domain/SimplePidRecord.java | 2 +- .../PidRecordElasticWrapper.java | 4 +- .../pit/pidsystem/IIdentifierSystem.java | 14 +- .../impl/InMemoryIdentifierSystem.java | 12 +- .../pidsystem/impl/handle/HandleBehavior.java | 8 +- .../impl/handle/HandleProtocolAdapter.java | 12 +- .../pidsystem/impl/local/LocalPidSystem.java | 11 +- .../impl/local/PidDatabaseObject.java | 4 +- .../pit/pitservice/ITypingService.java | 4 +- .../pit/pitservice/IValidationStrategy.java | 4 +- .../impl/EmbeddedStrictValidatorStrategy.java | 6 +- .../pitservice/impl/NoValidationStrategy.java | 4 +- .../pit/pitservice/impl/TypingService.java | 16 +- .../pit/recordModifiers/CopyAttribute.java | 4 +- .../pit/recordModifiers/RecordModifier.java | 4 +- .../datamanager/pit/resolver/Resolver.java | 4 +- .../pit/typeregistry/RegisteredProfile.java | 4 +- .../RegisteredProfileAttribute.java | 6 +- .../pit/web/BatchRecordResponse.java | 6 +- .../pit/web/ITypingRestResource.java | 26 +- .../converter/SimplePidRecordConverter.java | 14 +- .../pit/web/impl/TypingRESTResourceImpl.java | 44 +- .../kit/datamanager/pit/RecordTestHelper.java | 6 +- .../pit/domain/OperationsTest.java | 12 +- ...{PIDRecordTest.java => PidRecordTest.java} | 52 +- .../PidRecordElasticRepositoryTest.java | 8 +- .../PidRecordElasticWrapperTest.java | 6 +- .../pidsystem/IIdentifierSystemQueryTest.java | 10 +- .../pidsystem/IIdentifierSystemWriteTest.java | 6 +- .../impl/InMemoryIdentifierSystemTest.java | 8 +- .../impl/local/LocalPidSystemTest.java | 12 +- .../impl/local/PidDatabaseObjectDaoTest.java | 4 +- .../impl/local/PidDatabaseObjectTest.java | 6 +- .../recordModifiers/CopyAttributeTest.java | 16 +- .../pit/resolver/ResolverTest.java | 8 +- .../kit/datamanager/pit/web/ApiMockUtils.java | 36 +- .../pit/web/ConnectedPIDsTest.java | 114 ++-- .../datamanager/pit/web/CustomPidsTest.java | 12 +- .../edu/kit/datamanager/pit/web/EtagTest.java | 4 +- .../web/ExplicitValidationParametersTest.java | 12 +- .../datamanager/pit/web/PIDRecordBuilder.java | 12 +- .../pit/web/RestWithHandleProtocolTest.java | 6 +- .../pit/web/RestWithInMemoryTest.java | 42 +- .../pit/web/RestWithLocalPidSystemTest.java | 28 +- .../pit/web/SimpleJSONFormatTest.java | 48 +- 50 files changed, 645 insertions(+), 646 deletions(-) rename src/main/java/edu/kit/datamanager/pit/domain/{PIDRecord.java => PidRecord.java} (93%) rename src/test/java/edu/kit/datamanager/pit/domain/{PIDRecordTest.java => PidRecordTest.java} (83%) diff --git a/src/main/java/edu/kit/datamanager/pit/Application.java b/src/main/java/edu/kit/datamanager/pit/Application.java index 056ec5ee..847d3efc 100644 --- a/src/main/java/edu/kit/datamanager/pit/Application.java +++ b/src/main/java/edu/kit/datamanager/pit/Application.java @@ -26,7 +26,7 @@ import edu.kit.datamanager.pit.cli.PidSource; import edu.kit.datamanager.pit.common.InvalidConfigException; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem; import edu.kit.datamanager.pit.pitservice.ITypingService; import edu.kit.datamanager.pit.pitservice.impl.TypingService; @@ -164,7 +164,7 @@ public KeycloakJwtProperties properties() { } @Bean - public HttpMessageConverter simplePidRecordConverter() { + public HttpMessageConverter simplePidRecordConverter() { return new SimplePidRecordConverter(); } diff --git a/src/main/java/edu/kit/datamanager/pit/cli/CliTaskBootstrap.java b/src/main/java/edu/kit/datamanager/pit/cli/CliTaskBootstrap.java index 1e0d7e23..7a4ae715 100644 --- a/src/main/java/edu/kit/datamanager/pit/cli/CliTaskBootstrap.java +++ b/src/main/java/edu/kit/datamanager/pit/cli/CliTaskBootstrap.java @@ -15,7 +15,7 @@ import edu.kit.datamanager.pit.common.InvalidConfigException; import edu.kit.datamanager.pit.common.PidNotFoundException; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticRepository; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticWrapper; import edu.kit.datamanager.pit.pidlog.KnownPid; @@ -77,7 +77,7 @@ public boolean process() throws IOException, InvalidConfigException { // store in Elasticsearch elastic.ifPresent(elastic -> { try { - PIDRecord rec = typingService.queryPid(known.getPid()); + PidRecord rec = typingService.queryPid(known.getPid()); LOG.info("Store PID {} in Elasticsearch.", known.getPid()); PidRecordElasticWrapper wrapper = new PidRecordElasticWrapper(rec, typingService.getOperations()); elastic.save(wrapper); diff --git a/src/main/java/edu/kit/datamanager/pit/common/RecordValidationException.java b/src/main/java/edu/kit/datamanager/pit/common/RecordValidationException.java index 9dca9d21..84262350 100644 --- a/src/main/java/edu/kit/datamanager/pit/common/RecordValidationException.java +++ b/src/main/java/edu/kit/datamanager/pit/common/RecordValidationException.java @@ -16,7 +16,7 @@ package edu.kit.datamanager.pit.common; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -31,24 +31,24 @@ public class RecordValidationException extends ResponseStatusException { private static final HttpStatus HTTP_STATUS = HttpStatus.BAD_REQUEST; // For cases in which the PID record should be appended to the error response. - private final transient PIDRecord pidRecord; + private final transient PidRecord pidRecord; - public RecordValidationException(PIDRecord pidRecord) { + public RecordValidationException(PidRecord pidRecord) { super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed."); this.pidRecord = pidRecord; } - public RecordValidationException(PIDRecord pidRecord, String reason) { + public RecordValidationException(PidRecord pidRecord, String reason) { super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason); this.pidRecord = pidRecord; } - public RecordValidationException(PIDRecord pidRecord, String reason, Exception e) { + public RecordValidationException(PidRecord pidRecord, String reason, Exception e) { super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason, e); this.pidRecord = pidRecord; } - public PIDRecord getPidRecord() { + public PidRecord getPidRecord() { return pidRecord; } } diff --git a/src/main/java/edu/kit/datamanager/pit/domain/Operations.java b/src/main/java/edu/kit/datamanager/pit/domain/Operations.java index baa688ed..b5b5866d 100644 --- a/src/main/java/edu/kit/datamanager/pit/domain/Operations.java +++ b/src/main/java/edu/kit/datamanager/pit/domain/Operations.java @@ -55,7 +55,7 @@ public Operations(ITypeRegistry typeRegistry, IIdentifierSystem identifierSystem * @return the date, if it could have been extracted. * @throws IOException on IO errors regarding resolving types. */ - public Optional findDateCreated(PIDRecord pidRecord) throws IOException { + public Optional findDateCreated(PidRecord pidRecord) throws IOException { /* try known types */ List knownDateTypes = Arrays.asList(Operations.KNOWN_DATE_CREATED); Optional date = knownDateTypes @@ -117,7 +117,7 @@ public Optional findDateCreated(PIDRecord pidRecord) throws IOException { * @return the date, if it could have been extracted. * @throws IOException on IO errors regarding resolving types. */ - public Optional findDateModified(PIDRecord pidRecord) throws IOException { + public Optional findDateModified(PidRecord pidRecord) throws IOException { /* try known types */ List knownDateTypes = Arrays.asList(Operations.KNOWN_DATE_MODIFIED); Optional date = knownDateTypes diff --git a/src/main/java/edu/kit/datamanager/pit/domain/PIDRecord.java b/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java similarity index 93% rename from src/main/java/edu/kit/datamanager/pit/domain/PIDRecord.java rename to src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java index 4edac653..31ed6893 100644 --- a/src/main/java/edu/kit/datamanager/pit/domain/PIDRecord.java +++ b/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java @@ -1,293 +1,293 @@ -/* - * Copyright (c) 2025 Karlsruhe Institute of Technology. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package edu.kit.datamanager.pit.domain; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import edu.kit.datamanager.entities.EtagSupport; -import edu.kit.datamanager.pit.pidsystem.impl.local.PidDatabaseObject; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * The internal representation for a PID record, offering methods to manipulate - * the record. - *

- * While other representations exist, they are only used for easier database - * communication or representation for the outside. In contrast, this is the - * internal representation offering methods for manipulation. - */ -public class PIDRecord implements EtagSupport, Cloneable { - - private String pid = ""; - - private Map> entries = new HashMap<>(); - - /** - * Creates an empty record without PID. - */ - public PIDRecord() { - } - - /** - * Creates a record with the same content as the given representation. - * - * @param dbo the given record representation. - */ - public PIDRecord(PidDatabaseObject dbo) { - this.setPid(dbo.getPid()); - dbo.getEntries().forEach( - (key, valueList) -> valueList.forEach( - value -> this.addEntry(key, value))); - } - - public PIDRecord(SimplePidRecord rec) { - this.entries = new HashMap<>(); - for (SimplePair pair : rec.getPairs()) { - this.addEntry(pair.getKey(), "", pair.getValue()); - } - } - - /** - * Convenience setter / builder method. - * - * @param pid the pid to set in this object. - * @return this object (builder method). - */ - public PIDRecord withPID(String pid) { - this.setPid(pid); - return this; - } - - public String getPid() { - return pid; - } - - public void setPid(String pid) { - this.pid = pid; - } - - public Map> getEntries() { - return entries; - } - - /** - * Sets the entries of this record. - * - * @param entries the entries to set. - */ - public void setEntries(Map> entries) { - this.entries = entries; - } - - @JsonIgnore - public Set getSimpleEntries() { - return this.entries - .entrySet() - .stream() - .flatMap( - entry -> entry.getValue().stream() - .map(complexPair -> new SimplePair(complexPair.getKey(), complexPair.getValue()))) - .collect(Collectors.toSet()); - } - - public void addEntry(String propertyIdentifier, String propertyValue) { - this.addEntry(propertyIdentifier, "", propertyValue); - } - - /** - * Adds a new key-name-value triplet. - * - * @param propertyIdentifier the key/type PID. - * @param propertyName the human-readable name for the given key/type. - * @param propertyValue the value to this key/type. - */ - public void addEntry(String propertyIdentifier, String propertyName, String propertyValue) { - if (propertyIdentifier.isEmpty()) { - throw new IllegalArgumentException("The identifier of a property may not be empty!"); - } - PIDRecordEntry entry = new PIDRecordEntry(); - entry.setKey(propertyIdentifier); - entry.setName(propertyName); - entry.setValue(propertyValue); - - this.entries - .computeIfAbsent(propertyIdentifier, key -> new ArrayList<>()) - .add(entry); - } - - /** - * Sets the name for a given key/type in all available pairs. - * - * @param propertyIdentifier the key/type. - * @param name the new name. - */ - @JsonIgnore - public void setPropertyName(String propertyIdentifier, String name) { - List propertyEntries = this.entries.get(propertyIdentifier); - if (propertyEntries == null) { - throw new IllegalArgumentException( - "Property identifier not listed in this record: " + propertyIdentifier); - } - for (PIDRecordEntry entry : propertyEntries) { - entry.setName(name); - } - } - - /** - * Check if there is a pair or triplet containing the given property (key/type) - * is availeble in this record. - * - * @param propertyIdentifier the key/type to search for. - * @return true, if the property/key/type is present. - */ - public boolean hasProperty(String propertyIdentifier) { - return entries.containsKey(propertyIdentifier); - } - - /** - * Removes all properties that are not listed in the given collection. - * - * @param propertiesToKeep a collection of property identifiers to keep. - */ - public void removePropertiesNotListed(Collection propertiesToKeep) { - entries.keySet().removeIf(propID -> !propertiesToKeep.contains(propID)); - } - - public void removeAllValuesOf(String attribute) { - this.entries.remove(attribute); - } - - /** - * Get all properties contained in this record. - * - * @return al contained properties. - */ - @JsonIgnore - public Set getPropertyIdentifiers() { - return entries.keySet(); - } - - /** - * Get the value of the first element in case there are multiple elements - * for the provided propertyIndentifier. - */ - public String getPropertyValue(String propertyIdentifier) { - List entry = entries.get(propertyIdentifier); - if (entry == null) { - return ""; - } - return entry.getFirst().getValue(); - } - - /** - * Get all values of a given property. - * - * @param propertyIdentifier the given property identifier. - * @return all values of the given property. - */ - public String[] getPropertyValues(String propertyIdentifier) { - List entry = entries.get(propertyIdentifier); - if (entry == null) { - return new String[]{}; - } - - List values = new ArrayList<>(); - for (PIDRecordEntry e : entry) { - values.add(e.getValue()); - } - return values.toArray(new String[]{}); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((pid == null) ? 0 : pid.hashCode()); - Set simpleEntries = this.getSimpleEntries(); - result = prime * result + ((simpleEntries == null) ? 0 : simpleEntries.hashCode()); - return result; - } - - /** - * Checks if two PIDRecords are equivalent. - *

- * - Ignores the name attribute: Only keys and values matter. - * - Ignores order of keys or values - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - - PIDRecord other = (PIDRecord) obj; - boolean isThisPidEmpty = pid == null || pid.isBlank(); - boolean isOtherPidEmpty = other.pid == null || other.pid.isBlank(); - boolean isBothPidEmpty = isThisPidEmpty && isOtherPidEmpty; - boolean equalPIDs = isBothPidEmpty || (this.pid != null && this.pid.equals(other.pid)); - - if (!equalPIDs) { - return false; - } - - // this ignores attributes order, names, and even duplicates - return this.getSimpleEntries().equals(other.getSimpleEntries()); - } - - @Override - public String toString() { - return "PIDRecord [pid=" + pid + ", entries=" + entries + "]"; - } - - /** - * Calculates an etag for a record. - * - * @return an etag, which is independent of any order or duplicates in the - * entries. - */ - @JsonIgnore - @Override - public String getEtag() { - return Integer.toString(this.hashCode()); - } - - @Override - public PIDRecord clone() { - try { - PIDRecord clone = (PIDRecord) super.clone(); - clone.pid = this.pid; - clone.entries = new HashMap<>(); - for (Map.Entry> entry : this.entries.entrySet()) { - List entryList = new ArrayList<>(); - for (PIDRecordEntry e : entry.getValue()) { - entryList.add(e.clone()); - } - clone.entries.put(entry.getKey(), entryList); - } - return clone; - } catch (CloneNotSupportedException e) { - throw new AssertionError(); - } - } -} +/* + * Copyright (c) 2025 Karlsruhe Institute of Technology. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.kit.datamanager.pit.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import edu.kit.datamanager.entities.EtagSupport; +import edu.kit.datamanager.pit.pidsystem.impl.local.PidDatabaseObject; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * The internal representation for a PID record, offering methods to manipulate + * the record. + *

+ * While other representations exist, they are only used for easier database + * communication or representation for the outside. In contrast, this is the + * internal representation offering methods for manipulation. + */ +public class PidRecord implements EtagSupport, Cloneable { + + private String pid = ""; + + private Map> entries = new HashMap<>(); + + /** + * Creates an empty record without PID. + */ + public PidRecord() { + } + + /** + * Creates a record with the same content as the given representation. + * + * @param dbo the given record representation. + */ + public PidRecord(PidDatabaseObject dbo) { + this.setPid(dbo.getPid()); + dbo.getEntries().forEach( + (key, valueList) -> valueList.forEach( + value -> this.addEntry(key, value))); + } + + public PidRecord(SimplePidRecord rec) { + this.entries = new HashMap<>(); + for (SimplePair pair : rec.getPairs()) { + this.addEntry(pair.getKey(), "", pair.getValue()); + } + } + + /** + * Convenience setter / builder method. + * + * @param pid the pid to set in this object. + * @return this object (builder method). + */ + public PidRecord withPID(String pid) { + this.setPid(pid); + return this; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public Map> getEntries() { + return entries; + } + + /** + * Sets the entries of this record. + * + * @param entries the entries to set. + */ + public void setEntries(Map> entries) { + this.entries = entries; + } + + @JsonIgnore + public Set getSimpleEntries() { + return this.entries + .entrySet() + .stream() + .flatMap( + entry -> entry.getValue().stream() + .map(complexPair -> new SimplePair(complexPair.getKey(), complexPair.getValue()))) + .collect(Collectors.toSet()); + } + + public void addEntry(String propertyIdentifier, String propertyValue) { + this.addEntry(propertyIdentifier, "", propertyValue); + } + + /** + * Adds a new key-name-value triplet. + * + * @param propertyIdentifier the key/type PID. + * @param propertyName the human-readable name for the given key/type. + * @param propertyValue the value to this key/type. + */ + public void addEntry(String propertyIdentifier, String propertyName, String propertyValue) { + if (propertyIdentifier.isEmpty()) { + throw new IllegalArgumentException("The identifier of a property may not be empty!"); + } + PIDRecordEntry entry = new PIDRecordEntry(); + entry.setKey(propertyIdentifier); + entry.setName(propertyName); + entry.setValue(propertyValue); + + this.entries + .computeIfAbsent(propertyIdentifier, key -> new ArrayList<>()) + .add(entry); + } + + /** + * Sets the name for a given key/type in all available pairs. + * + * @param propertyIdentifier the key/type. + * @param name the new name. + */ + @JsonIgnore + public void setPropertyName(String propertyIdentifier, String name) { + List propertyEntries = this.entries.get(propertyIdentifier); + if (propertyEntries == null) { + throw new IllegalArgumentException( + "Property identifier not listed in this record: " + propertyIdentifier); + } + for (PIDRecordEntry entry : propertyEntries) { + entry.setName(name); + } + } + + /** + * Check if there is a pair or triplet containing the given property (key/type) + * is availeble in this record. + * + * @param propertyIdentifier the key/type to search for. + * @return true, if the property/key/type is present. + */ + public boolean hasProperty(String propertyIdentifier) { + return entries.containsKey(propertyIdentifier); + } + + /** + * Removes all properties that are not listed in the given collection. + * + * @param propertiesToKeep a collection of property identifiers to keep. + */ + public void removePropertiesNotListed(Collection propertiesToKeep) { + entries.keySet().removeIf(propID -> !propertiesToKeep.contains(propID)); + } + + public void removeAllValuesOf(String attribute) { + this.entries.remove(attribute); + } + + /** + * Get all properties contained in this record. + * + * @return al contained properties. + */ + @JsonIgnore + public Set getPropertyIdentifiers() { + return entries.keySet(); + } + + /** + * Get the value of the first element in case there are multiple elements + * for the provided propertyIndentifier. + */ + public String getPropertyValue(String propertyIdentifier) { + List entry = entries.get(propertyIdentifier); + if (entry == null) { + return ""; + } + return entry.getFirst().getValue(); + } + + /** + * Get all values of a given property. + * + * @param propertyIdentifier the given property identifier. + * @return all values of the given property. + */ + public String[] getPropertyValues(String propertyIdentifier) { + List entry = entries.get(propertyIdentifier); + if (entry == null) { + return new String[]{}; + } + + List values = new ArrayList<>(); + for (PIDRecordEntry e : entry) { + values.add(e.getValue()); + } + return values.toArray(new String[]{}); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((pid == null) ? 0 : pid.hashCode()); + Set simpleEntries = this.getSimpleEntries(); + result = prime * result + ((simpleEntries == null) ? 0 : simpleEntries.hashCode()); + return result; + } + + /** + * Checks if two PIDRecords are equivalent. + *

+ * - Ignores the name attribute: Only keys and values matter. + * - Ignores order of keys or values + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + PidRecord other = (PidRecord) obj; + boolean isThisPidEmpty = pid == null || pid.isBlank(); + boolean isOtherPidEmpty = other.pid == null || other.pid.isBlank(); + boolean isBothPidEmpty = isThisPidEmpty && isOtherPidEmpty; + boolean equalPIDs = isBothPidEmpty || (this.pid != null && this.pid.equals(other.pid)); + + if (!equalPIDs) { + return false; + } + + // this ignores attributes order, names, and even duplicates + return this.getSimpleEntries().equals(other.getSimpleEntries()); + } + + @Override + public String toString() { + return "PIDRecord [pid=" + pid + ", entries=" + entries + "]"; + } + + /** + * Calculates an etag for a record. + * + * @return an etag, which is independent of any order or duplicates in the + * entries. + */ + @JsonIgnore + @Override + public String getEtag() { + return Integer.toString(this.hashCode()); + } + + @Override + public PidRecord clone() { + try { + PidRecord clone = (PidRecord) super.clone(); + clone.pid = this.pid; + clone.entries = new HashMap<>(); + for (Map.Entry> entry : this.entries.entrySet()) { + List entryList = new ArrayList<>(); + for (PIDRecordEntry e : entry.getValue()) { + entryList.add(e.clone()); + } + clone.entries.put(entry.getKey(), entryList); + } + return clone; + } catch (CloneNotSupportedException e) { + throw new AssertionError(); + } + } +} diff --git a/src/main/java/edu/kit/datamanager/pit/domain/SimplePidRecord.java b/src/main/java/edu/kit/datamanager/pit/domain/SimplePidRecord.java index 9ea07cb7..c7734de1 100644 --- a/src/main/java/edu/kit/datamanager/pit/domain/SimplePidRecord.java +++ b/src/main/java/edu/kit/datamanager/pit/domain/SimplePidRecord.java @@ -30,7 +30,7 @@ public SimplePidRecord() {} * * @param rec a given PID record to convert. */ - public SimplePidRecord(PIDRecord rec) { + public SimplePidRecord(PidRecord rec) { this.pid = rec.getPid(); this.pairs = new ArrayList<>(); for (Entry> entry : rec.getEntries().entrySet()) { diff --git a/src/main/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapper.java b/src/main/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapper.java index 5f8ea750..2599ee48 100644 --- a/src/main/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapper.java +++ b/src/main/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapper.java @@ -16,7 +16,7 @@ package edu.kit.datamanager.pit.elasticsearch; import edu.kit.datamanager.pit.domain.Operations; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.impl.local.PidDatabaseObject; import java.io.IOException; @@ -57,7 +57,7 @@ public class PidRecordElasticWrapper { @Field(type = FieldType.Text) private List read = new ArrayList<>(); - public PidRecordElasticWrapper(PIDRecord pidRecord, Operations dateOperations) { + public PidRecordElasticWrapper(PidRecord pidRecord, Operations dateOperations) { pid = pidRecord.getPid(); PidDatabaseObject simple = new PidDatabaseObject(pidRecord); this.attributes = simple.getEntries(); diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java index a12eece6..6508c464 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java @@ -5,7 +5,7 @@ import edu.kit.datamanager.pit.common.PidAlreadyExistsException; import edu.kit.datamanager.pit.common.PidNotFoundException; import edu.kit.datamanager.pit.common.RecordValidationException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffix; import java.util.Collection; @@ -88,14 +88,14 @@ public default boolean isPidRegistered(PidSuffix suffix) throws ExternalServiceE * @throws ExternalServiceException on commonication errors or errors on other * services. */ - public PIDRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException; + public PidRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException; /** * Registers a new PID with given property values. The method takes the PID from * the record and treats it as a suffix. * * The method must process the given PID using the - * {@link #registerPid(PIDRecord)} method. + * {@link #registerPid(PidRecord)} method. * * @param pidRecord contains the initial PID record. * @return the PID that was assigned to the record. @@ -104,7 +104,7 @@ public default boolean isPidRegistered(PidSuffix suffix) throws ExternalServiceE * other services. * @throws RecordValidationException if record validation errors occurred. */ - public default String registerPid(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException, RecordValidationException { + public default String registerPid(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException, RecordValidationException { if (pidRecord.getPid() == null) { throw new RecordValidationException(pidRecord, "PID must not be null."); } @@ -119,7 +119,7 @@ public default String registerPid(final PIDRecord pidRecord) throws PidAlreadyEx /** * Registers the given record with its given PID, without applying any checks. - * Recommended to use {@link #registerPid(PIDRecord)} instead. + * Recommended to use {@link #registerPid(PidRecord)} instead. * * As an implementor, you can assume the PID to be not null, valid, * non-registered, and prefixed. @@ -130,7 +130,7 @@ public default String registerPid(final PIDRecord pidRecord) throws PidAlreadyEx * @throws ExternalServiceException if an error occured in communication with * other services. */ - public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException; + public String registerPidUnchecked(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException; /** * Updates an existing record with the new given values. If the PID in the given @@ -143,7 +143,7 @@ public default String registerPid(final PIDRecord pidRecord) throws PidAlreadyEx * other services. * @throws RecordValidationException if record validation errors occurred. */ - public boolean updatePid(PIDRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException; + public boolean updatePid(PidRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException; /** * Remove the given PID. diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java index 87e180f4..647c7d70 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java @@ -11,7 +11,7 @@ import edu.kit.datamanager.pit.common.PidNotFoundException; import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem; import org.slf4j.Logger; @@ -33,7 +33,7 @@ public class InMemoryIdentifierSystem implements IIdentifierSystem { private static final Logger LOG = LoggerFactory.getLogger(InMemoryIdentifierSystem.class); private static final String PREFIX = "sandboxed/"; - private Map records = new HashMap<>(); + private Map records = new HashMap<>(); public InMemoryIdentifierSystem() { LOG.warn("Using in-memory identifier system. REGISTERED PIDs ARE NOT STORED PERMANENTLY."); @@ -50,21 +50,21 @@ public boolean isPidRegistered(String pid) throws ExternalServiceException { } @Override - public PIDRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { - PIDRecord pidRecord = this.records.get(pid); + public PidRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { + PidRecord pidRecord = this.records.get(pid); if (pidRecord == null) { throw new PidNotFoundException(pid); } return pidRecord; } @Override - public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { + public String registerPidUnchecked(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { this.records.put(pidRecord.getPid(), pidRecord); LOG.debug("Registered record with PID: {}", pidRecord.getPid()); return pidRecord.getPid(); } @Override - public boolean updatePid(PIDRecord record) throws PidNotFoundException, ExternalServiceException, RecordValidationException { + public boolean updatePid(PidRecord record) throws PidNotFoundException, ExternalServiceException, RecordValidationException { if (this.records.containsKey(record.getPid())) { this.records.put(record.getPid(), record); return true; diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleBehavior.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleBehavior.java index 59ec8055..3219d835 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleBehavior.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleBehavior.java @@ -1,6 +1,6 @@ package edu.kit.datamanager.pit.pidsystem.impl.handle; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.PIDRecordEntry; import net.handle.hdllib.Common; import net.handle.hdllib.HandleValue; @@ -82,7 +82,7 @@ public static boolean isHandleInternalValue(HandleValue v) { * but e.g. without the name. */ public static ArrayList handleValuesFrom( - final PIDRecord pidRecord, + final PidRecord pidRecord, final Optional> toMerge) { ArrayList skippingIndices = new ArrayList<>(); @@ -111,8 +111,8 @@ public static ArrayList handleValuesFrom( return result; } - public static PIDRecord recordFrom(final Collection values) { - PIDRecord record = new PIDRecord(); + public static PidRecord recordFrom(final Collection values) { + PidRecord record = new PidRecord(); values.forEach(v -> record.addEntry( v.getTypeAsString(), v.getDataAsString()) diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleProtocolAdapter.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleProtocolAdapter.java index 3e21f14b..8d33564e 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleProtocolAdapter.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleProtocolAdapter.java @@ -28,7 +28,7 @@ import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.configuration.HandleCredentials; import edu.kit.datamanager.pit.configuration.HandleProtocolProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem; import net.handle.api.HSAdapter; import net.handle.api.HSAdapterFactory; @@ -131,7 +131,7 @@ public boolean isPidRegistered(final String pid) throws ExternalServiceException } @Override - public PIDRecord queryPid(final String pid) throws PidNotFoundException, ExternalServiceException { + public PidRecord queryPid(final String pid) throws PidNotFoundException, ExternalServiceException { Collection allValues = this.queryAllHandleValues(pid); if (allValues.isEmpty()) { return null; @@ -158,12 +158,12 @@ protected Collection queryAllHandleValues(final String pid) throws } @Override - public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { + public String registerPidUnchecked(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { // Add admin value for configured user only // TODO add options to add additional adminValues e.g. for user lists? ArrayList admin = new ArrayList<>(); admin.add(this.adminValue); - PIDRecord preparedRecord = pidRecord; + PidRecord preparedRecord = pidRecord; for (RecordModifier modifier : this.props.getConfiguredModifiers()) { preparedRecord = modifier.apply(preparedRecord); } @@ -185,11 +185,11 @@ public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyE } @Override - public boolean updatePid(final PIDRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException { + public boolean updatePid(final PidRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException { if (!this.isValidPID(pidRecord.getPid())) { return false; } - PIDRecord preparedRecord = pidRecord; + PidRecord preparedRecord = pidRecord; for (RecordModifier modifier : this.props.getConfiguredModifiers()) { preparedRecord = modifier.apply(preparedRecord); } diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java index 8190eb13..6f889eeb 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java @@ -2,7 +2,6 @@ import java.util.Collection; import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.common.InvalidConfigException; @@ -10,7 +9,7 @@ import edu.kit.datamanager.pit.common.PidNotFoundException; import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem; import org.slf4j.Logger; @@ -84,13 +83,13 @@ public boolean isPidRegistered(String pid) throws ExternalServiceException { } @Override - public PIDRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { + public PidRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { Optional dbo = this.db.findByPid(pid); - return new PIDRecord(dbo.orElseThrow(() -> new PidNotFoundException(pid))); + return new PidRecord(dbo.orElseThrow(() -> new PidNotFoundException(pid))); } @Override - public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { + public String registerPidUnchecked(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { if (this.db.existsById(pidRecord.getPid())) { throw new PidAlreadyExistsException(pidRecord.getPid()); } @@ -100,7 +99,7 @@ public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyE } @Override - public boolean updatePid(PIDRecord rec) throws PidNotFoundException, ExternalServiceException, RecordValidationException { + public boolean updatePid(PidRecord rec) throws PidNotFoundException, ExternalServiceException, RecordValidationException { if (this.db.existsById(rec.getPid())) { this.db.save(new PidDatabaseObject(rec)); return true; diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObject.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObject.java index 4134380f..88e08c86 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObject.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObject.java @@ -11,7 +11,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.Id; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.PIDRecordEntry; import lombok.Data; import lombok.EqualsAndHashCode; @@ -70,7 +70,7 @@ protected PidDatabaseObject(String pid, String hiddenIndentifier) { this.entries.put(hiddenIndentifier, values); } - public PidDatabaseObject(PIDRecord other) { + public PidDatabaseObject(PidRecord other) { this.pid = other.getPid(); other diff --git a/src/main/java/edu/kit/datamanager/pit/pitservice/ITypingService.java b/src/main/java/edu/kit/datamanager/pit/pitservice/ITypingService.java index ef5e44ff..44c6edb9 100644 --- a/src/main/java/edu/kit/datamanager/pit/pitservice/ITypingService.java +++ b/src/main/java/edu/kit/datamanager/pit/pitservice/ITypingService.java @@ -3,7 +3,7 @@ import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.domain.Operations; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem; @@ -16,7 +16,7 @@ public interface ITypingService extends IIdentifierSystem { public void setValidationStrategy(IValidationStrategy strategy); - public void validate(PIDRecord pidRecord) + public void validate(PidRecord pidRecord) throws RecordValidationException, ExternalServiceException; /** diff --git a/src/main/java/edu/kit/datamanager/pit/pitservice/IValidationStrategy.java b/src/main/java/edu/kit/datamanager/pit/pitservice/IValidationStrategy.java index 237ea1b7..a3dfe607 100644 --- a/src/main/java/edu/kit/datamanager/pit/pitservice/IValidationStrategy.java +++ b/src/main/java/edu/kit/datamanager/pit/pitservice/IValidationStrategy.java @@ -2,7 +2,7 @@ import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.common.RecordValidationException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; public interface IValidationStrategy { /** @@ -12,5 +12,5 @@ public interface IValidationStrategy { * * @param pidRecord the PID record to validate. */ - void validate(PIDRecord pidRecord) throws RecordValidationException, ExternalServiceException; + void validate(PidRecord pidRecord) throws RecordValidationException, ExternalServiceException; } diff --git a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/EmbeddedStrictValidatorStrategy.java b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/EmbeddedStrictValidatorStrategy.java index 19145874..4e9715a3 100644 --- a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/EmbeddedStrictValidatorStrategy.java +++ b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/EmbeddedStrictValidatorStrategy.java @@ -4,7 +4,7 @@ import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.common.TypeNotFoundException; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pitservice.IValidationStrategy; import edu.kit.datamanager.pit.typeregistry.AttributeInfo; import edu.kit.datamanager.pit.typeregistry.ITypeRegistry; @@ -42,7 +42,7 @@ public EmbeddedStrictValidatorStrategy( } @Override - public void validate(PIDRecord pidRecord) + public void validate(PidRecord pidRecord) throws RecordValidationException, ExternalServiceException { if (pidRecord.getPropertyIdentifiers().isEmpty()) { @@ -107,7 +107,7 @@ public void validate(PIDRecord pidRecord) * Usually used to avoid exposing exceptions related to futures. * @param e the exception to unwrap. */ - private static void unpackAsyncExceptions(PIDRecord pidRecord, Throwable e) { + private static void unpackAsyncExceptions(PidRecord pidRecord, Throwable e) { final int MAX_LEVEL = 10; Throwable cause = e; diff --git a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/NoValidationStrategy.java b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/NoValidationStrategy.java index 25fccffd..a0ce1fe9 100644 --- a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/NoValidationStrategy.java +++ b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/NoValidationStrategy.java @@ -2,7 +2,7 @@ import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.common.RecordValidationException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pitservice.IValidationStrategy; /** @@ -11,7 +11,7 @@ public class NoValidationStrategy implements IValidationStrategy { @Override - public void validate(PIDRecord pidRecord) throws RecordValidationException, ExternalServiceException { + public void validate(PidRecord pidRecord) throws RecordValidationException, ExternalServiceException { // No validation will take place. } diff --git a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/TypingService.java b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/TypingService.java index d9a2fc99..68a201d3 100644 --- a/src/main/java/edu/kit/datamanager/pit/pitservice/impl/TypingService.java +++ b/src/main/java/edu/kit/datamanager/pit/pitservice/impl/TypingService.java @@ -15,7 +15,7 @@ import edu.kit.datamanager.pit.pitservice.IValidationStrategy; import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.domain.Operations; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletionException; @@ -65,7 +65,7 @@ public void setValidationStrategy(IValidationStrategy strategy) { } @Override - public void validate(PIDRecord pidRecord) + public void validate(PidRecord pidRecord) throws RecordValidationException, ExternalServiceException { this.defaultStrategy.validate(pidRecord); } @@ -77,7 +77,7 @@ public boolean isPidRegistered(String pid) throws ExternalServiceException { } @Override - public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { + public String registerPidUnchecked(final PidRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException { LOG.trace("Performing registerPID({}).", pidRecord); return identifierSystem.registerPidUnchecked(pidRecord); } @@ -89,14 +89,14 @@ public boolean deletePid(String pid) throws ExternalServiceException { } @Override - public PIDRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { + public PidRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException { return queryPid(pid, false); } - public PIDRecord queryPid(String pid, boolean includePropertyNames) + public PidRecord queryPid(String pid, boolean includePropertyNames) throws PidNotFoundException, ExternalServiceException { LOG.trace("Performing queryAllProperties({}, {}).", pid, includePropertyNames); - PIDRecord pidInfo = identifierSystem.queryPid(pid); + PidRecord pidInfo = identifierSystem.queryPid(pid); if (includePropertyNames) { enrichPIDInformationRecord(pidInfo); @@ -104,7 +104,7 @@ public PIDRecord queryPid(String pid, boolean includePropertyNames) return pidInfo; } - private void enrichPIDInformationRecord(PIDRecord pidInfo) { + private void enrichPIDInformationRecord(PidRecord pidInfo) { // enrich record by querying type registry for all property definitions // to get the property names for (String typeIdentifier : pidInfo.getPropertyIdentifiers()) { @@ -125,7 +125,7 @@ private void enrichPIDInformationRecord(PIDRecord pidInfo) { } @Override - public boolean updatePid(PIDRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException { + public boolean updatePid(PidRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException { return this.identifierSystem.updatePid(pidRecord); } diff --git a/src/main/java/edu/kit/datamanager/pit/recordModifiers/CopyAttribute.java b/src/main/java/edu/kit/datamanager/pit/recordModifiers/CopyAttribute.java index 4bc80c21..0041a1a3 100644 --- a/src/main/java/edu/kit/datamanager/pit/recordModifiers/CopyAttribute.java +++ b/src/main/java/edu/kit/datamanager/pit/recordModifiers/CopyAttribute.java @@ -1,6 +1,6 @@ package edu.kit.datamanager.pit.recordModifiers; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import jakarta.validation.constraints.NotNull; import java.util.Collection; @@ -30,7 +30,7 @@ public record CopyAttribute( } @Override - public PIDRecord apply(PIDRecord record) { + public PidRecord apply(PidRecord record) { this.sources.stream() .filter(record::hasProperty) .findFirst() diff --git a/src/main/java/edu/kit/datamanager/pit/recordModifiers/RecordModifier.java b/src/main/java/edu/kit/datamanager/pit/recordModifiers/RecordModifier.java index 67d76802..d43c38c9 100644 --- a/src/main/java/edu/kit/datamanager/pit/recordModifiers/RecordModifier.java +++ b/src/main/java/edu/kit/datamanager/pit/recordModifiers/RecordModifier.java @@ -1,6 +1,6 @@ package edu.kit.datamanager.pit.recordModifiers; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; /** * An interface for types which allow for modification of PID records. @@ -12,5 +12,5 @@ public interface RecordModifier { * @param record the record to modify * @return the modified record (same as input). */ - public PIDRecord apply(final PIDRecord record); + public PidRecord apply(final PidRecord record); } diff --git a/src/main/java/edu/kit/datamanager/pit/resolver/Resolver.java b/src/main/java/edu/kit/datamanager/pit/resolver/Resolver.java index 66ac9044..f081354b 100644 --- a/src/main/java/edu/kit/datamanager/pit/resolver/Resolver.java +++ b/src/main/java/edu/kit/datamanager/pit/resolver/Resolver.java @@ -2,7 +2,7 @@ import edu.kit.datamanager.pit.common.ExternalServiceException; import edu.kit.datamanager.pit.common.PidNotFoundException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.impl.handle.HandleBehavior; import edu.kit.datamanager.pit.pitservice.ITypingService; import net.handle.api.HSAdapter; @@ -51,7 +51,7 @@ public Resolver(ITypingService identifierSystem) { * @throws PidNotFoundException if the PID could not be found in any system. * @throws ExternalServiceException if there was an error with the communication to an external system. */ - public PIDRecord resolve(String pid) throws PidNotFoundException, ExternalServiceException { + public PidRecord resolve(String pid) throws PidNotFoundException, ExternalServiceException { String prefix = Arrays.stream( pid.split("/", 2) ) diff --git a/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfile.java b/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfile.java index 661e1907..604fe79c 100644 --- a/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfile.java +++ b/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfile.java @@ -2,7 +2,7 @@ import edu.kit.datamanager.pit.common.RecordValidationException; import edu.kit.datamanager.pit.domain.ImmutableList; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import java.util.Objects; import java.util.Set; @@ -14,7 +14,7 @@ public record RegisteredProfile( ImmutableList attributes ) { public void validateAttributes( - PIDRecord pidRecord, + PidRecord pidRecord, boolean alwaysAllowAdditionalAttributes ) throws RecordValidationException { diff --git a/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfileAttribute.java b/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfileAttribute.java index 0469d296..b8c06dc5 100644 --- a/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfileAttribute.java +++ b/src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfileAttribute.java @@ -1,19 +1,19 @@ package edu.kit.datamanager.pit.typeregistry; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; public record RegisteredProfileAttribute( String pid, boolean mandatory, boolean repeatable ) { - public boolean violatesMandatoryProperty(PIDRecord pidRecord) { + public boolean violatesMandatoryProperty(PidRecord pidRecord) { boolean contains = pidRecord.getPropertyIdentifiers().contains(this.pid) && pidRecord.getPropertyValues(this.pid).length > 0; return this.mandatory && !contains; } - public boolean violatesRepeatableProperty(PIDRecord pidRecord) { + public boolean violatesRepeatableProperty(PidRecord pidRecord) { boolean repeats = pidRecord.getPropertyValues(this.pid).length > 1; return !this.repeatable && repeats; } diff --git a/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java b/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java index 91c41be5..aa171335 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java +++ b/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java @@ -16,7 +16,7 @@ package edu.kit.datamanager.pit.web; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import java.util.List; import java.util.Map; @@ -29,9 +29,9 @@ * * @param pidRecords List of PIDRecord objects representing the processed records. (List) * @param mapping Map where keys are user-provided identifiers (fictionary) and values are the corresponding real record Handle PIDs. (Map) - * @see PIDRecord + * @see PidRecord */ public record BatchRecordResponse( - List pidRecords, + List pidRecords, Map mapping) { } diff --git a/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java b/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java index b0a1985c..95badfb1 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java +++ b/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java @@ -15,7 +15,7 @@ */ package edu.kit.datamanager.pit.web; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; import edu.kit.datamanager.pit.pidlog.KnownPid; import io.swagger.v3.oas.annotations.Operation; @@ -64,7 +64,7 @@ public interface ITypingRestResource { description = "The body containing a list of all PID record values as they should be in the new PID records. To connect records, the PID fields must be specified. This placeholder PID value may then be used in the value fields of other PID Record entries. During creation, these placeholder PIDs whose sole purpose is to connect records will be overwritten with actual, resolvable PIDs as defined by the PID generator strategy.", required = true, content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = PIDRecord.class))) + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = PidRecord.class))) } ) @ApiResponses(value = { @@ -82,7 +82,7 @@ public interface ITypingRestResource { @ApiResponse(responseCode = "500", description = "Server error. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)) }) ResponseEntity createPIDs( - @RequestBody final List rec, + @RequestBody final List rec, @Parameter(description = "If true, only validation will be done and no PIDs will be created. No data will be changed and no services will be notified.") @RequestParam(name = "dryrun", required = false, defaultValue = "false") @@ -114,7 +114,7 @@ ResponseEntity createPIDs( description = "The body containing all PID record values as they should be in the new PIDs record.", required = true, content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PIDRecord.class)), + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PidRecord.class)), @Content(mediaType = SimplePidRecord.CONTENT_TYPE, schema = @Schema(implementation = SimplePidRecord.class)) } ) @@ -123,7 +123,7 @@ ResponseEntity createPIDs( responseCode = "201", description = "Created", content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PIDRecord.class)), + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PidRecord.class)), @Content(mediaType = SimplePidRecord.CONTENT_TYPE, schema = @Schema(implementation = SimplePidRecord.class)) }), @ApiResponse(responseCode = "400", description = "Validation failed. See body for details. Contains also the validated record.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), @@ -133,8 +133,8 @@ ResponseEntity createPIDs( @ApiResponse(responseCode = "503", description = "Communication to required external service failed.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), @ApiResponse(responseCode = "500", description = "Server error. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)) }) - ResponseEntity createPID( - @RequestBody final PIDRecord rec, + ResponseEntity createPID( + @RequestBody final PidRecord rec, @Parameter( description = "If true, only validation will be done" + @@ -166,7 +166,7 @@ ResponseEntity createPID( description = "The body containing all PID record values as they should be after the update.", required = true, content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PIDRecord.class)), + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PidRecord.class)), @Content(mediaType = SimplePidRecord.CONTENT_TYPE, schema = @Schema(implementation = SimplePidRecord.class)) } ) @@ -175,7 +175,7 @@ ResponseEntity createPID( responseCode = "200", description = "Success.", content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PIDRecord.class)), + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PidRecord.class)), @Content(mediaType = SimplePidRecord.CONTENT_TYPE, schema = @Schema(implementation = SimplePidRecord.class)) }), @ApiResponse(responseCode = "400", description = "Validation failed. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), @@ -186,8 +186,8 @@ ResponseEntity createPID( @ApiResponse(responseCode = "503", description = "Communication to required external service failed.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), @ApiResponse(responseCode = "500", description = "Server error. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)) }) - ResponseEntity updatePID( - @RequestBody final PIDRecord rec, + ResponseEntity updatePID( + @RequestBody final PidRecord rec, @Parameter( description = "If true, no PID will be updated. Only" + @@ -218,7 +218,7 @@ ResponseEntity updatePID( responseCode = "200", description = "Found", content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PIDRecord.class)), + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = PidRecord.class)), @Content(mediaType = SimplePidRecord.CONTENT_TYPE, schema = @Schema(implementation = SimplePidRecord.class)) } ), @@ -227,7 +227,7 @@ ResponseEntity updatePID( @ApiResponse(responseCode = "503", description = "Communication to required external service failed.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), @ApiResponse(responseCode = "500", description = "Server error. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)) }) - ResponseEntity getRecord( + ResponseEntity getRecord( @Parameter( description = "If true, validation will be run on the" + " resolved PID. On failure, an error will be" + diff --git a/src/main/java/edu/kit/datamanager/pit/web/converter/SimplePidRecordConverter.java b/src/main/java/edu/kit/datamanager/pit/web/converter/SimplePidRecordConverter.java index 8132f361..82e38ef3 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/converter/SimplePidRecordConverter.java +++ b/src/main/java/edu/kit/datamanager/pit/web/converter/SimplePidRecordConverter.java @@ -18,7 +18,7 @@ import org.springframework.http.converter.HttpMessageNotWritableException; import edu.kit.datamanager.pit.Application; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; /** @@ -45,7 +45,7 @@ * serializing the PIDRecord, this class will be used. It first converts the * record into the simple class representation before serializing into JSON. */ -public class SimplePidRecordConverter implements HttpMessageConverter { +public class SimplePidRecordConverter implements HttpMessageConverter { private static final Logger LOGGER = LoggerFactory.getLogger(SimplePidRecordConverter.class); @@ -59,13 +59,13 @@ public boolean canRead(Class arg0, MediaType arg1) { return false; } LOGGER.trace("canRead: Checking applicability for class {} and mediatype {}.", arg0, arg1); - return PIDRecord.class.equals(arg0) && isValidMediaType(arg1); + return PidRecord.class.equals(arg0) && isValidMediaType(arg1); } @Override public boolean canWrite(Class arg0, MediaType arg1) { LOGGER.trace("canWrite: Checking applicability for class {} and mediatype {}.", arg0, arg1); - return PIDRecord.class.equals(arg0) && isValidMediaType(arg1); + return PidRecord.class.equals(arg0) && isValidMediaType(arg1); } @Override @@ -76,17 +76,17 @@ public List getSupportedMediaTypes() { } @Override - public PIDRecord read(Class arg0, HttpInputMessage arg1) + public PidRecord read(Class arg0, HttpInputMessage arg1) throws IOException, HttpMessageNotReadableException { LOGGER.trace("Read simple message from client and convert to PIDRecord."); try (InputStreamReader reader = new InputStreamReader(arg1.getBody(), StandardCharsets.UTF_8)) { String data = new BufferedReader(reader).lines().collect(Collectors.joining("\n")); - return new PIDRecord(Application.jsonObjectMapper().readValue(data, SimplePidRecord.class)); + return new PidRecord(Application.jsonObjectMapper().readValue(data, SimplePidRecord.class)); } } @Override - public void write(PIDRecord arg0, MediaType arg1, HttpOutputMessage arg2) + public void write(PidRecord arg0, MediaType arg1, HttpOutputMessage arg2) throws IOException, HttpMessageNotWritableException { LOGGER.trace("Write PIDRecord to simple format for client."); SimplePidRecord sim = new SimplePidRecord(arg0); diff --git a/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java b/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java index 88a99f94..6699c1a4 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java +++ b/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java @@ -21,7 +21,7 @@ import edu.kit.datamanager.pit.common.*; import edu.kit.datamanager.pit.configuration.ApplicationProperties; import edu.kit.datamanager.pit.configuration.PidGenerationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticRepository; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticWrapper; import edu.kit.datamanager.pit.pidgeneration.PidSuffix; @@ -86,7 +86,7 @@ public TypingRESTResourceImpl(ITypingService typingService, Resolver resolver, A @Override public ResponseEntity createPIDs( - List rec, + List rec, boolean dryrun, WebRequest request, HttpServletResponse response, @@ -113,7 +113,7 @@ public ResponseEntity createPIDs( Instant mappingTime = Instant.now(); // Apply the mappings to the records and validate them - List validatedRecords = applyMappingsToRecordsAndValidate(rec, pidMappings, prefix); + List validatedRecords = applyMappingsToRecordsAndValidate(rec, pidMappings, prefix); Instant validationTime = Instant.now(); if (dryrun) { @@ -126,8 +126,8 @@ public ResponseEntity createPIDs( return ResponseEntity.status(HttpStatus.OK).body(new BatchRecordResponse(validatedRecords, pidMappings)); } - List failedRecords = new ArrayList<>(); - List successfulRecords = new ArrayList<>(); + List failedRecords = new ArrayList<>(); + List successfulRecords = new ArrayList<>(); // register the records validatedRecords.forEach(pidRecord -> { try { @@ -172,7 +172,7 @@ public ResponseEntity createPIDs( if (!failedRecords.isEmpty()) { List rollbackFailures = new ArrayList<>(); - for (PIDRecord successfulRecord : successfulRecords) { // rollback the successful records + for (PidRecord successfulRecord : successfulRecords) { // rollback the successful records try { LOG.debug("Rolling back PID creation for record with PID {}.", successfulRecord.getPid()); this.typingService.deletePid(successfulRecord.getPid()); @@ -209,9 +209,9 @@ private static void addPrefixToMapping(Map pidMappings, String p * @throws RecordValidationException if the same internal PID is used for multiple records * @throws ExternalServiceException if the PID generation fails */ - private Map generatePIDMapping(List rec, boolean dryrun) throws RecordValidationException, ExternalServiceException { + private Map generatePIDMapping(List rec, boolean dryrun) throws RecordValidationException, ExternalServiceException { Map pidMappings = new HashMap<>(); - for (PIDRecord pidRecord : rec) { + for (PidRecord pidRecord : rec) { String internalPID = pidRecord.getPid(); // the internal PID is the one given by the user if (internalPID == null) { internalPID = ""; // if no PID was given, we set it to an empty string @@ -242,9 +242,9 @@ private Map generatePIDMapping(List rec, boolean dryr * @throws RecordValidationException as a possible validation outcome * @throws ExternalServiceException as a possible validation outcome */ - private List applyMappingsToRecordsAndValidate(List rec, Map pidMappings, String prefix) throws RecordValidationException, ExternalServiceException { - List validatedRecords = new ArrayList<>(); - for (PIDRecord pidRecord : rec) { + private List applyMappingsToRecordsAndValidate(List rec, Map pidMappings, String prefix) throws RecordValidationException, ExternalServiceException { + List validatedRecords = new ArrayList<>(); + for (PidRecord pidRecord : rec) { // use this map to replace all temporary PIDs in the record values with their corresponding real PIDs pidRecord.getEntries().values().stream() // get all values of the record @@ -265,8 +265,8 @@ private List applyMappingsToRecordsAndValidate(List rec, M } @Override - public ResponseEntity createPID( - PIDRecord pidRecord, + public ResponseEntity createPID( + PidRecord pidRecord, boolean dryrun, final WebRequest request, @@ -308,11 +308,11 @@ public ResponseEntity createPID( return ResponseEntity.status(HttpStatus.CREATED).eTag(quotedEtag(pidRecord)).body(pidRecord); } - private boolean hasPid(PIDRecord pidRecord) { + private boolean hasPid(PidRecord pidRecord) { return pidRecord.getPid() != null && !pidRecord.getPid().isBlank(); } - private void setPid(PIDRecord pidRecord) { + private void setPid(PidRecord pidRecord) { boolean hasCustomPid = hasPid(pidRecord); boolean allowsCustomPids = pidGenerationProperties.isCustomClientPidsEnabled(); @@ -345,8 +345,8 @@ private void setPid(PIDRecord pidRecord) { } @Override - public ResponseEntity updatePID( - PIDRecord pidRecord, + public ResponseEntity updatePID( + PidRecord pidRecord, boolean dryrun, final WebRequest request, @@ -362,7 +362,7 @@ public ResponseEntity updatePID( "Optional PID in record is given (%s), but it was not the same as the PID in the URL (%s). Ignore request, assuming this was not intended.".formatted(pidInternal, pid)); } - PIDRecord existingRecord = this.resolver.resolve(pid); + PidRecord existingRecord = this.resolver.resolve(pid); if (existingRecord == null) { throw new PidNotFoundException(pid); } @@ -429,7 +429,7 @@ private String getContentPathFromRequest(String lastPathElement, WebRequest requ } @Override - public ResponseEntity getRecord( + public ResponseEntity getRecord( boolean validation, final WebRequest request, @@ -437,7 +437,7 @@ public ResponseEntity getRecord( final UriComponentsBuilder uriBuilder ) { String pid = getContentPathFromRequest("pid", request); - PIDRecord pidRecord = this.resolver.resolve(pid); + PidRecord pidRecord = this.resolver.resolve(pid); if (applicationProps.getStorageStrategy().storesResolved()) { storeLocally(pid, false); } @@ -448,7 +448,7 @@ public ResponseEntity getRecord( return ResponseEntity.ok().eTag(quotedEtag(pidRecord)).body(pidRecord); } - private void saveToElastic(PIDRecord rec) { + private void saveToElastic(PidRecord rec) { this.elastic.ifPresent( database -> database.save( new PidRecordElasticWrapper(rec, typingService.getOperations()) @@ -554,7 +554,7 @@ public ResponseEntity> findAllForTabular( return ResponseEntity.ok().body(tabPage); } - private String quotedEtag(PIDRecord pidRecord) { + private String quotedEtag(PidRecord pidRecord) { return String.format("\"%s\"", pidRecord.getEtag()); } diff --git a/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java b/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java index a4e88fe6..80868a11 100644 --- a/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java +++ b/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java @@ -4,7 +4,7 @@ import java.util.stream.IntStream; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffixGenerator; public class RecordTestHelper { @@ -18,13 +18,13 @@ public class RecordTestHelper { * above) * @return a PID record as configured. */ - public static PIDRecord getFakePidRecord( + public static PidRecord getFakePidRecord( final int numAttributes, final int numValues, final String prefix, final PidSuffixGenerator generator) { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.setPid(generator.generate().get()); IntStream.range(0, numAttributes) .mapToObj(i -> generator.generate().getWithPrefix(prefix)) diff --git a/src/test/java/edu/kit/datamanager/pit/domain/OperationsTest.java b/src/test/java/edu/kit/datamanager/pit/domain/OperationsTest.java index d9d1ebf1..8e2ec9ed 100644 --- a/src/test/java/edu/kit/datamanager/pit/domain/OperationsTest.java +++ b/src/test/java/edu/kit/datamanager/pit/domain/OperationsTest.java @@ -37,14 +37,14 @@ void testSpringSetup() { @Test void testFindDateCreated() throws IOException { - PIDRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); + PidRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); Optional date = typingService.getOperations().findDateCreated(pidRecord); assertTrue(date.isPresent()); } @Test void testFindDateCreatedFailUnregistered() throws IOException { - PIDRecord pidRecord = new PIDRecord(); + PidRecord pidRecord = new PidRecord(); // should fail because the type is not semantically recognizable as a date // (because it is not a registered type) pidRecord.addEntry("non-registered-creation-date", "", VALID_DATE); @@ -54,7 +54,7 @@ void testFindDateCreatedFailUnregistered() throws IOException { @Test void testFindDateCreatedFailRegistered() throws IOException { - PIDRecord pidRecord = new PIDRecord(); + PidRecord pidRecord = new PidRecord(); // should fail because the type is not semantically recognizable as a date // (although it is a resolveable type) pidRecord.addEntry(TYPE_PROFILE, "", "21.T11148/b9b76f887845e32d29f7"); @@ -64,14 +64,14 @@ void testFindDateCreatedFailRegistered() throws IOException { @Test void testFindDateModified() throws IOException { - PIDRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); + PidRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); Optional date = typingService.getOperations().findDateModified(pidRecord); assertTrue(date.isPresent()); } @Test void testFindDateModifiedFailUnregistered() throws IOException { - PIDRecord pidRecord = new PIDRecord(); + PidRecord pidRecord = new PidRecord(); // should fail because the type is not semantically recognizable as a date // (because it is not a registered type) pidRecord.addEntry("non-registered-creation-date", "", VALID_DATE); @@ -81,7 +81,7 @@ void testFindDateModifiedFailUnregistered() throws IOException { @Test void testFindDateModifiedFailRegistered() throws IOException { - PIDRecord pidRecord = new PIDRecord(); + PidRecord pidRecord = new PidRecord(); // should fail because the type is not semantically recognizable as a date // (although it is a resolveable type) pidRecord.addEntry(TYPE_PROFILE, "", "21.T11148/b9b76f887845e32d29f7"); diff --git a/src/test/java/edu/kit/datamanager/pit/domain/PIDRecordTest.java b/src/test/java/edu/kit/datamanager/pit/domain/PidRecordTest.java similarity index 83% rename from src/test/java/edu/kit/datamanager/pit/domain/PIDRecordTest.java rename to src/test/java/edu/kit/datamanager/pit/domain/PidRecordTest.java index c289482c..140c3df3 100644 --- a/src/test/java/edu/kit/datamanager/pit/domain/PIDRecordTest.java +++ b/src/test/java/edu/kit/datamanager/pit/domain/PidRecordTest.java @@ -16,18 +16,18 @@ * Test Ensure the Entry of Insertion And Extraction of the class */ -class PIDRecordTest { +class PidRecordTest { private static final String PID = "fake/pid/42"; @Test void assignPIDTest() { - PIDRecord r = new PIDRecord().withPID(PID); + PidRecord r = new PidRecord().withPID(PID); assertEquals(PID, r.getPid()); } @Test void testCorrectEntryInsertionAndExtraction() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = "propertyIdentifier"; String name = "propertyName"; String value = "propertyValue"; @@ -45,13 +45,13 @@ void testCorrectEntryInsertionAndExtraction() { @Test void assignPID() { - PIDRecord r = new PIDRecord().withPID(PID); + PidRecord r = new PidRecord().withPID(PID); assertEquals(PID, r.getPid()); } @Test void testAddEntryWithEmptyIdentifier() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = ""; String name = "propertyName"; String value = "propertyValue"; @@ -63,7 +63,7 @@ void testAddEntryWithEmptyIdentifier() { @Test void testAddEntry_IdIsSpace() { // TODO Discuss, is this a good thing? should we change it? - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = " "; String name = "propertyName"; String value = "propertyValue"; @@ -80,7 +80,7 @@ void testAddEntry_IdIsSpace() { @Test void testAddEntry_IdIsNull() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = null; String name = "propertyName"; String value = "propertyValue"; @@ -92,7 +92,7 @@ void testAddEntry_IdIsNull() { @Test void testGetPropertyValuesWithSameIdentifier() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = "propertyIdentifier"; String name = "propertyName"; String value = "propertyValue"; @@ -120,7 +120,7 @@ void testGetPropertyValuesWithSameIdentifier() { @Test void testHasProperty() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String identifier = "propertyIdentifier"; String name = "propertyName"; String value = "propertyValue"; @@ -130,7 +130,7 @@ void testHasProperty() { @Test void testRemovePropertiesNotListed() { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); String id1 = "propertyIdentifier"; String id2 = "otherIdentifier"; String name = "propertyName"; @@ -154,38 +154,38 @@ void testRemovePropertiesNotListed() { @Test void testEqualityOfEmpty() { - PIDRecord first = new PIDRecord(); - PIDRecord second = new PIDRecord(); + PidRecord first = new PidRecord(); + PidRecord second = new PidRecord(); this.equals(first, second); - PIDRecord third = new PIDRecord().withPID(null); - PIDRecord fourth = new PIDRecord().withPID(""); + PidRecord third = new PidRecord().withPID(null); + PidRecord fourth = new PidRecord().withPID(""); this.equals(third, fourth); } @Test void testEqualityViaPid() { - PIDRecord first = new PIDRecord().withPID("pid"); - PIDRecord second = new PIDRecord().withPID("pid"); + PidRecord first = new PidRecord().withPID("pid"); + PidRecord second = new PidRecord().withPID("pid"); this.equals(first, second); } @Test void testInequalityViaPid() { - PIDRecord first = new PIDRecord(); - PIDRecord second = new PIDRecord().withPID("first"); + PidRecord first = new PidRecord(); + PidRecord second = new PidRecord().withPID("first"); this.notEquals(first, second); - PIDRecord third = new PIDRecord().withPID("other"); + PidRecord third = new PidRecord().withPID("other"); this.notEquals(first, third); this.notEquals(second, third); } @Test void testEqualityAlthoughNamedAttribute() { - PIDRecord first = new PIDRecord(); - PIDRecord second = new PIDRecord(); - PIDRecord third = new PIDRecord(); + PidRecord first = new PidRecord(); + PidRecord second = new PidRecord(); + PidRecord third = new PidRecord(); first.addEntry("key", "name", "value"); second.addEntry("key", null, "value"); @@ -197,8 +197,8 @@ void testEqualityAlthoughNamedAttribute() { @Test void testEqualityAlthoughDifferentOrder() { - PIDRecord first = new PIDRecord(); - PIDRecord second = new PIDRecord(); + PidRecord first = new PidRecord(); + PidRecord second = new PidRecord(); first.addEntry("key", "name", "value1"); first.addEntry("key", "name", "value2"); @@ -208,14 +208,14 @@ void testEqualityAlthoughDifferentOrder() { this.equals(first, second); } - private void equals(PIDRecord first, PIDRecord second) { + private void equals(PidRecord first, PidRecord second) { assertEquals(first, second); assertEquals(second, first); assertEquals(first.hashCode(), second.hashCode()); assertEquals(first.getEtag(), second.getEtag()); } - private void notEquals(PIDRecord first, PIDRecord second) { + private void notEquals(PidRecord first, PidRecord second) { assertNotEquals(first, second); assertNotEquals(second, first); assertNotEquals(first.hashCode(), second.hashCode()); diff --git a/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticRepositoryTest.java b/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticRepositoryTest.java index c952e19d..06587e60 100644 --- a/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticRepositoryTest.java +++ b/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticRepositoryTest.java @@ -13,7 +13,7 @@ import com.fasterxml.jackson.core.JacksonException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pitservice.ITypingService; import edu.kit.datamanager.pit.web.ApiMockUtils; @@ -49,7 +49,7 @@ void testEmpty() { @Test @Transactional void testStorage() throws JacksonException { - PIDRecord r = ApiMockUtils.getSomePidRecordInstance(); + PidRecord r = ApiMockUtils.getSomePidRecordInstance(); PidRecordElasticWrapper w = new PidRecordElasticWrapper(r, typingService.getOperations()); assertEquals(0, dao.count()); dao.save(w); @@ -59,7 +59,7 @@ void testStorage() throws JacksonException { @Test @Transactional void testMultipleValues() throws JacksonException { - PIDRecord r = ApiMockUtils.getSomePidRecordInstance(); + PidRecord r = ApiMockUtils.getSomePidRecordInstance(); r.addEntry( r.getPropertyIdentifiers().stream().findFirst().get(), "", @@ -73,7 +73,7 @@ void testMultipleValues() throws JacksonException { @Test @Transactional void testStorageWithDateNull() throws JacksonException { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.setPid("not-a-pid"); r.addEntry("21.T11148/076759916209e5d62bd5", "", "21.T11148/b9b76f887845e32d29f7"); PidRecordElasticWrapper w = new PidRecordElasticWrapper(r, typingService.getOperations()); diff --git a/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapperTest.java b/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapperTest.java index e4c7d9be..084809ca 100644 --- a/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapperTest.java +++ b/src/test/java/edu/kit/datamanager/pit/elasticsearch/PidRecordElasticWrapperTest.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.core.JacksonException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pitservice.ITypingService; import edu.kit.datamanager.pit.web.ApiMockUtils; @@ -26,14 +26,14 @@ class PidRecordElasticWrapperTest { @Test void testCreateEmpty() { - PIDRecord pidRecord = new PIDRecord(); + PidRecord pidRecord = new PidRecord(); PidRecordElasticWrapper wrapper = new PidRecordElasticWrapper(pidRecord, typingService.getOperations()); assertNotNull(wrapper); } @Test void testCreateValid() throws JacksonException { - PIDRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); + PidRecord pidRecord = ApiMockUtils.getSomePidRecordInstance(); PidRecordElasticWrapper wrapper = new PidRecordElasticWrapper(pidRecord, typingService.getOperations()); assertNotNull(wrapper); } diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemQueryTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemQueryTest.java index e3d30253..04a3a3cc 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemQueryTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemQueryTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.params.provider.MethodSource; import edu.kit.datamanager.pit.common.PidNotFoundException; import edu.kit.datamanager.pit.configuration.HandleProtocolProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.impl.handle.HandleProtocolAdapter; import edu.kit.datamanager.pit.pidsystem.impl.InMemoryIdentifierSystem; import net.handle.hdllib.HandleException; @@ -39,7 +39,7 @@ private static Stream implProvider() throws HandleException, IOExcept handleProtocolInstance.init(); IIdentifierSystem handleProtocol = handleProtocolInstance; - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); rec.setPid("my-custom-suffix"); rec.addEntry( // this is actually a registered type, but not in a data type registry, but inline in the PID system. @@ -76,7 +76,7 @@ public void isPidRegisteredFalse(IIdentifierSystem impl, String pid, String pid_ @ParameterizedTest @MethodSource("implProvider") public void queryPidExample(IIdentifierSystem impl, String pid) throws IOException { - PIDRecord result = impl.queryPid(pid); + PidRecord result = impl.queryPid(pid); assertEquals(result.getPid(), pid); assertTrue(result.getPropertyIdentifiers().contains("10320/loc")); assertFalse(result.getPropertyIdentifiers().contains("HS_ADMIN")); @@ -93,7 +93,7 @@ public void queryPidOfNonexistent(IIdentifierSystem impl, String _pid, String pi @ParameterizedTest @MethodSource("implProvider") public void querySingleProperty(IIdentifierSystem impl, String pid) throws IOException { - PIDRecord record = impl.queryPid(pid); + PidRecord record = impl.queryPid(pid); String attributeKey = "10320/loc"; assertTrue(record.getPropertyIdentifiers().contains(attributeKey)); String value = record.getPropertyValue(attributeKey); @@ -104,7 +104,7 @@ public void querySingleProperty(IIdentifierSystem impl, String pid) throws IOExc @ParameterizedTest @MethodSource("implProvider") public void queryNonexistentProperty(IIdentifierSystem impl, String pid) throws IOException { - PIDRecord record = impl.queryPid(pid); + PidRecord record = impl.queryPid(pid); assertFalse(record.getPropertyIdentifiers().contains("Nonexistent_Attribute")); } } diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemWriteTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemWriteTest.java index f315595a..fd655c55 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemWriteTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystemWriteTest.java @@ -15,7 +15,7 @@ import org.springframework.test.context.TestPropertySource; import edu.kit.datamanager.pit.RecordTestHelper; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffixGenerator; import edu.kit.datamanager.pit.pidsystem.impl.local.LocalPidSystem; @@ -56,7 +56,7 @@ void setup() throws InterruptedException, IOException { assertNotNull(localPidSystem); // Register just a small record for the database to initialize maybe or so. - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.setPid(pidGenerator.generate().get()); String attribute = pidGenerator.generate().getWithPrefix(PID_PREFIX); String value = pidGenerator.generate().getWithPrefix(PID_PREFIX); @@ -72,7 +72,7 @@ void testExtensiveRecordWithLocalPidSystem() throws IOException { int numAttributes = 100; int numValues = 100; - PIDRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, PID_PREFIX, pidGenerator); + PidRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, PID_PREFIX, pidGenerator); assertEquals(numAttributes, r.getPropertyIdentifiers().size()); assertEquals(numValues, r.getPropertyValues(r.getPropertyIdentifiers().iterator().next()).length); diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystemTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystemTest.java index d6ae1eff..42accce0 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystemTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystemTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; import edu.kit.datamanager.pit.common.InvalidConfigException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; class InMemoryIdentifierSystemTest { @@ -23,7 +23,7 @@ void setup() { @Test void testDeletePid() throws IOException { - PIDRecord p = new PIDRecord().withPID("test/pid"); + PidRecord p = new PidRecord().withPID("test/pid"); sys.registerPid(p); String pid = p.getPid(); assertThrows( @@ -42,11 +42,11 @@ void testDeletePid() throws IOException { void testResolveAll() throws InvalidConfigException, IOException { assertEquals(0, sys.resolveAllPidsOfPrefix().size()); - PIDRecord p1 = new PIDRecord().withPID("p1"); + PidRecord p1 = new PidRecord().withPID("p1"); sys.registerPid(p1); assertEquals(1, sys.resolveAllPidsOfPrefix().size()); - PIDRecord p2 = new PIDRecord().withPID("p2"); + PidRecord p2 = new PidRecord().withPID("p2"); sys.registerPid(p2); assertEquals(2, sys.resolveAllPidsOfPrefix().size()); } diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystemTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystemTest.java index 23978f7e..5915e73d 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystemTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystemTest.java @@ -21,7 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import edu.kit.datamanager.pit.common.InvalidConfigException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.IIdentifierSystemQueryTest; /** @@ -60,7 +60,7 @@ void setup() throws InterruptedException, IOException { @Test @Transactional void testAllSystemTests() throws Exception { - PIDRecord rec = new PIDRecord(); + PidRecord rec = new PidRecord(); rec.setPid("my-custom-pid"); rec.addEntry( // this is actually a registered type, but not in a data type registry, but inline in the PID system. @@ -72,7 +72,7 @@ void testAllSystemTests() throws Exception { //rec.addEntry("10320/loc", "", "value"); String pid = localPidSystem.registerPid(rec); assertEquals(rec.getPid(), pid); - PIDRecord newRec = localPidSystem.queryPid(pid); + PidRecord newRec = localPidSystem.queryPid(pid); assertEquals(rec, newRec); Set publicMethods = new HashSet<>(Arrays.asList(IIdentifierSystemQueryTest.class.getMethods())); @@ -101,7 +101,7 @@ void testAllSystemTests() throws Exception { @Test void testDeletePid() throws IOException { - PIDRecord p = new PIDRecord().withPID("test/pid"); + PidRecord p = new PidRecord().withPID("test/pid"); this.localPidSystem.registerPid(p); String pid = p.getPid(); assertThrows( @@ -120,11 +120,11 @@ void testDeletePid() throws IOException { void testResolveAll() throws InvalidConfigException, IOException { assertEquals(0, this.localPidSystem.resolveAllPidsOfPrefix().size()); - PIDRecord p1 = new PIDRecord().withPID("p1"); + PidRecord p1 = new PidRecord().withPID("p1"); this.localPidSystem.registerPid(p1); assertEquals(1, this.localPidSystem.resolveAllPidsOfPrefix().size()); - PIDRecord p2 = new PIDRecord().withPID("p2"); + PidRecord p2 = new PidRecord().withPID("p2"); this.localPidSystem.registerPid(p2); assertEquals(2, this.localPidSystem.resolveAllPidsOfPrefix().size()); } diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectDaoTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectDaoTest.java index 67dee52d..f8546b75 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectDaoTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectDaoTest.java @@ -16,7 +16,7 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.transaction.annotation.Transactional; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; @SpringBootTest @TestPropertySource("/test/application-test.properties") @@ -57,7 +57,7 @@ void testOverridePidInDatabase() { @Transactional void testModifyRecord() { Optional dbo = dao.findById("first"); - PIDRecord rec = new PIDRecord(dbo.get()); + PidRecord rec = new PidRecord(dbo.get()); assertEquals( rec.getPropertyIdentifiers().iterator().next(), dbo.get().getEntries().keySet().iterator().next() diff --git a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectTest.java b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectTest.java index 54315066..6f110e1e 100644 --- a/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectTest.java +++ b/src/test/java/edu/kit/datamanager/pit/pidsystem/impl/local/PidDatabaseObjectTest.java @@ -7,15 +7,15 @@ import com.fasterxml.jackson.core.JacksonException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.web.ApiMockUtils; class PidDatabaseObjectTest { @Test void testConversion() throws JacksonException { - PIDRecord original = ApiMockUtils.getSomePidRecordInstance(); + PidRecord original = ApiMockUtils.getSomePidRecordInstance(); PidDatabaseObject dbo = new PidDatabaseObject(original); - PIDRecord equivalent = new PIDRecord(dbo); + PidRecord equivalent = new PidRecord(dbo); assertEquals(original, equivalent); original.addEntry("test", "", "test"); diff --git a/src/test/java/edu/kit/datamanager/pit/recordModifiers/CopyAttributeTest.java b/src/test/java/edu/kit/datamanager/pit/recordModifiers/CopyAttributeTest.java index 04a0cee5..1b02b735 100644 --- a/src/test/java/edu/kit/datamanager/pit/recordModifiers/CopyAttributeTest.java +++ b/src/test/java/edu/kit/datamanager/pit/recordModifiers/CopyAttributeTest.java @@ -1,6 +1,6 @@ package edu.kit.datamanager.pit.recordModifiers; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,7 +17,7 @@ class CopyAttributeTest { public static final String URL_VALUE_2 = URL_VALUE + "2"; public static final String TARGET = "URL"; - private final PIDRecord RECORD = new PIDRecord(); + private final PidRecord RECORD = new PidRecord(); @BeforeEach() void setupRecord() { @@ -31,7 +31,7 @@ void oneSourceNoTarget() { assertTrue(RECORD.hasProperty(SOURCE)); assertFalse(RECORD.hasProperty(TARGET)); - PIDRecord result = modifier.apply(RECORD); + PidRecord result = modifier.apply(RECORD); // Currently, we do unfortunately modify the record because making a proper copy in java for it is difficult. assertEquals(RECORD, result); assertTrue(result.hasProperty(TARGET)); @@ -45,7 +45,7 @@ void multipleSourceNoTarget() { assertTrue(RECORD.hasProperty(SOURCE_2)); assertFalse(RECORD.hasProperty(TARGET)); - PIDRecord result = modifier.apply(RECORD); + PidRecord result = modifier.apply(RECORD); assertTrue(result.hasProperty(TARGET)); assertEquals(URL_VALUE_2, result.getPropertyValue(TARGET)); @@ -59,7 +59,7 @@ void oneSourceOneTarget() { assertTrue(RECORD.hasProperty(TARGET)); RecordModifier modifier = new CopyAttribute(Set.of(SOURCE), TARGET); - PIDRecord result = modifier.apply(RECORD); + PidRecord result = modifier.apply(RECORD); assertEquals(URL_VALUE, result.getPropertyValue(SOURCE)); assertTrue(Arrays.asList(result.getPropertyValues(TARGET)).contains(URL_VALUE)); @@ -67,13 +67,13 @@ void oneSourceOneTarget() { @Test void noSourceNoTarget() { - PIDRecord record = new PIDRecord(); + PidRecord record = new PidRecord(); assertFalse(record.hasProperty(SOURCE)); assertFalse(record.hasProperty(TARGET)); RecordModifier modifier = new CopyAttribute(Set.of(SOURCE), TARGET); - PIDRecord result = modifier.apply(record); + PidRecord result = modifier.apply(record); // Shall not modify record - assertEquals(result, new PIDRecord()); + assertEquals(result, new PidRecord()); } } \ No newline at end of file diff --git a/src/test/java/edu/kit/datamanager/pit/resolver/ResolverTest.java b/src/test/java/edu/kit/datamanager/pit/resolver/ResolverTest.java index db26ecfa..c0dbab23 100644 --- a/src/test/java/edu/kit/datamanager/pit/resolver/ResolverTest.java +++ b/src/test/java/edu/kit/datamanager/pit/resolver/ResolverTest.java @@ -1,7 +1,7 @@ package edu.kit.datamanager.pit.resolver; import edu.kit.datamanager.pit.common.PidNotFoundException; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pitservice.ITypingService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,16 +39,16 @@ void resolveWithNonexistentPrefix() { @Test void resolveHandleReadOnly() { - PIDRecord result = resolver.resolve("10.5281/zenodo.8014937"); + PidRecord result = resolver.resolve("10.5281/zenodo.8014937"); assertNotNull(result); } @Test void resolveInMemory() { - PIDRecord record = new PIDRecord().withPID("suffix"); + PidRecord record = new PidRecord().withPID("suffix"); record.addEntry("key", "value"); String pid = this.identifierSystem.registerPid(record); - PIDRecord result = resolver.resolve(pid); + PidRecord result = resolver.resolve(pid); assertNotNull(result); assertEquals("value", result.getEntries().get("key").getFirst().getValue()); } diff --git a/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java b/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java index a4cc8a4a..511a8492 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java +++ b/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java @@ -31,7 +31,7 @@ import edu.kit.datamanager.pit.pidlog.KnownPid; import edu.kit.datamanager.pit.Application; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; /** @@ -57,8 +57,8 @@ public static ObjectMapper getJsonMapper() { * @return a valid PIDRecord instance. * @throws JacksonException on error. */ - public static PIDRecord getSomePidRecordInstance() throws JacksonException { - return getJsonMapper().readValue(JSON_RECORD, PIDRecord.class); + public static PidRecord getSomePidRecordInstance() throws JacksonException { + return getJsonMapper().readValue(JSON_RECORD, PidRecord.class); } /** @@ -153,7 +153,7 @@ public static JsonNode queryKnownPIDsInTabulatorFormat( * @return the record as it is after the update. * @throws Exception if any assumption breaks. */ - public static PIDRecord updateRecord(MockMvc mockMvc, PIDRecord oldRecord, PIDRecord newRecord) throws Exception { + public static PidRecord updateRecord(MockMvc mockMvc, PidRecord oldRecord, PidRecord newRecord) throws Exception { String body = updateRecord( mockMvc, oldRecord, @@ -166,8 +166,8 @@ public static PIDRecord updateRecord(MockMvc mockMvc, PIDRecord oldRecord, PIDRe public static MvcResult updateRecordAndReturnMvcResult( MockMvc mockMvc, - PIDRecord oldRecord, - PIDRecord newRecord) throws Exception + PidRecord oldRecord, + PidRecord newRecord) throws Exception { String pid = oldRecord.getPid(); String etag = oldRecord.getEtag(); @@ -189,8 +189,8 @@ public static MvcResult updateRecordAndReturnMvcResult( */ public static String updateRecord( MockMvc mockMvc, - PIDRecord oldRecord, - PIDRecord newRecord, + PidRecord oldRecord, + PidRecord newRecord, String bodyContentType, String acceptContentType) throws Exception { @@ -251,9 +251,9 @@ private static MvcResult updateRecordAndReturnMvcResult( * @return the resolved record of the given PID. * @throws Exception if any assumption breaks. */ - public static PIDRecord resolveRecord(MockMvc mockMvc, String pid) throws Exception { + public static PidRecord resolveRecord(MockMvc mockMvc, String pid) throws Exception { String resolvedBody = ApiMockUtils.resolveRecord(mockMvc, pid, null); - PIDRecord resolvedRecord = getJsonMapper().readValue(resolvedBody, PIDRecord.class); + PidRecord resolvedRecord = getJsonMapper().readValue(resolvedBody, PidRecord.class); return resolvedRecord; } @@ -307,9 +307,9 @@ private static MvcResult resolveRecordAndReturnMvcResult(MockMvc mockMvc, String * @return The created PID record. * @throws Exception if any assumption breaks. */ - public static PIDRecord registerSomeRecord(MockMvc mockMvc) throws Exception { + public static PidRecord registerSomeRecord(MockMvc mockMvc) throws Exception { MvcResult result = ApiMockUtils.registerRecordAndGetMvcResult(mockMvc, ApiMockUtils.JSON_RECORD, MediaType.APPLICATION_JSON_VALUE, MediaType.ALL_VALUE); - PIDRecord createdRecord = ApiMockUtils.deserializeRecord(result); + PidRecord createdRecord = ApiMockUtils.deserializeRecord(result); String createdPid = createdRecord.getPid(); assertFalse(createdPid.isEmpty()); return createdRecord; @@ -414,26 +414,26 @@ public static MvcResult registerRecordAndGetMvcResult( .andReturn(); } - public static PIDRecord clone(PIDRecord original) throws JsonMappingException, JsonProcessingException { + public static PidRecord clone(PidRecord original) throws JsonMappingException, JsonProcessingException { String body = serialize(original); return deserializeRecord(body); } - public static String serialize(PIDRecord pidRecord) throws JsonProcessingException { + public static String serialize(PidRecord pidRecord) throws JsonProcessingException { return getJsonMapper().writeValueAsString(pidRecord); } - public static PIDRecord deserializeRecord(MvcResult result) throws Exception { + public static PidRecord deserializeRecord(MvcResult result) throws Exception { return deserializeRecord(result.getResponse()); } - public static PIDRecord deserializeRecord(MockHttpServletResponse response) throws Exception { + public static PidRecord deserializeRecord(MockHttpServletResponse response) throws Exception { String body = response.getContentAsString(); return deserializeRecord(body); } - public static PIDRecord deserializeRecord(String body) throws JsonMappingException, JsonProcessingException { - return getJsonMapper().readValue(body, PIDRecord.class); + public static PidRecord deserializeRecord(String body) throws JsonMappingException, JsonProcessingException { + return getJsonMapper().readValue(body, PidRecord.class); } public static String quoted(String etag) { diff --git a/src/test/java/edu/kit/datamanager/pit/web/ConnectedPIDsTest.java b/src/test/java/edu/kit/datamanager/pit/web/ConnectedPIDsTest.java index ea729b98..f9151d73 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/ConnectedPIDsTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/ConnectedPIDsTest.java @@ -18,7 +18,7 @@ package edu.kit.datamanager.pit.web; import com.fasterxml.jackson.databind.ObjectMapper; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidlog.KnownPidsDao; import edu.kit.datamanager.pit.pitservice.ITypingService; import lombok.extern.slf4j.Slf4j; @@ -198,37 +198,37 @@ void testPIDRecordBuilderAllMethods() { // Test the completeProfile method PIDRecordBuilder profileBuilder = new PIDRecordBuilder().completeProfile(); - PIDRecord profileRecord = profileBuilder.build(); + PidRecord profileRecord = profileBuilder.build(); assertNotNull(profileRecord, "completeProfile should produce a non-null record"); assertFalse(profileRecord.getEntries().isEmpty(), "completeProfile should generate record entries"); // Test incompleteProfile method PIDRecordBuilder incompleteBuilder = new PIDRecordBuilder().incompleteProfile(); - PIDRecord incompleteRecord = incompleteBuilder.build(); + PidRecord incompleteRecord = incompleteBuilder.build(); assertNotNull(incompleteRecord, "incompleteProfile should produce a non-null record"); // Test invalidValues method with different parameters PIDRecordBuilder invalidValuesBuilder1 = new PIDRecordBuilder().invalidValues(3); - PIDRecord invalidRecord1 = invalidValuesBuilder1.build(); + PidRecord invalidRecord1 = invalidValuesBuilder1.build(); assertNotNull(invalidRecord1, "invalidValues(3) should produce a non-null record"); PIDRecordBuilder invalidValuesBuilder2 = new PIDRecordBuilder().invalidValues(2, "21.T11148/397d831aa3a9d18eb52c"); - PIDRecord invalidRecord2 = invalidValuesBuilder2.build(); + PidRecord invalidRecord2 = invalidValuesBuilder2.build(); assertNotNull(invalidRecord2, "invalidValues with specific key should produce a non-null record"); PIDRecordBuilder invalidValuesBuilder3 = new PIDRecordBuilder().invalidValues(0); - PIDRecord invalidRecord3 = invalidValuesBuilder3.build(); + PidRecord invalidRecord3 = invalidValuesBuilder3.build(); assertNotNull(invalidRecord3, "invalidValues(0) should produce a non-null record"); // Test invalidKeys method PIDRecordBuilder invalidKeysBuilder = new PIDRecordBuilder().invalidKeys(3); - PIDRecord invalidKeysRecord = invalidKeysBuilder.build(); + PidRecord invalidKeysRecord = invalidKeysBuilder.build(); assertNotNull(invalidKeysRecord, "invalidKeys should produce a non-null record"); assertTrue(invalidKeysRecord.getEntries().size() >= 3, "invalidKeys(3) should generate at least 3 entries"); // Test emptyRecord method PIDRecordBuilder emptyBuilder = new PIDRecordBuilder().completeProfile().emptyRecord(); - PIDRecord emptyRecord = emptyBuilder.build(); + PidRecord emptyRecord = emptyBuilder.build(); assertNotNull(emptyRecord, "emptyRecord should produce a non-null record"); assertEquals(0, emptyRecord.getEntries().size(), "emptyRecord should have no entries"); @@ -237,7 +237,7 @@ void testPIDRecordBuilderAllMethods() { assertThrows(Exception.class, nullBuilder::build, "nullRecord should throw exception when built"); // Test withPIDRecord method - PIDRecord existingRecord = new PIDRecord().withPID("test/existing"); + PidRecord existingRecord = new PidRecord().withPID("test/existing"); existingRecord.addEntry("test.key", "test.value"); PIDRecordBuilder recordBuilder = new PIDRecordBuilder().withPIDRecord(existingRecord); assertEquals(existingRecord.getPid(), recordBuilder.build().getPid(), "withPIDRecord should use PID from existing record"); @@ -274,12 +274,12 @@ void testPIDRecordBuilderConnections() { String connectionKey = "21.T11148/d0773859091aeb451528"; builder1.addConnection(connectionKey, false, builder2, builder3); - PIDRecord connectedRecord = builder1.build(); + PidRecord connectedRecord = builder1.build(); assertTrue(connectedRecord.hasProperty(connectionKey), "Record should have the connection property after addConnection"); // Test addConnection with replacement builder1.addConnection(connectionKey, true, builder2); - PIDRecord replacedRecord = builder1.build(); + PidRecord replacedRecord = builder1.build(); assertTrue(replacedRecord.hasProperty(connectionKey), "Record should have connection property after replace"); // Test addConnection error case @@ -294,7 +294,7 @@ void testPIDRecordBuilderConnections() { // Verify connections were established for (PIDRecordBuilder builder : connectedBuilders) { - PIDRecord record = builder.build(); + PidRecord record = builder.build(); assertTrue(record.hasProperty("21.T11148/d0773859091aeb451528") || record.hasProperty("21.T11148/4fe7cde52629b61e3b82"), "Connected records should have forward or backward connection property"); } @@ -319,7 +319,7 @@ void checkValidConnectedRecords() throws Exception { // Create connected records using all builder functionality long baseSeed = 12345L; - List records = new ArrayList<>(); + List records = new ArrayList<>(); // Use different PIDBuilder configurations PIDBuilder[] pidBuilders = { @@ -379,12 +379,12 @@ void testCreateSingleValidRecord() throws Exception { .validPrefix() .validSuffix(); - PIDRecord record = new PIDRecordBuilder(pidBuilder) + PidRecord record = new PIDRecordBuilder(pidBuilder) .withSeed(999L) .completeProfile() .build(); - List records = List.of(record); + List records = List.of(record); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -405,7 +405,7 @@ void testCreateSingleValidRecord() throws Exception { @Test @DisplayName("Test empty list") void testCreateEmptyList() throws Exception { - List emptyRecords = new ArrayList<>(); + List emptyRecords = new ArrayList<>(); String jsonContent = mapper.writeValueAsString(emptyRecords); this.mockMvc @@ -421,11 +421,11 @@ void testCreateEmptyList() throws Exception { @Test @DisplayName("Test dryrun functionality") void testDryRun() throws Exception { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .completeProfile() .build(); - List records = List.of(record); + List records = List.of(record); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -458,8 +458,8 @@ void testInvalidJsonFormat() throws Exception { @Test @DisplayName("Test unsupported media type") void testUnsupportedMediaType() throws Exception { - PIDRecord record = new PIDRecordBuilder().completeProfile().build(); - List records = List.of(record); + PidRecord record = new PIDRecordBuilder().completeProfile().build(); + List records = List.of(record); String content = mapper.writeValueAsString(records); this.mockMvc @@ -481,7 +481,7 @@ void testCircularReferences() throws Exception { builder1.addConnection("21.T11148/d0773859091aeb451528", false, builder2); builder2.addConnection("21.T11148/4fe7cde52629b61e3b82", false, builder1); - List records = List.of(builder1.build(), builder2.build()); + List records = List.of(builder1.build(), builder2.build()); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -505,10 +505,10 @@ void testDuplicateTemporaryPids() throws Exception { Long sameSeed = 555L; PIDBuilder sameBuilder = new PIDBuilder(sameSeed).validPrefix().validSuffix(); - PIDRecord record1 = new PIDRecordBuilder(sameBuilder.clone(), sameSeed).completeProfile().build(); - PIDRecord record2 = new PIDRecordBuilder(sameBuilder.clone(), sameSeed).completeProfile().build(); + PidRecord record1 = new PIDRecordBuilder(sameBuilder.clone(), sameSeed).completeProfile().build(); + PidRecord record2 = new PIDRecordBuilder(sameBuilder.clone(), sameSeed).completeProfile().build(); - List records = List.of(record1, record2); + List records = List.of(record1, record2); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -523,11 +523,11 @@ void testDuplicateTemporaryPids() throws Exception { @DisplayName("Test records with missing entries") void testRecordsWithMissingEntries() throws Exception { // Create an incomplete record - PIDRecord incompleteRecord = new PIDRecordBuilder() + PidRecord incompleteRecord = new PIDRecordBuilder() .incompleteProfile() .build(); - List records = List.of(incompleteRecord); + List records = List.of(incompleteRecord); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -552,7 +552,7 @@ void testLargeNumberOfConnectedRecords() throws Exception { PIDRecordBuilder.connectRecordBuilders(null, null, false, builders.toArray(new PIDRecordBuilder[0])); - List records = new ArrayList<>(); + List records = new ArrayList<>(); for (PIDRecordBuilder builder : builders) { records.add(builder.build()); } @@ -576,14 +576,14 @@ void testLargeNumberOfConnectedRecords() throws Exception { @Test @DisplayName("Test records with external references") void testRecordsWithExternalReferences() throws Exception { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .completeProfile() .build(); // Add external reference record.addEntry("21.T11148/d0773859091aeb451528", "externalRef", "external/pid/reference"); - List records = List.of(record); + List records = List.of(record); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -613,7 +613,7 @@ void testMixedConnectionTypes() throws Exception { builder2.addConnection("21.T11148/4fe7cde52629b61e3b82", false, builder3); builder3.addConnection(VALID_CONNECTION_KEYS[0], false, builder1); - List records = List.of(builder1.build(), builder2.build(), builder3.build()); + List records = List.of(builder1.build(), builder2.build(), builder3.build()); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -633,12 +633,12 @@ void testMixedConnectionTypes() throws Exception { @Test @DisplayName("Test records with null PIDs") void testRecordsWithNullPids() throws Exception { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .completeProfile() .withPid(null) .build(); - List records = List.of(record); + List records = List.of(record); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -656,11 +656,11 @@ void testRecordsWithNullPids() throws Exception { @Test @DisplayName("Test PID mapping persistence") void testPidMappingPersistence() throws Exception { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .completeProfile() .build(); - List records = List.of(record); + List records = List.of(record); String jsonContent = mapper.writeValueAsString(records); this.mockMvc @@ -718,14 +718,14 @@ void testPIDBuilderEdgeCases() { @DisplayName("Test PIDRecordBuilder with various invalid configurations") void testPIDRecordBuilderInvalidConfigurations() throws Exception { // Test record with invalid keys - PIDRecord invalidKeysRecord = new PIDRecordBuilder() + PidRecord invalidKeysRecord = new PIDRecordBuilder() .invalidKeys(5) .build(); assertTrue(invalidKeysRecord.getEntries().size() >= 5, "invalidKeys(5) should generate at least 5 entries"); // Test record with invalid values for specific keys - PIDRecord invalidSpecificRecord = new PIDRecordBuilder() + PidRecord invalidSpecificRecord = new PIDRecordBuilder() .completeProfile() .invalidValues(2, "21.T11148/397d831aa3a9d18eb52c", "21.T11148/8074aed799118ac263ad") .build(); @@ -733,14 +733,14 @@ void testPIDRecordBuilderInvalidConfigurations() throws Exception { assertNotNull(invalidSpecificRecord, "Invalid values for specific keys should produce non-null record"); // Test empty record - PIDRecord emptyRecord = new PIDRecordBuilder() + PidRecord emptyRecord = new PIDRecordBuilder() .emptyRecord() .build(); assertEquals(0, emptyRecord.getEntries().size(), "emptyRecord should have no entries"); // Submit invalid records to test API response - List invalidRecords = List.of(invalidKeysRecord); + List invalidRecords = List.of(invalidKeysRecord); String jsonContent = mapper.writeValueAsString(invalidRecords); this.mockMvc @@ -775,7 +775,7 @@ void testBuilderChainingCombinations() { .invalidValues(1, "21.T11148/397d831aa3a9d18eb52c") .invalidKeys(1); - PIDRecord complexRecord = complexRecordBuilder.build(); + PidRecord complexRecord = complexRecordBuilder.build(); assertEquals("custom/pid", complexRecord.getPid(), "Chained record builder should use the custom PID"); assertFalse(complexRecord.getEntries().isEmpty(), "Chained record builder should generate entries"); @@ -789,12 +789,12 @@ void testBuilderChainingCombinations() { @Test @DisplayName("Test multiple record creation with using RECORD_COUNT constant") void testMultipleRecordCreationWithRecordCount() throws Exception { - List records = new ArrayList<>(); + List records = new ArrayList<>(); // Create multiple records using RECORD_COUNT constant for (int i = 0; i < RECORD_COUNT; i++) { PIDBuilder pidBuilder = new PIDBuilder((long) i).validPrefix().validSuffix(); - PIDRecord record = new PIDRecordBuilder(pidBuilder, (long) i) + PidRecord record = new PIDRecordBuilder(pidBuilder, (long) i) .completeProfile() .build(); records.add(record); @@ -831,7 +831,7 @@ void testConnectedRecordsWithRecordCount() throws Exception { PIDRecordBuilder.connectRecordBuilders(null, null, false, builders.toArray(new PIDRecordBuilder[0])); - List records = new ArrayList<>(); + List records = new ArrayList<>(); for (PIDRecordBuilder builder : builders) { records.add(builder.build()); } @@ -855,11 +855,11 @@ void testConnectedRecordsWithRecordCount() throws Exception { @Test @DisplayName("Test partial failure and rollback scenario") void testPartialFailureAndRollback() throws Exception { - List records = new ArrayList<>(); + List records = new ArrayList<>(); // Create some valid records for (int i = 0; i < 3; i++) { - PIDRecord validRecord = new PIDRecordBuilder() + PidRecord validRecord = new PIDRecordBuilder() .completeProfile() .build(); records.add(validRecord); @@ -867,19 +867,19 @@ void testPartialFailureAndRollback() throws Exception { // Add records that should cause validation or creation failures // Record with incomplete profile (missing required entries) - PIDRecord incompleteRecord = new PIDRecordBuilder() + PidRecord incompleteRecord = new PIDRecordBuilder() .incompleteProfile() .build(); records.add(incompleteRecord); // Record with invalid keys - PIDRecord invalidKeysRecord = new PIDRecordBuilder() + PidRecord invalidKeysRecord = new PIDRecordBuilder() .invalidKeys(3) .build(); records.add(invalidKeysRecord); // Record with invalid values for specific keys - PIDRecord invalidValuesRecord = new PIDRecordBuilder() + PidRecord invalidValuesRecord = new PIDRecordBuilder() .completeProfile() .invalidValues(2, "21.T11148/397d831aa3a9d18eb52c") .build(); @@ -903,11 +903,11 @@ void testPartialFailureAndRollback() throws Exception { @Test @DisplayName("Test batch with mixed valid and invalid records for rollback coverage") void testBatchWithMixedRecordsForRollbackCoverage() throws Exception { - List records = new ArrayList<>(); + List records = new ArrayList<>(); // Create valid records that would initially succeed for (int i = 0; i < RECORD_COUNT / 2; i++) { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .withSeed((long) i) .completeProfile() .build(); @@ -917,27 +917,27 @@ void testBatchWithMixedRecordsForRollbackCoverage() throws Exception { // Add records with various failure scenarios to trigger rollback // Empty record (no entries) - PIDRecord emptyRecord = new PIDRecordBuilder() + PidRecord emptyRecord = new PIDRecordBuilder() .emptyRecord() .build(); records.add(emptyRecord); // Record with null PID and incomplete profile - PIDRecord nullPidRecord = new PIDRecordBuilder() + PidRecord nullPidRecord = new PIDRecordBuilder() .withPid(null) .incompleteProfile() .build(); records.add(nullPidRecord); // Record with completely invalid data - PIDRecord invalidRecord = new PIDRecordBuilder() + PidRecord invalidRecord = new PIDRecordBuilder() .invalidKeys(5) .invalidValues(3) .build(); records.add(invalidRecord); // Incomplete record with missing required entries - PIDRecord incompleteRecord = new PIDRecordBuilder() + PidRecord incompleteRecord = new PIDRecordBuilder() .incompleteProfile() .build(); records.add(incompleteRecord); @@ -959,11 +959,11 @@ void testBatchWithMixedRecordsForRollbackCoverage() throws Exception { @Test @DisplayName("Test record creation failure scenarios with duplicate PIDs in batch") void testRecordCreationFailureWithDuplicatePids() throws Exception { - List records = new ArrayList<>(); + List records = new ArrayList<>(); // Create multiple valid records first for (int i = 0; i < RECORD_COUNT / 4; i++) { - PIDRecord record = new PIDRecordBuilder() + PidRecord record = new PIDRecordBuilder() .withSeed((long) i) .completeProfile() .build(); @@ -973,13 +973,13 @@ void testRecordCreationFailureWithDuplicatePids() throws Exception { // Add duplicate PIDs to trigger failure String duplicatePid = "sandboxed/duplicate-test-pid"; - PIDRecord record1 = new PIDRecordBuilder() + PidRecord record1 = new PIDRecordBuilder() .completeProfile() .withPid(duplicatePid) .build(); records.add(record1); - PIDRecord record2 = new PIDRecordBuilder() + PidRecord record2 = new PIDRecordBuilder() .completeProfile() .withPid(duplicatePid) .build(); diff --git a/src/test/java/edu/kit/datamanager/pit/web/CustomPidsTest.java b/src/test/java/edu/kit/datamanager/pit/web/CustomPidsTest.java index a49f39ee..b11db188 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/CustomPidsTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/CustomPidsTest.java @@ -20,7 +20,7 @@ import org.springframework.web.context.WebApplicationContext; import edu.kit.datamanager.pit.configuration.PidGenerationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; @AutoConfigureMockMvc // JUnit5 + Spring @@ -53,10 +53,10 @@ void setup() throws Exception { */ @Test void testCreateExistingPid() throws Exception { - PIDRecord first = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord first = ApiMockUtils.registerSomeRecord(this.mockMvc); assertNotNull(first); - PIDRecord second = ApiMockUtils.getSomePidRecordInstance(); + PidRecord second = ApiMockUtils.getSomePidRecordInstance(); second.setPid(first.getPid()); String body = ApiMockUtils.getJsonMapper().writeValueAsString(second); @@ -75,7 +75,7 @@ void testCreateExistingPid() throws Exception { */ @Test void testCreateCustomPid() throws Exception { - PIDRecord record = ApiMockUtils.getSomePidRecordInstance(); + PidRecord record = ApiMockUtils.getSomePidRecordInstance(); record.setPid("my-custom-pid"); String body = ApiMockUtils.getJsonMapper().writeValueAsString(record); @@ -98,7 +98,7 @@ void testCrateCustomPidWhenFeatureDisabled() throws Exception { this.props.setCustomClientPidsEnabled(false); String customPid = "my-custom-pid"; - PIDRecord record = ApiMockUtils.getSomePidRecordInstance(); + PidRecord record = ApiMockUtils.getSomePidRecordInstance(); record.setPid(customPid); String body = ApiMockUtils.getJsonMapper().writeValueAsString(record); @@ -124,7 +124,7 @@ void testBrandingNotApplied() throws Exception { this.props.setBrandingPrefix(Optional.of(branding)); String customPid = "unbranded-pid"; - PIDRecord record = ApiMockUtils.getSomePidRecordInstance(); + PidRecord record = ApiMockUtils.getSomePidRecordInstance(); record.setPid(customPid); String body = ApiMockUtils.getJsonMapper().writeValueAsString(record); diff --git a/src/test/java/edu/kit/datamanager/pit/web/EtagTest.java b/src/test/java/edu/kit/datamanager/pit/web/EtagTest.java index ca6ff104..2eebeb10 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/EtagTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/EtagTest.java @@ -27,7 +27,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; @AutoConfigureMockMvc // JUnit5 + Spring @@ -48,7 +48,7 @@ class EtagTest { private MockMvc mockMvc; - private PIDRecord existingRecord; + private PidRecord existingRecord; /* * Pre-test to make sure there is at least one PID available. diff --git a/src/test/java/edu/kit/datamanager/pit/web/ExplicitValidationParametersTest.java b/src/test/java/edu/kit/datamanager/pit/web/ExplicitValidationParametersTest.java index 360893e1..dded9a52 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/ExplicitValidationParametersTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/ExplicitValidationParametersTest.java @@ -17,7 +17,7 @@ import edu.kit.datamanager.pit.RecordTestHelper; import edu.kit.datamanager.pit.SpringTestHelper; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffixGenerator; import edu.kit.datamanager.pit.pidlog.KnownPidsDao; @@ -141,7 +141,7 @@ void testExtensiveRecordDryRun() throws Exception { // as we use an in-memory data structure, lets not make it too large. int numAttributes = 100; int numValues = 100; - PIDRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); + PidRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); String rJson = ApiMockUtils.serialize(r); this.mockMvc @@ -168,7 +168,7 @@ void testExtensiveRecordWithoutDryRun() throws Exception { // as we use an in-memory data structure, lets not make it too large. int numAttributes = 100; int numValues = 100; - PIDRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); + PidRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); String rJson = ApiMockUtils.serialize(r); this.mockMvc @@ -189,7 +189,7 @@ void testExtensiveRecordWithoutDryRun() throws Exception { @Test void testNontypeRecord() throws Exception { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.addEntry("unregisteredType", "for Testing", "hello"); this.mockMvc .perform( @@ -209,7 +209,7 @@ void testNontypeRecord() throws Exception { @Test void testRecordWithInvalidValue() throws Exception { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); // valid attribute key, but wrong attribute value: String urlType = "21.T11969/e0efc41346cda4ba84ca"; r.addEntry(urlType, "", "not a url"); @@ -234,7 +234,7 @@ void testRecordWithInvalidValue() throws Exception { @Test void testRecordWithAdditionalAttribute() throws Exception { - PIDRecord r = ApiMockUtils.getSomePidRecordInstance(); + PidRecord r = ApiMockUtils.getSomePidRecordInstance(); r.addEntry( "21.T11969/86963861a2b249a83b93", "additional attribute", diff --git a/src/test/java/edu/kit/datamanager/pit/web/PIDRecordBuilder.java b/src/test/java/edu/kit/datamanager/pit/web/PIDRecordBuilder.java index 93f22a55..54f1d61f 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/PIDRecordBuilder.java +++ b/src/test/java/edu/kit/datamanager/pit/web/PIDRecordBuilder.java @@ -16,7 +16,7 @@ package edu.kit.datamanager.pit.web; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -124,7 +124,7 @@ public class PIDRecordBuilder implements Cloneable { * The PID record being built by this builder. * All operations performed on this builder modify this record instance. */ - private PIDRecord record; + private PidRecord record; /** * Creates a new PIDRecordBuilder with default settings. @@ -162,7 +162,7 @@ public PIDRecordBuilder(PIDBuilder pidBuilder) { public PIDRecordBuilder(PIDBuilder pidBuilder, Long seed) { this.seed = seed != null ? seed : new Random().nextLong(); this.random = new Random(this.seed); - this.record = new PIDRecord(); + this.record = new PidRecord(); if (pidBuilder == null) { pidBuilder = new PIDBuilder(this.seed).validPrefix().validSuffix(); @@ -226,7 +226,7 @@ public static List connectRecordBuilders(String a_to_b_key, St * * @return A new clone of the built PID record */ - public PIDRecord build() { + public PidRecord build() { return this.record.clone(); } @@ -300,7 +300,7 @@ public PIDRecordBuilder addConnection(String key, boolean replaceIdentical, PIDR * @param record The PIDRecord to use as the basis for further building * @return This builder instance for method chaining */ - public PIDRecordBuilder withPIDRecord(PIDRecord record) { + public PIDRecordBuilder withPIDRecord(PidRecord record) { this.record = record; return this; } @@ -441,7 +441,7 @@ public PIDRecordBuilder invalidKeys(int amount) { */ public PIDRecordBuilder emptyRecord() { String pid = this.record.getPid(); - this.record = new PIDRecord().withPID(pid); + this.record = new PidRecord().withPID(pid); return this; } diff --git a/src/test/java/edu/kit/datamanager/pit/web/RestWithHandleProtocolTest.java b/src/test/java/edu/kit/datamanager/pit/web/RestWithHandleProtocolTest.java index e1ab8b73..5d3aa20f 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/RestWithHandleProtocolTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/RestWithHandleProtocolTest.java @@ -18,7 +18,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidsystem.impl.handle.HandleProtocolAdapter; import edu.kit.datamanager.pit.pidsystem.impl.InMemoryIdentifierSystem; @@ -85,7 +85,7 @@ void resolveSomething() throws Exception { .andReturn(); String resolvedBody = resolved.getResponse().getContentAsString(); - PIDRecord resolvedRecord = mapper.readValue(resolvedBody, PIDRecord.class); + PidRecord resolvedRecord = mapper.readValue(resolvedBody, PidRecord.class); assertEquals(pid, resolvedRecord.getPid()); } @@ -103,7 +103,7 @@ void testDryrunUpdateWithPidGiven() throws Exception { String etag = response.getHeader("ETag"); // Parse so we can edit the record easily - PIDRecord record = mapper.readValue(response.getContentAsString(), PIDRecord.class); + PidRecord record = mapper.readValue(response.getContentAsString(), PidRecord.class); // fix record, it is actually invalid... record.removeAllValuesOf("URL"); diff --git a/src/test/java/edu/kit/datamanager/pit/web/RestWithInMemoryTest.java b/src/test/java/edu/kit/datamanager/pit/web/RestWithInMemoryTest.java index a78ec748..699d238a 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/RestWithInMemoryTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/RestWithInMemoryTest.java @@ -25,7 +25,7 @@ import edu.kit.datamanager.pit.RecordTestHelper; import edu.kit.datamanager.pit.SpringTestHelper; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffixGenerator; import edu.kit.datamanager.pit.pidlog.KnownPid; import edu.kit.datamanager.pit.pidlog.KnownPidsDao; @@ -152,7 +152,7 @@ void testCreateEmptyRecord() throws Exception { @Test @DisplayName("Test record with only a profile, no entries.") void testRecordWithOnlyProfile() throws Exception { - PIDRecord incompleteRecord = new PIDRecord(); + PidRecord incompleteRecord = new PidRecord(); incompleteRecord.addEntry( "21.T11148/076759916209e5d62bd5", "kernelInformationProfile", @@ -178,7 +178,7 @@ void testExtensiveRecord() throws Exception { int numAttributes = 100; int numValues = 100; assertTrue(numAttributes * numValues > 256); - PIDRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); + PidRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); String rJson = ApiMockUtils.serialize(r); ApiMockUtils.registerRecord( @@ -192,7 +192,7 @@ void testExtensiveRecord() throws Exception { @Test void testNontypeRecord() throws Exception { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.addEntry("unregisteredType", "for Testing", "hello"); this.mockMvc .perform( @@ -211,7 +211,7 @@ void testNontypeRecord() throws Exception { @Test void testRecordWithAdditionalAttribute() throws Exception { - PIDRecord r = new PIDRecord(); + PidRecord r = new PidRecord(); r.addEntry( "21.T11969/86963861a2b249a83b93", "additional attribute", @@ -237,14 +237,14 @@ void testRecordWithAdditionalAttribute() throws Exception { @Test void testCreateValidRecord() throws Exception { // test create - PIDRecord createdRecord = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord createdRecord = ApiMockUtils.registerSomeRecord(this.mockMvc); String createdPid = createdRecord.getPid(); // We store created PIDs assertEquals(1, this.knownPidsDao.count()); // test resolve - PIDRecord resolvedRecord = ApiMockUtils.resolveRecord(this.mockMvc, createdPid); + PidRecord resolvedRecord = ApiMockUtils.resolveRecord(this.mockMvc, createdPid); assertEquals(createdRecord, resolvedRecord); // Resolving the PID will override the available entry. @@ -258,18 +258,18 @@ void testCreateValidRecord() throws Exception { @Test void testUpdateRecord() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord modified = ApiMockUtils.clone(original); modified.getEntries().get("21.T11148/b8457812905b83046284").get(0).setValue("https://example.com/anotherUrlAsBefore"); assertNotEquals(original, modified); - PIDRecord updatedRecord = ApiMockUtils.updateRecord(this.mockMvc, original, modified); + PidRecord updatedRecord = ApiMockUtils.updateRecord(this.mockMvc, original, modified); assertEquals(modified, updatedRecord); } @Test void testIdPidRegisteredFails() throws Exception { // Nothing is registered, our local storags contains no PIDs - PIDRecord nonRegistered = mapper.readValue(RECORD, PIDRecord.class); + PidRecord nonRegistered = mapper.readValue(RECORD, PidRecord.class); boolean isRegistered = isPidRegistered(nonRegistered.getPid()); assertFalse(isRegistered); assertEquals(0, this.knownPidsDao.count()); @@ -277,7 +277,7 @@ void testIdPidRegisteredFails() throws Exception { @Test void testIsPidRecordRegisteredSucceeds() throws Exception { - PIDRecord existing = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord existing = ApiMockUtils.registerSomeRecord(this.mockMvc); // We know a PID after we create one. assertEquals(1, this.knownPidsDao.count()); // If we clear the locally stored PIDs and then ask if it is registered, it should appear again. @@ -310,7 +310,7 @@ void testKnownPidFailure() throws Exception { @Test void testKnownPidSuccess() throws Exception { - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); // we know it is in the local database: assertEquals(1, this.knownPidsDao.count()); // so we should be able to retrieve it via the REST api: @@ -344,8 +344,8 @@ void testKnownPidsQueryAll() throws Exception { */ @Test void testKnownPidIntervalSuccessWithCreatedInterval() throws Exception { - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r.getPid(), r2.getPid()); @@ -385,14 +385,14 @@ void testKnownPidIntervalSuccessWithCreatedInterval() throws Exception { @Test void testKnownPidIntervalSuccessIntervallMadness() throws Exception { - PIDRecord r1 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r1 = ApiMockUtils.registerSomeRecord(this.mockMvc); // do some simple assertions for a little more delay between the creation times of the records. // unfortunately we do not seem to be able to wait() within tests. assertEquals(r1.getPid(), this.knownPidsDao.findById(r1.getPid()).get().getPid()); assertEquals(1, this.knownPidsDao.count()); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r1.getPid(), r2.getPid()); @@ -427,8 +427,8 @@ void testKnownPidIntervalSuccessIntervallMadness() throws Exception { @Test void testKnownPidIntervalWithPaging() throws Exception { // see also https://www.baeldung.com/rest-api-pagination-in-spring - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r.getPid(), r2.getPid()); List pidinfos = ApiMockUtils.queryKnownPIDs(this.mockMvc, YESTERDAY, TOMORROW, null, null, Optional.empty()); @@ -447,8 +447,8 @@ void testKnownPidIntervalWithPaging() throws Exception { @Test void testTabulatorFormat() throws Exception { - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r.getPid(), r2.getPid()); JsonNode pidinfos = ApiMockUtils.queryKnownPIDsInTabulatorFormat(this.mockMvc, YESTERDAY, TOMORROW, null, null, Optional.empty()); diff --git a/src/test/java/edu/kit/datamanager/pit/web/RestWithLocalPidSystemTest.java b/src/test/java/edu/kit/datamanager/pit/web/RestWithLocalPidSystemTest.java index 1fc07585..0fa5eadd 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/RestWithLocalPidSystemTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/RestWithLocalPidSystemTest.java @@ -26,7 +26,7 @@ import edu.kit.datamanager.pit.RecordTestHelper; import edu.kit.datamanager.pit.configuration.ApplicationProperties; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.pidgeneration.PidSuffixGenerator; import edu.kit.datamanager.pit.pidlog.KnownPid; import edu.kit.datamanager.pit.pidlog.KnownPidsDao; @@ -158,14 +158,14 @@ void testCreateEmptyRecord() throws Exception { @Test void testCreateValidRecord() throws Exception { // test create - PIDRecord createdRecord = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord createdRecord = ApiMockUtils.registerSomeRecord(this.mockMvc); String createdPid = createdRecord.getPid(); // We store created PIDs assertEquals(1, this.knownPidsDao.count()); // test resolve - PIDRecord resolvedRecord = ApiMockUtils.resolveRecord(this.mockMvc, createdPid); + PidRecord resolvedRecord = ApiMockUtils.resolveRecord(this.mockMvc, createdPid); assertEquals(createdRecord, resolvedRecord); // Resolving the PID will override the available entry. @@ -186,7 +186,7 @@ void testExtensiveRecord() throws Exception { int numAttributes = 100; int numValues = 100; assertTrue(numAttributes * numValues > 256); - PIDRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); + PidRecord r = RecordTestHelper.getFakePidRecord(numAttributes, numValues, "sandboxed/", pidGenerator); String rJson = ApiMockUtils.serialize(r); ApiMockUtils.registerRecord( @@ -200,18 +200,18 @@ void testExtensiveRecord() throws Exception { @Test void testUpdateRecord() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord modified = ApiMockUtils.clone(original); modified.getEntries().get("21.T11148/b8457812905b83046284").get(0).setValue("https://example.com/anotherUrlAsBefore"); assertNotEquals(original, modified); - PIDRecord updatedRecord = ApiMockUtils.updateRecord(this.mockMvc, original, modified); + PidRecord updatedRecord = ApiMockUtils.updateRecord(this.mockMvc, original, modified); assertEquals(modified, updatedRecord); } @Test void testIdPidRegisteredFails() throws Exception { // Nothing is registered, our local storags contains no PIDs - PIDRecord nonRegistered = mapper.readValue(RECORD, PIDRecord.class); + PidRecord nonRegistered = mapper.readValue(RECORD, PidRecord.class); boolean isRegistered = isPidRegistered(nonRegistered.getPid()); assertFalse(isRegistered); assertEquals(0, this.knownPidsDao.count()); @@ -219,7 +219,7 @@ void testIdPidRegisteredFails() throws Exception { @Test void testIsPidRecordRegisteredSucceeds() throws Exception { - PIDRecord existing = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord existing = ApiMockUtils.registerSomeRecord(this.mockMvc); // We know a PID after we create one. assertEquals(1, this.knownPidsDao.count()); // If we clear the locally stored PIDs and then ask if it is registered, it should appear again. @@ -252,7 +252,7 @@ void testKnownPidFailure() throws Exception { @Test void testKnownPidSuccess() throws Exception { - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); // we know it is in the local database: assertEquals(1, this.knownPidsDao.count()); // so we should be able to retrieve it via the REST api: @@ -276,8 +276,8 @@ void testKnownPidIntervalFailure() throws Exception { */ @Test void testKnownPidIntervalSuccessWithCreatedInterval() throws Exception { - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r.getPid(), r2.getPid()); @@ -324,8 +324,8 @@ void testKnownPidIntervalSuccessWithCreatedInterval() throws Exception { @Test void testKnownPidIntervalWithPaging() throws Exception { // see also https://www.baeldung.com/rest-api-pagination-in-spring - PIDRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); - PIDRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord r2 = ApiMockUtils.registerSomeRecord(this.mockMvc); assertEquals(2, this.knownPidsDao.count()); assertNotEquals(r.getPid(), r2.getPid()); List pidinfos = ApiMockUtils.queryKnownPIDs(this.mockMvc, YESTERDAY, TOMORROW, null, null, Optional.empty()); diff --git a/src/test/java/edu/kit/datamanager/pit/web/SimpleJSONFormatTest.java b/src/test/java/edu/kit/datamanager/pit/web/SimpleJSONFormatTest.java index 78d13fad..9b5ce514 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/SimpleJSONFormatTest.java +++ b/src/test/java/edu/kit/datamanager/pit/web/SimpleJSONFormatTest.java @@ -19,7 +19,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import edu.kit.datamanager.pit.domain.PIDRecord; +import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; @AutoConfigureMockMvc @@ -45,7 +45,7 @@ void setup() throws Exception { */ @Test void testResolvePid() throws Exception { - PIDRecord complexFormat = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord complexFormat = ApiMockUtils.registerSomeRecord(this.mockMvc); assertNotNull(complexFormat); SimplePidRecord simpleFormat = ApiMockUtils.resolveSimpleRecord(this.mockMvc, complexFormat.getPid()); @@ -154,7 +154,7 @@ void testCreatePidFromSimpleAndAcceptAll() throws Exception { SimplePidRecord input = new SimplePidRecord(ApiMockUtils.getSomePidRecordInstance()); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(input); String responseBody = ApiMockUtils.registerRecord(mockMvc, requestBody, SimplePidRecord.CONTENT_TYPE, MediaType.ALL_VALUE); - PIDRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(modified); assertTrue(modified.getEntries().size() > 0); } @@ -168,10 +168,10 @@ void testCreatePidFromSimpleAndAcceptAll() throws Exception { */ @Test void testCreatePidFromComplexAndAcceptJson() throws Exception { - PIDRecord input = ApiMockUtils.getSomePidRecordInstance(); + PidRecord input = ApiMockUtils.getSomePidRecordInstance(); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(input); String responseBody = ApiMockUtils.registerRecord(mockMvc, requestBody, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE); - PIDRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(modified); assertTrue(modified.getEntries().size() > 0); } @@ -185,10 +185,10 @@ void testCreatePidFromComplexAndAcceptJson() throws Exception { */ @Test void testCreatePidFromComplexAndAcceptAll() throws Exception { - PIDRecord input = ApiMockUtils.getSomePidRecordInstance(); + PidRecord input = ApiMockUtils.getSomePidRecordInstance(); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(input); String responseBody = ApiMockUtils.registerRecord(mockMvc, requestBody, MediaType.APPLICATION_JSON_VALUE, MediaType.ALL_VALUE); - PIDRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord modified = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(modified); assertTrue(modified.getEntries().size() > 0); } @@ -202,13 +202,13 @@ void testCreatePidFromComplexAndAcceptAll() throws Exception { */ @Test void testUpdatePidFromComplexAndAcceptAll() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); String responseBody = ApiMockUtils.updateRecord(mockMvc, original, modified, MediaType.APPLICATION_JSON_VALUE, MediaType.ALL_VALUE); - PIDRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(receivedRecord); assertTrue(receivedRecord.getEntries().size() > 0); } @@ -222,13 +222,13 @@ void testUpdatePidFromComplexAndAcceptAll() throws Exception { */ @Test void testUpdatePidFromComplexAndAcceptComplex() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); String responseBody = ApiMockUtils.updateRecord(mockMvc, original, modified, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE); - PIDRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(receivedRecord); assertTrue(receivedRecord.getEntries().size() > 0); } @@ -242,15 +242,15 @@ void testUpdatePidFromComplexAndAcceptComplex() throws Exception { */ @Test void testUpdatePidFromSimpleAndAcceptJson() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); SimplePidRecord simple = new SimplePidRecord(modified); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(simple); String responseBody = ApiMockUtils.updateRecord(mockMvc, simple.getPid(), requestBody, original.getEtag(), SimplePidRecord.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - PIDRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(receivedRecord); assertTrue(receivedRecord.getEntries().size() > 0); } @@ -264,10 +264,10 @@ void testUpdatePidFromSimpleAndAcceptJson() throws Exception { */ @Test void testUpdatePidFromSimpleAndAcceptSimple() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); SimplePidRecord simple = new SimplePidRecord(modified); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(simple); @@ -286,15 +286,15 @@ void testUpdatePidFromSimpleAndAcceptSimple() throws Exception { */ @Test void testUpdatePidFromSimpleAndAcceptAll() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); SimplePidRecord simple = new SimplePidRecord(modified); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(simple); String responseBody = ApiMockUtils.updateRecord(mockMvc, simple.getPid(), requestBody, original.getEtag(), SimplePidRecord.CONTENT_TYPE, MediaType.ALL_VALUE); - PIDRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(receivedRecord); assertTrue(receivedRecord.getEntries().size() > 0); } @@ -308,16 +308,16 @@ void testUpdatePidFromSimpleAndAcceptAll() throws Exception { */ @Test void testUpdatePidFromSimpleAndAcceptComplex() throws Exception { - PIDRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); + PidRecord original = ApiMockUtils.registerSomeRecord(this.mockMvc); // add digitalObjectLocation, which is a property supported by most profiles. // in future, it would be more reliable to really ask the profile for the pid of this field. - PIDRecord modified = ApiMockUtils.clone(original); + PidRecord modified = ApiMockUtils.clone(original); modified.addEntry("21.T11148/b8457812905b83046284", "", "https://example.com/file2"); SimplePidRecord simple = new SimplePidRecord(modified); assertNotNull(simple.getPairs()); String requestBody = ApiMockUtils.getJsonMapper().writeValueAsString(simple); String responseBody = ApiMockUtils.updateRecord(mockMvc, simple.getPid(), requestBody, original.getEtag(), SimplePidRecord.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - PIDRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PIDRecord.class); + PidRecord receivedRecord = ApiMockUtils.getJsonMapper().readValue(responseBody, PidRecord.class); assertNotNull(receivedRecord); assertTrue(receivedRecord.getEntries().size() > 0); } From 2b9ae7c347ab66eadd48475c0b3c01aae7560456 Mon Sep 17 00:00:00 2001 From: Andreas Pfeil Date: Tue, 30 Sep 2025 15:59:19 +0200 Subject: [PATCH 2/4] fix(docs): javadoc compilation --- src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java | 2 +- src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java b/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java index 80868a11..5f4e9b69 100644 --- a/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java +++ b/src/test/java/edu/kit/datamanager/pit/RecordTestHelper.java @@ -10,7 +10,7 @@ public class RecordTestHelper { /** * Generates a PID record with N attibutes, each having M values. All attributes - * and values are PIDs of {@link pidGenerator} prefixed with {@link PID_PREFIX}. + * and values are PIDs of {@link PidSuffixGenerator} prefixed with the given prefix. * * @param numAttributes the number of attibutes (called N in the description * above) diff --git a/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java b/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java index 511a8492..92ab516c 100644 --- a/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java +++ b/src/test/java/edu/kit/datamanager/pit/web/ApiMockUtils.java @@ -275,7 +275,7 @@ public static SimplePidRecord resolveSimpleRecord(MockMvc mockMvc, String pid) t * Resolves a record using the REST API and MockMvc. * * @param mockMvc instance that mocks the REST API. - * @param createdPid the PID to resolve. + * @param pid the PID to resolve. * @param contentType the content type for the request. * @return the resolved record of the given PID. * @throws Exception if any assumption breaks. From f87422507f53793b718f26834cf46d755cc80583 Mon Sep 17 00:00:00 2001 From: Andreas Pfeil Date: Wed, 1 Oct 2025 10:30:47 +0200 Subject: [PATCH 3/4] feat: enable deletion of PIDs in InMemoryIdentifierSystem and LocalPidSystem --- .../kit/datamanager/pit/pidsystem/IIdentifierSystem.java | 4 ++-- .../pit/pidsystem/impl/InMemoryIdentifierSystem.java | 2 +- .../pit/pidsystem/impl/local/LocalPidSystem.java | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java index 6508c464..96f30d2a 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java @@ -147,8 +147,8 @@ public default String registerPid(final PidRecord pidRecord) throws PidAlreadyEx /** * Remove the given PID. - * - * Obviously, this method is only for testing purposes, since we should not + *

+ * This method is only for testing or rollback purposes, since we should not * delete persistent identifiers. * * @param pid the PID to delete. diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java index 647c7d70..3d9177af 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java @@ -74,7 +74,7 @@ public boolean updatePid(PidRecord record) throws PidNotFoundException, External @Override public boolean deletePid(String pid) { - throw new UnsupportedOperationException("Deleting PIDs is against the P in PID."); + return this.records.remove(pid) != null; } @Override diff --git a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java index 6f889eeb..21b94305 100644 --- a/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java +++ b/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/local/LocalPidSystem.java @@ -109,7 +109,12 @@ public boolean updatePid(PidRecord rec) throws PidNotFoundException, ExternalSer @Override public boolean deletePid(String pid) { - throw new UnsupportedOperationException("Deleting PIDs is against the P in PID."); + try { + this.db.deleteById(pid); + } catch (IllegalArgumentException e) { + return false; + } + return true; } @Override From a3e6112dc433c656427b0dca082562aff84b4b30 Mon Sep 17 00:00:00 2001 From: Andreas Pfeil Date: Wed, 1 Oct 2025 10:45:34 +0200 Subject: [PATCH 4/4] WIP --- .../pit/domain/PIDRecordEntry.java | 2 + .../kit/datamanager/pit/domain/PidNode.java | 25 ++++ .../kit/datamanager/pit/domain/PidRecord.java | 33 +---- .../pit/web/BatchRecordResponse.java | 8 +- .../pit/web/ITypingRestResource.java | 23 +++- .../pit/web/impl/TypingRESTResourceImpl.java | 119 +++++++++++++----- 6 files changed, 143 insertions(+), 67 deletions(-) create mode 100644 src/main/java/edu/kit/datamanager/pit/domain/PidNode.java diff --git a/src/main/java/edu/kit/datamanager/pit/domain/PIDRecordEntry.java b/src/main/java/edu/kit/datamanager/pit/domain/PIDRecordEntry.java index bacd2884..b3e9f038 100644 --- a/src/main/java/edu/kit/datamanager/pit/domain/PIDRecordEntry.java +++ b/src/main/java/edu/kit/datamanager/pit/domain/PIDRecordEntry.java @@ -17,10 +17,12 @@ package edu.kit.datamanager.pit.domain; import lombok.Data; +import lombok.EqualsAndHashCode; @Data public class PIDRecordEntry implements Cloneable { private String key; + @EqualsAndHashCode.Exclude private String name; private String value; diff --git a/src/main/java/edu/kit/datamanager/pit/domain/PidNode.java b/src/main/java/edu/kit/datamanager/pit/domain/PidNode.java new file mode 100644 index 00000000..42e787ca --- /dev/null +++ b/src/main/java/edu/kit/datamanager/pit/domain/PidNode.java @@ -0,0 +1,25 @@ +package edu.kit.datamanager.pit.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +// We assume that two PidNode are equal if their PidRecord parts are equal. +// The "exists" field is not making a difference for content equality. +// Therefore, just keep the "equal"-implementation from PidRecord. +@Getter +@Setter +@RequiredArgsConstructor +@ToString +public class PidNode extends PidRecord { + @JsonProperty("placeholder_pid") + private String placeholderPid; + + public + + @Override + public PidNode clone() { + PidNode clone = (PidNode) super.clone(); + clone.placeholderPid = this.placeholderPid; + return clone; + } +} diff --git a/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java b/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java index 31ed6893..51385c28 100644 --- a/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java +++ b/src/main/java/edu/kit/datamanager/pit/domain/PidRecord.java @@ -19,6 +19,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import edu.kit.datamanager.entities.EtagSupport; import edu.kit.datamanager.pit.pidsystem.impl.local.PidDatabaseObject; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import java.util.*; import java.util.stream.Collectors; @@ -31,18 +34,15 @@ * communication or representation for the outside. In contrast, this is the * internal representation offering methods for manipulation. */ +@Getter +@Setter +@RequiredArgsConstructor public class PidRecord implements EtagSupport, Cloneable { private String pid = ""; private Map> entries = new HashMap<>(); - /** - * Creates an empty record without PID. - */ - public PidRecord() { - } - /** * Creates a record with the same content as the given representation. * @@ -73,27 +73,6 @@ public PidRecord withPID(String pid) { return this; } - public String getPid() { - return pid; - } - - public void setPid(String pid) { - this.pid = pid; - } - - public Map> getEntries() { - return entries; - } - - /** - * Sets the entries of this record. - * - * @param entries the entries to set. - */ - public void setEntries(Map> entries) { - this.entries = entries; - } - @JsonIgnore public Set getSimpleEntries() { return this.entries diff --git a/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java b/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java index aa171335..edb64770 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java +++ b/src/main/java/edu/kit/datamanager/pit/web/BatchRecordResponse.java @@ -23,12 +23,12 @@ /** * Response object for batch record operations. - * Contains a list of the processed PID records and a mapping of the user-provided "fictionary" identifiers to their corresponding real record Handle PIDs. - * This mapping was used to link the user-provided identifiers with the actual records in the system. *

+ * Supports returning a list of processed records along with a mapping + * from user-provided identifiers (pseudo-PIDs) to actual record Handle PIDs. * - * @param pidRecords List of PIDRecord objects representing the processed records. (List) - * @param mapping Map where keys are user-provided identifiers (fictionary) and values are the corresponding real record Handle PIDs. (Map) + * @param pidRecords List of PIDRecord objects representing the processed records. + * @param mapping Map where keys are user-provided identifiers (pseudo-PIDs) and values are the corresponding real record Handle PIDs. * @see PidRecord */ public record BatchRecordResponse( diff --git a/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java b/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java index 95badfb1..b79025c0 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java +++ b/src/main/java/edu/kit/datamanager/pit/web/ITypingRestResource.java @@ -15,6 +15,7 @@ */ package edu.kit.datamanager.pit.web; +import edu.kit.datamanager.pit.domain.PidNode; import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.domain.SimplePidRecord; import edu.kit.datamanager.pit.pidlog.KnownPid; @@ -57,11 +58,25 @@ public interface ITypingRestResource { ) @Operation( summary = "Create a multiple, possibly related PID records", - description = "Create multiple, possibly related PID records using the record information. This endpoint is a convenience method to create multiple PID records at once. For connecting records, the PID fields must be specified and the value may be used in the value fields of other PIDRecordEntries. The provided PIDs will be overwritten as defined by the PID generator strategy.\n" + - "Note: This endpoint does not support custom PIDs, as the PID field is used for \"placeholder\" PIDs to connect records. These placeholder PIDs will be replaced by actual, resolvable PIDs as defined by the PID generator strategy. This goes for the PID referencing a record as well as references from other records, if they are provided as a single attribute value (i.e., not a JSON array within an attribute's value). If you want to create a record with custom PID suffixes, use the endpoint `POST /pid` and configure the Typed PID Maker accordingly." + description = "Create multiple, possibly related PID records using the record information. " + + "This endpoint is a convenience method to create multiple PID records at once. " + + "For connecting records, the PID fields must be specified and the value may be used " + + "in the value fields of other PIDRecordEntries. The provided PIDs will be overwritten " + + "as defined by the PID generator strategy.\n" + + "Note: This endpoint does not support custom PIDs, as the PID field is used for " + + "\"placeholder\" PIDs to connect records. These placeholder PIDs will be replaced by " + + "actual, resolvable PIDs as defined by the PID generator strategy. This goes for the " + + "PID referencing a record as well as references from other records, if they are provided " + + "as a single attribute value (i.e., not a JSON array within an attribute's value). If you " + + "want to create a record with custom PID suffixes, use the endpoint `POST /pid` and " + + "configure the Typed PID Maker accordingly." ) @io.swagger.v3.oas.annotations.parameters.RequestBody( - description = "The body containing a list of all PID record values as they should be in the new PID records. To connect records, the PID fields must be specified. This placeholder PID value may then be used in the value fields of other PID Record entries. During creation, these placeholder PIDs whose sole purpose is to connect records will be overwritten with actual, resolvable PIDs as defined by the PID generator strategy.", + description = "The body containing a list of all PID record values as they should be in the " + + "PID records. To connect records, the 'pseudoPid' fields must be specified. This placeholder " + + "PID value may then be used in the value fields of other PID Record entries. During " + + "creation, these placeholder PIDs whose sole purpose is to connect records will be " + + "overwritten with actual, resolvable PIDs as defined by the PID generator strategy.", required = true, content = { @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = PidRecord.class))) @@ -82,7 +97,7 @@ public interface ITypingRestResource { @ApiResponse(responseCode = "500", description = "Server error. See body for details.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)) }) ResponseEntity createPIDs( - @RequestBody final List rec, + @RequestBody final List graph, @Parameter(description = "If true, only validation will be done and no PIDs will be created. No data will be changed and no services will be notified.") @RequestParam(name = "dryrun", required = false, defaultValue = "false") diff --git a/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java b/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java index 6699c1a4..a274303e 100644 --- a/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java +++ b/src/main/java/edu/kit/datamanager/pit/web/impl/TypingRESTResourceImpl.java @@ -21,6 +21,7 @@ import edu.kit.datamanager.pit.common.*; import edu.kit.datamanager.pit.configuration.ApplicationProperties; import edu.kit.datamanager.pit.configuration.PidGenerationProperties; +import edu.kit.datamanager.pit.domain.PidNode; import edu.kit.datamanager.pit.domain.PidRecord; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticRepository; import edu.kit.datamanager.pit.elasticsearch.PidRecordElasticWrapper; @@ -72,7 +73,16 @@ public class TypingRESTResourceImpl implements ITypingRestResource { private final PidSuffixGenerator suffixGenerator; private final PidGenerationProperties pidGenerationProperties; - public TypingRESTResourceImpl(ITypingService typingService, Resolver resolver, ApplicationProperties applicationProps, IMessagingService messagingService, KnownPidsDao localPidStorage, Optional elastic, PidSuffixGenerator suffixGenerator, PidGenerationProperties pidGenerationProperties) { + public TypingRESTResourceImpl( + ITypingService typingService, + Resolver resolver, + ApplicationProperties applicationProps, + IMessagingService messagingService, + KnownPidsDao localPidStorage, + Optional elastic, + PidSuffixGenerator suffixGenerator, + PidGenerationProperties pidGenerationProperties + ) { super(); this.typingService = typingService; this.resolver = resolver; @@ -86,34 +96,51 @@ public TypingRESTResourceImpl(ITypingService typingService, Resolver resolver, A @Override public ResponseEntity createPIDs( - List rec, + List graph, boolean dryrun, WebRequest request, HttpServletResponse response, UriComponentsBuilder uriBuilder ) throws IOException, RecordValidationException, ExternalServiceException { - if (rec == null || rec.isEmpty()) { + if (graph == null || graph.isEmpty()) { LOG.warn("No records provided for PID creation."); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new BatchRecordResponse(Collections.emptyList(), Collections.emptyMap())); + return ResponseEntity + .status(HttpStatus.BAD_REQUEST) + .body(new BatchRecordResponse(Collections.emptyList(), Collections.emptyMap())); } - if (rec.size() == 1) { + if (graph.size() == 1) { // If only one record is provided, we can use the single record creation method. + // TODO but why should we? It would be more consistent to always use the batch method. LOG.info("Only one record provided. Using single record creation method."); - var result = createPID(rec.getFirst(), dryrun, request, response, uriBuilder); + PidNode singleNode = graph.getFirst(); + ResponseEntity result; + boolean exists = hasPid(singleNode) && this.typingService.isPidRegistered(singleNode.getPid()); + if (exists) { + result = updatePID(singleNode, dryrun, request, response, uriBuilder); + } else { + result = createPID(singleNode, dryrun, request, response, uriBuilder); + } // Return the single record in a list assert result.getBody() != null; - return ResponseEntity.status(result.getStatusCode()).headers(result.getHeaders()).body(new BatchRecordResponse(Collections.singletonList(result.getBody()), Collections.singletonMap(rec.getFirst().getPid(), result.getBody().getPid()))); + return ResponseEntity + .status(result.getStatusCode()) + .headers(result.getHeaders()) + .body(new BatchRecordResponse( + Collections.singletonList(result.getBody()), + Collections.singletonMap(singleNode.getPlaceholderPid(), result.getBody().getPid()) + )); } + Instant startTime = Instant.now(); - LOG.info("Creating PIDs for {} records.", rec.size()); + LOG.info("Creating PIDs for {} records.", graph.size()); String prefix = this.typingService.getPrefix().orElseThrow(() -> new IOException("No prefix configured.")); - // Generate a map between temporary (user-defined) PIDs and final PIDs (generated) - Map pidMappings = generatePIDMapping(rec, dryrun); + // Generate a map between pseudo-PIDs and generated suffixes that will actually be used. + Map pidMappings = generatePIDMapping(graph, dryrun); Instant mappingTime = Instant.now(); // Apply the mappings to the records and validate them - List validatedRecords = applyMappingsToRecordsAndValidate(rec, pidMappings, prefix); + List validatedRecords = applyMappingsToRecordsAndValidate(graph, pidMappings, prefix); Instant validationTime = Instant.now(); if (dryrun) { @@ -123,12 +150,15 @@ public ResponseEntity createPIDs( LOG.info("-- Time taken for validation: {} ms", ChronoUnit.MILLIS.between(mappingTime, validationTime)); LOG.info("Dryrun finished. Returning validated records for {} records.", validatedRecords.size()); addPrefixToMapping(pidMappings, prefix); - return ResponseEntity.status(HttpStatus.OK).body(new BatchRecordResponse(validatedRecords, pidMappings)); + return ResponseEntity + .status(HttpStatus.OK) + .body(new BatchRecordResponse(validatedRecords, pidMappings)); } List failedRecords = new ArrayList<>(); List successfulRecords = new ArrayList<>(); // register the records + boolean isNew(PidNode n) { !hasPid(n) || !this.typingService.isPidRegistered(n.getPid()); } validatedRecords.forEach(pidRecord -> { try { // register the PID @@ -201,33 +231,34 @@ private static void addPrefixToMapping(Map pidMappings, String p } /** - * This method generates a mapping between user-provided "fantasy" PIDs and real PIDs. + * This method generates a mapping between user-provided pseudo-PIDs and real PIDs. * - * @param rec the list of records produced by the user + * @param graph the list of records produced by the user * @param dryrun whether the operation is a dryrun or not * @return a map between the user-provided PIDs (key) and the real PIDs (values) * @throws RecordValidationException if the same internal PID is used for multiple records * @throws ExternalServiceException if the PID generation fails */ - private Map generatePIDMapping(List rec, boolean dryrun) throws RecordValidationException, ExternalServiceException { + private Map generatePIDMapping(List graph, boolean dryrun) throws RecordValidationException, ExternalServiceException { Map pidMappings = new HashMap<>(); - for (PidRecord pidRecord : rec) { - String internalPID = pidRecord.getPid(); // the internal PID is the one given by the user - if (internalPID == null) { - internalPID = ""; // if no PID was given, we set it to an empty string + for (PidNode record : graph) { + String placeholderPid = record.getPlaceholderPid(); + if (placeholderPid == null) { + placeholderPid = ""; } - if (!internalPID.isBlank() && pidMappings.containsKey(internalPID)) { // check if the internal PID was already used - // This internal PID was already used by some other record in the same request. - throw new RecordValidationException(pidRecord, "The PID " + internalPID + " was used for multiple records in the same request."); + boolean isUniquePlaceholder = placeholderPid.isBlank() || !pidMappings.containsKey(placeholderPid); + if (!isUniquePlaceholder) { + throw new RecordValidationException(record, "The PID " + placeholderPid + " was used for multiple records in the same request."); } - pidRecord.setPid(""); // clear the PID field in the record - if (dryrun) { // if it is a dryrun, we set the PID to a temporary value - pidRecord.setPid("dryrun_" + pidMappings.size()); + // We ignore any user-provided PID and always generate a new one in the batch API. + record.setPid(""); + if (dryrun) { + record.setPid("dryrun_" + pidMappings.size()); } else { - setPid(pidRecord); // otherwise, we generate a real PID + setPid(record); } - pidMappings.put(internalPID, pidRecord.getPid()); // store the mapping between the internal and real PID + pidMappings.put(placeholderPid, record.getPid()); } return pidMappings; } @@ -235,22 +266,29 @@ private Map generatePIDMapping(List rec, boolean dryr /** * This method applies the mappings between temporary PIDs and real PIDs to the records and validates them. * - * @param rec the list of records produced by the user + * @param graph the list of records produced by the user * @param pidMappings the map between the user-provided PIDs (key) and the real PIDs (values) * @param prefix the prefix to be used for the real PIDs * @return the list of validated records * @throws RecordValidationException as a possible validation outcome * @throws ExternalServiceException as a possible validation outcome */ - private List applyMappingsToRecordsAndValidate(List rec, Map pidMappings, String prefix) throws RecordValidationException, ExternalServiceException { + private List applyMappingsToRecordsAndValidate( + List graph, + Map pidMappings, + String prefix + ) throws + RecordValidationException, + ExternalServiceException + { List validatedRecords = new ArrayList<>(); - for (PidRecord pidRecord : rec) { + for (PidRecord pidRecord : graph) { // use this map to replace all temporary PIDs in the record values with their corresponding real PIDs pidRecord.getEntries().values().stream() // get all values of the record .flatMap(List::stream) // flatten the list of values .filter(entry -> entry.getValue() != null) // Filter out null values - .filter(entry -> pidMappings.containsKey(entry.getValue())) // replace only if the value (aka. "fantasy PID") is a key in the map + .filter(entry -> pidMappings.containsKey(entry.getValue())) // replace only if the value is a placeholder PID in the mapping .peek(entry -> LOG.debug("Found reference. Replacing {} with {}.", entry.getValue(), prefix + pidMappings.get(entry.getValue()))) // log the replacement .forEach(entry -> entry.setValue(prefix + pidMappings.get(entry.getValue()))); // replace the value with the real PID according to the map @@ -312,7 +350,24 @@ private boolean hasPid(PidRecord pidRecord) { return pidRecord.getPid() != null && !pidRecord.getPid().isBlank(); } - private void setPid(PidRecord pidRecord) { + /** + * Sets a PID for the given record. + *

+ * In the usual case, this method generates a new PID suffix and sets it in the record. + * In the special case that custom PIDs are allowed and a PID is already set in the record, + * this method checks if the PID is already registered and throws an exception if so. + * @param pidRecord the record to set the PID for + * @throws PidAlreadyExistsException if the PID is already registered and custom PIDs are allowed + * @throws InvalidConfigException if no prefix is configured but custom PIDs are allowed + * @throws ExternalServiceException if PID generation fails + */ + private void setPid( + PidRecord pidRecord + ) throws + PidAlreadyExistsException, + InvalidConfigException, + ExternalServiceException + { boolean hasCustomPid = hasPid(pidRecord); boolean allowsCustomPids = pidGenerationProperties.isCustomClientPidsEnabled();