Coverage Report - org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm
 
Classes in this File Line Coverage Branch Coverage Complexity
DisplayInactivationBlockersForm
0%
0/42
0%
0/10
2.714
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.encryption.EncryptionService;
 20  
 import org.kuali.rice.core.api.CoreApiServiceLocator;
 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  0
 public class DisplayInactivationBlockersForm extends KualiForm {
 39  0
     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  0
                 super.populate(request);
 48  0
                 primaryKeyFieldValues = new HashMap<String, String>();
 49  
 
 50  0
                 if (StringUtils.isBlank(businessObjectClassName)) {
 51  0
                         throw new IllegalArgumentException("BO Class Name missing.");
 52  
                 }
 53  
                 
 54  0
                 Class businessObjectClass = null;
 55  
                 try {
 56  0
                         businessObjectClass = Class.forName(businessObjectClassName);
 57  0
                 } catch (ClassNotFoundException e) {
 58  0
                         LOG.error("Unable to find class: " + businessObjectClassName, e);
 59  0
                         throw new IllegalArgumentException("Unable to find class: " + businessObjectClassName, e);
 60  0
                 }
 61  
                 
 62  0
                 if (!BusinessObject.class.isAssignableFrom(businessObjectClass)) {
 63  0
                         LOG.error("BO Class is not a BusinessObject: " + businessObjectClassName);
 64  0
                         throw new IllegalArgumentException("BO Class is not a BusinessObject: " + businessObjectClassName);
 65  
                 }
 66  
                 
 67  0
                 EncryptionService encryptionService = CoreApiServiceLocator.getEncryptionService();
 68  0
                 BusinessObjectAuthorizationService businessObjectAuthorizationService = KNSServiceLocator
 69  
                 .getBusinessObjectAuthorizationService();
 70  
                 
 71  0
                 List primaryKeyFieldNames = KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(businessObjectClass);
 72  0
                 for (Iterator i = primaryKeyFieldNames.iterator(); i.hasNext();) {
 73  0
                         String primaryKeyFieldName = (String) i.next();
 74  
                         
 75  0
                         String primaryKeyFieldValue = request.getParameter(primaryKeyFieldName);
 76  0
                         if (StringUtils.isBlank(primaryKeyFieldValue)) {
 77  0
                                 LOG.error("Missing primary key value for: " + primaryKeyFieldName);
 78  0
                                 throw new IllegalArgumentException("Missing primary key value for: " + primaryKeyFieldName);
 79  
                         }
 80  
                         
 81  
             // check if field is a secure
 82  0
             if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(businessObjectClass, primaryKeyFieldName)) {
 83  
                 try {
 84  0
                         primaryKeyFieldValue = encryptionService.decrypt(primaryKeyFieldValue);
 85  
                 }
 86  0
                 catch (GeneralSecurityException e) {
 87  0
                     LOG.error("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
 88  0
                     throw new RuntimeException("Unable to decrypt secure field for BO " + businessObjectClassName + " field " + primaryKeyFieldName, e);
 89  0
                 }
 90  
             }
 91  
             
 92  0
                         primaryKeyFieldValues.put(primaryKeyFieldName, primaryKeyFieldValue);
 93  0
                 }
 94  0
         }
 95  
 
 96  
         public String getBusinessObjectClassName() {
 97  0
                 return this.businessObjectClassName;
 98  
         }
 99  
 
 100  
         public void setBusinessObjectClassName(String businessObjectClassName) {
 101  0
                 this.businessObjectClassName = businessObjectClassName;
 102  0
         }
 103  
 
 104  
         public Map<String, String> getPrimaryKeyFieldValues() {
 105  0
                 return this.primaryKeyFieldValues;
 106  
         }
 107  
 
 108  
         public void setPrimaryKeyFieldValues(Map<String, String> primaryKeyFieldValues) {
 109  0
                 this.primaryKeyFieldValues = primaryKeyFieldValues;
 110  0
         }
 111  
 
 112  
         public Map<String, List<String>> getBlockingValues() {
 113  0
                 return this.blockingValues;
 114  
         }
 115  
 
 116  
         public void setBlockingValues(Map<String, List<String>> blockingValues) {
 117  0
                 this.blockingValues = blockingValues;
 118  0
         }        
 119  
 }