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