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