Skip to content

Commit

Permalink
Merge pull request #9 from yngwi:query_rework_2
Browse files Browse the repository at this point in the history
Rework query structure
  • Loading branch information
yngwi authored May 13, 2021
2 parents bf46a28 + f6f5529 commit a057652
Show file tree
Hide file tree
Showing 34 changed files with 1,231 additions and 927 deletions.
2 changes: 1 addition & 1 deletion eclipse-java-google-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_local_variable_annotation" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>eu.nampi</groupId>
<artifactId>backend</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
<name>nampi-backend</name>
<description>The NAMPI backend</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties prope
protected void configure(final HttpSecurity http) throws Exception {
super.configure(http);
http.addFilter(corsFilter().getFilter()).authorizeRequests()
.antMatchers("/", "/doc", "/event/**", "/events/**", "/person/**", "/persons/**",
"/aspect/**", "/aspects/**", "/author/**", "/authors/**", "/group/**", "/groups/**",
"/place/**", "/places/**", "/source/**", "/sources/**", "/act/**", "/acts/**")
.antMatchers("/", "/doc", "/classes/**", "/event/**", "/events/**", "/person/**",
"/persons/**", "/aspect/**", "/aspects/**", "/author/**", "/authors/**", "/group/**",
"/groups/**", "/place/**", "/places/**", "/source/**", "/sources/**", "/act/**",
"/acts/**")
.permitAll().antMatchers("/user/**").hasRole("USER").anyRequest().authenticated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public ResponseEntity<String> getAspects(@RequestHeader("accept") Lang lang,
@RequestParam("offset") Optional<Integer> offset,
@RequestParam("orderBy") Optional<OrderByClauses> orderBy,
@RequestParam("type") Optional<String> type, @RequestParam("text") Optional<String> text,
@RequestParam("person") Optional<String> person) {
@RequestParam("participant") Optional<String> participant) {
QueryParameters params = getParameters(page, pageIndex, limit, offset, orderBy, type, text);
String result = aspectRepository.findAll(params, lang, person);
String result = aspectRepository.findAll(params, lang, participant);
return new ResponseEntity<String>(result, HttpStatus.OK);
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/eu/nampi/backend/controller/ClassController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.nampi.backend.controller;

import java.util.Optional;
import org.apache.jena.riot.Lang;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.nampi.backend.model.OrderByClauses;
import eu.nampi.backend.model.QueryParameters;
import eu.nampi.backend.repository.ClassRepository;

@RestController
public class ClassController extends AbstractRdfController {

@Autowired
ClassRepository classRepository;

@GetMapping(value = "/classes", produces = {"application/ld+json", "text/turtle",
"application/rdf+xml", "application/n-triples"})
public ResponseEntity<String> getPlaces(@RequestHeader("accept") Lang lang,
@RequestParam("page") Optional<Integer> page,
@RequestParam("pageIndex") Optional<Integer> pageIndex,
@RequestParam("limit") Optional<Integer> limit,
@RequestParam("offset") Optional<Integer> offset,
@RequestParam("orderBy") Optional<OrderByClauses> orderBy,
@RequestParam("type") Optional<String> type, @RequestParam("text") Optional<String> text,
@RequestParam("ancestor") Optional<String> ancestor) {
QueryParameters params = getParameters(page, pageIndex, limit, offset, orderBy, type, text);
String result = classRepository.findAll(params, lang, ancestor);
return new ResponseEntity<String>(result, HttpStatus.OK);
}

}
5 changes: 2 additions & 3 deletions src/main/java/eu/nampi/backend/model/OrderByClauses.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.jena.arq.querybuilder.Order;
import org.apache.jena.arq.querybuilder.SelectBuilder;

import lombok.NoArgsConstructor;

@NoArgsConstructor
Expand Down Expand Up @@ -38,10 +36,11 @@ public void add(String orderBy) {
this.add(orderBy, DEFAULT_ORDER);
}

public void appendAllTo(SelectBuilder selectBuilder) {
public SelectBuilder appendAllTo(SelectBuilder selectBuilder) {
for (Map.Entry<String, Order> entry : this.clauses.entrySet()) {
selectBuilder.addOrderBy(padKey(entry.getKey()), entry.getValue());
}
return selectBuilder;
}

public boolean containsKey(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
package eu.nampi.backend.model.hydra;

import org.apache.jena.arq.querybuilder.ConstructBuilder;
import java.util.Optional;
import org.apache.jena.arq.querybuilder.ExprFactory;
import org.apache.jena.arq.querybuilder.WhereBuilder;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.apache.jena.vocabulary.XSD;
import eu.nampi.backend.service.JenaService;
import eu.nampi.backend.vocabulary.Api;
import eu.nampi.backend.vocabulary.Core;
import eu.nampi.backend.vocabulary.Hydra;
import eu.nampi.backend.vocabulary.SchemaOrg;

public abstract class AbstractHydraBuilder extends ConstructBuilder
implements InterfaceHydraBuilder {

public abstract class AbstractHydraBuilder implements InterfaceHydraBuilder {
protected JenaService jenaService;
protected Resource mainType;
protected String baseUri;
public ExprFactory ef;
public Model model = ModelFactory.createDefaultModel();
public Resource root;
public WhereBuilder coreData = new WhereBuilder();
public static final Node VAR_MAIN = NodeFactory.createVariable("main");
public static final Node VAR_MAIN_LABEL = NodeFactory.createVariable("label");
public static final Node VAR_MAIN_COMMENT = NodeFactory.createVariable("comment");
public static final Node VAR_COMMENT = NodeFactory.createVariable("comment");
public static final Node VAR_LABEL = NodeFactory.createVariable("label");

public final ExprFactory ef;
public final Node baseNode;
public final Property mainType;

public AbstractHydraBuilder(Node baseNode, Property mainType) {
super();
// @formatter:off
this
.addPrefix("api", Api.getURI())
.addPrefix("core", Core.getURI())
.addPrefix("hydra", Hydra.getURI())
.addPrefix("rdf", RDF.getURI())
.addPrefix("rdfs", RDFS.getURI())
.addPrefix("schema", SchemaOrg.getURI())
.addPrefix("xsd", XSD.getURI())
.addConstruct(VAR_MAIN, RDF.type, mainType)
.addConstruct(VAR_MAIN, RDFS.label, VAR_MAIN_LABEL)
.addConstruct(VAR_MAIN, RDFS.comment, VAR_MAIN_COMMENT);
// @formatter:on
this.baseNode = baseNode;
this.ef = this.getExprFactory();
protected AbstractHydraBuilder(JenaService jenaService, String baseUri, Resource mainType) {
this.jenaService = jenaService;
this.baseUri = baseUri;
this.mainType = mainType;
this.root = ResourceFactory.createResource(baseUri);
coreData.addWhere(VAR_MAIN, RDF.type, mainType);
model
.setNsPrefix("api", Api.getURI())
.setNsPrefix("core", Core.getURI())
.setNsPrefix("hydra", Hydra.getURI())
.setNsPrefix("rdf", RDF.getURI())
.setNsPrefix("rdfs", RDFS.getURI())
.setNsPrefix("schema", SchemaOrg.getURI())
.setNsPrefix("xsd", XSD.getURI());
this.ef = coreData.getExprFactory();
}

public WhereBuilder mainWhere() {
return new WhereBuilder().addWhere(VAR_MAIN, RDF.type, mainType);
}

public WhereBuilder labelWhere() {
return new WhereBuilder().addWhere(VAR_MAIN, RDFS.label, VAR_MAIN_LABEL);
}

public WhereBuilder commentWhere() {
return new WhereBuilder().addOptional(VAR_MAIN, RDFS.comment, VAR_MAIN_COMMENT);
protected Optional<RDFNode> get(QuerySolution row, Node variable) {
return Optional.ofNullable(row.get(variable.getName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.rdf.model.impl.ModelCom;
import org.apache.jena.vocabulary.RDF;

import eu.nampi.backend.vocabulary.Hydra;

public abstract class AbstractHydraNode extends ModelCom {

protected Resource base;

private AbstractHydraNode(String title, Property type, Resource base) {
private AbstractHydraNode(String title, Resource type, Resource base) {
super(ModelFactory.createDefaultModel().getGraph());
this.base = base;
this.add(base, RDF.type, type);
this.add(base, Hydra.title, ResourceFactory.createLangLiteral(title, "en"));
}

public AbstractHydraNode(String title, Property type) {
public AbstractHydraNode(String title, Resource type) {
this(title, type, ResourceFactory.createResource());
}

public AbstractHydraNode(String idUrl, String title, Property type) {
public AbstractHydraNode(String idUrl, String title, Resource type) {
this(title, type, ResourceFactory.createResource(idUrl));
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/eu/nampi/backend/model/hydra/Class.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.nampi.backend.model.hydra;

import org.apache.jena.rdf.model.Property;

import org.apache.jena.rdf.model.Resource;
import eu.nampi.backend.vocabulary.Hydra;

public class Class extends AbstractHydraNode {
Expand All @@ -10,11 +9,11 @@ public Class(String idUrl, String title) {
super(idUrl, title, Hydra.Class);
}

public Class(Property idProperty, String title) {
public Class(Resource idProperty, String title) {
super(idProperty.getURI(), title, Hydra.Class);
}

public Class(String idUrl, String title, Property type) {
public Class(String idUrl, String title, Resource type) {
super(idUrl, title, type);
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/eu/nampi/backend/model/hydra/Collection.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package eu.nampi.backend.model.hydra;

import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDFS;

import eu.nampi.backend.vocabulary.Hydra;

public class Collection extends Class {

public Collection(Property type, Property itemType) {
public Collection(Resource type, Resource itemType) {
super(type.getURI(), type.getLocalName());
add(RDFS.subClassOf, Hydra.Collection);
SupportedProperty manages = new SupportedProperty(Hydra.manages, true, false, false);
Expand Down
Loading

0 comments on commit a057652

Please sign in to comment.