Coverage Report - org.apache.shindig.social.opensocial.spi.CollectionOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
CollectionOptions
90%
37/41
44%
8/18
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations under the License.
 17  
  */
 18  
 package org.apache.shindig.social.opensocial.spi;
 19  
 
 20  
 import java.util.Date;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.apache.shindig.social.opensocial.service.RequestItem;
 24  
 
 25  
 public class CollectionOptions {
 26  
   private String sortBy;
 27  
   private PersonService.SortOrder sortOrder;
 28  
   private String filter;
 29  
   private PersonService.FilterOperation filterOperation;
 30  
   private String filterValue;
 31  
   private int first;
 32  
   private int max;
 33  
   private Date updatedSince;
 34  
 
 35  4
   public CollectionOptions() {}
 36  
 
 37  14
   public CollectionOptions(RequestItem request) {
 38  14
     this.sortBy = request.getSortBy();
 39  14
     this.sortOrder = request.getSortOrder();
 40  14
     this.setFilter(request.getFilterBy());
 41  14
     this.setFilterOperation(request.getFilterOperation());
 42  14
     this.setFilterValue(request.getFilterValue());
 43  14
     this.setFirst(request.getStartIndex());
 44  14
     this.setMax(request.getCount());
 45  14
     this.setUpdatedSince(request.getUpdatedSince());
 46  14
   }
 47  
   /**
 48  
    * This sortBy can be any field of the object being sorted or the special js sort of topFriends.
 49  
    * @return The field to sort by
 50  
    */
 51  
   public String getSortBy() {
 52  9
     return sortBy;
 53  
   }
 54  
 
 55  
   public void setSortBy(String sortBy) {
 56  4
     this.sortBy = sortBy;
 57  4
   }
 58  
 
 59  
   public PersonService.SortOrder getSortOrder() {
 60  9
     return sortOrder;
 61  
   }
 62  
 
 63  
   public void setSortOrder(PersonService.SortOrder sortOrder) {
 64  4
     this.sortOrder = sortOrder;
 65  4
   }
 66  
 
 67  
   /**
 68  
    * <p>
 69  
    * This filter can be any field of the object being filtered or the special js filters,
 70  
    * hasApp or topFriends.
 71  
    * Other special Filters are
 72  
    * </p>
 73  
    * <dl>
 74  
    * <dt>all</dt>
 75  
    * <dd>Retrieves all friends</dd>
 76  
    * <dt>hasApp</dt>
 77  
    * <dd>Retrieves all friends with any data for this application.</dd>
 78  
    * <dt>'topFriends</dt>
 79  
    * <dd>Retrieves only the user's top friends.</dd>
 80  
    * <dt>isFriendsWith</dt>
 81  
    * <dd>Will filter the people requested by checking if they are friends with
 82  
    * the given <a href="opensocial.IdSpec.html">idSpec</a>. Expects a
 83  
    *    filterOptions parameter to be passed with the following fields defined:
 84  
    *  - idSpec The <a href="opensocial.IdSpec.html">idSpec</a> that each person
 85  
    *        must be friends with.</dd>
 86  
    * </dl>
 87  
    * @return The field to filter by
 88  
    */
 89  
   public String getFilter() {
 90  1
     return filter;
 91  
   }
 92  
 
 93  
   public void setFilter(String filter) {
 94  18
     this.filter = filter;
 95  18
   }
 96  
 
 97  
   public PersonService.FilterOperation getFilterOperation() {
 98  1
     return filterOperation;
 99  
   }
 100  
 
 101  
   public void setFilterOperation(PersonService.FilterOperation filterOperation) {
 102  18
     this.filterOperation = filterOperation;
 103  18
   }
 104  
 
 105  
   /**
 106  
    * Where a field filter has been specified (ie a non special filter) then this is the value of the
 107  
    * filter. The exception is the isFriendsWith filter where this contains the value of the id who
 108  
    * the all the results need to be friends with.
 109  
    *
 110  
    * @return
 111  
    */
 112  
   public String getFilterValue() {
 113  1
     return filterValue;
 114  
   }
 115  
 
 116  
   public void setFilterValue(String filterValue) {
 117  18
     this.filterValue = filterValue;
 118  18
   }
 119  
 
 120  
   /**
 121  
    * When paginating, the index of the first item to fetch.
 122  
    * @return
 123  
    */
 124  
   public int getFirst() {
 125  24
     return first;
 126  
   }
 127  
 
 128  
   public void setFirst(int first) {
 129  18
     this.first = first;
 130  18
   }
 131  
 
 132  
   
 133  
   /**
 134  
    * The maximum number of items to fetch; defaults to 20. If set to a larger
 135  
    * number, a container may honor the request, or may limit the number to a
 136  
    * container-specified limit of at least 20.
 137  
    * @return
 138  
    */
 139  
   public int getMax() {
 140  8
     return max;
 141  
   }
 142  
 
 143  
   public void setMax(int max) {
 144  18
     this.max = max;
 145  18
   }
 146  
 
 147  
   public Date getUpdatedSince() {
 148  0
     return updatedSince;
 149  
   }
 150  
 
 151  
   public void setUpdatedSince(Date updatedSince) {
 152  14
     this.updatedSince = updatedSince;
 153  14
   }
 154  
 
 155  
 
 156  
   // These are overriden so that EasyMock doesn't throw a fit
 157  
   @Override
 158  
   public boolean equals(Object o) {
 159  4
     if (!(o instanceof CollectionOptions)) {
 160  0
       return false;
 161  
     }
 162  
 
 163  4
     CollectionOptions actual = (CollectionOptions) o;
 164  4
     return StringUtils.equals(this.sortBy, actual.sortBy)
 165  
         && this.sortOrder == actual.sortOrder
 166  
         && StringUtils.equals(this.filter, actual.filter)
 167  
         && this.filterOperation == actual.filterOperation
 168  
         && StringUtils.equals(this.filterValue, actual.filterValue)
 169  
         && this.first == actual.first
 170  
         && this.max == actual.max;
 171  
   }
 172  
 
 173  
   @Override
 174  
   public int hashCode() {
 175  0
     return getHashCode(this.sortBy) + getHashCode(this.sortOrder) + getHashCode(this.filter)
 176  
         + getHashCode(this.filterOperation) + getHashCode(this.filterValue)
 177  
         + getHashCode(this.first) + getHashCode(this.max);
 178  
   }
 179  
 
 180  
   private int getHashCode(Object o) {
 181  0
     return o == null ? 0 : o.hashCode();
 182  
   }
 183  
 }