View Javadoc

1   package org.kuali.ole.service;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.incubator.SolrRequestReponseHandler;
5   import org.kuali.ole.docstore.model.bo.OleDocument;
6   import org.kuali.ole.docstore.model.bo.WorkBibDocument;
7   import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
8   import org.kuali.ole.license.bo.OleAgreementSearch;
9   
10  import java.util.ArrayList;
11  import java.util.Iterator;
12  import java.util.List;
13  import java.util.Map;
14  
15  /**
16   *OleAgreementSearchService performs search operation and return list of agreement related information.
17   */
18  public class OleAgreementSearchService {
19      private final String queryString = "(DocType:license AND DocFormat:onixpl)";
20      SolrRequestReponseHandler solrRequestReponseHandler;
21  
22      /**
23       *  This method returns the responses from Solr.
24       * @param queryField
25       * @param value
26       * @return  List
27       */
28      public List getResponseFromSOLR(String queryField, String value) {
29          String queryString = queryField + ":" + value;
30          return getSolrRequestReponseHandler().retriveResults(queryString);
31      }
32  
33      /**
34       *  This method returns list of agreement information based on search criteria.
35       * @param searchCriteria
36       * @return   List<OleAgreementSearch>
37       */
38      public List<OleAgreementSearch> getAgreementInformation(Map searchCriteria) {
39          List<OleAgreementSearch> agreementSearchResults = new ArrayList<OleAgreementSearch>();
40          OleAgreementSearch agreemetSearch;
41          List solrResponse = getSolrResponse(searchCriteria);
42          if(solrResponse.size() > 0) {
43              Iterator listIterator = solrResponse.iterator();
44              while(listIterator.hasNext()) {
45                  Map results = (Map)listIterator.next();
46                  agreemetSearch = new OleAgreementSearch();
47                  ArrayList titleValue = (ArrayList<String>)results.get("Title_search");
48                  if(titleValue.size() > 0) {
49                      String title = titleValue.toString();
50                      agreemetSearch.setAgreementTitle(StringUtils.substring(title,1, title.length() - 1));
51                  }
52                  ArrayList contractNumValue = (ArrayList<String>)results.get("ContractNumber_search");
53                  if(contractNumValue.size() > 0) {
54                      String contractNum = contractNumValue.toString();
55                      agreemetSearch.setContractNumber(StringUtils.substring(contractNum,1, contractNum.length() - 1));
56                  }
57                  /*ArrayList licenseeValue = (ArrayList<String>)results.get("Licensee_search");
58                  if(licenseeValue.size() > 0) {
59                      String licensee = licenseeValue.toString();
60                      agreemetSearch.setLicensee(licensee);
61                  }
62                  ArrayList licensorValue = (ArrayList<String>)results.get("Licensor_search");
63                  if(licensorValue.size() > 0) {
64                      String licensor = licensorValue.toString();
65                      agreemetSearch.setLicensor(licensor);
66                  }*/
67                  agreemetSearch.setUniqueId((String)results.get("uniqueId"));
68                  agreementSearchResults.add(agreemetSearch);
69              }
70          }
71          return agreementSearchResults;
72      }
73  
74      /**
75       *  This method returns the SolrResponse as List based on searchCriteria.
76       * @param searchCriteria
77       * @return  List
78       */
79      private List getSolrResponse(Map searchCriteria) {
80          String query = queryString;
81          String key = null;
82          String value = null;
83          if(!searchCriteria.isEmpty()) {
84              OleDocument oleDocument = new WorkBibDocument();
85              WorkInstanceDocument workInstance = new WorkInstanceDocument();
86              if ((searchCriteria.containsKey("agreementTitle")) &&
87                      searchCriteria.get("agreementTitle") != null & !searchCriteria.get("agreementTitle").equals("")) {
88                  query = query + " AND Title_search:" +searchCriteria.get("agreementTitle");
89              }
90              if ((searchCriteria.containsKey("contractNumber")) &&
91                          searchCriteria.get("contractNumber") != null & !searchCriteria.get("contractNumber").equals("")) {
92                  query = query + " AND ContractNumber_search:" +searchCriteria.get("contractNumber");
93              }
94              /*if ((searchCriteria.containsKey("licensee")) &&
95                      searchCriteria.get("licensee") != null & !searchCriteria.get("licensee").equals("")){
96                  query = query + " AND Licensee_search:" +searchCriteria.get("licensee");
97              }
98              if ((searchCriteria.containsKey("licensor")) &&
99                      searchCriteria.get("licensor") != null & !searchCriteria.get("licensor").equals("")) {
100                 query = query + " AND Licensor_search:" +searchCriteria.get("licensor");
101             }*/
102             //query = query+"&fl=id,Title_search,ContractNumber_search,Licensee_search,Licensor_search";
103         }
104         return getSolrRequestReponseHandler().retriveResults(query);
105     }
106 
107     /**
108      * Gets the solrRequestReponseHandler attribute value.
109      * @return solrRequestReponseHandler
110      */
111     public SolrRequestReponseHandler getSolrRequestReponseHandler() {
112         if (null == solrRequestReponseHandler) {
113             solrRequestReponseHandler = new SolrRequestReponseHandler();
114         }
115         return solrRequestReponseHandler;
116     }
117 
118     /**
119      *  Sets the solrRequestReponseHandler attribute value.
120      * @param solrRequestReponseHandler
121      */
122     public void setSolrRequestReponseHandler(SolrRequestReponseHandler solrRequestReponseHandler) {
123         this.solrRequestReponseHandler = solrRequestReponseHandler;
124     }
125 }