Cisco Cisco Prime Home 5.0 Guía Del Desarrollador
Cisco Prime Home – Integration Guide
OL-28558-01 v5.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()(
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
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 = {
def query(caql: String): SearchResults = {
val queryUrl =
"http://%s/prime-
home/portal/query/execute".format(httpConfiguration.host)
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 {
import org.json.{JSONObject, JSONArray}
class SearchResult(val json: JSONObject) extends JSONHelpers {
/**
* @return the underlying json object
*/
def getJSON(): JSONObject = json
/**
* @return the underlying json object
*/
def getJSON(): JSONObject = json
/**