{\r
//console.log('rendering ' + renderWhileActiveclients);\r
var sourcecomp = document.getElementById("pz2watch:activeclientsField");\r
- jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients});\r
+ jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients + " pz2watch:errorMessages"});\r
if (doRefresh) {\r
//console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField'); \r
renderTargetsReqVar=setTimeout(\r
//]]>\r
</script> \r
\r
- <h:form id="activeclientsForm" prependId="false" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}">\r
- Active clients: <h:outputText id="activeclientsField" value="${pz2.update()}" />\r
+ <h:form id="activeclientsForm" prependId="false">\r
+ <h:outputText id="activeClientsLabel" value="Active clients: " style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/> \r
+ <h:outputText id="activeclientsField" value="${pz2.update()}" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/>\r
+ <h:panelGrid id="errorMessages" style="${pz2.hasErrors() ? 'color: red;' : 'display: none;'}">\r
+ <p><h:outputText id="messages" value="Error: #{pz2.firstErrorMessage}"/></p>\r
+ </h:panelGrid> \r
</h:form>\r
\r
<h:form id="stateForm" prependId="false" rendered="${cc.attrs.trackHistory == 'true'}" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}">\r
\r
import com.indexdata.pz2utils4jsf.pazpar2.CommandThread;\r
import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
+import com.indexdata.utils.XmlUtils;\r
import com.indexdata.masterkey.pazpar2.client.ClientCommand;\r
import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;\r
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
long end = System.currentTimeMillis(); \r
logger.debug("Executed " + command.getName() + " in " + (end-start) + " ms." );\r
} catch (IOException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ logger.error("Message: " + e.getMessage()); \r
+ response = new StringBuilder("<"+command.getName()+"><error exception=\"io\">"+XmlUtils.escape(e.getMessage())+"</error></"+command.getName()+">");\r
+ logger.error(response.toString());\r
} catch (Pazpar2ErrorException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ logger.error(e.getMessage());\r
+ response = new StringBuilder("<"+command.getName()+"><error exception=\"pazpar2error\">"+XmlUtils.escape(e.getMessage())+"</error></"+command.getName()+">"); \r
+ logger.error(response.toString());\r
}\r
}\r
\r
public void setCurrentStateKey(String key) {\r
pz2.setCurrentStateKey(key); \r
}\r
+ \r
+ public boolean hasErrors() {\r
+ return pz2.hasErrors();\r
+ }\r
+ \r
+ public String getErrorMessages() {\r
+ return pz2.getErrorMessages();\r
+ }\r
+ \r
+ public String getFirstErrorMessage() {\r
+ return pz2.getFirstErrorMessage();\r
+ }\r
+ \r
\r
}\r
* @param key corresponding to browsers hash string\r
*/\r
public void setCurrentStateKey(String key);\r
+ \r
+ public boolean hasErrors();\r
+ \r
+ public String getErrorMessages();\r
+ \r
+ public String getFirstErrorMessage();\r
+ \r
}\r
import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.SearchResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse;\r
logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
return update("show,stat,termlist,bytarget");\r
}\r
- \r
+ \r
/**\r
* Refreshes the data objects listed in 'commands' from pazpar2\r
* \r
}\r
}\r
for (CommandThread thread : threadList) {\r
- if (!thread.getCommand().getName().equals("search")) {\r
- dataObjects.put(thread.getCommand().getName(), new Pazpar2ResponseParser().getObject(thread.getResponse()));\r
- }\r
+ dataObjects.put(thread.getCommand().getName(), new Pazpar2ResponseParser().getObject(thread.getResponse())); \r
}\r
return getActiveClients();\r
} else {\r
logger.debug("************** request to set state key to: [" + key + "]"); \r
queryStates.setCurrentStateKey(key);\r
}\r
+ \r
+ public boolean hasErrors () {\r
+ if (dataObjects.get("search").isError()) {\r
+ logger.info("Error detected in search");\r
+ return true;\r
+ }\r
+ for (String name : dataObjects.keySet()) {\r
+ if (dataObjects.get(name).isError()) {\r
+ logger.info("Error detected in " + name);\r
+ return true;\r
+ }\r
+ } \r
+ return false;\r
+ }\r
+ \r
+ public String getErrorMessages() {\r
+ StringBuilder msgs = new StringBuilder("");\r
+ for (String name : dataObjects.keySet()) { \r
+ if (dataObjects.get(name).isError()) { \r
+ msgs.append(name + ": " + dataObjects.get(name).getErrorMessage());\r
+ } \r
+ }\r
+ return msgs.toString();\r
+ }\r
+ \r
+ public String getFirstErrorMessage() {\r
+ if (dataObjects.get("search").isError()) {\r
+ return "Error doing search: " + dataObjects.get("search").getErrorMessage();\r
+ }\r
+ for (String name : dataObjects.keySet()) { \r
+ if (dataObjects.get(name).isError()) { \r
+ return name + ": " + dataObjects.get(name).getErrorMessage(); \r
+ } \r
+ }\r
+ return "";\r
+ \r
+ }\r
+\r
\r
private boolean hasTargetFilter(TargetFilter targetFilter) {\r
return hasTargetFilter() && targetFilter.equals(this.targetFilter);\r
} \r
}\r
\r
- private String getActiveClients() {\r
- logger.debug("Active clients: "+getShow().getActiveClients());\r
+ private String getActiveClients() { \r
if (getShow()!=null) {\r
+ logger.debug("Active clients: "+getShow().getActiveClients());\r
return getShow().getActiveClients();\r
} else {\r
return "";\r
}\r
\r
private void resetDataObjects() {\r
- logger.debug("Resetting show,stat,termlist,bytarget response objects.");\r
+ logger.debug("Resetting show,stat,termlist,bytarget,search response objects.");\r
dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
dataObjects.put("show", new ShowResponse());\r
dataObjects.put("stat", new StatResponse());\r
dataObjects.put("termlist", new TermListsResponse());\r
dataObjects.put("bytarget", new ByTarget());\r
dataObjects.put("record", new RecordResponse());\r
+ dataObjects.put("search", new SearchResponse());\r
}\r
+ \r
\r
}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.data;\r
+\r
+public class Pazpar2ErrorResponse extends Pazpar2ResponseData {\r
+\r
+ private static final long serialVersionUID = 5261091417784893149L;\r
+\r
+}\r
HashMap<String,String> attributes = new HashMap<String,String>();\r
HashMap<String,List<Pazpar2ResponseData>> elements = new HashMap<String,List<Pazpar2ResponseData>>();\r
String textContent = "";\r
+ String errorText = null;\r
\r
public void setType (String type) {\r
this.type = type;\r
return Integer.parseInt(val);\r
}\r
}\r
+ \r
+ public boolean isError () {\r
+ return (getOneElement("error") != null); \r
+ }\r
+ \r
+ public String getErrorMessage() {\r
+ return getOneElementValue("error");\r
+ }\r
\r
\r
}\r
private Pazpar2ResponseData result = null;\r
\r
private static final List<String> docTypes = \r
- Arrays.asList("bytarget","termlist","show","stat","record");\r
+ Arrays.asList("bytarget","termlist","show","stat","record","search");\r
\r
public Pazpar2ResponseParser() { \r
try {\r
((TermListResponse)dataElements.peek()).addTerm((TermResponse)currentElement);\r
} else if (localName.equals("record")) {\r
currentElement = new RecordResponse();\r
+ } else if (localName.equals("search")) {\r
+ currentElement = new SearchResponse();\r
} else {\r
currentElement = new Pazpar2ResponseData();\r
}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.data;\r
+\r
+public class SearchResponse extends Pazpar2ResponseData {\r
+\r
+ private static final long serialVersionUID = -3320013021497018972L;\r
+ \r
+}\r
\r
\r
public String getStatus() {\r
- return getOneElement("status").getValue();\r
+ return getOneElementValue("status");\r
}\r
\r
public String getActiveClients () {\r
public String getActiveclients () {\r
return ":pz2watch:activeclientsForm:activeclientsField";\r
}\r
+ \r
+ public String getErrorMessages () {\r
+ return ":pz2watch:activeclientsForm:errorMessages";\r
+ }\r
\r
}\r