1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.encryption.EncryptionService;
21 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
22 import org.kuali.rice.kns.service.KNSServiceLocator;
23 import org.kuali.rice.krad.bo.BusinessObject;
24
25 import javax.servlet.http.HttpServletRequest;
26 import java.security.GeneralSecurityException;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35
36
37
38 public class DisplayInactivationBlockersForm extends KualiForm {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisplayInactivationBlockersForm.class);
40
41 private String businessObjectClassName;
42 private Map<String, String> primaryKeyFieldValues;
43 private Map<String, List<String>> blockingValues;
44
45 @Override
46 public void populate(HttpServletRequest request) {
47 super.populate(request);
48 primaryKeyFieldValues = new HashMap<String, String>();
49
50 if (StringUtils.isBlank(businessObjectClassName)) {
51 throw new IllegalArgumentException("BO Class Name missing.");
52 }
53
54 Class businessObjectClass = null;
55 try {
56 businessObjectClass = Class.forName(businessObjectClassName);
57 } catch (ClassNotFoundException e) {
58 LOG.error("Unable to find class: " + businessObjectClassName, e);
59 throw new IllegalArgumentException("Unable to find class: " + businessObjectClassName, e);
60 }
61
62 if (!BusinessObject.class.isAssignableFrom(businessObjectClass)) {
63 LOG.error("BO Class is not a BusinessObject: " + businessObjectClassName);
64 throw new IllegalArgumentException("BO Class is not a BusinessObject: " + businessObjectClassName);
65 }
66
67 EncryptionService encryptionService = CoreApiServiceLocator.getEncryptionService();
68 BusinessObjectAuthorizationService businessObjectAuthorizationService = KNSServiceLocator
69 .getBusinessObjectAuthorizationService();
70
71 List primaryKeyFieldNames = KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(businessObjectClass);
72 for (Iterator i = primaryKeyFieldNames.iterator(); i.hasNext();) {
73 String primaryKeyFieldName = (String) i.next();
74
75 String primaryKeyFieldValue = request.getParameter(primaryKeyFieldName);
76 if (StringUtils.isBlank(primaryKeyFieldValue)) {
77 LOG.error("Missing primary key value for: " + primaryKeyFieldName);
78 throw new IllegalArgumentException("Missing primary key value for: " + primaryKeyFieldName);
79 }
80
81
82 if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(businessObjectClass, primaryKeyFieldName)) {
83 try {
84 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
85 primaryKeyFieldValue = encryptionService.decrypt(primaryKeyFieldValue);
86 }
87 }
88 catch (GeneralSecurityException e) {
89 LOG.error("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
90 throw new RuntimeException("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
91 }
92 }
93
94 primaryKeyFieldValues.put(primaryKeyFieldName, primaryKeyFieldValue);
95 }
96 }
97
98 public String getBusinessObjectClassName() {
99 return this.businessObjectClassName;
100 }
101
102 public void setBusinessObjectClassName(String businessObjectClassName) {
103 this.businessObjectClassName = businessObjectClassName;
104 }
105
106 public Map<String, String> getPrimaryKeyFieldValues() {
107 return this.primaryKeyFieldValues;
108 }
109
110 public void setPrimaryKeyFieldValues(Map<String, String> primaryKeyFieldValues) {
111 this.primaryKeyFieldValues = primaryKeyFieldValues;
112 }
113
114 public Map<String, List<String>> getBlockingValues() {
115 return this.blockingValues;
116 }
117
118 public void setBlockingValues(Map<String, List<String>> blockingValues) {
119 this.blockingValues = blockingValues;
120 }
121 }