Cleans up auth logic
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / Pz2Bean.java
index 5b45551..1c825a8 100644 (file)
@@ -26,12 +26,10 @@ import com.indexdata.mkjsf.errors.ErrorHelper;
 import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
-import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
 import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
 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.sp.auth.ServiceProxyUser;\r
 import com.indexdata.mkjsf.pazpar2.state.StateListener;\r
 import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
 import com.indexdata.mkjsf.utils.Utils;\r
@@ -61,8 +59,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
   @Inject StateManager stateMgr;\r
   @Inject Pazpar2Commands pzreq;\r
   @Inject Responses pzresp;\r
-  @Inject ErrorCentral errors;\r
-  @Inject ServiceProxyUser user;\r
+  @Inject ErrorCentral errors;  \r
   \r
   protected ResultsPager pager = null; \r
   \r
@@ -98,7 +95,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
       errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage()));                \r
     } \r
     logger.info(configReader.document());\r
-    pzresp.resetAllSessionData();    \r
+    pzresp.getSp().resetAuthAndBeyond(true);    \r
   }\r
   \r
   public void resetSearchAndRecordCommands () {\r
@@ -119,9 +116,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
       errors.addConfigurationError(new ConfigurationError("No client defined","Client is null","No search client defined. A client must be pre-configured or selected runtime, prior to searching."));\r
     } else {\r
       stateMgr.hasPendingStateChange("search",false);\r
-      pzresp.resetSearchResponses();\r
-      // resets some record and show command parameters without \r
-      // changing state or creating state change feedback\r
+      pzresp.resetSearchAndBeyond();\r
       pzreq.getRecord().removeParametersInState();        \r
       pzreq.getShow().setParameterInState(new CommandParameter("start","=",0));    \r
       logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query"));\r
@@ -172,17 +167,19 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
    * Refreshes the data objects listed in 'commands' from pazpar2\r
    * \r
    * @param commands\r
-   * @return Number of activeclients at the time of the 'show' command\r
+   * @return Number of activeclients at the time of the 'show' command,\r
+   *         or 'new' if search was just initiated.\r
    */\r
   public String update (String commands) {\r
     logger.debug("Request to update: " + commands);\r
     try {\r
       if (commands.equals("search")) {\r
         doSearch();\r
-        return "";\r
+        return "new";\r
       } else if (commands.equals("record")) {\r
         return doRecord();\r
       } else if (pzresp.getSearch().isNew()) {\r
+        // For returning notification of 'search started' quickly to UI\r
         logger.info("New search. Marking it old, then returning 'new' to trigger another round-trip.");\r
         pzresp.getSearch().setIsNew(false);\r
         return "new";\r
@@ -403,8 +400,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
     if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) {\r
       pzreq.getRecord().removeParametersInState();\r
       pzreq.getSearch().removeParametersInState();\r
-      pzresp.resetAllSessionData();\r
-      user.clear();\r
+      pzresp.getSp().resetAuthAndBeyond(true);      \r
       searchClient.setServiceUrl(url);\r
     }    \r
   }\r
@@ -416,7 +412,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
   public void setServiceId () {\r
     pzreq.getRecord().removeParametersInState();\r
     pzreq.getSearch().removeParametersInState();\r
-    pzresp.resetSearchResponses();\r
+    pzresp.resetSearchAndBeyond();\r
     pz2Client.setServiceId(pzreq.getInit().getService());\r
   }\r
   \r
@@ -540,7 +536,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria
     if (!serviceType.equals(type)  &&\r
         !serviceType.equals(SERVICE_TYPE_TBD)) {\r
       resetSearchAndRecordCommands();\r
-      pzresp.resetAllSessionData();\r
+      pzresp.getSp().resetAuthAndBeyond(true);\r
     }\r
     serviceType = type;\r
     if (serviceType.equals(SERVICE_TYPE_PZ2)) {\r