X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2FRecordCommand.java;h=d453b75be2e5c61752da96a6bb3444810bf09f76;hb=969f879c807d127cbf47c5656771fcf5adc27a02;hp=e52afac2f9c668fe7d5e463217088106ef5147ea;hpb=11ff48b9d37193a89a4b74da75db8c58415c46a6;p=mkjsf-moved-to-github.git
diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java
index e52afac..d453b75 100644
--- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java
+++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java
@@ -4,17 +4,24 @@ import org.apache.log4j.Logger;
import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;
import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;
+import com.indexdata.mkjsf.pazpar2.Pz2Service;
import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp;
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;
import com.indexdata.mkjsf.pazpar2.data.RecordResponse;
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;
+/**
+ * Represents a Pazpar2 record
command.
+ *
+ * @author Niels Erik
+ *
+ */
public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand {
private static final long serialVersionUID = 2817539422114569506L;
private static Logger logger = Logger.getLogger(RecordCommand.class);
+ private RecordCommandSp spCommand = null;
public RecordCommand() {
super("record");
@@ -22,86 +29,136 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
@Override
public ResponseDataObject run() {
- HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this);
ResponseDataObject responseObject = null;
- if (commandResponse.getContentType().contains("xml")) {
- responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);
- if (ResponseParser.docTypes.contains(responseObject.getType())) {
- logger.debug("Storing " + responseObject.getType() + " in pzresp. ");
- } else {
- logger.debug("Command was 'record' but response not '' - assuming raw record response.");
- ResponseDataObject recordResponse = new RecordResponse();
- recordResponse.setType("record");
- recordResponse.setXml(responseObject.getXml());
- recordResponse.setAttribute("activeclients", "0");
- }
- } else if (commandResponse.isBinary()) {
- responseObject = new RecordResponse();
- responseObject.setType(getCommandName());
- logger.info("Binary response");
- responseObject.setAttribute("activeclients", "0");
- responseObject.setXml("binary response");
- responseObject.setBinary(commandResponse.getBytes());
+ if (hasParameterValue("id")) {
+ HttpResponseWrapper commandResponse = Pz2Service.get().getSearchClient().executeCommand(this);
+ if (commandResponse.getContentType().contains("xml")) {
+ responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {
+ logger.debug("Storing " + responseObject.getType() + " in pzresp. ");
+ } else {
+ logger.debug("Command was 'record' but response not '' - assuming raw record response.");
+ ResponseDataObject recordResponse = new RecordResponse();
+ recordResponse.setType("record");
+ recordResponse.setXml(responseObject.getXml());
+ recordResponse.setAttribute("activeclients", "0");
+ responseObject = recordResponse;
+ }
+ } else if (commandResponse.isBinary()) {
+ responseObject = new RecordResponse();
+ responseObject.setType(getCommandName());
+ logger.info("Binary response");
+ responseObject.setAttribute("activeclients", "0");
+ responseObject.setXml("binary response");
+ responseObject.setBinary(commandResponse.getBytes());
+ } else {
+ logger.error("Response was not found to be XML or binary. The response was not handled.");
+ }
+ Pz2Service.get().getPzresp().put(getCommandName(), responseObject);
} else {
- logger.error("Response was not found to be XML or binary. The response was not handled.");
+ logger.debug("No record id parameter on this command. Ignoring request but clearing any previous record result.");
+ Pz2Service.get().getPzresp().put(getCommandName(), new RecordResponse());
}
- Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);
return responseObject;
}
+ /**
+ * Sets the id
parameter. See Pazpar2 documentation for details.
+ *
+ * @param recId record ID
+ */
public void setId(String recId) {
setParameter(new CommandParameter("id","=",recId));
}
-
+
+ /**
+ * Returns the id
parameter value.
+ */
public String getId () {
return getParameterValue("id");
}
-
+
+ /**
+ * Sets the offset
parameter. See Pazpar2 documentation for details.
+ */
public void setOffset (String offset) {
setParameter(new CommandParameter("offset","=",offset));
}
-
+
+ /**
+ * Returns the offset
parameter value.
+ */
public String getOffset () {
return getParameterValue("offset");
}
+ /**
+ * Sets the checksum
parameter. See Pazpar2 documentation for details.
+ */
public void setChecksum (String checksum) {
setParameter(new CommandParameter("checksum","=",checksum));
}
+ /**
+ * Returns the checksum
parameter value.
+ */
public String getChecksum () {
return getParameterValue("checksum");
}
+ /**
+ * Sets the nativesyntax
parameter. See Pazpar2 documentation for details.
+ */
public void setNativesyntax (String nativesyntax) {
setParameterInState(new CommandParameter("nativesyntax","=",nativesyntax));
}
+ /**
+ * Returns the nativesyntax
parameter value.
+ */
public String getNativesyntax () {
return getParameterValue("nativesyntax");
}
+ /**
+ * Sets the syntax
parameter. See Pazpar2 documentation for details.
+ */
public void setSyntax (String syntax) {
setParameterInState(new CommandParameter("syntax","=",syntax));
}
+ /**
+ * Returns the syntax
parameter value.
+ */
public String getSyntax () {
return getParameterValue("syntax");
}
+ /**
+ * Sets the esn
parameter. See Pazpar2 documentation for details.
+ */
public void setEsn (String esn) {
setParameter(new CommandParameter("esn","=",esn));
}
+ /**
+ * Returns the esn
parameter value.
+ */
public String getEsn () {
return getParameterValue("esn");
}
+ /**
+ * Sets the binary
parameter. See Pazpar2 documentation for details.
+ */
public void setBinary (String binary) {
setParameter(new CommandParameter("binary","=",binary));
}
+ /**
+ * Returns the binary
parameter value.
+ */
public String getBinary () {
return getParameterValue("binary");
}
@@ -112,6 +169,7 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
for (String parameterName : parameters.keySet()) {
newCommand.setParameterInState(parameters.get(parameterName).copy());
}
+ newCommand.spCommand = this.spCommand;
return newCommand;
}
@@ -121,7 +179,10 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
*
*/
public RecordCommandSp getSp () {
- return new RecordCommandSp(this);
+ if (spCommand==null) {
+ spCommand = new RecordCommandSp(this);
+ }
+ return spCommand;
}
@Override