1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.struts.action; |
17 | |
|
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
import java.util.Set; |
21 | |
import java.util.TreeMap; |
22 | |
|
23 | |
import javax.servlet.http.HttpServletRequest; |
24 | |
import javax.servlet.http.HttpServletResponse; |
25 | |
|
26 | |
import org.apache.commons.lang.StringUtils; |
27 | |
import org.apache.struts.action.ActionForm; |
28 | |
import org.apache.struts.action.ActionForward; |
29 | |
import org.apache.struts.action.ActionMapping; |
30 | |
import org.kuali.rice.core.util.RiceConstants; |
31 | |
import org.kuali.rice.kns.bo.BusinessObject; |
32 | |
import org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata; |
33 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
34 | |
import org.kuali.rice.kns.service.InactivationBlockingDisplayService; |
35 | |
import org.kuali.rice.kns.service.KNSServiceLocatorInternal; |
36 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
37 | |
import org.kuali.rice.kns.util.ObjectUtils; |
38 | |
import org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class DisplayInactivationBlockersAction extends KualiAction { |
47 | |
|
48 | |
public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
49 | 0 | DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form; |
50 | 0 | DataDictionaryService dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
51 | 0 | InactivationBlockingDisplayService inactivationBlockingDisplayService = KNSServiceLocatorInternal.getInactivationBlockingDisplayService(); |
52 | |
|
53 | 0 | Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName()); |
54 | 0 | BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance(); |
55 | 0 | for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) { |
56 | 0 | ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key)); |
57 | |
} |
58 | |
|
59 | 0 | Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>(); |
60 | |
|
61 | 0 | Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass); |
62 | 0 | for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) { |
63 | 0 | String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel(); |
64 | 0 | String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel(); |
65 | |
String displayLabel; |
66 | 0 | if (StringUtils.isEmpty(relationshipLabel)) { |
67 | 0 | displayLabel = blockingBoLabel; |
68 | |
} |
69 | |
else { |
70 | 0 | displayLabel = blockingBoLabel + " (" + relationshipLabel + ")"; |
71 | |
} |
72 | 0 | List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata); |
73 | |
|
74 | 0 | if (!blockerObjectList.isEmpty()) { |
75 | 0 | List<String> existingList = allBlockers.get(displayLabel); |
76 | 0 | if (existingList != null) { |
77 | 0 | existingList.addAll(blockerObjectList); |
78 | |
} |
79 | |
else { |
80 | 0 | allBlockers.put(displayLabel, blockerObjectList); |
81 | |
} |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | 0 | displayInactivationBlockersForm.setBlockingValues(allBlockers); |
86 | |
|
87 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
88 | |
} |
89 | |
} |