3333@ RestController
3434public 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