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 != null && 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 != null && 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                  ArrayList methodValue = (ArrayList<String>)results.get("Method_search");
68                  if(methodValue != null && methodValue.size() > 0) {
69                      String agrMethod = methodValue.toString();
70                      agreemetSearch.setMethodName(StringUtils.substring(agrMethod,1, agrMethod.length() - 1));
71                  }
72                  ArrayList typeValue = (ArrayList<String>)results.get("Type_search");
73                  if(typeValue!= null && typeValue.size() > 0) {
74                      String agrType = typeValue.toString();
75                      agreemetSearch.setType(StringUtils.substring(agrType,1, agrType.length() - 1));
76                  }
77                  ArrayList statusValue = (ArrayList<String>)results.get("Status_search");
78                  if(statusValue != null && statusValue.size() > 0) {
79                      String agrStatus = statusValue.toString();
80                      agreemetSearch.setStatus(StringUtils.substring(agrStatus,1, agrStatus.length() - 1));
81                  }
82                  agreemetSearch.setUniqueId((String)results.get("uniqueId"));
83                  agreementSearchResults.add(agreemetSearch);
84              }
85          }
86          return agreementSearchResults;
87      }
88  
89      /**
90       *  This method returns the SolrResponse as List based on searchCriteria.
91       * @param searchCriteria
92       * @return  List
93       */
94      private List getSolrResponse(Map searchCriteria) {
95          String query = queryString;
96          String key = null;
97          String value = null;
98          if(!searchCriteria.isEmpty()) {
99              OleDocument oleDocument = new WorkBibDocument();
100             WorkInstanceDocument workInstance = new WorkInstanceDocument();
101             if ((searchCriteria.containsKey("agreementTitle")) &&
102                     searchCriteria.get("agreementTitle") != null & !searchCriteria.get("agreementTitle").equals("")) {
103                 query = query + " AND Title_search:" +searchCriteria.get("agreementTitle");
104             }
105             if ((searchCriteria.containsKey("contractNumber")) &&
106                         searchCriteria.get("contractNumber") != null & !searchCriteria.get("contractNumber").equals("")) {
107                 query = query + " AND ContractNumber_search:" +searchCriteria.get("contractNumber");
108             }
109             /*if ((searchCriteria.containsKey("licensee")) &&
110                     searchCriteria.get("licensee") != null & !searchCriteria.get("licensee").equals("")){
111                 query = query + " AND Licensee_search:" +searchCriteria.get("licensee");
112             }
113             if ((searchCriteria.containsKey("licensor")) &&
114                     searchCriteria.get("licensor") != null & !searchCriteria.get("licensor").equals("")) {
115                 query = query + " AND Licensor_search:" +searchCriteria.get("licensor");
116             }*/
117             //query = query+"&fl=id,Title_search,ContractNumber_search,Licensee_search,Licensor_search";
118             if(searchCriteria.containsKey("uuid")) {
119                 query = query + "id:"+ searchCriteria.get("uuid");
120             }
121         }
122         return getSolrRequestReponseHandler().retriveResults(query);
123     }
124 
125     /**
126      * Gets the solrRequestReponseHandler attribute value.
127      * @return solrRequestReponseHandler
128      */
129     public SolrRequestReponseHandler getSolrRequestReponseHandler() {
130         if (null == solrRequestReponseHandler) {
131             solrRequestReponseHandler = new SolrRequestReponseHandler();
132         }
133         return solrRequestReponseHandler;
134     }
135 
136     /**
137      *  Sets the solrRequestReponseHandler attribute value.
138      * @param solrRequestReponseHandler
139      */
140     public void setSolrRequestReponseHandler(SolrRequestReponseHandler solrRequestReponseHandler) {
141         this.solrRequestReponseHandler = solrRequestReponseHandler;
142     }
143 }