-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
386 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/edu/kit/datamanager/pit/domain/ImmutableList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.kit.datamanager.pit.domain; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public record ImmutableList<I>(List<I> items) { | ||
public ImmutableList { | ||
items = Collections.unmodifiableList(items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/edu/kit/datamanager/pit/typeregistry/AttributeInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package edu.kit.datamanager.pit.typeregistry; | ||
|
||
import org.everit.json.schema.Schema; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @param pid the pid of this attribute | ||
* @param typeName name of the schema type of this attribute in the DTR, | ||
* e.g. "Profile", "InfoType", "Special-Info-Type", ... | ||
* @param jsonSchema the json schema to validate a value of this attribute | ||
*/ | ||
public record AttributeInfo( | ||
String pid, | ||
String typeName, | ||
Schema jsonSchema | ||
) {} |
21 changes: 8 additions & 13 deletions
21
src/main/java/edu/kit/datamanager/pit/typeregistry/ITypeRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
package edu.kit.datamanager.pit.typeregistry; | ||
|
||
import java.io.IOException; | ||
import org.everit.json.schema.Schema; | ||
|
||
import edu.kit.datamanager.pit.domain.TypeDefinition; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Main abstraction interface towards the type registry. Contains all methods | ||
* required from the registry by the core services. | ||
* | ||
*/ | ||
public interface ITypeRegistry { | ||
|
||
/** | ||
* Queries a type definition record from the type registry. | ||
* | ||
* @param typeIdentifier | ||
* @return a type definition record or null if the type is not registered. | ||
* @throws IOException on communication errors with a remote registry | ||
*/ | ||
public TypeDefinition queryTypeDefinition(String typeIdentifier) throws IOException, URISyntaxException; | ||
@Deprecated | ||
CompletableFuture<Schema> queryAttributeSchemaOf(String attributePid); | ||
CompletableFuture<AttributeInfo> queryAttributeInfo(String attributePid); | ||
CompletableFuture<RegisteredProfile> queryAsProfile(String profilePid); | ||
URL getRegistryUrl(); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.kit.datamanager.pit.typeregistry; | ||
|
||
import edu.kit.datamanager.pit.common.RecordValidationException; | ||
import edu.kit.datamanager.pit.domain.ImmutableList; | ||
import edu.kit.datamanager.pit.domain.PIDRecord; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public record RegisteredProfile( | ||
String pid, | ||
ImmutableList<RegisteredProfileAttribute> attributes | ||
) { | ||
public void validateAttributes(PIDRecord pidRecord, boolean allowAdditionalAttributes) { | ||
Set<String> additionalAttributes = pidRecord.getPropertyIdentifiers().stream() | ||
.filter(recordKey -> attributes.items().stream().anyMatch( | ||
profileAttribute -> Objects.equals(profileAttribute.pid(), recordKey))) | ||
.collect(Collectors.toSet()); | ||
|
||
boolean violatesAdditionalAttributes = !allowAdditionalAttributes && !additionalAttributes.isEmpty(); | ||
if (violatesAdditionalAttributes) { | ||
throw new RecordValidationException( | ||
pidRecord, | ||
String.format("Attributes %s are not allowed in profile %s", | ||
String.join(", ", additionalAttributes), | ||
this.pid) | ||
); | ||
} | ||
|
||
for (RegisteredProfileAttribute profileAttribute : this.attributes.items()) { | ||
if (profileAttribute.violatesMandatoryProperty(pidRecord)) { | ||
throw new RecordValidationException( | ||
pidRecord, | ||
String.format("Attribute %s missing, but is mandatory in profile %s", | ||
profileAttribute.pid(), | ||
this.pid) | ||
); | ||
} | ||
if (profileAttribute.violatesRepeatableProperty(pidRecord)) { | ||
throw new RecordValidationException( | ||
pidRecord, | ||
String.format("Attribute %s is not repeatable in profile %s, but has multiple values", | ||
profileAttribute.pid(), | ||
this.pid) | ||
); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/edu/kit/datamanager/pit/typeregistry/RegisteredProfileAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.kit.datamanager.pit.typeregistry; | ||
|
||
import edu.kit.datamanager.pit.common.RecordValidationException; | ||
import edu.kit.datamanager.pit.domain.PIDRecord; | ||
|
||
public record RegisteredProfileAttribute( | ||
String pid, | ||
boolean mandatory, | ||
boolean repeatable | ||
) { | ||
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) { | ||
boolean repeats = pidRecord.getPropertyValues(this.pid).length > 1; | ||
return !this.repeatable && repeats; | ||
} | ||
} |
Oops, something went wrong.