import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
\r
+/**\r
+ * <b><code>record</code></b> Pazpar2 command, referenced as: <code>pzreq.record</code>\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 2817539422114569506L;\r
private static Logger logger = Logger.getLogger(RecordCommand.class);\r
+ private RecordCommandSp spCommand = null;\r
\r
public RecordCommand() {\r
super("record");\r
}\r
\r
+ /**\r
+ * Special handling of record responses since they come in three distinctly different ways\r
+ * <ol>\r
+ * <li>As a regular <record> document</li>\r
+ * <li>In arbitrary XML format, in case of an offset request to get the native format</li>\r
+ * <li>In binary (non XML) format</li>\r
+ * </ol> \r
+ */\r
@Override\r
public ResponseDataObject run() {\r
ResponseDataObject responseObject = null;\r
responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
logger.debug("Storing " + responseObject.getType() + " in pzresp. ");\r
- } else { \r
+ } else {\r
logger.debug("Command was 'record' but response not '<record>' - assuming raw record response.");\r
- ResponseDataObject recordResponse = new RecordResponse(); \r
+ ResponseDataObject recordResponse = new RecordResponse();\r
recordResponse.setType("record");\r
- recordResponse.setXml(responseObject.getXml()); \r
- recordResponse.setAttribute("activeclients", "0"); \r
+ recordResponse.setXml(responseObject.getXml());\r
+ recordResponse.setAttribute("activeclients", "0");\r
+ responseObject = recordResponse;\r
}\r
} else if (commandResponse.isBinary()) {\r
- responseObject = new RecordResponse(); \r
+ responseObject = new RecordResponse();\r
responseObject.setType(getCommandName());\r
logger.info("Binary response");\r
responseObject.setAttribute("activeclients", "0");\r
responseObject.setXml("<record>binary response</record>");\r
responseObject.setBinary(commandResponse.getBytes());\r
- \r
} else {\r
logger.error("Response was not found to be XML or binary. The response was not handled.");\r
}\r
return responseObject;\r
}\r
\r
+ /**\r
+ * Sets the <code>id</code> parameter. See Pazpar2 documentation for details.\r
+ * \r
+ * @param recId record ID\r
+ */\r
public void setId(String recId) {\r
setParameter(new CommandParameter("id","=",recId));\r
}\r
- \r
+\r
+ /** \r
+ * Returns the <code>id</code> parameter value.\r
+ */\r
public String getId () {\r
return getParameterValue("id");\r
}\r
- \r
+\r
+ /**\r
+ * Sets the <code>offset</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setOffset (String offset) {\r
setParameter(new CommandParameter("offset","=",offset));\r
}\r
- \r
+\r
+ /** \r
+ * Returns the <code>offset</code> parameter value.\r
+ */\r
public String getOffset () {\r
return getParameterValue("offset");\r
}\r
\r
+ /**\r
+ * Sets the <code>checksum</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setChecksum (String checksum) {\r
setParameter(new CommandParameter("checksum","=",checksum));\r
}\r
\r
+ /** \r
+ * Returns the <code>checksum</code> parameter value.\r
+ */\r
public String getChecksum () {\r
return getParameterValue("checksum");\r
}\r
\r
+ /**\r
+ * Sets the <code>nativesyntax</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setNativesyntax (String nativesyntax) {\r
setParameterInState(new CommandParameter("nativesyntax","=",nativesyntax));\r
}\r
\r
+ /** \r
+ * Returns the <code>nativesyntax</code> parameter value.\r
+ */\r
public String getNativesyntax () {\r
return getParameterValue("nativesyntax");\r
}\r
\r
+ /**\r
+ * Sets the <code>syntax</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setSyntax (String syntax) {\r
setParameterInState(new CommandParameter("syntax","=",syntax)); \r
}\r
\r
+ /** \r
+ * Returns the <code>syntax</code> parameter value.\r
+ */\r
public String getSyntax () {\r
return getParameterValue("syntax");\r
}\r
\r
+ /**\r
+ * Sets the <code>esn</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setEsn (String esn) {\r
setParameter(new CommandParameter("esn","=",esn));\r
}\r
\r
+ /** \r
+ * Returns the <code>esn</code> parameter value.\r
+ */\r
public String getEsn () {\r
return getParameterValue("esn");\r
}\r
\r
+ /**\r
+ * Sets the <code>binary</code> parameter. See Pazpar2 documentation for details.\r
+ */ \r
public void setBinary (String binary) {\r
setParameter(new CommandParameter("binary","=",binary));\r
}\r
\r
+ /** \r
+ * Returns the <code>binary</code> parameter value.\r
+ */\r
public String getBinary () {\r
return getParameterValue("binary");\r
}\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
+ newCommand.spCommand = new RecordCommandSp(newCommand);\r
return newCommand;\r
}\r
\r
* \r
*/\r
public RecordCommandSp getSp () {\r
- return new RecordCommandSp(this);\r
+ if (spCommand==null) {\r
+ spCommand = new RecordCommandSp(this);\r
+ } \r
+ return spCommand;\r
}\r
\r
@Override\r