Moves init doc upload to InitCommandSp (sp ext of init)
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 28 May 2013 00:58:13 +0000 (20:58 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 28 May 2013 00:58:13 +0000 (20:58 -0400)
.. effectively making ServiceProxyExtensions bean and interface obsolete

src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java [deleted file]
src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java [deleted file]
src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java
src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java [new file with mode: 0644]
src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java
src/main/java/com/indexdata/mkjsf/utils/FileUpload.java

diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java
deleted file mode 100644 (file)
index d11a55b..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.indexdata.mkjsf.pazpar2;\r
-\r
-import java.io.IOException;\r
-import java.io.Serializable;\r
-import java.io.UnsupportedEncodingException;\r
-\r
-import javax.enterprise.context.SessionScoped;\r
-import javax.inject.Inject;\r
-import javax.inject.Named;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.apache.myfaces.custom.fileupload.UploadedFile;\r
-\r
-import com.indexdata.mkjsf.config.ConfigurationReader;\r
-import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
-import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
-import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
-import com.indexdata.mkjsf.utils.Utils;\r
-\r
-@Named("pz2x") @SessionScoped\r
-public class ServiceProxyExtensions implements ServiceProxyInterface, Serializable {\r
-    \r
-  private static final long serialVersionUID = 4221824985678758225L;\r
-  private static Logger logger = Logger.getLogger(ServiceProxyExtensions.class);  \r
-  private String initDocFileName = "";\r
-  private String initDocResponse = "";  \r
-  private InitDocUpload initDocUpload; \r
-    \r
-  @Inject ConfigurationReader configurator;    \r
-    \r
-  public ServiceProxyExtensions() {\r
-    this.initDocUpload = new InitDocUpload(this);\r
-    // TODO: \r
-    //stateMgr.addStateListener(this);\r
-  }\r
-           \r
-  public String getInitDocPath () {\r
-    return Pz2Service.get().getSpClient().getConfiguration().get("INIT_DOC_PATH");\r
-  }\r
-  \r
-  @Override\r
-  public void setInitFileName(String fileName) {\r
-    this.initDocFileName = fileName;    \r
-  }\r
-\r
-  @Override\r
-  public String getInitFileName() {\r
-    return initDocFileName;\r
-  }\r
-\r
-  @Override\r
-  public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException {    \r
-    String initDocPath = Pz2Service.get().getSpClient().getInitDocPaths().get(0);\r
-    logger.info("Paths: " + Pz2Service.get().getSpClient().getInitDocPaths());\r
-    logger.info("Path: " + initDocPath);   \r
-    Pz2Service.get().resetSearchAndRecordCommands();\r
-    Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
-    ClientCommandResponse response = Pz2Service.get().getSpClient().postInitDoc(initDocPath + getInitFileName());    \r
-    return response;\r
-  }\r
-  \r
-  @Override\r
-  public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {    \r
-    Pz2Service.get().resetSearchAndRecordCommands();\r
-    Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
-    HttpResponseWrapper response = Pz2Service.get().getSpClient().postInitDoc(initDoc,includeDebug);    \r
-    return response;\r
-  }\r
-\r
-  @Override\r
-  public String getInitResponse() {\r
-    return initDocResponse;\r
-  }\r
-  \r
-  public void setUploadedInitDoc (UploadedFile uploadedFile) {\r
-    initDocUpload.setUploadedFile(uploadedFile);\r
-  }\r
-  \r
-  public UploadedFile getUploadedInitDoc () {\r
-    return initDocUpload.getUploadedFile();\r
-  }\r
-  \r
-  public void submitInitDoc () throws IOException {\r
-    ClientCommandResponse response =  (ClientCommandResponse) initDocUpload.submit();\r
-    ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response);    \r
-    Pz2Service.get().getPzresp().put("init", responseObject);\r
-  }\r
-  \r
-  public void setIncludeInitDocDebug(boolean bool) {\r
-    logger.info(Utils.objectId(this) + " setting debug to " + bool);\r
-    initDocUpload.setIncludeDebug(bool);\r
-  }\r
-\r
-  public boolean getIncludeInitDocDebug() {\r
-    return initDocUpload.getIncludeDebug();\r
-  }\r
-  \r
-  // TODO: Remove when obsolete\r
-  public InitDocUpload getInitDocUpload () {\r
-    return initDocUpload;\r
-  }\r
-  \r
-   \r
-}\r
diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java
deleted file mode 100644 (file)
index 3a2e6a2..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.indexdata.mkjsf.pazpar2;\r
-\r
-import java.io.IOException;\r
-import java.io.UnsupportedEncodingException;\r
-\r
-\r
-public interface ServiceProxyInterface  {      \r
-  public void setInitFileName (String fileName);  \r
-  public String getInitFileName();\r
-  public HttpResponseWrapper postInit() throws UnsupportedEncodingException, IOException;\r
-  public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException;\r
-  public String getInitResponse();\r
-}\r
index 958aff7..d52ec51 100644 (file)
@@ -1,10 +1,15 @@
 package com.indexdata.mkjsf.pazpar2.commands;\r
 \r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.InitCommandSp;\r
 import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
 \r
 public class InitCommand extends Pazpar2Command implements ServiceProxyCommand {\r
 \r
   private static final long serialVersionUID = -4915976465898889987L;\r
+  private static Logger logger = Logger.getLogger(InitCommand.class);\r
+  private InitCommandSp spCommand = null;\r
   \r
   public InitCommand() {\r
     super("init");\r
@@ -34,18 +39,23 @@ public class InitCommand extends Pazpar2Command implements ServiceProxyCommand {
   @Override\r
   public String getSession () {\r
     throw new UnsupportedOperationException("Cannot set or get session id on init command");\r
-  }\r
+  }  \r
   \r
   public InitCommand copy () {\r
+    logger.info("Copying init command");\r
     InitCommand newCommand = new InitCommand();\r
     for (String parameterName : parameters.keySet()) {\r
       newCommand.setParameterInState(parameters.get(parameterName).copy());      \r
-    }    \r
+    }\r
+    newCommand.spCommand = this.spCommand;\r
     return newCommand;\r
   }\r
   \r
   public ServiceProxyCommand getSp() {\r
-    return this;\r
+    if (spCommand==null) {\r
+      spCommand = new InitCommandSp(this);\r
+    } \r
+    return spCommand;\r
   }\r
 \r
   @Override\r
diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java
new file mode 100644 (file)
index 0000000..629c07c
--- /dev/null
@@ -0,0 +1,75 @@
+package com.indexdata.mkjsf.pazpar2.commands.sp;\r
+\r
+import java.io.IOException;\r
+import java.io.Serializable;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.apache.myfaces.custom.fileupload.UploadedFile;\r
+\r
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
+import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
+import com.indexdata.mkjsf.pazpar2.commands.InitCommand;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;\r
+\r
+public class InitCommandSp implements Serializable, ServiceProxyCommand {\r
+\r
+  private static final long serialVersionUID = -6609045941782375651L;\r
+  private static Logger logger = Logger.getLogger(InitCommandSp.class);\r
+  private InitCommand command = null;\r
+  \r
+  private InitDocUpload initDocUpload;\r
+\r
+  public InitCommandSp(InitCommand initCommand) {\r
+    this.command=initCommand;\r
+    initDocUpload = new InitDocUpload();\r
+  }\r
+  \r
+  public void setIncludeDebug (String includeDebug) {\r
+    command.setParameterInState(new CommandParameter("includeDebug","=",includeDebug));\r
+  }\r
+  \r
+  public String getIncludeDebug () {\r
+    return command.getParameterValue("includeDebug");\r
+  }\r
+\r
+  public void setUploadedInitDoc (UploadedFile uploadedFile) {\r
+    initDocUpload.setUploadedFile(uploadedFile);\r
+  }\r
+  \r
+  public UploadedFile getUploadedInitDoc () {\r
+    logger.info("initDocUpload is: " + initDocUpload );\r
+    logger.info("initDocUpload.getUploadedFile() is: " +initDocUpload.getUploadedFile());\r
+    return initDocUpload.getUploadedFile();\r
+  }\r
+  \r
+  public void downloadInitDoc () throws IOException {\r
+    initDocUpload.downloadDoc();\r
+  }\r
+  \r
+  public SpResponseDataObject run() {\r
+    Pz2Service.get().resetSearchAndRecordCommands();\r
+    Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);    \r
+    try {\r
+      byte[] bytes = getUploadedInitDoc().getBytes();\r
+      HttpResponseWrapper response = Pz2Service.get().getSpClient().postInitDoc(bytes,getIncludeDebug().equals("yes"));    \r
+      ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)response);    \r
+      Pz2Service.get().getPzresp().put("init", responseObject);\r
+    } catch (IOException e) {\r
+      // TODO Auto-generated catch block\r
+      e.printStackTrace();\r
+    }\r
+    return null;\r
+  }\r
+\r
+  @Override\r
+  public boolean spOnly() {\r
+    return true;\r
+  }\r
+  \r
+  \r
+  \r
+}\r
index f85a5c6..1d0b90f 100644 (file)
@@ -8,8 +8,6 @@ import javax.inject.Named;
 import org.apache.log4j.Logger;\r
 import org.apache.myfaces.custom.fileupload.UploadedFile;\r
 \r
-import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
-import com.indexdata.mkjsf.pazpar2.ServiceProxyExtensions;\r
 import com.indexdata.mkjsf.utils.FileUpload;\r
 import com.indexdata.mkjsf.utils.Utils;\r
 \r
@@ -21,20 +19,10 @@ public class InitDocUpload extends FileUpload {
   private UploadedFile uploadedFile = null;\r
   private static Logger logger = Logger.getLogger(InitDocUpload.class);\r
   private static final long serialVersionUID = 1846749236304941323L;  \r
-  private boolean includeDebug = false;\r
-  private ServiceProxyExtensions spBean;    \r
   \r
-  public InitDocUpload(ServiceProxyExtensions spBean) {\r
-    this.spBean = spBean;\r
+  public InitDocUpload() {    \r
   }\r
-  \r
-  public HttpResponseWrapper submit() throws IOException {\r
-    logger.info(Utils.objectId(this) + " submitting");\r
-    byte[] bytes = uploadedFile.getBytes();\r
-    response = spBean.postInit(bytes, includeDebug);\r
-    return response;\r
-  }\r
-  \r
+    \r
   public UploadedFile getUploadedFile() {\r
     return uploadedFile;\r
   }\r
@@ -42,16 +30,12 @@ public class InitDocUpload extends FileUpload {
   public void setUploadedFile(UploadedFile uploadedFile) {\r
     logger.info(Utils.objectId(this) + " received an uploaded file [" + Utils.objectId(uploadedFile) + "]");\r
     this.uploadedFile = uploadedFile;\r
-  }\r
-\r
-\r
-  public void setIncludeDebug(boolean bool) {\r
-    logger.info(Utils.objectId(this) + " setting debug to " + bool);\r
-    includeDebug = bool;\r
-  }\r
-\r
-  public boolean getIncludeDebug() {\r
-    return includeDebug;\r
+    try {\r
+      logger.info("File length: " + this.uploadedFile.getBytes().length);\r
+    } catch (IOException e) {\r
+      // TODO Auto-generated catch block\r
+      e.printStackTrace();\r
+    }\r
   }\r
 \r
 }\r
index b974437..ac21771 100644 (file)
@@ -10,20 +10,14 @@ import org.apache.commons.io.FilenameUtils;
 import org.apache.log4j.Logger;\r
 import org.apache.myfaces.custom.fileupload.UploadedFile;\r
 \r
-import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
-\r
 public abstract class FileUpload implements Serializable {\r
 \r
-\r
-  protected HttpResponseWrapper response;\r
   private static Logger logger = Logger.getLogger(FileUpload.class);\r
   private static final long serialVersionUID = 748784638056392862L;\r
 \r
   public FileUpload() {\r
   }\r
 \r
-  public abstract HttpResponseWrapper submit() throws IOException;\r
-  \r
   public abstract UploadedFile getUploadedFile();\r
   \r
   public abstract void setUploadedFile(UploadedFile uploadedFile);\r