Coverage Report - org.kuali.rice.devtools.pdle.PostDataLoadEncryptionServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PostDataLoadEncryptionServiceImpl
0%
0/46
0%
0/18
2.333
 
 1  
 /*
 2  
  * Copyright 2006-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.devtools.pdle;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
 20  
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 21  
 import org.kuali.rice.core.api.encryption.EncryptionService;
 22  
 import org.kuali.rice.core.framework.persistence.ojb.conversion.OjbKualiEncryptDecryptFieldConversion;
 23  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 24  
 import org.kuali.rice.kns.exception.ClassNotPersistableException;
 25  
 import org.kuali.rice.kns.service.BusinessObjectService;
 26  
 import org.kuali.rice.kns.service.impl.PersistenceServiceImplBase;
 27  
 
 28  
 import java.util.HashMap;
 29  
 import java.util.Set;
 30  
 
 31  0
 public class PostDataLoadEncryptionServiceImpl extends PersistenceServiceImplBase implements PostDataLoadEncryptionService {
 32  
     private BusinessObjectService businessObjectService;
 33  
     private EncryptionService encryptionService;
 34  
     private PostDataLoadEncryptionDao postDataLoadEncryptionDao;
 35  
 
 36  
     public void checkArguments(Class businessObjectClass, Set<String> attributeNames) {
 37  0
             checkArguments(businessObjectClass, attributeNames, true);
 38  0
     }
 39  
     
 40  
     public void checkArguments(Class businessObjectClass, Set<String> attributeNames, boolean checkOjbEncryptConfig) {
 41  0
         if ((businessObjectClass == null) || (attributeNames == null)) {
 42  0
             throw new IllegalArgumentException(
 43  
                     "PostDataLoadEncryptionServiceImpl.encrypt does not allow a null business object Class or attributeNames Set");
 44  
         }
 45  0
         ClassDescriptor classDescriptor = null;
 46  
         try {
 47  0
             classDescriptor = getClassDescriptor(businessObjectClass);
 48  0
         } catch (ClassNotPersistableException e) {
 49  0
             throw new IllegalArgumentException(
 50  
                     "PostDataLoadEncryptionServiceImpl.encrypt does not handle business object classes that do not have a corresponding ClassDescriptor defined in the OJB repository",
 51  
                     e);
 52  0
         }
 53  0
         for (String attributeName : attributeNames) {
 54  0
             if (classDescriptor.getFieldDescriptorByName(attributeName) == null) {
 55  0
                 throw new IllegalArgumentException(
 56  
                         new StringBuffer("Attribute ")
 57  
                                 .append(attributeName)
 58  
                                 .append(
 59  
                                         " specified to PostDataLoadEncryptionServiceImpl.encrypt is not in the OJB repository ClassDescriptor for Class ")
 60  
                                 .append(businessObjectClass).toString());
 61  
             }
 62  0
             if (checkOjbEncryptConfig && !(classDescriptor.getFieldDescriptorByName(attributeName).getFieldConversion() instanceof OjbKualiEncryptDecryptFieldConversion)) {
 63  0
                 throw new IllegalArgumentException(
 64  
                         new StringBuffer("Attribute ")
 65  
                                 .append(attributeName)
 66  
                                 .append(" of business object Class ")
 67  
                                 .append(businessObjectClass)
 68  
                                 .append(
 69  
                                         " specified to PostDataLoadEncryptionServiceImpl.encrypt is not configured for encryption in the OJB repository")
 70  
                                 .toString());
 71  
             }
 72  
         }
 73  0
     }
 74  
 
 75  
     public void createBackupTable(Class businessObjectClass) {
 76  0
         postDataLoadEncryptionDao.createBackupTable(getClassDescriptor(businessObjectClass).getFullTableName());
 77  0
     }
 78  
 
 79  
     public void prepClassDescriptor(Class businessObjectClass, Set<String> attributeNames) {
 80  0
         ClassDescriptor classDescriptor = getClassDescriptor(businessObjectClass);
 81  0
         for (String attributeName : attributeNames) {
 82  0
             classDescriptor.getFieldDescriptorByName(attributeName).setFieldConversionClassName(
 83  
                     FieldConversionDefaultImpl.class.getName());
 84  
         }
 85  0
     }
 86  
 
 87  
     public void truncateTable(Class businessObjectClass) {
 88  0
         postDataLoadEncryptionDao.truncateTable(getClassDescriptor(businessObjectClass).getFullTableName());
 89  0
     }
 90  
 
 91  
     public void encrypt(PersistableBusinessObject businessObject, Set<String> attributeNames) {
 92  0
         for (String attributeName : attributeNames) {
 93  
             try {
 94  0
                 PropertyUtils.setProperty(businessObject, attributeName, encryptionService.encrypt(PropertyUtils
 95  
                         .getProperty(businessObject, attributeName)));
 96  0
             } catch (Exception e) {
 97  0
                 throw new RuntimeException(new StringBuffer(
 98  
                         "PostDataLoadEncryptionServiceImpl caught exception while attempting to encrypt attribute ").append(
 99  
                         attributeName).append(" of Class ").append(businessObject.getClass()).toString(), e);
 100  0
             }
 101  
         }
 102  0
         businessObjectService.save(businessObject);
 103  0
     }
 104  
 
 105  
     public void restoreClassDescriptor(Class businessObjectClass, Set<String> attributeNames) {
 106  0
         ClassDescriptor classDescriptor = getClassDescriptor(businessObjectClass);
 107  0
         for (String attributeName : attributeNames) {
 108  0
             classDescriptor.getFieldDescriptorByName(attributeName).setFieldConversionClassName(
 109  
                     OjbKualiEncryptDecryptFieldConversion.class.getName());
 110  
         }
 111  0
         businessObjectService.countMatching(businessObjectClass, new HashMap());
 112  0
     }
 113  
 
 114  
     public void restoreTableFromBackup(Class businessObjectClass) {
 115  0
         postDataLoadEncryptionDao.restoreTableFromBackup(getClassDescriptor(businessObjectClass).getFullTableName());
 116  0
     }
 117  
 
 118  
     public void dropBackupTable(Class businessObjectClass) {
 119  0
         postDataLoadEncryptionDao.dropBackupTable(getClassDescriptor(businessObjectClass).getFullTableName());
 120  0
     }
 121  
 
 122  
     public void setPostDataLoadEncryptionDao(PostDataLoadEncryptionDao postDataLoadEncryptionDao) {
 123  0
         this.postDataLoadEncryptionDao = postDataLoadEncryptionDao;
 124  0
     }
 125  
 
 126  
     public void setEncryptionService(EncryptionService encryptionService) {
 127  0
         this.encryptionService = encryptionService;
 128  0
     }
 129  
 
 130  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 131  0
         this.businessObjectService = businessObjectService;
 132  0
     }
 133  
 }