BrightSide Workbench Full Report + Source Code
DaoSearchKey.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.jpa.search;
20 
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import org.turro.string.Strings;
26 import org.jdom.Attribute;
27 import org.jdom.Element;
28 import org.turro.elephant.context.IConstructor;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.sql.SQLUtil;
31 
36 public class DaoSearchKey implements Serializable {
37 
38  private final String type, name;
39  private String tag, value;
40  private final HashMap<String, String> attributes;
41  private final ArrayList<String> options;
42 
43  public DaoSearchKey(String name, String type) {
44  this.name = name;
45  this.type = type;
46  attributes = new HashMap<>();
47  options = new ArrayList<>();
48  }
49 
50  public String getTag() {
51  return tag;
52  }
53 
54  public String getType() {
55  return type;
56  }
57 
58  public String getName() {
59  return name;
60  }
61 
62  public String getValue() {
63  return value == null ? "" : value;
64  }
65 
66  public String getValue(String defaultValue) {
67  return value == null ? defaultValue : value;
68  }
69 
70  public void setValue(String value) {
71  this.value = value;
72  }
73 
74  public HashMap<String, String> getAttributes() {
75  return attributes;
76  }
77 
78  public ArrayList<String> getOptions() {
79  return options;
80  }
81 
82  public void readXML(Element item) {
83  tag = item.getName();
84  for(Object attr : item.getAttributes()) {
85  if(attr instanceof Attribute) {
86  Attribute attribute = (Attribute) attr;
87  String name = attribute.getName();
88  if(!name.equals("name") && !name.equals("type")) {
89  attributes.put(name, attribute.getValue());
90  }
91  }
92  }
93  for(Element option : (List<Element>) item.getChildren()) {
94  options.add(option.getTextNormalize());
95  }
96  }
97 
98  public void readParam(IConstructor constructor) {
99  value = constructor.getParameter(name);
100  }
101 
102  public boolean applyToQuery(WhereClause wc, List<String> fields, boolean withSynonyms) {
103  if(!Strings.isBlank(getValue())) {
104  SQLUtil.applySearchToQuery(getValue(), wc, fields, withSynonyms);
105  return true;
106  }
107  return false;
108  }
109 
110  public boolean applyToQueryFull(WhereClause wc, String fields, boolean withSynonyms) {
111  if(!Strings.isBlank(getValue())) {
112  SQLUtil.applyFullsearchToQuery(getValue(), wc, fields, withSynonyms);
113  return true;
114  }
115  return false;
116  }
117 
118 }
boolean applyToQueryFull(WhereClause wc, String fields, boolean withSynonyms)
ArrayList< String > getOptions()
void readParam(IConstructor constructor)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
HashMap< String, String > getAttributes()
DaoSearchKey(String name, String type)
String getValue(String defaultValue)
static void applyFullsearchToQuery(String search, WhereClause wc, String fields)
Definition: SQLUtil.java:69
static void applySearchToQuery(String search, WhereClause wc, List< String > fields)
Definition: SQLUtil.java:36