1 17 package org.alfresco.service.cmr.search; 18 19 import java.util.ArrayList ; 20 21 import org.alfresco.service.cmr.repository.Path; 22 import org.alfresco.service.cmr.repository.StoreRef; 23 24 35 public class SearchParameters extends SearchStatement 36 { 37 40 private static int DEFAULT_LIMIT = 500; 41 42 45 public static final SortDefinition SORT_IN_DOCUMENT_ORDER_ASCENDING = new SortDefinition(SortDefinition.SortType.DOCUMENT, null, true); 46 public static final SortDefinition SORT_IN_DOCUMENT_ORDER_DESCENDING = new SortDefinition(SortDefinition.SortType.DOCUMENT, null, false); 47 public static final SortDefinition SORT_IN_SCORE_ORDER_ASCENDING = new SortDefinition(SortDefinition.SortType.SCORE, null, false); 48 public static final SortDefinition SORT_IN_SCORE_ORDER_DESCENDING = new SortDefinition(SortDefinition.SortType.SCORE, null, true); 49 50 54 public enum Operator 55 { 56 OR, AND 57 } 58 59 62 public static final Operator OR = Operator.OR; 63 public static final Operator AND = Operator.AND; 64 65 private ArrayList <StoreRef> stores = new ArrayList <StoreRef>(1); 66 private ArrayList <Path> attributePaths = new ArrayList <Path>(1); 67 private ArrayList <QueryParameterDefinition> queryParameterDefinitions = new ArrayList <QueryParameterDefinition>(1); 68 private boolean excludeDataInTheCurrentTransaction = false; 69 private ArrayList <SortDefinition> sortDefinitions = new ArrayList <SortDefinition>(1); 70 private Operator defaultOperator = Operator.OR; 71 72 public SearchParameters() 73 { 74 super(); 75 } 76 77 83 public void addStore(StoreRef store) 84 { 85 if(stores.size() != 0) 86 { 87 throw new IllegalStateException ("At the moment, there can only be one store set for the search"); 88 } 89 stores.add(store); 90 } 91 92 101 public void addAttrbutePath(Path attributePath) 102 { 103 attributePaths.add(attributePath); 104 } 105 106 111 public void addQueryParameterDefinition(QueryParameterDefinition queryParameterDefinition) 112 { 113 queryParameterDefinitions.add(queryParameterDefinition); 114 } 115 116 129 public void excludeDataInTheCurrentTransaction(boolean excludeDataInTheCurrentTransaction) 130 { 131 this.excludeDataInTheCurrentTransaction = excludeDataInTheCurrentTransaction; 132 } 133 134 146 public void addSort(String field, boolean ascending) 147 { 148 addSort(new SortDefinition(SortDefinition.SortType.FIELD, field, ascending)); 149 } 150 151 157 public void addSort(SortDefinition sortDefinition) 158 { 159 sortDefinitions.add(sortDefinition); 160 } 161 162 168 public static class SortDefinition 169 { 170 171 public enum SortType {FIELD, DOCUMENT, SCORE}; 172 173 SortType sortType; 174 String field; 175 boolean ascending; 176 177 SortDefinition(SortType sortType, String field, boolean ascending) 178 { 179 this.sortType = sortType; 180 this.field = field; 181 this.ascending = ascending; 182 } 183 184 public boolean isAscending() 185 { 186 return ascending; 187 } 188 189 public String getField() 190 { 191 return field; 192 } 193 194 public SortType getSortType() 195 { 196 return sortType; 197 } 198 199 } 200 201 206 public ArrayList <Path> getAttributePaths() 207 { 208 return attributePaths; 209 } 210 211 216 public boolean excludeDataInTheCurrentTransaction() 217 { 218 return excludeDataInTheCurrentTransaction; 219 } 220 221 226 public ArrayList <QueryParameterDefinition> getQueryParameterDefinitions() 227 { 228 return queryParameterDefinitions; 229 } 230 231 236 public ArrayList <SortDefinition> getSortDefinitions() 237 { 238 return sortDefinitions; 239 } 240 241 246 public ArrayList <StoreRef> getStores() 247 { 248 return stores; 249 } 250 251 256 public void setDefaultOperator(Operator defaultOperator) 257 { 258 this.defaultOperator = defaultOperator; 259 } 260 261 266 public Operator getDefaultOperator() 267 { 268 return defaultOperator; 269 } 270 271 private LimitBy limitBy = LimitBy.UNLIMITED; 272 273 private PermissionEvaluationMode permissionEvaluation = PermissionEvaluationMode.EAGER; 274 275 private int limit = DEFAULT_LIMIT; 276 277 282 public LimitBy getLimitBy() 283 { 284 return limitBy; 285 } 286 287 292 public void setLimitBy(LimitBy limitBy) 293 { 294 this.limitBy = limitBy; 295 } 296 297 302 public PermissionEvaluationMode getPermissionEvaluation() 303 { 304 return permissionEvaluation; 305 } 306 307 312 public void setPermissionEvaluation(PermissionEvaluationMode permissionEvaluation) 313 { 314 this.permissionEvaluation = permissionEvaluation; 315 } 316 317 public int getLimit() 318 { 319 return limit; 320 } 321 322 public void setLimit(int limit) 323 { 324 this.limit = limit; 325 } 326 327 328 } 329 | Popular Tags |