1 package org.kuali.ole.service;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
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.select.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
21
22
23
24
25
26
27
28 public List getResponseFromSOLR(String queryField, String value) {
29 String queryString = queryField + ":" + value;
30 return QueryServiceImpl.getInstance().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 != 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
58
59
60
61
62
63
64
65
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
91
92
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
110
111
112
113
114
115
116
117
118 if(searchCriteria.containsKey("uuid")) {
119 query = query + "id:"+ searchCriteria.get("uuid");
120 }
121 }
122 return QueryServiceImpl.getInstance().retriveResults(query);
123 }
124
125
126 }