Skip to content

Commit

Permalink
Merge pull request #9 from codeforberlin/config-files-submodule
Browse files Browse the repository at this point in the history
Test with Travis CI
  • Loading branch information
k-nut authored Jul 6, 2018
2 parents d96f4f6 + 7834992 commit 4543a5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "opacapp-config-files"]
path = opacapp-config-files
url = git://github.com/opacapp/opacapp-config-files.git
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: java
jdk:
- oraclejdk8
1 change: 1 addition & 0 deletions opacapp-config-files
Submodule opacapp-config-files added at 79a409
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 4543a5c

Please sign in to comment.