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