pzreq.getRecord().removeParametersInState();\r
pzreq.getSearch().removeParametersInState(); \r
}\r
-\r
\r
public void doSearch(String query) {\r
pzreq.getSearch().setParameter(new CommandParameter("query","=",query)); \r
doSearch();\r
}\r
\r
- public void doSearch() { \r
- stateMgr.hasPendingStateChange("search",false);\r
- pzresp.resetSearchResponses();\r
- // resets some record and show command parameters without \r
- // changing state or creating state change feedback\r
- pzreq.getRecord().removeParametersInState(); \r
- pzreq.getShow().setParameterInState(new CommandParameter("start","=",0)); \r
- logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query"));\r
- doCommand("search"); \r
+ public void doSearch() {\r
+ if (errors.hasConfigurationErrors()) {\r
+ logger.error("Ignoring search request due to configuration errors.");\r
+ } else {\r
+ stateMgr.hasPendingStateChange("search",false);\r
+ pzresp.resetSearchResponses();\r
+ // resets some record and show command parameters without \r
+ // changing state or creating state change feedback\r
+ pzreq.getRecord().removeParametersInState(); \r
+ pzreq.getShow().setParameterInState(new CommandParameter("start","=",0)); \r
+ logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query"));\r
+ doCommand("search");\r
+ }\r
}\r
\r
public String doRecord() {\r
- ResponseDataObject responseObject = doCommand("record");\r
- if (pzreq.getRecord().hasParameterValue("offset") ||\r
- pzreq.getRecord().hasParameterValue("checksum")) {\r
+ if (errors.hasConfigurationErrors()) {\r
+ logger.error("Ignoring record request due to configuration errors.");\r
+ return "";\r
+ } else if (!pzreq.getCommand("record").hasParameterValue("id")) {\r
+ logger.debug("Ignoring record request due to no id parameter.");\r
+ return "";\r
+ } else if (pzresp.getSearch().hasApplicationError()) {\r
+ logger.debug("Ignoring record request due search error.");\r
+ return "";\r
+ } else {\r
+ ResponseDataObject responseObject = doCommand("record");\r
+ if (pzreq.getRecord().hasParameterValue("offset") ||\r
+ pzreq.getRecord().hasParameterValue("checksum")) {\r
RecordResponse recordResponse = new RecordResponse();\r
recordResponse.setType("record");\r
recordResponse.setXml(responseObject.getXml());\r
recordResponse.setAttribute("activeclients", "0");\r
pzresp.put("record", recordResponse);\r
- }\r
- return pzresp.getRecord().getActiveClients(); \r
+ }\r
+ return pzresp.getRecord().getActiveClients();\r
+ }\r
}\r
\r
/**\r
*/\r
public String update () {\r
logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
- return update("show,stat,termlist,bytarget");\r
- }\r
- \r
- public boolean validateUpdateRequest(String commands) {\r
if (errors.hasConfigurationErrors()) {\r
- logger.error("The command(s) " + commands + " are cancelled due to configuration errors.");\r
- return false;\r
- } else if (!commands.equals("search") && pzresp.getSearch().hasApplicationError()) {\r
- logger.error("The command(s) " + commands + " are cancelled because the latest search command had an error.");\r
- return false;\r
- } else if (!commandsAreValid(commands)) {\r
- logger.debug("The command(s) " + commands + " are cancelled because the were not found to be ready/valid.");\r
- return false;\r
- } else if (!hasQuery() && !(commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) {\r
- logger.debug("The command(s) " + commands + " are held off because there's not yet a query.");\r
- return false;\r
+ logger.error("Ignoring show,stat,termlist,bytarget commands due to configuration errors.");\r
+ return "";\r
+ } else if (pzresp.getSearch().hasApplicationError()) {\r
+ logger.error("Ignoring show,stat,termlist,bytarget commands due to problem with most recent search.");\r
+ return "";\r
+ } else if (!hasQuery()) {\r
+ logger.error("Ignoring show,stat,termlist,bytarget commands because there is not yet a query.");\r
+ return "";\r
} else {\r
- return true;\r
+ return update("show,stat,termlist,bytarget");\r
}\r
- \r
- \r
}\r
- \r
+ \r
/**\r
* Refreshes the data objects listed in 'commands' from pazpar2\r
* \r
public String update (String commands) {\r
logger.info("Request to update: " + commands);\r
try {\r
- if (!validateUpdateRequest(commands)) {\r
- return "0";\r
- } else if (commands.equals("search")) {\r
+ if (commands.equals("search")) {\r
doSearch();\r
return "";\r
} else if (commands.equals("record")) {\r
}\r
\r
}\r
- \r
- public boolean commandsAreValid(String commands) {\r
- if (commands.equals("record")) {\r
- if (!pzreq.getCommand("record").hasParameterValue("id")) {\r
- logger.debug("Skips sending record command due to lacking id parameter");\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- \r
+ \r
public String toggleRecord (String recId) {\r
if (hasRecord(recId)) {\r
pzreq.getRecord().removeParameters(); \r
* @return An XML response parsed to form a response data object\r
*/\r
protected ResponseDataObject doCommand(String commandName) {\r
- ResponseDataObject responseObject = null; \r
- if (validateUpdateRequest(commandName)) {\r
- logger.debug(pzreq.getCommand(commandName).getEncodedQueryString() + ": Results for "+ pzreq.getCommand("search").getEncodedQueryString());\r
- Pazpar2Command command = pzreq.getCommand(commandName);\r
- long start = System.currentTimeMillis();\r
- HttpResponseWrapper commandResponse = searchClient.executeCommand(command);\r
- long end = System.currentTimeMillis();\r
- logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
- responseLogger.debug("Response was: " + commandResponse.getResponseString());\r
- responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
- if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
- pzresp.put(commandName, responseObject);\r
- } \r
- }\r
+ ResponseDataObject responseObject = null; \r
+ // logger.debug(pzreq.getCommand(commandName).getEncodedQueryString() + ": Results for "+ pzreq.getCommand("search").getEncodedQueryString());\r
+ Pazpar2Command command = pzreq.getCommand(commandName);\r
+ long start = System.currentTimeMillis();\r
+ HttpResponseWrapper commandResponse = searchClient.executeCommand(command);\r
+ long end = System.currentTimeMillis();\r
+ logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
+ responseLogger.debug("Response was: " + commandResponse.getResponseString());\r
+ responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ pzresp.put(commandName, responseObject);\r
+ } \r
return responseObject;\r
}\r
\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
import com.indexdata.mkjsf.pazpar2.data.Responses;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
public InitDocUpload getInitDocUpload () {\r
return initDocUpload;\r
}\r
+ \r
+ public CategoriesResponse getCategories () {\r
+ ResponseDataObject response = pz2.doCommand("categories");\r
+ if (response.hasApplicationError()) {\r
+ logger.debug(response.getXml());\r
+ return new CategoriesResponse();\r
+ } else {\r
+ try {\r
+ return (CategoriesResponse) response;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ logger.debug(response.getXml());\r
+ return new CategoriesResponse();\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
}\r
return (BytargetCommand) (stateMgr.getCommand(BYTARGET));\r
}\r
\r
- public Pazpar2Command getCommand(String name) {\r
+ public Pazpar2Command getCommand(String name) { \r
return stateMgr.getCommand(name);\r
}\r
\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.commands.sp;\r
+\r
+import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
+import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+\r
+public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand {\r
+\r
+ private static final long serialVersionUID = 5023993689780291641L;\r
+\r
+ public CategoriesCommand(StateManager stateMgr) {\r
+ super("categories", stateMgr);\r
+ }\r
+\r
+ @Override\r
+ public Pazpar2Command copy() {\r
+ CategoriesCommand newCommand = new CategoriesCommand(stateMgr);\r
+ return newCommand;\r
+ }\r
+\r
+ @Override\r
+ public ServiceProxyCommand getSp() {\r
+ return this;\r
+ }\r
+\r
+}\r
public class ServiceProxyCommands implements Serializable {\r
\r
public static final String AUTH = "auth";\r
+ public static final String CATEGORIES = "categories";\r
private static final long serialVersionUID = 6223527018096841188L;\r
private static Logger logger = Logger.getLogger(ServiceProxyCommands.class);\r
private StateManager stateMgr = null; \r
logger.info("Initializing ServiceProxyCommands [" + Utils.objectId(this) + "]");\r
this.stateMgr = stateMgr;\r
}\r
-\r
\r
public AuthCommand getAuth() {\r
return (AuthCommand) (stateMgr.getCommand(AUTH));\r
}\r
+ \r
+ public CategoriesCommand getCategories() {\r
+ return (CategoriesCommand) (stateMgr.getCommand(CATEGORIES));\r
+ }\r
\r
\r
}\r
import org.xml.sax.helpers.DefaultHandler;\r
\r
import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.TargetCategory;\r
\r
public class ResponseParser extends DefaultHandler {\r
\r
private static Logger logger = Logger.getLogger(ResponseParser.class);\r
\r
public static List<String> docTypes = Arrays.asList( "bytarget","termlist","show","stat","record","search","init",\r
- /* SP extras */ "auth" ); \r
+ /* SP extras */ "auth", "categories" ); \r
\r
public ResponseParser() {\r
try {\r
currentElement = new CommandError();\r
} else if (localName.equals("error") && dataElements.peek().getType().equals("applicationerror")) {\r
currentElement = new Pazpar2Error(); \r
+ // Service Proxy extras \r
} else if (localName.equals("auth")) { \r
currentElement = new AuthResponse();\r
+ } else if (localName.equals("categories")) {\r
+ currentElement = new CategoriesResponse();\r
+ } else if (localName.equals("category") && dataElements.peek().getType().equals("categories")) {\r
+ currentElement = new TargetCategory();\r
+ // Catch all\r
} else {\r
currentElement = new ResponseDataObject();\r
}\r
\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.errors.ErrorInterface;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pzresp") @SessionScoped\r
resetSearchResponses();\r
dataObjects.put("init", new InitResponse());\r
dataObjects.put("auth", new AuthResponse());\r
+ dataObjects.put("categories", new CategoriesResponse());\r
}\r
\r
public InitResponse getInit () { \r
return ((InitResponse) dataObjects.get("init"));\r
}\r
\r
- public AuthResponse getAuth () {\r
- return ((AuthResponse) dataObjects.get("auth"));\r
- }\r
-\r
public ShowResponse getShow () {\r
return ((ShowResponse) dataObjects.get("show"));\r
}\r
public TermListsResponse getTermLists () {\r
return ((TermListsResponse) dataObjects.get("termlist"));\r
}\r
- \r
+ \r
public List<TermResponse> getFacetTerms (String facet, int count) {\r
return (getTermLists().getTermList(facet).getTerms(count));\r
}\r
return ((ByTarget) dataObjects.get("bytarget"));\r
}\r
\r
+ // Service Proxy extras \r
+ public AuthResponse getAuth () {\r
+ return ((AuthResponse) dataObjects.get("auth"));\r
+ }\r
+\r
+ public CategoriesResponse getCategories() {\r
+ return ((CategoriesResponse) dataObjects.get("categories"));\r
+ }\r
+ // Service Proxy extras\r
+ \r
+\r
public ResponseDataObject getResponseObject (String name) {\r
return dataObjects.get(name);\r
}\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.data.sp;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+\r
+@SessionScoped\r
+public class CategoriesResponse extends ResponseDataObject {\r
+\r
+ private static final long serialVersionUID = 5502182636437956412L;\r
+ \r
+ public List<TargetCategory> getTargetCategories() {\r
+ List<TargetCategory> targetCategories = new ArrayList<TargetCategory>(); \r
+ if (getElements("category") != null) {\r
+ for (ResponseDataObject element : getElements("category")) {\r
+ targetCategories.add((TargetCategory)element);\r
+ }\r
+ }\r
+ return targetCategories;\r
+ }\r
+\r
+ \r
+}\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.data.sp;\r
+\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+\r
+public class TargetCategory extends ResponseDataObject {\r
+\r
+ private static final long serialVersionUID = -3027515807117682584L;\r
+\r
+ public String getCategoryName () {\r
+ return getOneElementValue("categoryName");\r
+ }\r
+ \r
+ public String getCategoryId() {\r
+ return getOneElementValue("categoryId");\r
+ }\r
+ \r
+}\r
import com.indexdata.mkjsf.pazpar2.commands.StatCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.TermlistCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.CategoriesCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands;\r
\r
/**\r
commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(mgr)); \r
\r
commands.put(ServiceProxyCommands.AUTH, new AuthCommand(mgr));\r
+ commands.put(ServiceProxyCommands.CATEGORIES, new CategoriesCommand(mgr));\r
key = "#1";\r
}\r
\r
\r
Map<String, Pazpar2State> states = new HashMap<String, Pazpar2State>();\r
String currentKey = "";\r
- private static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget","auth"));\r
+ private static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget",\r
+ /* SP extras */ "auth","categories"));\r
Map<String,Boolean> pendingStateChanges = new HashMap<String,Boolean>();\r
private static Logger logger = Logger.getLogger(StateManager.class);\r
private List<StateListener> listeners = new ArrayList<StateListener>();\r