Coverage Report - org.codeforamerica.open311.facade.data.operations.GETServiceRequestsFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
GETServiceRequestsFilter
85%
17/20
78%
11/14
2.167
 
 1  
 package org.codeforamerica.open311.facade.data.operations;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Date;
 5  
 import java.util.HashMap;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.codeforamerica.open311.facade.APIWrapper;
 9  
 import org.codeforamerica.open311.facade.data.ServiceRequest.Status;
 10  
 import org.codeforamerica.open311.internals.parsing.DataParser;
 11  
 import org.codeforamerica.open311.internals.parsing.DateParser;
 12  
 
 13  
 /**
 14  
  * Useful to pass optional parameters to the
 15  
  * {@link APIWrapper#getServiceRequests(GETServiceRequestsFilter)} operation.
 16  
  * 
 17  
  * Use the method chaining to add optional values to the object.
 18  
  * 
 19  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 20  
  * 
 21  
  */
 22  5
 public class GETServiceRequestsFilter implements Serializable {
 23  
 
 24  
         private static final long serialVersionUID = 3037178220547056225L;
 25  5
         private Map<String, String> parameters = new HashMap<String, String>();
 26  
 
 27  
         /**
 28  
          * Adds one or more service request ids to the filtering parameters.
 29  
          * 
 30  
          * @param serviceRequestId
 31  
          *            A comma delimited list of service request ids. Example:
 32  
          *            <code>1</code> or </code>1,2,3</code>.
 33  
          * @return The same object with the given parameter added as an argument.
 34  
          */
 35  
         public GETServiceRequestsFilter setServiceRequestId(String serviceRequestId) {
 36  2
                 if (serviceRequestId != null && serviceRequestId.length() > 0) {
 37  0
                         parameters.put(DataParser.SERVICE_REQUEST_ID_TAG, serviceRequestId);
 38  
                 }
 39  2
                 return this;
 40  
         }
 41  
 
 42  
         public GETServiceRequestsFilter setServiceCode(String serviceCode) {
 43  5
                 if (serviceCode != null && serviceCode.length() > 0) {
 44  3
                         parameters.put(DataParser.SERVICE_CODE_TAG, serviceCode);
 45  
                 }
 46  5
                 return this;
 47  
         }
 48  
 
 49  
         public GETServiceRequestsFilter setStartDate(Date startDate) {
 50  1
                 if (startDate != null) {
 51  0
                         parameters.put(DataParser.START_DATE_TAG,
 52  
                                         new DateParser().printDate(startDate));
 53  
                 }
 54  1
                 return this;
 55  
         }
 56  
 
 57  
         public GETServiceRequestsFilter setEndDate(Date endDate) {
 58  1
                 if (endDate != null) {
 59  0
                         parameters.put(DataParser.END_DATE_TAG,
 60  
                                         new DateParser().printDate(endDate));
 61  
                 }
 62  1
                 return this;
 63  
         }
 64  
 
 65  
         public GETServiceRequestsFilter setStatus(Status status) {
 66  2
                 if (status != null) {
 67  1
                         parameters.put(DataParser.STATUS_TAG, status.toString());
 68  
                 }
 69  2
                 return this;
 70  
         }
 71  
 
 72  
         /**
 73  
          * Builds a map containing all the set arguments.
 74  
          * 
 75  
          * @return List of pairs (key, value) with the required arguments.
 76  
          */
 77  
         public Map<String, String> getOptionalParametersMap() {
 78  6
                 Map<String, String> result = new HashMap<String, String>();
 79  6
                 result.putAll(parameters);
 80  6
                 return result;
 81  
         }
 82  
 }