Skip to content

Commit

Permalink
FAIRSPC-79: light refactoring + important todo
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreenwood committed Oct 17, 2024
1 parent 00ccac3 commit 5725884
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.fairspace.saturn.config;

import io.fairspace.saturn.rdf.transactions.Transactions;
import io.fairspace.saturn.services.metadata.MetadataPermissions;
import io.fairspace.saturn.services.metadata.MetadataService;
import io.fairspace.saturn.services.metadata.validation.ComposedValidator;
import org.apache.jena.query.Dataset;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.sparql.util.Symbol;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.fairspace.saturn.rdf.transactions.Transactions;
import io.fairspace.saturn.services.metadata.MetadataPermissions;
import io.fairspace.saturn.services.metadata.MetadataService;
import io.fairspace.saturn.services.metadata.validation.ComposedValidator;

@Configuration
public class MetadataConfig {

Expand All @@ -26,6 +27,10 @@ public MetadataService metadataService(
@Qualifier("composedValidator") ComposedValidator composedValidator) {
var metadataService =
new MetadataService(transactions, vocabulary, systemVocabulary, composedValidator, metadataPermissions);
// This is a workaround (old, not a new one) to resolve circular dependency:
// MetadataService --> ComposedValidator --> URIPrefixValidator --> DavFactory --> DirectoryResource -->
// MetadataService
// See comment with a suggestion to refactor resources to be anemic (not rich)
dataset.getContext().set(METADATA_SERVICE, metadataService);
return metadataService;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.fairspace.saturn.services.metadata.validation;

import java.util.List;

import org.apache.jena.graph.Node;
import org.apache.jena.rdf.model.Model;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* Combines a few validators into one. Stops on a first failing validator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.springframework.stereotype.Component;

import io.fairspace.saturn.vocabulary.FS;
import org.springframework.stereotype.Component;

@Component
public class DeletionValidator implements MetadataRequestValidator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.shacl.vocabulary.SHACLM;
import org.apache.jena.vocabulary.RDF;

import io.fairspace.saturn.vocabulary.FS;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import io.fairspace.saturn.vocabulary.FS;

import static io.fairspace.saturn.rdf.ModelUtils.getBooleanProperty;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.shacl.vocabulary.SHACLM;
import org.apache.jena.vocabulary.RDF;

import io.fairspace.saturn.vocabulary.FS;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import io.fairspace.saturn.vocabulary.FS;

import static io.fairspace.saturn.rdf.ModelUtils.getBooleanProperty;
import static io.fairspace.saturn.rdf.ModelUtils.getResourceProperties;
import static io.fairspace.saturn.vocabulary.ShapeUtils.getClassShapeForClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.fairspace.saturn.services.metadata.validation;

import io.fairspace.saturn.webdav.DavFactory;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import io.fairspace.saturn.webdav.DavFactory;

@Component
public class URIPrefixValidator implements MetadataRequestValidator {
private final String restrictedPrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.springframework.stereotype.Component;

import io.fairspace.saturn.vocabulary.FS;
import org.springframework.stereotype.Component;

@Component
public class UniqueLabelValidator implements MetadataRequestValidator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ private void uploadMetadata(FileItem file) throws BadRequestException, ConflictE
throw new BadRequestException("Error parsing file " + file.getName(), e);
}

// TODO: I would refactor all resources to be anemic rather than rich.
// Due to the "rich" nature of the resources,
// the resources (directory, collections, etc.) are responsible for handling the request and performing the
// actions.
// I would go more "spring way" and use services to handle the request and perform the actions over resources
// via the services
// It would suggest not to mix the responsibilities and make the code more maintainable.
// It would let us avoid such an inelegant workaround as the one below.
MetadataService metadataService = factory.context.get(METADATA_SERVICE);
try {
metadataService.patch(model, Boolean.TRUE);
Expand Down

0 comments on commit 5725884

Please sign in to comment.