PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/lolay/citygrid/content/places/detail/DetailInvoker.java

https://github.com/lolay/citygrid-java-old
Java | 213 lines | 165 code | 26 blank | 22 comment | 4 complexity | aabffeef4924e5fb65f08ba43e1be36c MD5 | raw file
  1. /*
  2. * Licensed to Lolay, Inc. under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. Lolay, Inc. 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://github.com/lolay/citygrid/raw/master/LICENSE
  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
  17. * under the License.
  18. */
  19. package com.lolay.citygrid.content.places.detail;
  20. import java.io.Serializable;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import com.lolay.citygrid.BaseInvoker;
  24. import com.lolay.citygrid.Format;
  25. import com.lolay.citygrid.InvokerException;
  26. /**
  27. * @see http://docs.citygridmedia.com/display/citygridv2/Places+API#PlacesAPI-PlacesDetail
  28. * @see DetailClient
  29. */
  30. public class DetailInvoker extends BaseInvoker {
  31. private static final long serialVersionUID = 1L;
  32. private static final Log log = LogFactory.getLog(DetailInvoker.class);
  33. private Long warningLimit = 10000L;
  34. private Integer listingId = null;
  35. private Integer infoUsaId = null;
  36. private String phone = null;
  37. private String publisher = null;
  38. private String apiKey = null;
  39. private Boolean customerOnly = null;
  40. private Boolean allResults = null;
  41. private Integer reviewCount = null;
  42. private String placement = null;
  43. private String clientIp = null;
  44. public Long getWarningLimit() {
  45. return warningLimit;
  46. }
  47. public void setWarningLimit(Long warningLimit) {
  48. this.warningLimit = warningLimit;
  49. }
  50. public Integer getListingId() {
  51. return listingId;
  52. }
  53. public void setListingId(Integer listingId) {
  54. this.listingId = listingId;
  55. }
  56. public Integer getInfoUsaId() {
  57. return infoUsaId;
  58. }
  59. public void setInfoUsaId(Integer infoUsaId) {
  60. this.infoUsaId = infoUsaId;
  61. }
  62. public String getPhone() {
  63. return phone;
  64. }
  65. public void setPhone(String phone) {
  66. this.phone = phone;
  67. }
  68. public String getPublisher() {
  69. return publisher;
  70. }
  71. public void setPublisher(String publisher) {
  72. this.publisher = publisher;
  73. }
  74. public String getApiKey() {
  75. return apiKey;
  76. }
  77. public void setApiKey(String apiKey) {
  78. this.apiKey = apiKey;
  79. }
  80. public Boolean getCustomerOnly() {
  81. return customerOnly;
  82. }
  83. public void setCustomerOnly(Boolean customerOnly) {
  84. this.customerOnly = customerOnly;
  85. }
  86. public Boolean getAllResults() {
  87. return allResults;
  88. }
  89. public void setAllResults(Boolean allResults) {
  90. this.allResults = allResults;
  91. }
  92. public Integer getReviewCount() {
  93. return reviewCount;
  94. }
  95. public void setReviewCount(Integer reviewCount) {
  96. this.reviewCount = reviewCount;
  97. }
  98. public String getPlacement() {
  99. return placement;
  100. }
  101. public void setPlacement(String placement) {
  102. this.placement = placement;
  103. }
  104. public String getClientIp() {
  105. return clientIp;
  106. }
  107. public void setClientIp(String clientIp) {
  108. this.clientIp = clientIp;
  109. }
  110. public DetailResults profile(DetailClient client) throws InvokerException {
  111. DetailResults results;
  112. Long start = System.currentTimeMillis();
  113. results = parseResults(DetailResults.class, client.profile(getListingId(), getInfoUsaId(),
  114. getPhone(), getPublisher(), getApiKey(), getCustomerOnly(), getAllResults(),
  115. getReviewCount(), getPlacement(), getClientIp(), Format.XML));
  116. Long end = System.currentTimeMillis();
  117. Long diff = end - start;
  118. if (log.isTraceEnabled()) {
  119. log.trace(String.format("CityGrid profile took %s milliseconds", diff));
  120. } else if (log.isWarnEnabled() && diff > getWarningLimit()) {
  121. log.warn(String.format("CityGrid profile took %s milliseconds which is longer than the threshold %s milliseconds", diff, getWarningLimit()));
  122. }
  123. return results;
  124. }
  125. public static Builder builder(DetailInvoker prototype) {
  126. return builder().listingId(prototype.getListingId()).infoUsaId(prototype.getInfoUsaId())
  127. .phone(prototype.getPhone()).publisher(prototype.getPublisher())
  128. .apiKey(prototype.getApiKey()).customerOnly(prototype.getCustomerOnly())
  129. .allResults(prototype.getAllResults()).reviewCount(prototype.getReviewCount())
  130. .placement(prototype.getPlacement()).clientIp(prototype.getClientIp());
  131. }
  132. public static Builder builder() {
  133. return new Builder();
  134. }
  135. public static class Builder implements Serializable {
  136. private static final long serialVersionUID = 1L;
  137. private DetailInvoker instance = new DetailInvoker();
  138. private Builder() { }
  139. public Builder warningLimit(Long warningLimit) {
  140. instance.setWarningLimit(warningLimit);
  141. return this;
  142. }
  143. public Builder listingId(Integer listingId) {
  144. instance.setListingId(listingId);
  145. return this;
  146. }
  147. public Builder infoUsaId(Integer infoUsaId) {
  148. instance.setInfoUsaId(infoUsaId);
  149. return this;
  150. }
  151. public Builder phone(String phone) {
  152. instance.setPhone(phone);
  153. return this;
  154. }
  155. public Builder publisher(String publisher) {
  156. instance.setPublisher(publisher);
  157. return this;
  158. }
  159. public Builder apiKey(String apiKey) {
  160. instance.setApiKey(apiKey);
  161. return this;
  162. }
  163. public Builder customerOnly(Boolean customerOnly) {
  164. instance.setCustomerOnly(customerOnly);
  165. return this;
  166. }
  167. public Builder allResults(Boolean allResults) {
  168. instance.setAllResults(allResults);
  169. return this;
  170. }
  171. public Builder reviewCount(Integer reviewCount) {
  172. instance.setReviewCount(reviewCount);
  173. return this;
  174. }
  175. public Builder placement(String placement) {
  176. instance.setPlacement(placement);
  177. return this;
  178. }
  179. public Builder clientIp(String clientIp) {
  180. instance.setClientIp(clientIp);
  181. return this;
  182. }
  183. public DetailInvoker build() {
  184. return instance;
  185. }
  186. }
  187. }