package com.indexdata.mkjsf.pazpar2.commands.sp;\r
\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
\r
+/**\r
+ * Retrieves target categories available to the current Service Proxy user.\r
+ * <p>\r
+ * Target categories can be used to limit a search to resources tagged with the given \r
+ * category. The following request in a Faces page would obtain categories for displaying, say, a select list:\r
+ * <p>\r
+ * pzreq.sp.categories.run().targetCategories \r
+ * <p>\r
+ * This would get the Service Proxy extension commands, pick the categories command, execute it, and retrieve\r
+ * a list of TargetCategory objects from the returned response data object. \r
+ * </p>\r
+ * @author Niels Erik\r
+ *\r
+ */\r
public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 5023993689780291641L;\r
+ private static Logger logger = Logger.getLogger(CategoriesCommand.class);\r
\r
- public CategoriesCommand(StateManager stateMgr) {\r
- super("categories", stateMgr);\r
+ public CategoriesCommand() {\r
+ super("categories");\r
+ }\r
+ \r
+ @Override\r
+ public CategoriesResponse run () {\r
+ if (Pz2Service.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
+ logger.info("Skipping seemingly unsupported categories command"); \r
+ return new CategoriesResponse();\r
+ } else {\r
+ if (Pz2Service.get().isServiceProxyService()) {\r
+ try {\r
+ CategoriesResponse response = (CategoriesResponse) super.run();\r
+ if (response.unsupportedCommand()) {\r
+ logger.warn("Command 'categories' not supported by this Service Proxy"); \r
+ }\r
+ return response;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return new CategoriesResponse();\r
+ }\r
+ } else {\r
+ return new CategoriesResponse();\r
+ }\r
+ }\r
}\r
\r
@Override\r
public Pazpar2Command copy() {\r
- CategoriesCommand newCommand = new CategoriesCommand(stateMgr);\r
+ CategoriesCommand newCommand = new CategoriesCommand();\r
return newCommand;\r
}\r
\r