1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.select.OleSelectConstant;
20 import org.kuali.ole.select.businessobject.OleAcquisitionSearchResult;
21 import org.kuali.ole.select.document.service.OleAcquisitionSearchService;
22 import org.kuali.ole.select.lookup.DocData;
23 import org.kuali.ole.select.service.impl.OleDocStoreSearchService;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.core.api.util.RiceKeyConstants;
26 import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
27 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
28 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
29 import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
30 import org.kuali.rice.kew.exception.WorkflowServiceError;
31 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
32 import org.kuali.rice.kew.service.KEWServiceLocator;
33 import org.kuali.rice.krad.util.GlobalVariables;
34
35 import java.util.*;
36
37
38 public class OleAcquisitionSearchServiceImpl implements OleAcquisitionSearchService {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleAcquisitionSearchServiceImpl.class);
40
41
42
43
44
45
46
47 protected Collection<DocData> getDocData(List<DocumentSearchResult> documentSearchResults) {
48 List<Object> titleIds = new ArrayList<Object>();
49 for (DocumentSearchResult documentSearchResult : documentSearchResults) {
50 for (DocumentAttribute documentAttribute : documentSearchResult.getDocumentAttributes()) {
51 if (documentAttribute.getName().equalsIgnoreCase(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID) &&
52 documentAttribute.getValue() != null &&
53 StringUtils.isNotBlank(documentAttribute.getValue().toString())) {
54 titleIds.add(documentAttribute.getValue());
55 }
56 }
57 }
58 if (!titleIds.isEmpty()) {
59 try {
60 return SpringContext.getBean(OleDocStoreSearchService.class).getResult(DocData.class, "", titleIds);
61 } catch (Exception ex) {
62 GlobalVariables.getMessageMap().putError(OleSelectConstant.AcquisitionsSearch.REQUISITIONS, "Error While connecting to DocStore",
63 new String[]{});
64 LOG.error("Exception access document store for lookup by titleIds: " + titleIds, ex);
65 }
66 }
67 return Collections.emptyList();
68 }
69
70
71
72
73
74
75
76
77
78 private DocumentSearchCriteria addDocumentAttributesToCriteria(DocumentSearchCriteria.Builder criteria, Map<String, List<String>> propertyFields) {
79 Map<String, List<String>> attributes = new HashMap<String, List<String>>();
80 if (criteria != null) {
81 if (!propertyFields.isEmpty()) {
82 for (String propertyField : propertyFields.keySet()) {
83 if (propertyFields.get(propertyField) != null) {
84 attributes.put(propertyField, propertyFields.get(propertyField));
85 }
86 }
87 }
88 }
89 criteria.setDocumentAttributeValues(attributes);
90 return criteria.build();
91 }
92
93
94
95
96
97
98
99 @Override
100 public List<String> getTitleIds(List<DocData> docDataList) {
101 List<String> titleIds = new ArrayList<String>();
102 int i = 0;
103 for (DocData docData : docDataList) {
104 if (StringUtils.isNotEmpty(docData.getUniqueId())) {
105 titleIds.add(docData.getUniqueId());
106 }
107 }
108
109 return titleIds;
110 }
111
112
113
114
115
116
117
118
119 private List<OleAcquisitionSearchResult> getFinalDocumentTypeResult(List<DocumentSearchResult> componentResults) {
120 List<OleAcquisitionSearchResult> docResult = new ArrayList<OleAcquisitionSearchResult>();
121 OleAcquisitionSearchResult acqSearchResult;
122 if (!componentResults.isEmpty()) {
123 for (DocumentSearchResult searchResult : componentResults) {
124 acqSearchResult = new OleAcquisitionSearchResult();
125 acqSearchResult.setResultDetails(false, searchResult, new ArrayList());
126 if (acqSearchResult != null) {
127 docResult.add(acqSearchResult);
128 }
129 }
130 }
131 return docResult;
132
133 }
134
135
136
137
138
139
140
141 @Override
142 public List<OleAcquisitionSearchResult> performDocumentSearch(DocumentSearchCriteria docSearchCriteria, Map<String, List<String>> fixedParameters) {
143 DocumentSearchCriteria docSearchCriteriaDTO = addDocumentAttributesToCriteria(DocumentSearchCriteria.Builder.create(docSearchCriteria), fixedParameters);
144 LOG.debug("Inside filterWorkflowStatusDate of OleAcquisitionsSearchDocument");
145 List result = new ArrayList();
146 List<OleAcquisitionSearchResult> finalResult = new ArrayList<OleAcquisitionSearchResult>();
147 DocumentSearchResults components = null;
148 boolean isDateSpecified = true;
149 try {
150 components = KEWServiceLocator.getDocumentSearchService().lookupDocuments(GlobalVariables.getUserSession().getPrincipalId(),
151 docSearchCriteriaDTO);
152
153 List<DocumentSearchResult> docSearchResults = components.getSearchResults();
154 if (!fixedParameters.containsKey("displayType")) {
155 finalResult = getFinalDocumentTypeResult(docSearchResults);
156 } else {
157 finalResult = getFinalBibTypeResult(docSearchResults);
158 }
159 } catch (WorkflowServiceErrorException wsee) {
160 for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>) wsee.getServiceErrors()) {
161 if (workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()) {
162 GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
163 } else {
164 GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM,
165 workflowServiceError.getMessage());
166 }
167 }
168 ;
169 }
170 return finalResult;
171 }
172
173
174
175
176
177
178
179
180 protected List<OleAcquisitionSearchResult> getFinalBibTypeResult(List<DocumentSearchResult> componentResults) {
181 List<OleAcquisitionSearchResult> bibResult = new ArrayList<OleAcquisitionSearchResult>();
182 List<DocData> docDatas = (List<DocData>) getDocData(componentResults);
183 OleAcquisitionSearchResult acqSearchResult;
184 if (!componentResults.isEmpty()) {
185 for (DocumentSearchResult searchResult : componentResults) {
186 acqSearchResult = new OleAcquisitionSearchResult();
187 acqSearchResult.setResultDetails(true, searchResult, docDatas);
188 if (acqSearchResult != null) {
189 bibResult.add(acqSearchResult);
190 }
191 }
192 }
193 return bibResult;
194 }
195
196 }