1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.routeheader.service.impl; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
21 | |
import org.kuali.rice.kew.docsearch.SearchableAttributeValue; |
22 | |
import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO; |
23 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
24 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
25 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
26 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
27 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueContent; |
28 | |
import org.kuali.rice.kew.routeheader.dao.DocumentRouteHeaderDAO; |
29 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
30 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
31 | |
import org.kuali.rice.kew.util.KEWConstants; |
32 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
33 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
34 | |
|
35 | |
import java.math.BigDecimal; |
36 | |
import java.sql.Timestamp; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Collection; |
39 | |
import java.util.HashMap; |
40 | |
import java.util.List; |
41 | |
import java.util.Map; |
42 | |
import java.util.Set; |
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class RouteHeaderServiceImpl implements RouteHeaderService { |
47 | |
|
48 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RouteHeaderServiceImpl.class); |
49 | |
|
50 | |
private DocumentRouteHeaderDAO routeHeaderDAO; |
51 | |
private SearchableAttributeDAO searchableAttributeDAO; |
52 | |
|
53 | |
public DocumentRouteHeaderValue getRouteHeader(String documentId) { |
54 | 0 | return getRouteHeaderDAO().findRouteHeader(documentId); |
55 | |
} |
56 | |
|
57 | |
public DocumentRouteHeaderValue getRouteHeader(String documentId, boolean clearCache) { |
58 | 0 | return getRouteHeaderDAO().findRouteHeader(documentId, clearCache); |
59 | |
} |
60 | |
|
61 | |
public Collection<DocumentRouteHeaderValue> getRouteHeaders(Collection<String> documentIds) { |
62 | 0 | return getRouteHeaderDAO().findRouteHeaders(documentIds); |
63 | |
} |
64 | |
|
65 | |
public Collection<DocumentRouteHeaderValue> getRouteHeaders(Collection<String> documentIds, boolean clearCache) { |
66 | 0 | return getRouteHeaderDAO().findRouteHeaders(documentIds, clearCache); |
67 | |
} |
68 | |
|
69 | |
public Map<String,DocumentRouteHeaderValue> getRouteHeadersForActionItems(Collection<ActionItem> actionItems) { |
70 | 0 | Map<String,DocumentRouteHeaderValue> routeHeaders = new HashMap<String,DocumentRouteHeaderValue>(); |
71 | 0 | List<String> documentIds = new ArrayList<String>(actionItems.size()); |
72 | 0 | for (ActionItem actionItem : actionItems) { |
73 | 0 | documentIds.add(actionItem.getDocumentId()); |
74 | |
} |
75 | 0 | Collection<DocumentRouteHeaderValue> actionItemRouteHeaders = getRouteHeaders(documentIds); |
76 | 0 | if (actionItemRouteHeaders != null) { |
77 | 0 | for (DocumentRouteHeaderValue routeHeader : actionItemRouteHeaders) { |
78 | 0 | routeHeaders.put(routeHeader.getDocumentId(), routeHeader); |
79 | |
} |
80 | |
} |
81 | 0 | return routeHeaders; |
82 | |
} |
83 | |
|
84 | |
public void lockRouteHeader(String documentId, boolean wait) { |
85 | 0 | getRouteHeaderDAO().lockRouteHeader(documentId, wait); |
86 | 0 | LOG.debug("Successfully locked document [docId=" + documentId + "]"); |
87 | 0 | } |
88 | |
|
89 | |
public void saveRouteHeader(DocumentRouteHeaderValue routeHeader) { |
90 | 0 | this.getRouteHeaderDAO().saveRouteHeader(routeHeader); |
91 | 0 | } |
92 | |
|
93 | |
public void deleteRouteHeader(DocumentRouteHeaderValue routeHeader) { |
94 | 0 | getRouteHeaderDAO().deleteRouteHeader(routeHeader); |
95 | 0 | } |
96 | |
|
97 | |
public String getNextDocumentId() { |
98 | 0 | return getRouteHeaderDAO().getNextDocumentId(); |
99 | |
} |
100 | |
|
101 | |
public Collection findPendingByResponsibilityIds(Set responsibilityIds) { |
102 | 0 | return getRouteHeaderDAO().findPendingByResponsibilityIds(responsibilityIds); |
103 | |
} |
104 | |
|
105 | |
public void clearRouteHeaderSearchValues(String documentId) { |
106 | 0 | getRouteHeaderDAO().clearRouteHeaderSearchValues(documentId); |
107 | 0 | } |
108 | |
|
109 | |
public void updateRouteHeaderSearchValues(String documentId, List<SearchableAttributeValue> searchAttributes) { |
110 | 0 | getRouteHeaderDAO().clearRouteHeaderSearchValues(documentId); |
111 | 0 | for (SearchableAttributeValue searchAttribute : searchAttributes) { |
112 | 0 | getRouteHeaderDAO().save(searchAttribute); |
113 | |
} |
114 | 0 | } |
115 | |
|
116 | |
public void validateRouteHeader(DocumentRouteHeaderValue routeHeader){ |
117 | 0 | LOG.debug("Enter validateRouteHeader(..)"); |
118 | 0 | List errors = new ArrayList(); |
119 | |
|
120 | 0 | if (routeHeader.getDocRouteStatus() == null || routeHeader.getDocRouteStatus().trim().equals("")) { |
121 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader route status null.", "routeheader.routestatus.empty")); |
122 | 0 | } else if (!KEWConstants.DOCUMENT_STATUSES.containsKey(routeHeader.getDocRouteStatus())){ |
123 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader route status invalid.", "routeheader.routestatus.invalid")); |
124 | |
} |
125 | |
|
126 | 0 | if(routeHeader.getDocRouteLevel() == null || routeHeader.getDocRouteLevel().intValue() < 0){ |
127 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader route level invalid.", "routeheader.routelevel.invalid")); |
128 | |
} |
129 | |
|
130 | 0 | if(routeHeader.getStatusModDate() == null){ |
131 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader status modification date empty.", "routeheader.statusmoddate.empty")); |
132 | |
} |
133 | |
|
134 | 0 | if(routeHeader.getCreateDate() == null){ |
135 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader status create date empty.", "routeheader.createdate.empty")); |
136 | |
} |
137 | 0 | if(routeHeader.getDocVersion() == null || routeHeader.getDocVersion().intValue() < 0){ |
138 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader doc version invalid.", "routeheader.docversion.invalid")); |
139 | |
} |
140 | |
|
141 | 0 | if (routeHeader.getInitiatorWorkflowId () == null || routeHeader.getInitiatorWorkflowId().trim().equals("")) { |
142 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader initiator null.", "routeheader.initiator.empty")); |
143 | |
} |
144 | |
else |
145 | |
{ |
146 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(routeHeader.getInitiatorWorkflowId()); |
147 | 0 | if(principal == null) |
148 | |
{ |
149 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader initiator id invalid.", "routeheader.initiator.invalid")); |
150 | |
} |
151 | |
} |
152 | |
|
153 | 0 | if(!StringUtils.isBlank(routeHeader.getDocumentTypeId())){ |
154 | 0 | DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(routeHeader.getDocumentTypeId()); |
155 | 0 | if(docType == null){ |
156 | 0 | errors.add(new WorkflowServiceErrorImpl("RouteHeader document type id invalid.", "routeheader.doctypeid.invalid")); |
157 | |
} |
158 | |
} |
159 | |
|
160 | 0 | LOG.debug("Exit validateRouteHeader(..) "); |
161 | 0 | if (!errors.isEmpty()) { |
162 | 0 | throw new WorkflowServiceErrorException("RouteHeader Validation Error", errors); |
163 | |
} |
164 | 0 | } |
165 | |
|
166 | |
public String getApplicationIdByDocumentId(String documentId) { |
167 | 0 | return getRouteHeaderDAO().getApplicationIdByDocumentId(documentId); |
168 | |
} |
169 | |
|
170 | |
public DocumentRouteHeaderValueContent getContent(String documentId) { |
171 | 0 | if (documentId == null) { |
172 | 0 | return new DocumentRouteHeaderValueContent(); |
173 | |
} |
174 | 0 | DocumentRouteHeaderValueContent content = getRouteHeaderDAO().getContent(documentId); |
175 | 0 | if (content == null) { |
176 | 0 | content = new DocumentRouteHeaderValueContent(documentId); |
177 | |
} |
178 | 0 | return content; |
179 | |
} |
180 | |
|
181 | |
public boolean hasSearchableAttributeValue(String documentId, String searchableAttributeKey, String searchableAttributeValue) { |
182 | 0 | return getRouteHeaderDAO().hasSearchableAttributeValue(documentId, searchableAttributeKey, searchableAttributeValue); |
183 | |
} |
184 | |
|
185 | |
public String getDocumentStatus(String documentId) { |
186 | 0 | return getRouteHeaderDAO().getDocumentStatus(documentId); |
187 | |
} |
188 | |
|
189 | |
public String getAppDocId(String documentId) { |
190 | 0 | if (documentId == null) { |
191 | 0 | return null; |
192 | |
} |
193 | 0 | return getRouteHeaderDAO().getAppDocId(documentId); |
194 | |
} |
195 | |
|
196 | |
public DocumentRouteHeaderDAO getRouteHeaderDAO() { |
197 | 0 | return routeHeaderDAO; |
198 | |
} |
199 | |
|
200 | |
public void setRouteHeaderDAO(DocumentRouteHeaderDAO routeHeaderDAO) { |
201 | 0 | this.routeHeaderDAO = routeHeaderDAO; |
202 | 0 | } |
203 | |
|
204 | |
public List<Timestamp> getSearchableAttributeDateTimeValuesByKey( |
205 | |
String documentId, String key) { |
206 | 0 | return getSearchableAttributeDAO().getSearchableAttributeDateTimeValuesByKey(documentId, key); |
207 | |
} |
208 | |
|
209 | |
public List<BigDecimal> getSearchableAttributeFloatValuesByKey( |
210 | |
String documentId, String key) { |
211 | 0 | return getSearchableAttributeDAO().getSearchableAttributeFloatValuesByKey(documentId, key); |
212 | |
} |
213 | |
|
214 | |
public List<Long> getSearchableAttributeLongValuesByKey(String documentId, |
215 | |
String key) { |
216 | 0 | return getSearchableAttributeDAO().getSearchableAttributeLongValuesByKey(documentId, key); |
217 | |
} |
218 | |
|
219 | |
public List<String> getSearchableAttributeStringValuesByKey( |
220 | |
String documentId, String key) { |
221 | |
|
222 | 0 | return getSearchableAttributeDAO().getSearchableAttributeStringValuesByKey(documentId, key); |
223 | |
} |
224 | |
|
225 | |
public void setSearchableAttributeDAO(SearchableAttributeDAO searchableAttributeDAO) { |
226 | 0 | this.searchableAttributeDAO = searchableAttributeDAO; |
227 | 0 | } |
228 | |
|
229 | |
public SearchableAttributeDAO getSearchableAttributeDAO() { |
230 | 0 | return searchableAttributeDAO; |
231 | |
} |
232 | |
|
233 | |
public Collection findByDocTypeAndAppId(String documentTypeName, |
234 | |
String appId) { |
235 | 0 | return getRouteHeaderDAO().findByDocTypeAndAppId(documentTypeName, appId); |
236 | |
} |
237 | |
} |