1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.workflow.attribute;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.engine.RouteContext;
20 import org.kuali.rice.kew.api.exception.WorkflowException;
21 import org.kuali.rice.kew.role.QualifierResolver;
22 import org.kuali.rice.kim.api.KimConstants;
23 import org.kuali.rice.krad.document.Document;
24 import org.kuali.rice.krad.service.DocumentService;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26
27 import java.util.List;
28 import java.util.Map;
29
30
31
32
33
34
35 @Deprecated
36 public abstract class QualifierResolverBase implements QualifierResolver {
37 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(QualifierResolverBase.class);
38
39 protected static final String KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME = KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME;
40 protected static final String KIM_ATTRIBUTE_DOCUMENT_NUMBER = KimConstants.AttributeConstants.DOCUMENT_NUMBER;
41 protected static final String KIM_ATTRIBUTE_ROUTE_LEVEL_NAME = KimConstants.AttributeConstants.ROUTE_NODE_NAME;
42
43 private static DocumentService documentService;
44
45
46
47
48
49
50 protected Document getDocument(RouteContext context) {
51 String documentID = getDocumentId(context);
52
53 if (documentID != null) {
54 try {
55 return getDocumentService().getByDocumentHeaderIdSessionless(documentID);
56 }
57 catch (WorkflowException e) {
58 LOG.error("Unable to retrieve document with system user.", e);
59 return null;
60 }
61 }
62 return null;
63 }
64
65
66
67
68
69
70
71 protected String getDocumentId(RouteContext context) {
72 final String documentID = context.getNodeInstance().getDocumentId();
73 return documentID != null ? documentID.toString() : null;
74 }
75
76
77 public DocumentService getDocumentService() {
78 if ( documentService == null ) {
79 documentService = KRADServiceLocatorWeb.getDocumentService();
80 }
81 return documentService;
82 }
83
84
85
86
87
88
89
90
91 protected void decorateWithCommonQualifiers(List<Map<String, String>> qualifiers, RouteContext context, String customDocTypeName) {
92 for (Map<String, String> qualifier : qualifiers) {
93 addCommonQualifiersToMap(qualifier, context, customDocTypeName);
94 }
95 }
96
97
98
99
100
101
102
103
104 protected void addCommonQualifiersToMap(Map<String, String> qualifier, RouteContext context, String customDocTypeName) {
105 qualifier.put(KIM_ATTRIBUTE_DOCUMENT_NUMBER, context.getDocument().getDocumentId() );
106 if ( !qualifier.containsKey(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME) ) {
107 if ( StringUtils.isBlank(customDocTypeName)) {
108 qualifier.put(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME,
109 context.getDocument().getDocumentType().getName() );
110 } else {
111 qualifier.put(KIM_ATTRIBUTE_DOCUMENT_TYPE_NAME, customDocTypeName );
112 }
113 }
114 qualifier.put(KIM_ATTRIBUTE_ROUTE_LEVEL_NAME, context.getNodeInstance().getName());
115 }
116
117 }