Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 9711117

Browse files
committed
Extract path to ontologies to constant
1 parent d1b2dfe commit 9711117

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/main/java/de/linkvt/bachelor/web/GeneratorController.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
@RestController
3737
public class GeneratorController {
3838

39+
public static final String ONTOLOGY_PATH_WITHOUT_SLASH = "ontology";
40+
public static final String ONTOLOGY_PATH = ONTOLOGY_PATH_WITHOUT_SLASH + "/";
41+
3942
private ApplicationContext applicationContext;
4043
private FeatureParameterMapping featureMapping;
4144
private StoredGenerationRepository repository;
@@ -47,23 +50,23 @@ public GeneratorController(ApplicationContext applicationContext, FeatureParamet
4750
this.repository = repository;
4851
}
4952

50-
@RequestMapping("/ontology/")
53+
@RequestMapping(ONTOLOGY_PATH)
5154
public OWLOntology completeOntology(HttpServletResponse response) throws OWLOntologyCreationException {
5255
return ontologyFromParameters(response, featureMapping.getAll());
5356
}
5457

55-
@RequestMapping(value = "/ontology/", params = "features")
58+
@RequestMapping(value = ONTOLOGY_PATH, params = "features")
5659
public OWLOntology ontologyFromParameters(HttpServletResponse response, @RequestParam("features") List<Feature> features) {
5760
return ontologyFromParametersWithFilename(response, features);
5861
}
5962

60-
@RequestMapping(value = "/ontology/{filename}", params = "features", method = RequestMethod.GET)
63+
@RequestMapping(value = ONTOLOGY_PATH + "{filename}", params = "features", method = RequestMethod.GET)
6164
public OWLOntology ontologyFromParametersWithFilename(HttpServletResponse response, @RequestParam("features") List<Feature> features) {
6265
OntologyGenerator generator = applicationContext.getBean(OntologyGenerator.class);
6366
RequestInformation information = applicationContext.getBean(RequestInformation.class);
6467

6568
StoredGeneration generation = storeGenerationIfRequired(features);
66-
response.addHeader("Short-Path", "/ontology/" + generation.getId() + "/" + generation.getId());
69+
response.addHeader("Short-Path", "/" + ONTOLOGY_PATH + generation.getId() + "/" + generation.getId());
6770

6871
information.setGenerationId(generation.getId());
6972

@@ -87,12 +90,12 @@ private StoredGeneration storeGenerationIfRequired(List<Feature> features) {
8790
return generation;
8891
}
8992

90-
@RequestMapping("/ontology/{id}/")
93+
@RequestMapping(ONTOLOGY_PATH + "{id}/")
9194
public OWLOntology ontologyFromId(HttpServletResponse response, @PathVariable("id") Long id) {
9295
return ontologyFromIdWithFilename(response, id);
9396
}
9497

95-
@RequestMapping("/ontology/{id}/{filename}")
98+
@RequestMapping(ONTOLOGY_PATH + "{id}/{filename}")
9699
public OWLOntology ontologyFromIdWithFilename(HttpServletResponse response, @PathVariable("id") Long id) {
97100
StoredGeneration storedGeneration = repository.findOne(id);
98101
if (storedGeneration == null) {

src/main/java/de/linkvt/bachelor/web/TrailingSlashRedirectController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.linkvt.bachelor.web;
22

3-
import org.springframework.util.StringUtils;
3+
import org.apache.commons.lang3.StringUtils;
44
import org.springframework.web.bind.annotation.PathVariable;
55
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RestController;
@@ -16,14 +16,14 @@
1616
@RestController
1717
public class TrailingSlashRedirectController {
1818

19-
@RequestMapping("/ontology")
19+
@RequestMapping(GeneratorController.ONTOLOGY_PATH_WITHOUT_SLASH)
2020
public void ontologyRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
21-
response.sendRedirect(appendQueryString("/ontology/", request));
21+
response.sendRedirect(appendQueryString("/" + GeneratorController.ONTOLOGY_PATH, request));
2222
}
2323

24-
@RequestMapping("/ontology/{id}")
24+
@RequestMapping(GeneratorController.ONTOLOGY_PATH + "{id}")
2525
public void ontologyFromIdRedirect(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id) throws IOException {
26-
response.sendRedirect(appendQueryString("/ontology/" + id + "/", request));
26+
response.sendRedirect(appendQueryString("/" + GeneratorController.ONTOLOGY_PATH + id + "/", request));
2727
}
2828

2929
private String appendQueryString(String path, HttpServletRequest request) {

0 commit comments

Comments
 (0)