Skip to content

Commit

Permalink
pull path to config files into constant
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nut committed Jul 6, 2018
1 parent 82340a6 commit 7834992
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/de/codefor/opacapi/RestAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
@RestController
public class RestAPI {

public static final String CONFIG_FILES_PATH = "./opacapp-config-files/bibs";

private static String readFile(String fileName) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
StringBuilder sb = new StringBuilder();
Expand All @@ -47,6 +49,16 @@ private static String readFile(String fileName) throws IOException {
}
}


private File[] getConfigFiles() {
return new File(CONFIG_FILES_PATH).listFiles();
}

private File getConfigFile(String libraryName) {
return new File(String.format("%s/%s.json", CONFIG_FILES_PATH, libraryName));
}


@RequestMapping(value = "/libraries/{libraryName}/search",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},
Expand Down Expand Up @@ -203,7 +215,7 @@ private void checkSearchTerm(String searchTerm) {

private OpacApi getOpacApi(String libraryName) {
try {
File file = new File("../opacapp-config-files/bibs/" + libraryName + ".json");
File file = getConfigFile(libraryName);
Library library = Library.fromJSON(libraryName, new JSONObject(readFile(file.getAbsolutePath())));
return OpacApiFactory.create(library, new DummyStringProvider(),
new HttpClientFactory("HelloOpac/1.0.0", new OpacAPI().pathToTrustStore()), null, null);
Expand All @@ -217,9 +229,7 @@ private OpacApi getOpacApi(String libraryName) {
private List<String> libraries(String nameOfCity) {
List<String> libraries = new ArrayList<>();

File[] listOfFiles = new File("../opacapp-config-files/bibs").listFiles();

for (File file : listOfFiles) {
for (File file : getConfigFiles()) {

String libraryName = file.getName().replace(".json", "");

Expand All @@ -240,8 +250,7 @@ public List<String> libraries() {

List<String> libraries = new ArrayList<>();

File[] listOfFiles = new File("./opacapp-config-files/bibs").listFiles();
for (File file : listOfFiles) {
for (File file : getConfigFiles()) {
libraries.add(file.getName().replace(".json", ""));
}

Expand Down

0 comments on commit 7834992

Please sign in to comment.