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