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 org.joda.time.DateTime;
19 import org.kuali.rice.kew.api.KewApiServiceLocator;
20 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
21 import org.kuali.rice.kew.api.document.Document;
22 import org.kuali.rice.kew.api.document.DocumentStatus;
23 import org.kuali.rice.kew.docsearch.DocumentSearchCriteriaEbo;
24 import org.kuali.rice.kew.doctype.bo.DocumentType;
25 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
26 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
27 import org.kuali.rice.krad.service.impl.ModuleServiceBase;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37
38
39 public class KEWModuleService extends ModuleServiceBase {
40
41 protected DocumentTypeService docTypeService = null;
42
43
44
45
46
47
48
49 @Override
50 public List<String> listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) {
51 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
52 List<String> pkFields = new ArrayList<String>( 1 );
53 pkFields.add( "documentTypeId" );
54 return pkFields;
55 }else if(DocumentSearchCriteriaEbo.class.isAssignableFrom( businessObjectInterfaceClass )){
56 List<String> pkFields = new ArrayList<String>( 1 );
57 pkFields.add( "documentId" );
58 return pkFields;
59 }
60 return super.listPrimaryKeyFieldNames(businessObjectInterfaceClass);
61 }
62
63
64
65
66
67
68
69 @Override
70 public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(
71 Class<T> businessObjectClass, Map<String, Object> fieldValues) {
72 if(DocumentTypeEBO.class.isAssignableFrom(businessObjectClass)){
73 if ( fieldValues.containsKey( "name" ) ) {
74 return (T) DocumentType.from(getDocumentTypeService().getDocumentTypeByName((String) fieldValues.get("name")));
75 }else if( fieldValues.containsKey( "documentTypeId" ) ){
76 return (T) DocumentType.from(getDocumentTypeService().getDocumentTypeById(fieldValues.get("documentTypeId").toString()));
77 }else if (fieldValues.containsKey( "id" ) ) {
78
79 return (T) DocumentType.from(getDocumentTypeService().getDocumentTypeById(fieldValues.get("id").toString()));
80 }
81
82 }else if(DocumentSearchCriteriaEbo.class.isAssignableFrom( businessObjectClass )){
83 if ( fieldValues.containsKey( "documentId" ) ) {
84 return (T)createDocumentSearchEbo(KewApiServiceLocator.getWorkflowDocumentService().getDocument(
85 fieldValues.get("documentId").toString()));
86 }
87
88 }
89
90
91 return super.getExternalizableBusinessObject(businessObjectClass, fieldValues);
92 }
93
94
95
96
97 protected synchronized DocumentTypeService getDocumentTypeService() {
98 if(this.docTypeService == null){
99
100 this.docTypeService = KewApiServiceLocator.getDocumentTypeService();
101 }
102 return this.docTypeService;
103 }
104
105
106
107
108 public synchronized void setDocumentTypeService(DocumentTypeService docTypeService) {
109 this.docTypeService = docTypeService;
110 }
111
112 private DocumentSearchCriteriaEbo createDocumentSearchEbo(final Document doc){
113 return new DocumentSearchCriteriaEbo(){
114
115 @Override
116 public String getApplicationDocumentId() {
117 return doc.getApplicationDocumentId();
118 }
119
120 @Override
121 public DocumentStatus getStatus() {
122 return doc.getStatus();
123 }
124
125 @Override
126 public String getApplicationDocumentStatus() {
127 return doc.getApplicationDocumentStatus();
128 }
129
130 @Override
131 public String getTitle() {
132 return doc.getTitle();
133 }
134
135 @Override
136 public String getDocumentTypeName() {
137 return doc.getDocumentTypeName();
138 }
139
140 @Override
141 public String getInitiatorPrincipalId() {
142 return doc.getInitiatorPrincipalId();
143 }
144
145 @Override
146 public String getDocumentId() {
147 return doc.getDocumentId();
148 }
149
150 @Override
151 public DateTime getDateCreated() {
152 return doc.getDateCreated();
153 }
154
155 @Override
156 public void refresh() {
157
158 }
159
160 };
161 }
162
163
164
165
166
167 @Override
168 public String getExternalizableBusinessObjectInquiryUrl(
169 Class inquiryBusinessObjectClass, Map<String, String[]> parameters) {
170 if ( DocumentTypeEBO.class.isAssignableFrom( inquiryBusinessObjectClass ) ) {
171 int nonBlank = 0;
172 boolean nameFound = false;
173
174 for(String key: parameters.keySet()){
175 if("name".equals(key) && parameters.get(key) != null){
176 nameFound=true;
177 }else if(!"name".equals(key) && parameters.get(key) != null){
178 nonBlank ++;
179 }
180 }
181
182 if(nonBlank == 0 && nameFound == true){
183 parameters.clear();
184 DocumentTypeEBO dte = (DocumentTypeEBO) DocumentType.from(getDocumentTypeService().getDocumentTypeByName(parameters.get( "name" )[0] ));
185 String[] strArr = {dte.getDocumentTypeId().toString()};
186 parameters.put("documentTypeId", strArr);
187 }
188
189 }
190
191 return super.getExternalizableBusinessObjectInquiryUrl(
192 inquiryBusinessObjectClass, parameters);
193 }
194
195
196
197
198
199
200 public List<List<String>> listAlternatePrimaryKeyFieldNames(
201 Class businessObjectInterfaceClass) {
202 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
203 ArrayList<List<String>> retList = new ArrayList<List<String>>();
204 ArrayList<String> keyList = new ArrayList<String>();
205
206 keyList.add("name");
207 retList.add(keyList);
208 return retList;
209 }else{
210 return null;
211 }
212
213 }
214 }
215