Cisco Cisco Prime Home 6.5 Developer's Guide

Page of 78
Cisco Prime Home – Integration Guide
 
 
OL-28557-01   v5.0.1
 
36 
Code 
SearchService.scala 
package com.clearaccess.example.api 
 
import org.springframework.beans.factory.annotation.Autowired 
import org.springframework.web.client.RestTemplate 
import com.clearaccess.example.HttpConfiguration 
import org.json.JSONArray 
import org.springframework.stereotype.Component 
@Component 
class SearchService @Autowired()( 
val restTemplate: RestTemplate, 
val httpConfiguration: HttpConfiguration 
) { 
/** 
  * executes a CAQL query and returns results 
  * 
  * services: 
  * POST /prime-home/portal/query/execute 
  * 
  * @param caql the ClearAccess Query Language string to 
execute 
  * @return the search result json array wrapped in a 
SearchResults object 
  */ 
def query(caql: String): SearchResults = { 
val queryUrl = 
"http://%s/prime-
home/portal/query/execute".format(httpConfiguration.host) 
new SearchResults(restTemplate.postForObject(queryUrl, caql, 
classOf[JSONArray])) 
 
 
 
 
 
 
 
 
 
 
 
 
 
SearchResult.scala 
package com.clearaccess.example.api 
 
import org.json.{JSONObject, JSONArray} 
 
class SearchResult(val json: JSONObject) extends JSONHelpers { 
/** 
  * @return the underlying json object 
  */ 
def getJSON(): JSONObject = json 
/**