View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This is a description of what this class does - wliang don't forget to fill this in. 
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
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              // check if field is a secure
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 }