-
Notifications
You must be signed in to change notification settings - Fork 0
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 #6 from WSE-research/refactoringController
Refactoring controller
- Loading branch information
Showing
25 changed files
with
783 additions
and
524 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
41 changes: 30 additions & 11 deletions
41
src/main/java/com/wse/qanaryexplanationservice/controller/AnnotationController.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,34 +1,53 @@ | ||
package com.wse.qanaryexplanationservice.controller; | ||
|
||
import com.wse.qanaryexplanationservice.pojos.ResultObject; | ||
|
||
import com.wse.qanaryexplanationservice.pojos.ComponentPojo; | ||
import com.wse.qanaryexplanationservice.pojos.ExplanationObject; | ||
import com.wse.qanaryexplanationservice.services.AnnotationsService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
|
||
import com.wse.qanaryexplanationservice.services.GetAnnotationsService; | ||
|
||
@RestController | ||
public class AnnotationController { | ||
|
||
@Autowired | ||
private GetAnnotationsService getAnnotationsService; | ||
private AnnotationsService annotationsService; | ||
|
||
/** | ||
* @param graphID graphId to work with | ||
* @return the list of results (ResultObjects) | ||
* @param graphURI graphURI to work with | ||
* @return the list of results (ExplanationObjects) | ||
*/ | ||
@CrossOrigin | ||
@GetMapping("/getannotations") | ||
public ResponseEntity<ResultObject[]> getAnnotations(@RequestParam String graphID) throws IOException { | ||
ResultObject[] resultObjects = getAnnotationsService.getAnnotations(graphID); | ||
if (resultObjects != null) | ||
return new ResponseEntity<>(resultObjects, HttpStatus.OK); | ||
@GetMapping("/annotations/{graphURI}") | ||
@Operation( | ||
summary = "Endpoint to request every made annotation within a QA-process", | ||
description = "This endpoint returns a list of annotations made by the QA-process of the " | ||
+ "provided graphURI. Requires graphURI." | ||
) | ||
public ResponseEntity<ExplanationObject[]> getAnnotations(@PathVariable String graphURI) throws IOException { | ||
ExplanationObject[] explanationObjects = annotationsService.getAnnotations(graphURI); | ||
if (explanationObjects != null) | ||
return new ResponseEntity<>(explanationObjects, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@CrossOrigin | ||
@GetMapping("/components") | ||
@Operation( | ||
summary = "Endpoint to receive any involved component in a QA-process", | ||
description = "To use that endpoint you have to provide a graphURI from a QA-process " | ||
+ "and it'll return a distinct list of involved components" | ||
) | ||
public ResponseEntity<ComponentPojo[]> getComponents(@RequestParam String graphURI) throws IOException { | ||
ComponentPojo[] result = annotationsService.getUsedComponents(graphURI); | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
87 changes: 33 additions & 54 deletions
87
src/main/java/com/wse/qanaryexplanationservice/controller/ExplanationController.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,81 +1,60 @@ | ||
package com.wse.qanaryexplanationservice.controller; | ||
|
||
import com.wse.qanaryexplanationservice.pojos.ExplanationObject; | ||
import com.wse.qanaryexplanationservice.services.ExplanationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@ControllerAdvice | ||
public class ExplanationController { | ||
|
||
private static final String DBpediaSpotlight_SPARQL_QUERY = "/queries/explanation_for_dbpediaSpotlight_sparql_query.rq"; | ||
private static final String QBBirthdateWikidata_SPARQL_QUERY = "/queries/explanation_for_birthdate_wikidata.rq"; | ||
private static final String GENERAL_EXPLANATION_SPARQL_QUERY = "/queries/general_explanation.rq"; | ||
private Logger logger = LoggerFactory.getLogger(ExplanationController.class); | ||
private static final String QueryBuilder_SPARQL_QUERY = "/queries/explanation_for_query_builder.rq"; | ||
private final Logger logger = LoggerFactory.getLogger(ExplanationController.class); | ||
|
||
@Autowired | ||
private ExplanationService explanationService; | ||
|
||
/** | ||
* @param graphID graphId to work with | ||
*/ | ||
@CrossOrigin | ||
@GetMapping("/explanation") | ||
public ResponseEntity<ExplanationObject[]> explainComponentDBpediaSpotlight(@RequestParam String graphID) throws IOException { | ||
ExplanationObject[] explanationObjects = explanationService.explainComponentDBpediaSpotlight(graphID, DBpediaSpotlight_SPARQL_QUERY); | ||
if (explanationObjects != null) | ||
return new ResponseEntity<>(explanationObjects, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* Provides an explanation of query builder and returns the created sparql queries | ||
* | ||
* @param graphID Given graphID | ||
* @return textual explanation if there are any annotations made by any query builder | ||
* @throws IOException | ||
*/ | ||
@CrossOrigin | ||
@GetMapping("/explanationforquerybuilder") | ||
public ResponseEntity<String> explainQueryBuilder(@RequestParam String graphID) throws IOException { | ||
String explanation = explanationService.explainQueryBuilder(graphID, QueryBuilder_SPARQL_QUERY); | ||
|
||
if (explanation != null) | ||
return new ResponseEntity<>(explanation, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>("There are no created sparql queries", HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* @param graphURI given graph URI | ||
* @param componentURI given component URI | ||
* @return String as RDF-Turtle | ||
* @throws IOException | ||
*/ | ||
@CrossOrigin | ||
@GetMapping(value = "/explainspecificcomponent", produces = { | ||
@GetMapping(value = {"/explanations/{graphURI}", "/explanations/{graphURI}/{componentURI}"}, produces = { | ||
"application/rdf+xml", | ||
"text/turtle", | ||
"application/ld+json"}) | ||
public ResponseEntity<?> getRdfTurtle(@RequestParam String graphURI, | ||
@RequestParam String componentURI, | ||
@RequestHeader Map<String, String> headers, | ||
@RequestHeader(value = "accept", required = false) String acceptHeader) throws IOException { | ||
String result = this.explanationService.explainSpecificComponent(graphURI, componentURI, GENERAL_EXPLANATION_SPARQL_QUERY, acceptHeader); | ||
"application/ld+json", | ||
"*/*"}) | ||
@Operation( | ||
summary = "Get either the explanation for a the whole QA-system on a graphURI" | ||
+ "or the explanation for a specific component by attaching the componentURI", | ||
description = "This endpoint currently offers two sort of requests: " | ||
+ "\n 1. Explanation for a QA-system by providing a graphURI and " | ||
+ "\n 2. Explanation for a component within a QA-process by providing the graphURI" | ||
+ "\n as well as the URI for the component" | ||
+ "\n Note: You must at least provide a graphURI to use this endpoint" | ||
) | ||
public ResponseEntity<?> getExplanations( | ||
@PathVariable(required = true) String graphURI, | ||
@PathVariable(required = false) String componentURI, | ||
@RequestHeader(value = "accept", required = false) String acceptHeader) throws Exception { | ||
if (componentURI == null) { | ||
String result = explanationService.explainQaSystem(graphURI, GENERAL_EXPLANATION_SPARQL_QUERY, acceptHeader); | ||
if (result != null) | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); | ||
} else { | ||
String result = this.explanationService.explainSpecificComponent(graphURI, componentURI, GENERAL_EXPLANATION_SPARQL_QUERY, acceptHeader); | ||
if (result != null) | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
if (result != null) | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
else | ||
return new ResponseEntity<>(result, HttpStatus.NOT_ACCEPTABLE); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/wse/qanaryexplanationservice/pojos/ComponentPojo.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,23 @@ | ||
package com.wse.qanaryexplanationservice.pojos; | ||
|
||
import com.wse.qanaryexplanationservice.pojos.ResultObjectDTOs.Component; | ||
|
||
public class ComponentPojo { | ||
|
||
private Component component; | ||
|
||
public ComponentPojo() { | ||
} | ||
|
||
public ComponentPojo(Component component) { | ||
this.component = component; | ||
} | ||
|
||
public Component getComponent() { | ||
return component; | ||
} | ||
|
||
public void setComponent(Component component) { | ||
this.component = component; | ||
} | ||
} |
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
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.