1 package com.indexdata.mkjsf.pazpar2.commands;
\r
3 import org.apache.log4j.Logger;
\r
5 import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;
\r
6 import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;
\r
7 import com.indexdata.mkjsf.pazpar2.Pz2Bean;
\r
8 import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp;
\r
9 import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;
\r
10 import com.indexdata.mkjsf.pazpar2.data.RecordResponse;
\r
11 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;
\r
12 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;
\r
14 public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand {
\r
16 private static final long serialVersionUID = 2817539422114569506L;
\r
17 private static Logger logger = Logger.getLogger(RecordCommand.class);
\r
19 public RecordCommand() {
\r
24 public ResponseDataObject run() {
\r
25 HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this);
\r
26 ResponseDataObject responseObject = null;
\r
27 if (commandResponse.getContentType().contains("xml")) {
\r
28 responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);
\r
29 if (ResponseParser.docTypes.contains(responseObject.getType())) {
\r
30 logger.debug("Storing " + responseObject.getType() + " in pzresp. ");
\r
32 logger.debug("Command was 'record' but response not '<record>' - assuming raw record response.");
\r
33 ResponseDataObject recordResponse = new RecordResponse();
\r
34 recordResponse.setType("record");
\r
35 recordResponse.setXml(responseObject.getXml());
\r
36 recordResponse.setAttribute("activeclients", "0");
\r
38 } else if (commandResponse.isBinary()) {
\r
39 responseObject = new RecordResponse();
\r
40 responseObject.setType(getCommandName());
\r
41 logger.info("Binary response");
\r
42 responseObject.setAttribute("activeclients", "0");
\r
43 responseObject.setXml("<record>binary response</record>");
\r
44 responseObject.setBinary(commandResponse.getBytes());
\r
47 logger.error("Response was not found to be XML or binary. The response was not handled.");
\r
49 Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);
\r
50 return responseObject;
\r
53 public void setId(String recId) {
\r
54 setParameter(new CommandParameter("id","=",recId));
\r
57 public String getId () {
\r
58 return getParameterValue("id");
\r
61 public void setOffset (String offset) {
\r
62 setParameter(new CommandParameter("offset","=",offset));
\r
65 public String getOffset () {
\r
66 return getParameterValue("offset");
\r
69 public void setChecksum (String checksum) {
\r
70 setParameter(new CommandParameter("checksum","=",checksum));
\r
73 public String getChecksum () {
\r
74 return getParameterValue("checksum");
\r
77 public void setNativesyntax (String nativesyntax) {
\r
78 setParameterInState(new CommandParameter("nativesyntax","=",nativesyntax));
\r
81 public String getNativesyntax () {
\r
82 return getParameterValue("nativesyntax");
\r
85 public void setSyntax (String syntax) {
\r
86 setParameterInState(new CommandParameter("syntax","=",syntax));
\r
89 public String getSyntax () {
\r
90 return getParameterValue("syntax");
\r
93 public void setEsn (String esn) {
\r
94 setParameter(new CommandParameter("esn","=",esn));
\r
97 public String getEsn () {
\r
98 return getParameterValue("esn");
\r
101 public void setBinary (String binary) {
\r
102 setParameter(new CommandParameter("binary","=",binary));
\r
105 public String getBinary () {
\r
106 return getParameterValue("binary");
\r
110 public RecordCommand copy () {
\r
111 RecordCommand newCommand = new RecordCommand();
\r
112 for (String parameterName : parameters.keySet()) {
\r
113 newCommand.setParameterInState(parameters.get(parameterName).copy());
\r
120 * Returns a record command object with Service Proxy extension parameters
\r
123 public RecordCommandSp getSp () {
\r
124 return new RecordCommandSp(this);
\r
128 public boolean spOnly() {
\r