Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 4543a5c

Browse files
authored
Merge pull request #9 from codeforberlin/config-files-submodule
Test with Travis CI
2 parents d96f4f6 + 7834992 commit 4543a5c

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "opacapp-config-files"]
2+
path = opacapp-config-files
3+
url = git://github.com/opacapp/opacapp-config-files.git

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8

opacapp-config-files

Submodule opacapp-config-files added at 79a4094

src/main/java/de/codefor/opacapi/RestAPI.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
@RestController
3434
public class RestAPI {
3535

36+
public static final String CONFIG_FILES_PATH = "./opacapp-config-files/bibs";
37+
3638
private static String readFile(String fileName) throws IOException {
3739
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
3840
StringBuilder sb = new StringBuilder();
@@ -47,6 +49,16 @@ private static String readFile(String fileName) throws IOException {
4749
}
4850
}
4951

52+
53+
private File[] getConfigFiles() {
54+
return new File(CONFIG_FILES_PATH).listFiles();
55+
}
56+
57+
private File getConfigFile(String libraryName) {
58+
return new File(String.format("%s/%s.json", CONFIG_FILES_PATH, libraryName));
59+
}
60+
61+
5062
@RequestMapping(value = "/libraries/{libraryName}/search",
5163
method = RequestMethod.GET,
5264
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},
@@ -203,7 +215,7 @@ private void checkSearchTerm(String searchTerm) {
203215

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

220-
File[] listOfFiles = new File("../opacapp-config-files/bibs").listFiles();
221-
222-
for (File file : listOfFiles) {
232+
for (File file : getConfigFiles()) {
223233

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

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

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

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

0 commit comments

Comments
 (0)