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