001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kns.web.struts.form; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.CoreApiServiceLocator; 020import org.kuali.rice.core.api.encryption.EncryptionService; 021import org.kuali.rice.kns.service.BusinessObjectAuthorizationService; 022import org.kuali.rice.kns.service.KNSServiceLocator; 023import org.kuali.rice.krad.bo.BusinessObject; 024import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 025 026import javax.servlet.http.HttpServletRequest; 027import java.security.GeneralSecurityException; 028import java.util.HashMap; 029import java.util.Iterator; 030import java.util.List; 031import java.util.Map; 032 033/** 034 * This is a description of what this class does - wliang don't forget to fill this in. 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 * 038 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework. 039 */ 040@Deprecated 041public class DisplayInactivationBlockersForm extends KualiForm { 042 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisplayInactivationBlockersForm.class); 043 044 private String businessObjectClassName; 045 private Map<String, String> primaryKeyFieldValues; 046 private Map<String, List<String>> blockingValues; 047 048 @Override 049 public void populate(HttpServletRequest request) { 050 super.populate(request); 051 primaryKeyFieldValues = new HashMap<String, String>(); 052 053 if (StringUtils.isBlank(businessObjectClassName)) { 054 throw new IllegalArgumentException("BO Class Name missing."); 055 } 056 057 Class businessObjectClass = null; 058 try { 059 businessObjectClass = Class.forName(businessObjectClassName); 060 } catch (ClassNotFoundException e) { 061 LOG.error("Unable to find class: " + businessObjectClassName, e); 062 throw new IllegalArgumentException("Unable to find class: " + businessObjectClassName, e); 063 } 064 065 if (!BusinessObject.class.isAssignableFrom(businessObjectClass)) { 066 LOG.error("BO Class is not a BusinessObject: " + businessObjectClassName); 067 throw new IllegalArgumentException("BO Class is not a BusinessObject: " + businessObjectClassName); 068 } 069 070 EncryptionService encryptionService = CoreApiServiceLocator.getEncryptionService(); 071 BusinessObjectAuthorizationService businessObjectAuthorizationService = KNSServiceLocator 072 .getBusinessObjectAuthorizationService(); 073 074 List primaryKeyFieldNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass); 075 for (Iterator i = primaryKeyFieldNames.iterator(); i.hasNext();) { 076 String primaryKeyFieldName = (String) i.next(); 077 078 String primaryKeyFieldValue = request.getParameter(primaryKeyFieldName); 079 if (StringUtils.isBlank(primaryKeyFieldValue)) { 080 LOG.error("Missing primary key value for: " + primaryKeyFieldName); 081 throw new IllegalArgumentException("Missing primary key value for: " + primaryKeyFieldName); 082 } 083 084 // check if field is a secure 085 if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(businessObjectClass, primaryKeyFieldName)) { 086 try { 087 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) { 088 primaryKeyFieldValue = encryptionService.decrypt(primaryKeyFieldValue); 089 } 090 } 091 catch (GeneralSecurityException e) { 092 LOG.error("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e); 093 throw new RuntimeException("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e); 094 } 095 } 096 097 primaryKeyFieldValues.put(primaryKeyFieldName, primaryKeyFieldValue); 098 } 099 } 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}