1 package org.kuali.ole.service;
2
3 import org.apache.commons.lang.StringUtils;
4
5 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
6 import org.kuali.ole.docstore.common.search.*;
7 import org.kuali.ole.select.bo.OleAgreementSearch;
8 import org.kuali.ole.sys.context.SpringContext;
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 private DocstoreClientLocator docstoreClientLocator;
22
23 public DocstoreClientLocator getDocstoreClientLocator() {
24 if (null == docstoreClientLocator) {
25 return SpringContext.getBean(DocstoreClientLocator.class);
26 }
27 return docstoreClientLocator;
28 }
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public List<OleAgreementSearch> getAgreementInformation(Map searchCriteria) {
48 List<OleAgreementSearch> agreementSearchResults = new ArrayList<OleAgreementSearch>();
49 OleAgreementSearch agreemetSearch;
50 SearchResponse solrResponse = getSolrResponse(searchCriteria);
51
52 for(SearchResult searchResult : solrResponse.getSearchResults()) {
53 agreemetSearch = new OleAgreementSearch();
54 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
55 if (searchResultField.getFieldName().equalsIgnoreCase("Title_search")) {
56 agreemetSearch.setAgreementTitle(searchResultField.getFieldValue());
57 }
58 else if (searchResultField.getFieldName().equalsIgnoreCase("ContractNumber_search")) {
59 agreemetSearch.setContractNumber(searchResultField.getFieldValue());
60 }
61 else if (searchResultField.getFieldName().equalsIgnoreCase("Method_search")) {
62 agreemetSearch.setMethodName(searchResultField.getFieldValue());
63 }
64 else if (searchResultField.getFieldName().equalsIgnoreCase("Type_search")) {
65 agreemetSearch.setType(searchResultField.getFieldValue());
66 }
67 else if (searchResultField.getFieldName().equalsIgnoreCase("Status_search")) {
68 agreemetSearch.setStatus(searchResultField.getFieldValue());
69 }
70 else if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
71 agreemetSearch.setUniqueId(searchResultField.getFieldValue());
72 }
73 }
74
75 agreementSearchResults.add(agreemetSearch);
76
77 }
78 return agreementSearchResults;
79 }
80
81
82
83
84
85
86 private SearchResponse getSolrResponse(Map searchCriteria) {
87 String query = queryString;
88 String key = null;
89 String value = null;
90 SearchParams searchParams = new SearchParams();
91 if(!searchCriteria.isEmpty()) {
92 int count = 0;
93 if ((searchCriteria.containsKey("agreementTitle")) &&
94 searchCriteria.get("agreementTitle") != null & !searchCriteria.get("agreementTitle").equals("")) {
95 SearchField searchField = searchParams.buildSearchField("license", "Title_search", (String) searchCriteria.get("agreementTitle"));
96 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("OR", searchField, "AND"));
97
98
99 }
100 else {
101 count ++;
102 }
103 if ((searchCriteria.containsKey("contractNumber")) &&
104 searchCriteria.get("contractNumber") != null & !searchCriteria.get("contractNumber").equals("")) {
105 SearchField searchField = searchParams.buildSearchField("license", "ContractNumber_search", (String) searchCriteria.get("contractNumber"));
106 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("OR", searchField, "AND"));
107
108 }
109 else {
110 count ++;
111 }
112
113
114
115
116
117
118
119
120
121
122 if(searchCriteria.containsKey("uuid")) {
123 SearchField searchField = searchParams.buildSearchField("license", "id", (String) searchCriteria.get("uuid"));
124 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("OR", searchField, "AND"));
125
126
127 }
128 else {
129 count ++;
130 }
131 if( count > 0) {
132 SearchField searchField = searchParams.buildSearchField("license", "DocFormat", "onixpl");
133 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("OR", searchField , "AND"));
134 }
135 }
136
137 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "Title_search"));
138 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "ContractNumber_search"));
139 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "Method_search"));
140 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "Type_search"));
141 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "Status_search"));
142 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("license", "id"));
143 SearchResponse searchResponse = null;
144
145 try {
146 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
147 } catch (Exception e) {
148 e.printStackTrace();
149 }
150
151 return searchResponse;
152 }
153
154
155 }