1 package com.indexdata.mkjsf.pazpar2.commands;
\r
4 * Represents a query parameter as it applies to the Pazpar2 search command
\r
6 * <p>A query parameter can consist of a term value and/or one or more expressions
\r
7 * separated by boolean operators.</p>
\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
15 * @author Niels Erik
\r
18 public class QueryParameter extends CommandParameter {
\r
20 private static final long serialVersionUID = -3649052232241100927L;
\r
21 private String booleanOperator = "AND";
\r
23 public QueryParameter(String name) {
\r
27 public QueryParameter(String name, String operator, String value,
\r
28 Expression... expressions) {
\r
29 super(name, operator, value, expressions);
\r
32 public QueryParameter(String name, String operator, Expression... expressions) {
\r
33 super(name, operator, expressions);
\r
36 public QueryParameter(String name, String operator, String value) {
\r
37 super(name, operator, value);
\r
40 public QueryParameter(String name, String operator, int value) {
\r
41 super(name, operator, value);
\r
44 public void setBooleanOperator (String operator) {
\r
45 this.booleanOperator = operator;
\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
54 completeValue.append(expr.toString());
\r
56 completeValue.append(" "+booleanOperator+" " + expr.toString());
\r
59 return completeValue.toString();
\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