Advertisement
Guest User

Untitled

a guest
Jul 17th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.25 KB | None | 0 0
  1.   def getSearchProductItemFitmentPage(searchProduct: SearchProduct, itemId: String, page: Int): FitmentPage = {
  2.     DB.FitmentPagesDB.ensureOpen
  3.     val fitmentPageKey = s"${searchProduct.productId}/$itemId/$page"
  4.  
  5.     // Try fetching the response from our cache first
  6.     if(DB.FitmentPagesDB.contains(fitmentPageKey)) {
  7.         val fitmentPageJson = DB.FitmentPagesDB(fitmentPageKey)
  8.         val fitmentPage = JSON.fromJSON[FitmentPage](fitmentPageJson)
  9.  
  10.         if(Option(fitmentPage.status).isDefined) return fitmentPage
  11.     }
  12.  
  13.     // Request data from remote sercie
  14.     val fitmentPageUrl = createFitmentUrl(searchProduct, itemId, page)
  15.  
  16.     val (fitmentPageJson, fitmentPage) =  Service.call("Calling Fitment JSON URL", logging = logger, maxRetries = 3) {
  17.       val fitmentPageJson: String = urlDownloader.getString(fitmentPageUrl, UrlDownloaderOptions.default)
  18.       val fitmentPage: FitmentPage = JSON.fromJSON[FitmentPage](fitmentPageJson)
  19.  
  20.       if(fitmentPage.status == null) throw new Exception(s"$fitmentPageUrl results had a null status: $fitmentPageJson")
  21.  
  22.       (fitmentPageJson, fitmentPage)
  23.     }
  24.  
  25.     DB.FitmentPagesDB.update(fitmentPageKey, fitmentPageJson) // cache the response so we don't have to re-request it
  26.     fitmentPageJson
  27.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement