1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.service.impl;
17
18 import java.sql.Timestamp;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.kuali.rice.kew.docsearch.DocumentRouteHeaderEBO;
24 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
25 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
26 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kns.bo.ExternalizableBusinessObject;
29 import org.kuali.rice.kns.service.impl.ModuleServiceBase;
30
31
32
33
34
35
36
37 public class KEWModuleService extends ModuleServiceBase {
38
39 protected DocumentTypeService docTypeService = null;
40
41
42
43
44
45
46
47 @Override
48 public List<String> listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) {
49 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
50 List<String> pkFields = new ArrayList<String>( 1 );
51 pkFields.add( "documentTypeId" );
52 return pkFields;
53 }else if(DocumentRouteHeaderEBO.class.isAssignableFrom( businessObjectInterfaceClass )){
54 List<String> pkFields = new ArrayList<String>( 1 );
55 pkFields.add( "routeHeaderId" );
56 return pkFields;
57 }
58 return super.listPrimaryKeyFieldNames(businessObjectInterfaceClass);
59 }
60
61
62
63
64
65
66
67 @Override
68 public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(
69 Class<T> businessObjectClass, Map<String, Object> fieldValues) {
70 if(DocumentTypeEBO.class.isAssignableFrom(businessObjectClass)){
71 if ( fieldValues.containsKey( "name" ) ) {
72 return (T)getDocumentTypeService().findByName((String)fieldValues.get( "name" ) );
73 }else if( fieldValues.containsKey( "documentTypeId" ) ){
74 return (T)getDocumentTypeService().findById(Long.valueOf(fieldValues.get( "documentTypeId" ).toString()));
75 }else if (fieldValues.containsKey( "id" ) ) {
76
77 return (T)getDocumentTypeService().findById(Long.valueOf(fieldValues.get( "id" ).toString()));
78 }
79
80 }else if(DocumentRouteHeaderEBO.class.isAssignableFrom( businessObjectClass )){
81 if ( fieldValues.containsKey( "routeHeaderId" ) ) {
82 return (T)createDocSearchCriteriaEBO(KEWServiceLocator.getRouteHeaderService().getRouteHeader(Long.valueOf(fieldValues.get( "routeHeaderId" ).toString())));
83 }
84
85 }
86
87
88 return super.getExternalizableBusinessObject(businessObjectClass, fieldValues);
89 }
90
91
92
93
94 protected DocumentTypeService getDocumentTypeService() {
95 if(this.docTypeService == null){
96
97 this.docTypeService = KEWServiceLocator.getDocumentTypeService();
98 }
99 return this.docTypeService;
100 }
101
102
103
104
105 public void setDocumentTypeService(DocumentTypeService docTypeService) {
106 this.docTypeService = docTypeService;
107 }
108
109 private DocumentRouteHeaderEBO createDocSearchCriteriaEBO(final DocumentRouteHeaderValue routeHeaderValue){
110 return new DocumentRouteHeaderEBO(){
111
112 public String getAppDocId() {
113 return routeHeaderValue.getAppDocId();
114 }
115
116 public Timestamp getDateCreated() {
117 return routeHeaderValue.getCreateDate();
118 }
119
120 public String getDocRouteStatus() {
121
122 return routeHeaderValue.getDocRouteStatus();
123 }
124
125 public String getAppDocStatus() {
126
127 return routeHeaderValue.getAppDocStatus();
128 }
129
130 public String getDocTitle() {
131 return routeHeaderValue.getDocTitle();
132 }
133
134 public String getDocTypeFullName() {
135 return routeHeaderValue.getDocumentType().getName();
136 }
137
138 public String getInitiator() {
139 return routeHeaderValue.getInitiatorPrincipal().getPrincipalName();
140 }
141
142 public String getRouteHeaderId() {
143
144 return routeHeaderValue.getRouteHeaderId().toString();
145 }
146
147 public void prepareForWorkflow() {
148
149
150 }
151
152 public void refresh() {
153
154
155 }
156
157 };
158 }
159
160
161
162
163
164 @Override
165 public String getExternalizableBusinessObjectInquiryUrl(
166 Class inquiryBusinessObjectClass, Map<String, String[]> parameters) {
167 if ( DocumentTypeEBO.class.isAssignableFrom( inquiryBusinessObjectClass ) ) {
168 int nonBlank = 0;
169 boolean nameFound = false;
170
171 for(String key: parameters.keySet()){
172 if("name".equals(key) && parameters.get(key) != null){
173 nameFound=true;
174 }else if(!"name".equals(key) && parameters.get(key) != null){
175 nonBlank ++;
176 }
177 }
178
179 if(nonBlank == 0 && nameFound == true){
180 parameters.clear();
181 DocumentTypeEBO dte = (DocumentTypeEBO)getDocumentTypeService().findByName(parameters.get( "name" )[0] );
182 String[] strArr = {dte.getDocumentTypeId().toString()};
183 parameters.put("documentTypeId", strArr);
184 }
185
186 }
187
188 return super.getExternalizableBusinessObjectInquiryUrl(
189 inquiryBusinessObjectClass, parameters);
190 }
191
192
193
194
195
196 public List<List<String>> listAlternatePrimaryKeyFieldNames(
197 Class businessObjectInterfaceClass) {
198 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
199 ArrayList<List<String>> retList = new ArrayList<List<String>>();
200 ArrayList<String> keyList = new ArrayList<String>();
201
202 keyList.add("name");
203 retList.add(keyList);
204 return retList;
205 }else{
206 return null;
207 }
208
209 }
210 }
211