Coverage Report - org.codeforamerica.open311.facade.data.Service
 
Classes in this File Line Coverage Branch Coverage Complexity
Service
100%
18/18
N/A
1.545
Service$Type
100%
10/10
100%
6/6
1.545
 
 1  
 package org.codeforamerica.open311.facade.data;
 2  
 
 3  
 import java.io.Serializable;
 4  
 
 5  
 import org.codeforamerica.open311.facade.exceptions.APIWrapperException;
 6  
 
 7  
 /**
 8  
  * Represents a GeoReport service.
 9  
  * 
 10  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 11  
  * 
 12  
  */
 13  
 public class Service implements Serializable {
 14  
         private static final long serialVersionUID = 1124990264010718071L;
 15  
         private String serviceCode;
 16  
         private String serviceName;
 17  
         private String description;
 18  
         private Boolean metadata;
 19  
         private Type type;
 20  
         private String[] keywords;
 21  
         private String group;
 22  
 
 23  
         public Service(String serviceCode, String serviceName, String description,
 24  
                         Boolean metadata, Type type, String[] keywords, String group) {
 25  13
                 super();
 26  13
                 this.serviceCode = serviceCode;
 27  13
                 this.serviceName = serviceName;
 28  13
                 this.description = description;
 29  13
                 this.metadata = metadata;
 30  13
                 this.type = type;
 31  13
                 this.keywords = keywords;
 32  13
                 this.group = group;
 33  13
         }
 34  
 
 35  
         public String getServiceCode() {
 36  4
                 return serviceCode;
 37  
         }
 38  
 
 39  
         public String getServiceName() {
 40  3
                 return serviceName;
 41  
         }
 42  
 
 43  
         public String getDescription() {
 44  3
                 return description;
 45  
         }
 46  
 
 47  
         public Boolean hasMetadata() {
 48  3
                 return metadata;
 49  
         }
 50  
 
 51  
         public Type getType() {
 52  3
                 return type;
 53  
         }
 54  
 
 55  
         public String[] getKeywords() {
 56  3
                 return keywords;
 57  
         }
 58  
 
 59  
         public String getGroup() {
 60  3
                 return group;
 61  
         }
 62  
 
 63  
         /**
 64  
          * Retrieves the {@link ServiceDefinition} of this instance. This may take a
 65  
          * lot of time so it is a good idea not to do it in the UI thread.
 66  
          * 
 67  
          * @return The <a
 68  
          *         href="http://wiki.open311.org/GeoReport_v2#GET_Service_Definition"
 69  
          *         >definition</a> of the service which represents the instance.
 70  
          * @throws APIWrapperException
 71  
          *             If there was any problem getting the definition (such as IO,
 72  
          *             response parsing...) or if the instance wasn't created by an
 73  
          *             {@link APIWrapperException}.
 74  
          */
 75  
         public ServiceDefinition getServiceDefinition() throws APIWrapperException {
 76  2
                 return RelationshipManager.getInstance()
 77  
                                 .getServiceDefinitionFromService(this);
 78  
         }
 79  
 
 80  
         /**
 81  
          * Different types of Service.
 82  
          * 
 83  
          */
 84  5
         public static enum Type {
 85  1
                 REALTIME, BATCH, BLACKBOX;
 86  
                 /**
 87  
                  * Returns an instance of this class from a given string.
 88  
                  * 
 89  
                  * @param type
 90  
                  * @return <code>null</code> if the string is not one of the contained
 91  
                  *         types.
 92  
                  */
 93  
                 public static Type getFromString(String type) {
 94  18
                         type = type.toLowerCase();
 95  18
                         if (type.equals("realtime")) {
 96  12
                                 return REALTIME;
 97  
                         }
 98  6
                         if (type.equals("batch")) {
 99  2
                                 return BATCH;
 100  
                         }
 101  4
                         if (type.equals("blackbox")) {
 102  2
                                 return BLACKBOX;
 103  
                         }
 104  2
                         return null;
 105  
                 }
 106  
         }
 107  
 
 108  
         public String toString() {
 109  2
                 return "[" + this.serviceCode + "] " + this.serviceName + " ("
 110  
                                 + this.description + ")";
 111  
         }
 112  
 
 113  
 }