6522b08562c461ec62fe74cadda0cd01ceb1320d
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / pz2utils4jsf / pazpar2 / commands / ShowCommand.java
1 package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
2 \r
3 import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
4 \r
5 public class ShowCommand extends Pazpar2Command {\r
6 \r
7   private static final long serialVersionUID = -8242768313266051307L;\r
8 \r
9   public ShowCommand(StateManager stateMgr) {\r
10     super("show",stateMgr);\r
11   }\r
12 \r
13   /**\r
14    * Sets the sort order for results, the updates the 'show' data object\r
15    * from pazpar2. Set valid sort options in the documentation for pazpar2.\r
16    * \r
17    * The parts of the UI that display 'show' data should be rendered following\r
18    * this request.\r
19    * \r
20    * @param sortOption\r
21    */\r
22   public void setSort (String sort) {\r
23     setParameter(new CommandParameter("sort","=",sort));\r
24   }\r
25   \r
26   /**\r
27    * Retrieves the current sort order for results\r
28    * @return sort order - i.e. 'relevance'\r
29    */\r
30   public String getSort () {\r
31     return getParameter("sort") != null ? getParameter("sort").value : "relevance";\r
32   }\r
33   \r
34   /**\r
35    * Sets the number of records that pazpar2 should show at a time. Is \r
36    * followed by an update of the show data object from pazpar2.  \r
37    * \r
38    * To be used by the UI for paging. After setting page size the parts\r
39    * of the UI that displays 'show' data should be rendered. \r
40    * \r
41    * @param perPageOption i.e. 10, default is 20.\r
42    */\r
43   public void setPageSize (String perPageOption) {    \r
44     setParameters(new CommandParameter("num","=",perPageOption),\r
45                   new CommandParameter("start","=",0));\r
46   }\r
47   \r
48   /**\r
49    * Retrieves the currently defined number of items to show at a time\r
50    * \r
51    * @return number of result records that will be shown from pazpar2\r
52    */\r
53   public String getPageSize () {\r
54     return getParameter("num") != null ? getParameter("num").value : "20";\r
55   }\r
56   \r
57   /**\r
58    * Sets the first record to show - starting at record '0'. After setting\r
59    * first record number, the 'show' data object will be updated from pazpar2,\r
60    * and the parts of the UI displaying show data should be re-rendered.\r
61    * \r
62    * To be used by the UI for paging.\r
63    * \r
64    * @param start first record to show\r
65    */\r
66   public void setStart (int start) {    \r
67     setParameter(new CommandParameter("start","=",start));      \r
68   }\r
69   \r
70   /**\r
71    * Retrieves the sequence number of the record that pazpaz2 will return as\r
72    * the first record in 'show'\r
73    * \r
74    * @return sequence number of the first record to be shown (numbering starting at '0')\r
75    * \r
76    */\r
77   public int getStart() {\r
78     return getParameter("start") != null ? Integer.parseInt(getParameter("start").value) : 0;\r
79   }\r
80 \r
81   \r
82   public ShowCommand copy () {\r
83     ShowCommand newCommand = new ShowCommand(stateMgr);\r
84     for (String parameterName : parameters.keySet()) {\r
85       newCommand.setParameterSilently(parameters.get(parameterName).copy());      \r
86     }    \r
87     return newCommand;\r
88   }\r
89 \r
90 }\r