Further reducing auth code
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 21 May 2013 20:43:22 +0000 (16:43 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 21 May 2013 20:43:22 +0000 (16:43 -0400)
src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java

index da21541..d283b29 100644 (file)
@@ -19,7 +19,6 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;
 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
 import com.indexdata.mkjsf.pazpar2.data.Responses;\r
-import com.indexdata.mkjsf.pazpar2.data.sp.AuthResponse;\r
 import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
 import com.indexdata.mkjsf.utils.Utils;\r
 \r
@@ -44,51 +43,43 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab
     //stateMgr.addStateListener(this);\r
   }\r
    \r
-\r
-  \r
-  public void login(String un, String pw) {\r
-      logger.info("doing un/pw login");\r
-      pzreq.getSp().getAuth().setUsername(un);\r
-      pzreq.getSp().getAuth().setPassword(pw);\r
-      login("");\r
-  }\r
-\r
-\r
-  \r
-  @Override  \r
-  public String login(String navigateTo) {\r
-    logger.info("doing login using " + pz2 + " and client " + pz2.getSpClient());\r
+  public void authenticate() {\r
     pz2.resetSearchAndRecordCommands();\r
     pzresp.getSp().resetAuthAndBeyond(true);\r
-    AuthCommand auth = pzreq.getSp().getAuth(); \r
-    auth.setParameterInState(new CommandParameter("action","=","login"));\r
-    ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);\r
+    AuthCommand auth = pzreq.getSp().getAuth();     \r
+    ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);      \r
     String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth");\r
     commandResponse.setResponseToParse(renamedResponse);\r
-    AuthResponse responseObject = (AuthResponse) ResponseParser.getParser().getDataObject(commandResponse);\r
+    ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(commandResponse);\r
     if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
       pzresp.put(auth.getCommandName(), responseObject);\r
     }\r
     String responseStr = commandResponse.getResponseString();\r
-    logger.info(responseStr);      \r
-    return navigateTo;\r
+    logger.info(responseStr);          \r
   }\r
   \r
+  public void login(String un, String pw) {      \r
+      login(un,pw,"");\r
+  }\r
   \r
+  public void login(String un, String pw, String navigateTo) {      \r
+    pzreq.getSp().getAuth().setUsername(un);\r
+    pzreq.getSp().getAuth().setPassword(pw);\r
+    login("");\r
+  }  \r
+    \r
+  @Override  \r
+  public String login(String navigateTo) {\r
+    AuthCommand auth = pzreq.getSp().getAuth(); \r
+    auth.setParameterInState(new CommandParameter("action","=","login"));\r
+    authenticate();\r
+    return navigateTo;\r
+  }\r
+    \r
   public void ipAuthenticate () {  \r
-    pz2.resetSearchAndRecordCommands();\r
-    pzresp.getSp().resetAuthAndBeyond(true);\r
     AuthCommand auth = pzreq.getSp().getAuth(); \r
     auth.setParameterInState(new CommandParameter("action","=","ipAuth"));\r
-    ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);      \r
-    String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth");\r
-    commandResponse.setResponseToParse(renamedResponse);\r
-    ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(commandResponse);\r
-    if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
-      pzresp.put(auth.getCommandName(), responseObject);\r
-    }\r
-    String responseStr = commandResponse.getResponseString();\r
-    logger.info(responseStr);      \r
+    authenticate();\r
   }\r
   \r
   private String renameResponseElement(String responseString, String newName) {\r