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