package soph.collab;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import soph.collab.remoteservice.pubmed.EInfoService;
import soph.collab.remoteservice.pubmed.ESearchService;

@RestController
public class MainController {

    @Autowired
    EInfoService eInfoservice;
    @Autowired
    ESearchService eSearchservice;

    @RequestMapping("/")
    public String index() {
        return "Greetings from SoPH Collab!";
    }

    @RequestMapping("/listdatabases")
    public String listDatabases() {
        StringBuilder buffer = new StringBuilder();
        for (String db : eInfoservice.listDatabases()) {
            if (buffer.length() > 0)
                buffer.append(", ");
            buffer.append(db);
        }
        return "Databases: " + buffer.toString();
    }

    @RequestMapping("/searchpubmed")
    public String searchpubmed() {
        StringBuilder buffer = new StringBuilder();
        for (String db : eSearchservice.searchForAuthor("Allison DB")) {
            if (buffer.length() > 0)
                buffer.append(", ");
            buffer.append(db);
        }
        return "Articles: " + buffer.toString();
    }
}

@@ -753,49 +753,8 @@
 ) %7B%0A
-            if (buffer.length() %3E 0)%0A    
     
@@ -767,36 +767,34 @@
   buffer.append(
-%22, %22
+db
 );%0A            b
@@ -798,34 +798,36 @@
   buffer.append(
-db
+%22%5Cn%22
 );%0A        %7D%0A   
@@ -849,17 +849,18 @@
 tabases:
- 
+%5Cn
 %22 + buff
@@ -1082,49 +1082,8 @@
 ) %7B%0A
-            if (buffer.length() %3E 0)%0A    
     
@@ -1108,12 +1108,10 @@
 end(
-%22, %22
+db
 );%0A 
@@ -1127,34 +1127,36 @@
   buffer.append(
-db
+%22%5Cn%22
 );%0A        %7D%0A   
@@ -1177,17 +1177,18 @@
 rticles:
- 
+%5Cn
 %22 + buff

tweak output formating for test queries.