Fixes cce with new QueryParameter type
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / QueryParameter.java
1 package com.indexdata.mkjsf.pazpar2.commands;\r
2 \r
3 /**\r
4  * Represents a query parameter as it applies to the Pazpar2 search command\r
5  * \r
6  * <p>A query parameter can consists of a term value and/or one or more expressions \r
7  * separated by boolean operators.</p>\r
8  * \r
9  * <p>A complex query can be represented in the object as either one long string \r
10  * set by <code>setQuery(string)</code> or as a series of expressions set by \r
11  * <code>setQueryExpression(...)</code> (or a combination of the two). The difference\r
12  * between the two approaches would be the option of easily removing individual \r
13  * expressions again or otherwise treat them has separate entities in the UI.</p>\r
14  * \r
15  * @author Niels Erik\r
16  *\r
17  */\r
18 public class QueryParameter extends CommandParameter {\r
19 \r
20   private static final long serialVersionUID = -3649052232241100927L;\r
21   private String booleanOperator = "AND";\r
22 \r
23   public QueryParameter(String name) {\r
24     super(name);\r
25   }\r
26 \r
27   public QueryParameter(String name, String operator, String value,\r
28       Expression... expressions) {\r
29     super(name, operator, value, expressions);\r
30   }\r
31 \r
32   public QueryParameter(String name, String operator, Expression... expressions) {\r
33     super(name, operator, expressions);\r
34   }\r
35 \r
36   public QueryParameter(String name, String operator, String value) {\r
37     super(name, operator, value);\r
38   }\r
39 \r
40   public QueryParameter(String name, String operator, int value) {\r
41     super(name, operator, value);\r
42   }\r
43   \r
44   public void setBooleanOperator (String operator) {\r
45     this.booleanOperator = operator;\r
46   }\r
47   \r
48   public String getValueWithExpressions () {\r
49     StringBuilder completeValue = new StringBuilder((value==null ? "" : value));\r
50     boolean first = true;\r
51     for (Expression expr : expressions) {\r
52       if (value == null && first) {\r
53         first = false;\r
54         completeValue.append(expr.toString());\r
55       } else {\r
56         completeValue.append(" "+booleanOperator+" " + expr.toString());\r
57       }\r
58     }\r
59     return completeValue.toString();    \r
60   }  \r
61   \r
62   public QueryParameter copy() {    \r
63     QueryParameter newParam = new QueryParameter(name);\r
64     newParam.value = this.value;\r
65     newParam.operator = this.operator;\r
66     newParam.booleanOperator = this.booleanOperator;\r
67     for (Expression expr : expressions) {\r
68       newParam.addExpression(expr.copy());      \r
69     }\r
70     return newParam;\r
71   }\r
72 \r
73 \r
74 }\r