| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | package org.topazproject.ambra.search2; |
|---|
| 22 | |
|---|
| 23 | import java.io.Serializable; |
|---|
| 24 | import java.text.DateFormat; |
|---|
| 25 | import java.text.ParseException; |
|---|
| 26 | import java.text.SimpleDateFormat; |
|---|
| 27 | import java.util.Arrays; |
|---|
| 28 | import java.util.Date; |
|---|
| 29 | import java.util.LinkedList; |
|---|
| 30 | import java.util.List; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | public class SearchParameters implements Serializable { |
|---|
| 49 | |
|---|
| 50 | private static final long serialVersionUID = -7837640277704487921L; |
|---|
| 51 | private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|---|
| 52 | |
|---|
| 53 | private String query = ""; |
|---|
| 54 | private String textSearchAll = ""; |
|---|
| 55 | private String textSearchExactPhrase = ""; |
|---|
| 56 | private String textSearchAtLeastOne = ""; |
|---|
| 57 | private String textSearchWithout = ""; |
|---|
| 58 | private String textSearchOption = ""; |
|---|
| 59 | private String[] creator = {}; |
|---|
| 60 | private String authorNameOp = ""; |
|---|
| 61 | private String subjectCatOpt = ""; |
|---|
| 62 | private String dateTypeSelect = ""; |
|---|
| 63 | private Date startDate = null; |
|---|
| 64 | private Date endDate = null; |
|---|
| 65 | private String[] limitToCategory = {}; |
|---|
| 66 | private String journalOpt = ""; |
|---|
| 67 | |
|---|
| 68 | private String[] limitToJournal = {}; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | private int startPage = 0; |
|---|
| 72 | private int pageSize = 0; |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | public String getQuery() { |
|---|
| 76 | return query; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public void setQuery(String query) { |
|---|
| 80 | if (query == null || query.trim().length() < 1) |
|---|
| 81 | this.query = ""; |
|---|
| 82 | else |
|---|
| 83 | this.query = query.trim(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | public String[] getCreator() { |
|---|
| 87 | return creator; |
|---|
| 88 | } |
|---|
| 89 | public void setCreator(String[] creator) { |
|---|
| 90 | if (creator == null || creator.length < 1) { |
|---|
| 91 | this.creator = new String[]{}; |
|---|
| 92 | } else { |
|---|
| 93 | List<String> creatorList = new LinkedList<String>(); |
|---|
| 94 | for (String author : creator) { |
|---|
| 95 | if (author != null && author.trim().length() > 0) |
|---|
| 96 | creatorList.add(author.trim()); |
|---|
| 97 | } |
|---|
| 98 | this.creator = new String[creatorList.size()]; |
|---|
| 99 | int counter = 0; |
|---|
| 100 | for (String author : creatorList) { |
|---|
| 101 | this.creator[counter++] = author; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | public String getAuthorNameOp() { |
|---|
| 107 | return authorNameOp; |
|---|
| 108 | } |
|---|
| 109 | public void setAuthorNameOp(String authorNameOp) { |
|---|
| 110 | if (authorNameOp == null || authorNameOp.trim().length() < 1) |
|---|
| 111 | this.authorNameOp = ""; |
|---|
| 112 | else |
|---|
| 113 | this.authorNameOp = authorNameOp.trim(); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | public String getTextSearchAll() { |
|---|
| 117 | return textSearchAll; |
|---|
| 118 | } |
|---|
| 119 | public void setTextSearchAll(String textSearchAll) { |
|---|
| 120 | if (textSearchAll == null || textSearchAll.trim().length() < 1) |
|---|
| 121 | this.textSearchAll = ""; |
|---|
| 122 | else |
|---|
| 123 | this.textSearchAll = textSearchAll.trim(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | public String getTextSearchExactPhrase() { |
|---|
| 127 | return textSearchExactPhrase; |
|---|
| 128 | } |
|---|
| 129 | public void setTextSearchExactPhrase(String textSearchExactPhrase) { |
|---|
| 130 | if (textSearchExactPhrase == null || textSearchExactPhrase.trim().length() < 1) |
|---|
| 131 | this.textSearchExactPhrase = ""; |
|---|
| 132 | else |
|---|
| 133 | this.textSearchExactPhrase = textSearchExactPhrase.trim(); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | public String getTextSearchAtLeastOne() { |
|---|
| 137 | return textSearchAtLeastOne; |
|---|
| 138 | } |
|---|
| 139 | public void setTextSearchAtLeastOne(String textSearchAtLeastOne) { |
|---|
| 140 | if (textSearchAtLeastOne == null || textSearchAtLeastOne.trim().length() < 1) |
|---|
| 141 | this.textSearchAtLeastOne = ""; |
|---|
| 142 | else |
|---|
| 143 | this.textSearchAtLeastOne = textSearchAtLeastOne.trim(); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | public String getTextSearchWithout() { |
|---|
| 147 | return textSearchWithout; |
|---|
| 148 | } |
|---|
| 149 | public void setTextSearchWithout(String textSearchWithout) { |
|---|
| 150 | if (textSearchWithout == null || textSearchWithout.trim().length() < 1) |
|---|
| 151 | this.textSearchWithout = ""; |
|---|
| 152 | else |
|---|
| 153 | this.textSearchWithout = textSearchWithout.trim(); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | public String getTextSearchOption() { |
|---|
| 157 | return textSearchOption; |
|---|
| 158 | } |
|---|
| 159 | public void setTextSearchOption(String textSearchOption) { |
|---|
| 160 | if (textSearchOption == null || textSearchOption.trim().length() < 1) |
|---|
| 161 | this.textSearchOption = ""; |
|---|
| 162 | else |
|---|
| 163 | this.textSearchOption = textSearchOption.trim(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public String getSubjectCatOpt() { |
|---|
| 167 | return subjectCatOpt; |
|---|
| 168 | } |
|---|
| 169 | public void setSubjectCatOpt(String subjectCatOpt) { |
|---|
| 170 | if (subjectCatOpt == null || subjectCatOpt.trim().length() < 1) |
|---|
| 171 | this.subjectCatOpt = ""; |
|---|
| 172 | else |
|---|
| 173 | this.subjectCatOpt = subjectCatOpt.trim(); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | public String getDateTypeSelect() { |
|---|
| 177 | return dateTypeSelect; |
|---|
| 178 | } |
|---|
| 179 | public void setDateTypeSelect(String dateTypeSelect) { |
|---|
| 180 | if (dateTypeSelect == null || dateTypeSelect.trim().length() < 1) |
|---|
| 181 | this.dateTypeSelect = ""; |
|---|
| 182 | else |
|---|
| 183 | this.dateTypeSelect = dateTypeSelect.trim(); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | public Date getStartDate() { |
|---|
| 187 | return startDate; |
|---|
| 188 | } |
|---|
| 189 | public void setStartDate(Date startDate) { |
|---|
| 190 | this.startDate = startDate; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | public String getStartDateAsString() { |
|---|
| 196 | if (startDate == null) |
|---|
| 197 | return ""; |
|---|
| 198 | else |
|---|
| 199 | return dateFormat.format(startDate); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | public void setStartDateAsString(String startDateAsString) throws ParseException { |
|---|
| 208 | if (startDateAsString == null || startDateAsString.trim().length() < 1) |
|---|
| 209 | this.startDate = null; |
|---|
| 210 | else |
|---|
| 211 | this.startDate = dateFormat.parse(startDateAsString.trim()); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | public Date getEndDate() { |
|---|
| 215 | return endDate; |
|---|
| 216 | } |
|---|
| 217 | public void setEndDate(Date endDate) { |
|---|
| 218 | this.endDate = endDate; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | public String getEndDateAsString() { |
|---|
| 224 | if (endDate == null) |
|---|
| 225 | return ""; |
|---|
| 226 | else |
|---|
| 227 | return dateFormat.format(endDate); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | public void setEndDateAsString(String endDateAsString) throws ParseException { |
|---|
| 236 | if (endDateAsString == null || endDateAsString.trim().length() < 1) |
|---|
| 237 | this.endDate = null; |
|---|
| 238 | else |
|---|
| 239 | this.endDate = dateFormat.parse(endDateAsString.trim()); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | public boolean isDateRangeValid() { |
|---|
| 247 | if (startDate == null || endDate == null || endDate.before(startDate)) |
|---|
| 248 | return false; |
|---|
| 249 | else |
|---|
| 250 | return true; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | public String[] getLimitToCategory() { |
|---|
| 254 | return limitToCategory; |
|---|
| 255 | } |
|---|
| 256 | public void setLimitToCategory(String[] limitToCategory) { |
|---|
| 257 | if (limitToCategory == null || limitToCategory.length < 1) { |
|---|
| 258 | this.limitToCategory = new String[]{}; |
|---|
| 259 | } else { |
|---|
| 260 | List<String> limitToCategoryList = new LinkedList<String>(); |
|---|
| 261 | for (String category : limitToCategory) { |
|---|
| 262 | if (category != null && category.trim().length() > 0) |
|---|
| 263 | limitToCategoryList.add(category.trim()); |
|---|
| 264 | } |
|---|
| 265 | this.limitToCategory = new String[limitToCategoryList.size()]; |
|---|
| 266 | int counter = 0; |
|---|
| 267 | for (String category : limitToCategoryList) { |
|---|
| 268 | this.limitToCategory[counter++] = category; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | public String getJournalOpt() { |
|---|
| 274 | return journalOpt; |
|---|
| 275 | } |
|---|
| 276 | public void setJournalOpt(String journalOpt) { |
|---|
| 277 | if (journalOpt == null || journalOpt.trim().length() < 1) |
|---|
| 278 | this.journalOpt = ""; |
|---|
| 279 | else |
|---|
| 280 | this.journalOpt = journalOpt.trim(); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | public String[] getLimitToJournal() { |
|---|
| 284 | return limitToJournal; |
|---|
| 285 | } |
|---|
| 286 | public void setLimitToJournal(String[] limitToJournal) { |
|---|
| 287 | if (limitToJournal == null || limitToJournal.length < 1) { |
|---|
| 288 | this.limitToJournal = new String[]{}; |
|---|
| 289 | } else { |
|---|
| 290 | List<String> limitToJournalList = new LinkedList<String>(); |
|---|
| 291 | for (String journal : limitToJournal) { |
|---|
| 292 | if (journal != null && journal.trim().length() > 0) |
|---|
| 293 | limitToJournalList.add(journal.trim()); |
|---|
| 294 | } |
|---|
| 295 | this.limitToJournal = new String[limitToJournalList.size()]; |
|---|
| 296 | int counter = 0; |
|---|
| 297 | for (String journal : limitToJournalList) { |
|---|
| 298 | this.limitToJournal[counter++] = journal; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | public int getStartPage() { |
|---|
| 304 | return startPage; |
|---|
| 305 | } |
|---|
| 306 | public void setStartPage(int startPage) { |
|---|
| 307 | this.startPage = startPage; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | public int getPageSize() { |
|---|
| 311 | return pageSize; |
|---|
| 312 | } |
|---|
| 313 | public void setPageSize(int pageSize) { |
|---|
| 314 | this.pageSize = pageSize; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | public boolean isContainsSearchTerms() { |
|---|
| 325 | if (getCreator().length > 0 |
|---|
| 326 | || getTextSearchAll().length() > 0 || getTextSearchAtLeastOne().length() > 0 |
|---|
| 327 | || getTextSearchExactPhrase().length() > 0 || getTextSearchWithout().length() > 0 |
|---|
| 328 | || ( getStartDate() != null && getEndDate() != null && ! getStartDate().equals(getEndDate()) ) ) |
|---|
| 329 | return true; |
|---|
| 330 | return false; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | @Override |
|---|
| 334 | public String toString() { |
|---|
| 335 | return "SearchParameters{" + |
|---|
| 336 | "query='" + query + '\'' + |
|---|
| 337 | ", textSearchAll='" + textSearchAll + '\'' + |
|---|
| 338 | ", textSearchExactPhrase='" + textSearchExactPhrase + '\'' + |
|---|
| 339 | ", textSearchAtLeastOne='" + textSearchAtLeastOne + '\'' + |
|---|
| 340 | ", textSearchWithout='" + textSearchWithout + '\'' + |
|---|
| 341 | ", textSearchOption='" + textSearchOption + '\'' + |
|---|
| 342 | ", creator=" + (creator == null ? null : Arrays.asList(creator)) + |
|---|
| 343 | ", authorNameOp='" + authorNameOp + '\'' + |
|---|
| 344 | ", subjectCatOpt='" + subjectCatOpt + '\'' + |
|---|
| 345 | ", dateTypeSelect='" + dateTypeSelect + '\'' + |
|---|
| 346 | ", startDate=" + startDate + |
|---|
| 347 | ", endDate=" + endDate + |
|---|
| 348 | ", limitToCategory=" + (limitToCategory == null ? null : Arrays.asList(limitToCategory)) + |
|---|
| 349 | ", journalOpt='" + journalOpt + '\'' + |
|---|
| 350 | ", limitToJournal=" + (limitToJournal == null ? null : Arrays.asList(limitToJournal)) + |
|---|
| 351 | ", startPage=" + startPage + |
|---|
| 352 | ", pageSize=" + pageSize + |
|---|
| 353 | '}'; |
|---|
| 354 | } |
|---|
| 355 | } |
|---|