Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ $RECYCLE.BIN/
**/*.properties
!/config/application-default.properties
!/config/application-docker.properties
##############
##############

test_prefix_data/
config/*.bin
config/*.pem
14 changes: 7 additions & 7 deletions config/application-default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ spring.cloud.gateway.proxy.sensitive=content-length
# the all properties with 'binding' define from where messages are received, e.g. the
# exchange aka. topic and the queue. The routingKeys are defining wich messages are
# routed to the aforementioned queue.
repo.messaging.enabled: false
repo.messaging.hostname: localhost
repo.messaging.port: 5672
repo.messaging.sender.exchange: record_events

repo.messaging.enabled=false
management.health.rabbit.enabled=false
repo.messaging.hostname=localhost
repo.messaging.port=5672
repo.messaging.sender.exchange=record_events
# The rate in milliseconds at which the repository itself will check for new messages.
# E.g. if a resource has been created, the repository may has to perform additional
# ingest steps. Therefor, special handlers can be added which will be executed at the
# ingest steps. Therefore, special handlers can be added which will be executed at the
# configured repo.schedule.rate if a new message has been received.
repo.schedule.rate:1000

Expand Down Expand Up @@ -201,7 +201,7 @@ pit.validation.alwaysAllowAdditionalAttributes = true
# where a DTR may not be available or an external validator is being
# used.
#
# pit.validation.strategy = debug-none
# pit.validation.strategy=none-debug
### DANGEROUS OPTIONS! Please read carefully! ########################################

#######################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
package edu.kit.datamanager.pit.common;
/*
* Copyright (c) 2024 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.
*/

import org.springframework.web.server.ResponseStatusException;
import org.springframework.http.HttpStatus;
package edu.kit.datamanager.pit.common;

import edu.kit.datamanager.pit.domain.PIDRecord;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

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

private static final String VALIDATION_OF_RECORD = "Validation of record ";
private static final long serialVersionUID = 1L;
private static final HttpStatus HTTP_STATUS = HttpStatus.BAD_REQUEST;
private static final String VALIDATION_OF_RECORD = "Validation of record ";
private static final long serialVersionUID = 1L;
private static final HttpStatus HTTP_STATUS = HttpStatus.BAD_REQUEST;

// For cases in which the PID record shold be appended to the error response.
private final transient PIDRecord pidRecord;
// For cases in which the PID record should be appended to the error response.
private final transient PIDRecord pidRecord;

public RecordValidationException(PIDRecord pidRecord) {
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed.");
this.pidRecord = pidRecord;
}
public RecordValidationException(PIDRecord pidRecord) {
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed.");
this.pidRecord = pidRecord;
}

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) {
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason);
this.pidRecord = pidRecord;
}

public RecordValidationException(PIDRecord pidRecord, String reason, Exception e) {
super(HTTP_STATUS, VALIDATION_OF_RECORD + pidRecord.getPid() + " failed. Reason: " + reason, e);
this.pidRecord = pidRecord;
}
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() {
return pidRecord;
}
public PIDRecord getPidRecord() {
return pidRecord;
}
}
100 changes: 68 additions & 32 deletions src/main/java/edu/kit/datamanager/pit/domain/PIDRecord.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
/*
* 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.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Set;

/**
* The internal representation for a PID record, offering methods to manipulate
Expand All @@ -21,7 +31,7 @@
* communication or representation for the outside. In contrast, this is the
* internal representation offering methods for manipulation.
*/
public class PIDRecord implements EtagSupport {
public class PIDRecord implements EtagSupport, Cloneable {

private String pid = "";

Expand All @@ -30,11 +40,12 @@ public class PIDRecord implements EtagSupport {
/**
* Creates an empty record without PID.
*/
public PIDRecord() {}
public PIDRecord() {
}

/**
* Creates a record with the same content as the given representation.
*
*
* @param dbo the given record representation.
*/
public PIDRecord(PidDatabaseObject dbo) {
Expand All @@ -53,7 +64,7 @@ public PIDRecord(SimplePidRecord rec) {

/**
* Convenience setter / builder method.
*
*
* @param pid the pid to set in this object.
* @return this object (builder method).
*/
Expand All @@ -74,6 +85,10 @@ public Map<String, List<PIDRecordEntry>> getEntries() {
return entries;
}

public void setEntries(Map<String, List<PIDRecordEntry>> entries) {
this.entries = entries;
}

@JsonIgnore
public Set<SimplePair> getSimpleEntries() {
return this.entries
Expand All @@ -85,20 +100,16 @@ public Set<SimplePair> getSimpleEntries() {
.collect(Collectors.toSet());
}

public void setEntries(Map<String, List<PIDRecordEntry>> entries) {
this.entries = entries;
}

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.
* @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()) {
Expand All @@ -110,22 +121,22 @@ public void addEntry(String propertyIdentifier, String propertyName, String prop
entry.setValue(propertyValue);

this.entries
.computeIfAbsent(propertyIdentifier, key -> new ArrayList<>())
.add(entry);
.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.
* @param name the new name.
*/
@JsonIgnore
public void setPropertyName(String propertyIdentifier, String name) {
List<PIDRecordEntry> propertyEntries = this.entries.get(propertyIdentifier);
if (propertyEntries == null) {
throw new IllegalArgumentException(
"Property identifier not listed in this record: " + propertyIdentifier);
"Property identifier not listed in this record: " + propertyIdentifier);
}
for (PIDRecordEntry entry : propertyEntries) {
entry.setName(name);
Expand All @@ -135,7 +146,7 @@ public void setPropertyName(String propertyIdentifier, String 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.
*/
Expand All @@ -158,7 +169,7 @@ public void removeAllValuesOf(String attribute) {

/**
* Get all properties contained in this record.
*
*
* @return al contained properties.
*/
@JsonIgnore
Expand All @@ -180,7 +191,7 @@ public String getPropertyValue(String propertyIdentifier) {

/**
* Get all values of a given property.
*
*
* @param propertyIdentifier the given property identifier.
* @return all values of the given property.
*/
Expand All @@ -194,7 +205,7 @@ public String[] getPropertyValues(String propertyIdentifier) {
for (PIDRecordEntry e : entry) {
values.add(e.getValue());
}
return values.toArray(new String[] {});
return values.toArray(new String[]{});
}

@Override
Expand All @@ -215,9 +226,15 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {return true;}
if (obj == null) {return false;}
if (getClass() != obj.getClass()) {return false;}
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();
Expand All @@ -240,13 +257,32 @@ public String toString() {

/**
* Calculates an etag for a record.
*
*
* @return an etag, which is independent of any order or duplicates in the
* entries.
* 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<String, List<PIDRecordEntry>> entry : this.entries.entrySet()) {
List<PIDRecordEntry> 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();
}
}
}
31 changes: 30 additions & 1 deletion src/main/java/edu/kit/datamanager/pit/domain/PIDRecordEntry.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
/*
* 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 lombok.Data;

@Data
public class PIDRecordEntry {
public class PIDRecordEntry implements Cloneable {
private String key;
private String name;
private String value;

@Override
public PIDRecordEntry clone() {
try {
PIDRecordEntry clone = (PIDRecordEntry) super.clone();
clone.setKey(this.key);
clone.setName(this.name);
clone.setValue(this.value);
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}
Loading
Loading