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
17
18 public class OleAgreementSearchService {
19 private final String queryString = "(DocType:license AND DocFormat:onixpl)";
20 SolrRequestReponseHandler solrRequestReponseHandler;
21
22
23
24
25
26
27
28 public List getResponseFromSOLR(String queryField, String value) {
29 String queryString = queryField + ":" + value;
30 return getSolrRequestReponseHandler().retriveResults(queryString);
31 }
32
33
34
35
36
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
58
59
60
61
62
63
64
65
66
67 agreemetSearch.setUniqueId((String)results.get("uniqueId"));
68 agreementSearchResults.add(agreemetSearch);
69 }
70 }
71 return agreementSearchResults;
72 }
73
74
75
76
77
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
95
96
97
98
99
100
101
102
103 }
104 return getSolrRequestReponseHandler().retriveResults(query);
105 }
106
107
108
109
110
111 public SolrRequestReponseHandler getSolrRequestReponseHandler() {
112 if (null == solrRequestReponseHandler) {
113 solrRequestReponseHandler = new SolrRequestReponseHandler();
114 }
115 return solrRequestReponseHandler;
116 }
117
118
119
120
121
122 public void setSolrRequestReponseHandler(SolrRequestReponseHandler solrRequestReponseHandler) {
123 this.solrRequestReponseHandler = solrRequestReponseHandler;
124 }
125 }