-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from yngwi:query_rework_2
Rework query structure
- Loading branch information
Showing
34 changed files
with
1,231 additions
and
927 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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/eu/nampi/backend/controller/ClassController.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,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); | ||
} | ||
|
||
} |
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
71 changes: 34 additions & 37 deletions
71
src/main/java/eu/nampi/backend/model/hydra/AbstractHydraBuilder.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,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())); | ||
} | ||
|
||
} |
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
Oops, something went wrong.