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.KNSServiceLocator;
36 import org.kuali.rice.kns.util.ObjectUtils;
37 import org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm;
38
39
40
41
42
43
44
45 public class DisplayInactivationBlockersAction extends KualiAction {
46
47 public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
48 DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form;
49 DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
50 InactivationBlockingDisplayService inactivationBlockingDisplayService = KNSServiceLocator.getInactivationBlockingDisplayService();
51
52 Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName());
53 BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance();
54 for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) {
55 ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key));
56 }
57
58 Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>();
59
60 Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass);
61 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) {
62 String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel();
63 String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel();
64 String displayLabel;
65 if (StringUtils.isEmpty(relationshipLabel)) {
66 displayLabel = blockingBoLabel;
67 }
68 else {
69 displayLabel = blockingBoLabel + " (" + relationshipLabel + ")";
70 }
71 List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata);
72
73 if (!blockerObjectList.isEmpty()) {
74 List<String> existingList = allBlockers.get(displayLabel);
75 if (existingList != null) {
76 existingList.addAll(blockerObjectList);
77 }
78 else {
79 allBlockers.put(displayLabel, blockerObjectList);
80 }
81 }
82 }
83
84 displayInactivationBlockersForm.setBlockingValues(allBlockers);
85
86 return mapping.findForward(RiceConstants.MAPPING_BASIC);
87 }
88 }