Renames class, removes obsolete, javadoc
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / sp / CategoriesCommand.java
1 package com.indexdata.mkjsf.pazpar2.commands.sp;\r
2 \r
3 import org.apache.log4j.Logger;\r
4 \r
5 import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
6 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
7 import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
8 \r
9 /**\r
10  * Represents a Service Proxy <code>categories</code> command, can be accessed by <code>pzreq.sp.categories</code>\r
11  * \r
12  * <p>Retrieves target categories available to the current Service Proxy user.</p> \r
13  * <p>Target categories can be used to limit a search to resources tagged with the given \r
14  * category. The following request in a Faces page would obtain categories for display in, say, a select list:\r
15  * <p>\r
16  *  <code>pzreq.sp.categories.run().targetCategories</code>   \r
17  * <p>\r
18  * This would get the Service Proxy extension commands, pick the categories command, execute it, and retrieve\r
19  *  a list of TargetCategory objects from the returned response data object.  \r
20  * </p>\r
21  * @author Niels Erik\r
22  *\r
23  */\r
24 public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand {\r
25 \r
26   private static final long serialVersionUID = 5023993689780291641L;\r
27   private static Logger logger = Logger.getLogger(CategoriesCommand.class);\r
28 \r
29   public CategoriesCommand() {\r
30     super("categories");\r
31   }\r
32   \r
33   @Override\r
34   public CategoriesResponse run () {\r
35     if (Pz2Service.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
36       logger.info("Skipping seemingly unsupported categories command");  \r
37       return new CategoriesResponse();\r
38     } else {\r
39       if (Pz2Service.get().isServiceProxyService()) {\r
40         try {\r
41           CategoriesResponse response = (CategoriesResponse) super.run();\r
42           if (response.unsupportedCommand()) {\r
43             logger.warn("Command 'categories' not supported by this Service Proxy");          \r
44           }\r
45           return response;\r
46         } catch (Exception e) {\r
47           e.printStackTrace();\r
48           return new CategoriesResponse();\r
49         }\r
50       } else {\r
51         return new CategoriesResponse();\r
52       }\r
53     }\r
54   }\r
55 \r
56   @Override\r
57   public Pazpar2Command copy() {\r
58     CategoriesCommand newCommand = new CategoriesCommand();\r
59     return newCommand;\r
60   }\r
61 \r
62   @Override\r
63   public ServiceProxyCommand getSp() {\r
64     return this;\r
65   }\r
66 \r
67   @Override\r
68   public boolean spOnly() {\r
69     return true;\r
70   }\r
71 \r
72 }\r