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