// Path: src/main/java/org/springframework/social/salesforce/api/ResultItem.java
// public class ResultItem implements Serializable {
// 
//     private String type;
// 
//     private String url;
// 
//     private Map attributes;
// 
// 
//     public ResultItem(String type, String url) {
//         this.type = type;
//         this.url = url;
//         this.attributes = new HashMap();
//     }
// 
// 
//     public String getType() {
//         return this.type;
//     }
// 
//     public void setType(String type) {
//         this.type = type;
//     }
// 
//     public String getUrl() {
//         return this.url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     public Map getAttributes() {
//         return attributes;
//     }
// 
//     public void setAttributes(Map attributes) {
//         this.attributes = attributes;
//     }
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/Salesforce.java
// public interface Salesforce extends ApiBinding {
// 
//     public ApiOperations apiOperations();
// 
//     public ApiOperations apiOperations(String instanceUrl);
// 
//     public ChatterOperations chatterOperations();
// 
//     public ChatterOperations chatterOperations(String instanceUrl);
// 
//     public QueryOperations queryOperations();
// 
//     public QueryOperations queryOperations(String instanceUrl);
// 
//     public RecentOperations recentOperations();
// 
//     public RecentOperations recentOperations(String instanceUrl);
// 
//     public SearchOperations searchOperations();
// 
//     public SearchOperations searchOperations(String instanceUrl);
// 
//     public SObjectOperations sObjectsOperations();
// 
//     public SObjectOperations sObjectsOperations(String instanceUrl);
// 
//     public UserOperations userOperations();
// 
//     public UserOperations userOperations(String gatewayUrl);
// 
//     public LimitsOperations limitsOperations();
// 
//     public LimitsOperations limitsOperations(String instanceUrl);
// 
//     public <T> List<T> readList(JsonNode jsonNode, Class<T> type);
// 
//     public <T> T readObject(JsonNode jsonNode, Class<T> type);
// 
//     public String getBaseUrl();
// 
//     public String getInstanceUrl();
// 
//     public void setInstanceUrl(String instanceUrl);
// 
//     public String getUserInfoUrl();
// 
//     public String getAuthGatewayUrl();
// 
//     public void setAuthGatewayBaseUrl(String gatewayUrl);
// 
//     public ConnectOperations connectOperations();
// 
//     public ConnectOperations connectOperations(String instanceUrl);
//     
//     public CustomApiOperations customApiOperations();
// 
//     public CustomApiOperations customApiOperations(String instanceUrl);
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/SearchOperations.java
// public interface SearchOperations {
// 
//     /**
//      * Execute SOSL Query and retrieve results
//      * 
//      * @param soslQuery The SOSL Query to execute
//      * @return List of ResultItem
//      */
//     List<ResultItem> search(String soslQuery);
//     
// 
// }


import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.social.salesforce.api.ResultItem;
import org.springframework.social.salesforce.api.Salesforce;
import org.springframework.social.salesforce.api.SearchOperations;
import org.springframework.social.support.URIBuilder;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.util.List;
/**
 * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.salesforce.api.impl;



/**
 * Default implementation of SearchOperations.
 * 
 * @author Umut Utkan
 * @author Jared Ottley
 */
public class SearchTemplate extends AbstractSalesForceOperations<Salesforce> implements SearchOperations {

    private RestTemplate restTemplate;

    public SearchTemplate(Salesforce api, RestTemplate restTemplate) {
        super(api);
        this.restTemplate = restTemplate;
    }

    /**
     * @see org.springframework.social.salesforce.api.SearchOperations#search(java.lang.String)
     */
    @Override
    public List<ResultItem> search(String soslQuery) {
        requireAuthorization();
        URI uri = URIBuilder.fromUri(api.getBaseUrl() + "/" + getVersion() + "/search").queryParam("q", soslQuery).build();
        JsonNode arr = restTemplate.getForObject(uri, JsonNode.class);
// Path: src/main/java/org/springframework/social/salesforce/api/ResultItem.java
// public class ResultItem implements Serializable {
// 
//     private String type;
// 
//     private String url;
// 
//     private Map attributes;
// 
// 
//     public ResultItem(String type, String url) {
//         this.type = type;
//         this.url = url;
//         this.attributes = new HashMap();
//     }
// 
// 
//     public String getType() {
//         return this.type;
//     }
// 
//     public void setType(String type) {
//         this.type = type;
//     }
// 
//     public String getUrl() {
//         return this.url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     public Map getAttributes() {
//         return attributes;
//     }
// 
//     public void setAttributes(Map attributes) {
//         this.attributes = attributes;
//     }
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/Salesforce.java
// public interface Salesforce extends ApiBinding {
// 
//     public ApiOperations apiOperations();
// 
//     public ApiOperations apiOperations(String instanceUrl);
// 
//     public ChatterOperations chatterOperations();
// 
//     public ChatterOperations chatterOperations(String instanceUrl);
// 
//     public QueryOperations queryOperations();
// 
//     public QueryOperations queryOperations(String instanceUrl);
// 
//     public RecentOperations recentOperations();
// 
//     public RecentOperations recentOperations(String instanceUrl);
// 
//     public SearchOperations searchOperations();
// 
//     public SearchOperations searchOperations(String instanceUrl);
// 
//     public SObjectOperations sObjectsOperations();
// 
//     public SObjectOperations sObjectsOperations(String instanceUrl);
// 
//     public UserOperations userOperations();
// 
//     public UserOperations userOperations(String gatewayUrl);
// 
//     public LimitsOperations limitsOperations();
// 
//     public LimitsOperations limitsOperations(String instanceUrl);
// 
//     public <T> List<T> readList(JsonNode jsonNode, Class<T> type);
// 
//     public <T> T readObject(JsonNode jsonNode, Class<T> type);
// 
//     public String getBaseUrl();
// 
//     public String getInstanceUrl();
// 
//     public void setInstanceUrl(String instanceUrl);
// 
//     public String getUserInfoUrl();
// 
//     public String getAuthGatewayUrl();
// 
//     public void setAuthGatewayBaseUrl(String gatewayUrl);
// 
//     public ConnectOperations connectOperations();
// 
//     public ConnectOperations connectOperations(String instanceUrl);
//     
//     public CustomApiOperations customApiOperations();
// 
//     public CustomApiOperations customApiOperations(String instanceUrl);
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/SearchOperations.java
// public interface SearchOperations {
// 
//     /**
//      * Execute SOSL Query and retrieve results
//      * 
//      * @param soslQuery The SOSL Query to execute
//      * @return List of ResultItem
//      */
//     List<ResultItem> search(String soslQuery);
//     
// 
// }


// Path: src/main/java/org/springframework/social/salesforce/api/impl/SearchTemplate.java
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.social.salesforce.api.ResultItem;
import org.springframework.social.salesforce.api.Salesforce;
import org.springframework.social.salesforce.api.SearchOperations;
import org.springframework.social.support.URIBuilder;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.util.List;

/**
 * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.salesforce.api.impl;



/**
 * Default implementation of SearchOperations.
 * 
 * @author Umut Utkan
 * @author Jared Ottley
 */
public class SearchTemplate extends AbstractSalesForceOperations<Salesforce> implements SearchOperations {

    private RestTemplate restTemplate;

    public SearchTemplate(Salesforce api, RestTemplate restTemplate) {
        super(api);
        this.restTemplate = restTemplate;
    }

    /**
     * @see org.springframework.social.salesforce.api.SearchOperations#search(java.lang.String)
     */
    @Override
    public List<ResultItem> search(String soslQuery) {
        requireAuthorization();
        URI uri = URIBuilder.fromUri(api.getBaseUrl() + "/" + getVersion() + "/search").queryParam("q", soslQuery).build();
        JsonNode arr = restTemplate.getForObject(uri, JsonNode.class);
        return api.readList(arr, ResultItem.class);