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.encryption.EncryptionService; |
20 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
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 | 0 | public class DisplayInactivationBlockersForm extends KualiForm { |
39 | 0 | 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 | 0 | super.populate(request); |
48 | 0 | primaryKeyFieldValues = new HashMap<String, String>(); |
49 | |
|
50 | 0 | if (StringUtils.isBlank(businessObjectClassName)) { |
51 | 0 | throw new IllegalArgumentException("BO Class Name missing."); |
52 | |
} |
53 | |
|
54 | 0 | Class businessObjectClass = null; |
55 | |
try { |
56 | 0 | businessObjectClass = Class.forName(businessObjectClassName); |
57 | 0 | } catch (ClassNotFoundException e) { |
58 | 0 | LOG.error("Unable to find class: " + businessObjectClassName, e); |
59 | 0 | throw new IllegalArgumentException("Unable to find class: " + businessObjectClassName, e); |
60 | 0 | } |
61 | |
|
62 | 0 | if (!BusinessObject.class.isAssignableFrom(businessObjectClass)) { |
63 | 0 | LOG.error("BO Class is not a BusinessObject: " + businessObjectClassName); |
64 | 0 | throw new IllegalArgumentException("BO Class is not a BusinessObject: " + businessObjectClassName); |
65 | |
} |
66 | |
|
67 | 0 | EncryptionService encryptionService = CoreApiServiceLocator.getEncryptionService(); |
68 | 0 | BusinessObjectAuthorizationService businessObjectAuthorizationService = KNSServiceLocator |
69 | |
.getBusinessObjectAuthorizationService(); |
70 | |
|
71 | 0 | List primaryKeyFieldNames = KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(businessObjectClass); |
72 | 0 | for (Iterator i = primaryKeyFieldNames.iterator(); i.hasNext();) { |
73 | 0 | String primaryKeyFieldName = (String) i.next(); |
74 | |
|
75 | 0 | String primaryKeyFieldValue = request.getParameter(primaryKeyFieldName); |
76 | 0 | if (StringUtils.isBlank(primaryKeyFieldValue)) { |
77 | 0 | LOG.error("Missing primary key value for: " + primaryKeyFieldName); |
78 | 0 | throw new IllegalArgumentException("Missing primary key value for: " + primaryKeyFieldName); |
79 | |
} |
80 | |
|
81 | |
|
82 | 0 | if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(businessObjectClass, primaryKeyFieldName)) { |
83 | |
try { |
84 | 0 | primaryKeyFieldValue = encryptionService.decrypt(primaryKeyFieldValue); |
85 | |
} |
86 | 0 | catch (GeneralSecurityException e) { |
87 | 0 | LOG.error("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e); |
88 | 0 | throw new RuntimeException("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e); |
89 | 0 | } |
90 | |
} |
91 | |
|
92 | 0 | primaryKeyFieldValues.put(primaryKeyFieldName, primaryKeyFieldValue); |
93 | 0 | } |
94 | 0 | } |
95 | |
|
96 | |
public String getBusinessObjectClassName() { |
97 | 0 | return this.businessObjectClassName; |
98 | |
} |
99 | |
|
100 | |
public void setBusinessObjectClassName(String businessObjectClassName) { |
101 | 0 | this.businessObjectClassName = businessObjectClassName; |
102 | 0 | } |
103 | |
|
104 | |
public Map<String, String> getPrimaryKeyFieldValues() { |
105 | 0 | return this.primaryKeyFieldValues; |
106 | |
} |
107 | |
|
108 | |
public void setPrimaryKeyFieldValues(Map<String, String> primaryKeyFieldValues) { |
109 | 0 | this.primaryKeyFieldValues = primaryKeyFieldValues; |
110 | 0 | } |
111 | |
|
112 | |
public Map<String, List<String>> getBlockingValues() { |
113 | 0 | return this.blockingValues; |
114 | |
} |
115 | |
|
116 | |
public void setBlockingValues(Map<String, List<String>> blockingValues) { |
117 | 0 | this.blockingValues = blockingValues; |
118 | 0 | } |
119 | |
} |