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.kuali.rice.kew.api.KewApiServiceLocator; |
19 | |
import org.kuali.rice.kew.api.doctype.DocumentTypeService; |
20 | |
import org.kuali.rice.kim.api.KimConstants; |
21 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
22 | |
import org.kuali.rice.kim.framework.responsibility.ResponsibilityTypeService; |
23 | |
import org.kuali.rice.kns.kim.responsibility.KimResponsibilityTypeServiceBase; |
24 | |
|
25 | |
import java.util.ArrayList; |
26 | |
import java.util.Collections; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class DocumentTypeResponsibilityTypeServiceImpl extends |
35 | |
KimResponsibilityTypeServiceBase implements ResponsibilityTypeService { |
36 | |
DocumentTypeService documentTypeService; |
37 | |
protected String exactMatchStringAttributeName; |
38 | |
|
39 | |
@Override |
40 | |
protected List<String> getRequiredAttributes() { |
41 | 0 | final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes()); |
42 | 0 | attrs.add(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME); |
43 | 0 | return Collections.unmodifiableList(attrs); |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
protected boolean isCheckRequiredAttributes() { |
48 | 0 | return true; |
49 | |
} |
50 | |
|
51 | |
@Override |
52 | |
protected List<Responsibility> performResponsibilityMatches( |
53 | |
Map<String, String> requestedDetails, |
54 | |
List<Responsibility> responsibilitiesList) { |
55 | 0 | Map<String, List<Responsibility>> potentialDocumentTypeMatches = new HashMap<String, List<Responsibility>>(); |
56 | 0 | for (Responsibility responsibility : responsibilitiesList) { |
57 | 0 | if ((exactMatchStringAttributeName == null) |
58 | |
|| responsibility |
59 | |
.getAttributes() |
60 | |
.get(exactMatchStringAttributeName) |
61 | |
.equals( |
62 | |
requestedDetails |
63 | |
.get(exactMatchStringAttributeName))) { |
64 | 0 | if (!potentialDocumentTypeMatches.containsKey(responsibility |
65 | |
.getAttributes().get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) { |
66 | 0 | potentialDocumentTypeMatches.put( |
67 | |
responsibility.getAttributes().get( |
68 | |
KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME), |
69 | |
new ArrayList<Responsibility>()); |
70 | |
} |
71 | 0 | potentialDocumentTypeMatches.get( |
72 | |
responsibility.getAttributes().get( |
73 | |
KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)).add( |
74 | |
responsibility); |
75 | |
} |
76 | |
} |
77 | 0 | List<Responsibility> matchingResponsibilities = new ArrayList<Responsibility>(); |
78 | 0 | if (potentialDocumentTypeMatches.containsKey(requestedDetails |
79 | |
.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) { |
80 | 0 | matchingResponsibilities |
81 | |
.addAll(potentialDocumentTypeMatches.get(requestedDetails |
82 | |
.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))); |
83 | |
} else { |
84 | 0 | String closestParentDocumentTypeName = getClosestParentDocumentTypeName( |
85 | |
getDocumentTypeService().getDocumentTypeByName( |
86 | |
requestedDetails |
87 | |
.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)), |
88 | |
potentialDocumentTypeMatches.keySet()); |
89 | 0 | if (closestParentDocumentTypeName != null) { |
90 | 0 | matchingResponsibilities.addAll(potentialDocumentTypeMatches |
91 | |
.get(closestParentDocumentTypeName)); |
92 | |
} |
93 | |
} |
94 | 0 | return matchingResponsibilities; |
95 | |
} |
96 | |
|
97 | |
public DocumentTypeService getDocumentTypeService() { |
98 | 0 | if (documentTypeService == null) { |
99 | 0 | documentTypeService = KewApiServiceLocator.getDocumentTypeService(); |
100 | |
} |
101 | 0 | return this.documentTypeService; |
102 | |
} |
103 | |
} |