* @return Number of activeclients at the time of the 'show' command\r
*/\r
public String update (String commands) {\r
+ try {\r
if (! errors.hasConfigurationErrors()) {\r
if (commandsAreValid(commands)) {\r
- if (hasQuery() || (commands.equals("record") && pzreq.getCommand("record").hasParameterSet("recordquery"))) {\r
+ if (hasQuery() || (commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) {\r
handleQueryStateChanges(commands);\r
logger.debug("Processing request for " + commands); \r
List<CommandThread> threadList = new ArrayList<CommandThread>();\r
String response = thread.getResponse();\r
responseLogger.debug("Response was: " + response);\r
Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
- pzresp.put(commandName, responseObject); \r
+ if (Pazpar2ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ pzresp.put(commandName, responseObject);\r
+ } else {\r
+ if (commandName.equals("record") && pzreq.getRecord().hasParameterValue("offset")) {\r
+ RecordResponse recordResponse = new RecordResponse();\r
+ recordResponse.setType("record");\r
+ recordResponse.setXml(responseObject.getXml());\r
+ recordResponse.setAttribute("activeclients", "0");\r
+ pzresp.put(commandName, recordResponse);\r
+ }\r
+ }\r
}\r
- if (commands.equals("record")) { \r
- logger.debug("Record: Active clients: "+pzresp.getRecord().getActiveClients());\r
+ if (commands.equals("record")) {\r
return pzresp.getRecord().getActiveClients();\r
} else {\r
return pzresp.getActiveClients();\r
logger.error("Did not attempt to execute query since there are configuration errors.");\r
return "0";\r
}\r
+ } catch (ClassCastException cce) {\r
+ cce.printStackTrace(); \r
+ return "";\r
+ } catch (NullPointerException npe) {\r
+ npe.printStackTrace();\r
+ return "";\r
+ }\r
\r
}\r
\r
public boolean commandsAreValid(String commands) {\r
if (commands.equals("record")) {\r
- if (!pzreq.getCommand("record").hasParameterSet("id")) {\r
+ if (!pzreq.getCommand("record").hasParameterValue("id")) {\r
logger.error("Attempt to send record command without the id parameter");\r
return false;\r
}\r
}\r
\r
protected boolean hasQuery() { \r
- return pzreq.getCommand("search").hasParameterSet("query"); \r
+ return pzreq.getCommand("search").hasParameterValue("query"); \r
}\r
\r
\r
if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r
logger.debug("Found pending record ID change. Doing record before updating " + commands);\r
stateMgr.hasPendingStateChange("record",false);\r
- if (pzreq.getCommand("record").hasParameterSet("id")) {\r
+ if (pzreq.getCommand("record").hasParameterValue("id")) {\r
update("record");\r
} else { \r
pzresp.put("record", new RecordResponse());\r
return operator != null;\r
}\r
\r
+ public boolean hasValue() {\r
+ return value != null && value.length()>0;\r
+ }\r
+ \r
public String getEncodedQueryString () {\r
try {\r
return name + operator + URLEncoder.encode(getValueWithExpressions(),"UTF-8");\r
return (parameters.keySet().size()>0);\r
}\r
\r
- public boolean hasParameterSet(String parameterName) {\r
- return (parameters.get(parameterName) != null);\r
+ public boolean hasParameterValue(String parameterName) {\r
+ return (parameters.get(parameterName) != null && parameters.get(parameterName).hasValue());\r
}\r
\r
public String getEncodedQueryString () {\r
StringBuilder queryString = new StringBuilder("command="+name);\r
for (CommandParameter parameter : parameters.values()) {\r
- queryString.append("&"+parameter.getEncodedQueryString()); \r
+ if (parameter.hasValue()) {\r
+ queryString.append("&"+parameter.getEncodedQueryString());\r
+ }\r
}\r
return queryString.toString();\r
} \r
public String getValueWithExpressions() { \r
StringBuilder value = new StringBuilder("");\r
for (CommandParameter parameter : parameters.values()) {\r
- value.append("&" + parameter.getName() + parameter.operator + parameter.getValueWithExpressions()); \r
+ if (parameter.hasValue()) {\r
+ value.append("&" + parameter.getName() + parameter.operator + parameter.getValueWithExpressions());\r
+ }\r
}\r
return value.toString();\r
}\r
public void setBinary (String binary) {\r
setParameter(new CommandParameter("binary","=",binary));\r
}\r
+ \r
+ public String getBinary () {\r
+ return getParameterValue("binary");\r
+ }\r
\r
@Override\r
public RecordCommand copy () {\r
\r
public void addFilter(String filterExpression) {\r
// TODO: implement\r
- if (hasParameterSet("filter")) {\r
+ if (hasParameterValue("filter")) {\r
setFilter(filterExpression);\r
} else {\r
getParameter("filter");\r
import javax.xml.parsers.SAXParser;\r
import javax.xml.parsers.SAXParserFactory;\r
\r
+import org.apache.log4j.Logger;\r
import org.xml.sax.Attributes;\r
import org.xml.sax.InputSource;\r
import org.xml.sax.SAXException;\r
private Stack<Pazpar2ResponseData> dataElements = new Stack<Pazpar2ResponseData>();\r
private Pazpar2ResponseData result = null;\r
private String xml = null;\r
+ private static Logger logger = Logger.getLogger(Pazpar2ResponseParser.class);\r
\r
- private static final List<String> docTypes = \r
+ public static final List<String> docTypes = \r
Arrays.asList("bytarget","termlist","show","stat","record","search");\r
\r
public Pazpar2ResponseParser() { \r
currentElement.setType(localName);\r
for (int i=0; i< atts.getLength(); i++) {\r
currentElement.setAttribute(atts.getLocalName(i), atts.getValue(i));\r
- }\r
+ } \r
if (!docTypes.contains(localName)) {\r
- dataElements.peek().addElement(localName, currentElement);\r
+ if (dataElements.size() == 0) {\r
+ logger.info("Encountered unknown top level element [" + localName + "]");\r
+ currentElement.setType(localName);\r
+ } else {\r
+ dataElements.peek().addElement(localName, currentElement);\r
+ }\r
}\r
if (this.xml != null) { // Store XML for doc level elements\r
currentElement.setXml(xml);\r
}\r
\r
public RecordResponse getRecord() {\r
+ logger.info("Request to get record response.");\r
+ logger.info("Has record response: [" + ((dataObjects.get("record")!=null) ? "true" : "false") + "]");\r
+ logger.info("Its of type record: [" + ((dataObjects.get("record") instanceof RecordResponse) ? "true" : "false") +"]");\r
+ logger.info("It has xml: [" + ((dataObjects.get("record").getXml()!=null) ? "true" : "false") + "]");\r
return ((RecordResponse) dataObjects.get("record"));\r
}\r
\r
return ((ByTarget) dataObjects.get("bytarget"));\r
}\r
\r
+ public Pazpar2ResponseData getResponseObject (String name) {\r
+ return dataObjects.get(name);\r
+ }\r
+ \r
public boolean hasRecords () {\r
return getStat().getRecords() > 0 \r
&& getShow().getHits() != null \r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.data;\r
+\r
+public class RecordOffsetResponse extends Pazpar2ResponseData {\r
+\r
+ private static final long serialVersionUID = -601620728296476450L;\r
+\r
+ \r
+}\r
}\r
\r
public String getActiveClients () {\r
+ logger.info("Request to get activeclients");\r
return getOneElementValue("activeclients");\r
}\r
-\r
- \r
+ \r
}\r