View Javadoc

1   /**
2    * Copyright 2005-2012 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  
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   * This is a description of what this class does - wliang don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
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              // check if field is a secure
82              if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(businessObjectClass, primaryKeyFieldName)) {
83                  try {
84                  	primaryKeyFieldValue = encryptionService.decrypt(primaryKeyFieldValue);
85                  }
86                  catch (GeneralSecurityException e) {
87                      LOG.error("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
88                      throw new RuntimeException("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
89                  }
90              }
91              
92  			primaryKeyFieldValues.put(primaryKeyFieldName, primaryKeyFieldValue);
93  		}
94  	}
95  
96  	public String getBusinessObjectClassName() {
97  		return this.businessObjectClassName;
98  	}
99  
100 	public void setBusinessObjectClassName(String businessObjectClassName) {
101 		this.businessObjectClassName = businessObjectClassName;
102 	}
103 
104 	public Map<String, String> getPrimaryKeyFieldValues() {
105 		return this.primaryKeyFieldValues;
106 	}
107 
108 	public void setPrimaryKeyFieldValues(Map<String, String> primaryKeyFieldValues) {
109 		this.primaryKeyFieldValues = primaryKeyFieldValues;
110 	}
111 
112 	public Map<String, List<String>> getBlockingValues() {
113 		return this.blockingValues;
114 	}
115 
116 	public void setBlockingValues(Map<String, List<String>> blockingValues) {
117 		this.blockingValues = blockingValues;
118 	}	
119 }