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