Fixes comment typo
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / Pz2ProxyBean.java
index fce82ca..7bc0145 100644 (file)
@@ -2,6 +2,8 @@ package com.indexdata.mkjsf.pazpar2;
 \r
 import java.io.IOException;\r
 import java.io.UnsupportedEncodingException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
 import javax.annotation.PostConstruct;\r
 import javax.enterprise.context.SessionScoped;\r
@@ -13,6 +15,7 @@ import org.apache.log4j.Logger;
 \r
 import com.indexdata.mkjsf.config.ConfigurationReader;\r
 import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyClient;\r
+import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyCommandResponse;\r
 import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyInterface;\r
 import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
 import com.indexdata.mkjsf.utils.Utils;\r
@@ -24,7 +27,6 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   private static Logger logger = Logger.getLogger(Pz2ProxyBean.class);  \r
   private String initDocFileName = "";\r
   private String initDocResponse = "";\r
-  private String serviceProxyUrl = "";  \r
     \r
   @Inject ConfigurationReader configurator;\r
   @Inject ServiceProxyUser user;    \r
@@ -40,7 +42,7 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
       logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
                             + Utils.objectId(configurator) + "]" );    \r
       configureClient(searchClient,configurator);\r
-      stateMgr.addStateListener(this);\r
+      stateMgr.addStateListener(this);      \r
     } else {\r
       logger.debug("Pz2ProxyBean:postConstruct: searchClient already instantiated " +\r
                        "during construction of parent object Pz2Bean.");\r
@@ -48,7 +50,7 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   }\r
   \r
   public void login(String un, String pw) {\r
-    if (user.isAuthenticated() && user.getName().equals(un) && ((ServiceProxyClient) searchClient).checkAuthentication()) {\r
+    if (user.isAuthenticated() && user.getName().equals(un) && ((ServiceProxyClient) searchClient).checkAuthentication(user)) {\r
       logger.info("Repeat request from UI to authenticate user. Auth verified for given user name so skipping log-in.");\r
     } else {\r
       logger.info("doing un/pw login");\r
@@ -67,18 +69,44 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
     pzresp.reset();\r
     return navigateTo;\r
   }\r
+  \r
+  public void ipAuthenticate (ServiceProxyUser user) {\r
+    if (!user.isIpAuthenticated()) {\r
+      if (user.isAuthenticated()) {\r
+        user.clear();\r
+      }\r
+      pzreq.getRecord().removeParametersInState();\r
+      pzreq.getSearch().removeParametersInState();\r
+      pzresp.reset();\r
+      ((ServiceProxyClient)searchClient).ipAuthenticate(user);\r
+    }\r
+  }\r
 \r
   @Override\r
   public void setServiceProxyUrl(String url) {\r
-    logger.info("Setting Service Proxy url: " + url);\r
-    serviceProxyUrl = url;\r
-    pzreq.getRecord().removeParametersInState();\r
-    pzreq.getSearch().removeParametersInState();\r
-    pzresp.reset();\r
+    logger.info("Setting Service Proxy url: " + url);    \r
+    if (url!=null & !url.equals(((ServiceProxyClient)searchClient).getServiceProxyUrl())) {\r
+      pzreq.getRecord().removeParametersInState();\r
+      pzreq.getSearch().removeParametersInState();\r
+      pzresp.reset();\r
+      user.clear();\r
+      ((ServiceProxyClient)searchClient).setServiceProxyUrl(url);\r
+    }    \r
   }\r
   \r
   public String getServiceProxyUrl() {\r
-    return serviceProxyUrl;\r
+    return ((ServiceProxyClient)searchClient).getServiceProxyUrl();\r
+  }\r
+  \r
+  public boolean getServiceProxyUrlIsDefined() {\r
+    return ((ServiceProxyClient)searchClient).getServiceProxyUrl().length()>0;\r
+  }\r
+  \r
+  public List<String> getServiceProxyUrls() {\r
+    List<String> urls = new ArrayList<String>();\r
+    urls.add("");\r
+    urls.addAll(((ServiceProxyClient)searchClient).getServiceProxyUrls());\r
+    return urls;\r
   }\r
     \r
   public String getInitDocPath () {\r
@@ -97,38 +125,25 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
   }\r
 \r
   @Override\r
-  public String postInit() throws UnsupportedEncodingException, IOException {    \r
-    String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths()[0];\r
+  public ServiceProxyCommandResponse postInit() throws UnsupportedEncodingException, IOException {    \r
+    String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths().get(0);\r
     logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());\r
     logger.info("Path: " + initDocPath);\r
     pzresp.reset();\r
-    byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName());\r
-    initDocResponse = new String(response,"UTF-8");\r
-    return initDocResponse;\r
+    ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName());    \r
+    return response;\r
   }\r
   \r
   @Override\r
-  public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException {    \r
+  public ServiceProxyCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {    \r
     pzresp.reset();\r
-    byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc);\r
-    initDocResponse = new String(response,"UTF-8");\r
-    return initDocResponse;\r
+    ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc,includeDebug);    \r
+    return response;\r
   }\r
 \r
-\r
   @Override\r
   public String getInitResponse() {\r
     return initDocResponse;\r
   }\r
   \r
-  public void setAceFilter(String filterExpression) {\r
-    //setCommandParameter("record",new CommandParameter("acefilter","=",filterExpression));\r
-  }\r
-  \r
-  public String getAceFilter () {\r
-    return null;\r
-    // return getCommandParameterValue("record","acefilter","");\r
-  }\r
-\r
-\r
 }\r