Coverage Report - org.kuali.rice.kim.document.ReviewResponsibilityMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintainable
0%
0/52
0%
0/28
4.333
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.kim.document;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.log4j.Logger;
 22  
 import org.kuali.rice.kew.util.KEWConstants;
 23  
 import org.kuali.rice.kim.bo.impl.KimAttributes;
 24  
 import org.kuali.rice.kim.bo.impl.ResponsibilityImpl;
 25  
 import org.kuali.rice.kim.bo.impl.ReviewResponsibility;
 26  
 import org.kuali.rice.kim.bo.role.dto.KimResponsibilityTemplateInfo;
 27  
 import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl;
 28  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 29  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 30  
 import org.kuali.rice.kns.bo.BusinessObject;
 31  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 32  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 33  
 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
 34  
 import org.kuali.rice.kns.maintenance.Maintainable;
 35  
 import org.kuali.rice.kns.web.ui.Field;
 36  
 import org.kuali.rice.kns.web.ui.Row;
 37  
 import org.kuali.rice.kns.web.ui.Section;
 38  
 
 39  
 /**
 40  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 41  
  * 
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl {
 46  
 
 47  0
         private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class );        
 48  
         private static final long serialVersionUID = -8102504656976243468L;
 49  
 
 50  0
         protected static String reviewTemplateId = null;
 51  
 
 52  
     public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
 53  0
         List<Section> sections = super.getSections(document, oldMaintainable);
 54  0
         if(document.isEdit()){
 55  0
                 for (Section section : sections) {
 56  0
                 for (Row row : section.getRows()) {
 57  0
                     for (Field field : row.getFields()) {
 58  0
                             if(ReviewResponsibility.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL_FIELD_NAME.equals(field.getPropertyName())){
 59  0
                                     field.setReadOnly(true);
 60  
                             }
 61  
                     }
 62  
                 }
 63  
                 }
 64  
         }
 65  0
         return sections;
 66  
     }
 67  
                 
 68  
         /**
 69  
          * Saves the responsibility via the responsibility update service
 70  
          * 
 71  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#saveBusinessObject()
 72  
          */
 73  
         @Override
 74  
         public void saveBusinessObject() {
 75  
                 try {
 76  0
                         if ( LOG.isInfoEnabled() ) {
 77  0
                                 LOG.info( "Attempting to save ReviewResponsibility BO via ResponsibilityUpdateService:" + getBusinessObject() );
 78  
                         }
 79  
                         // find the template ID if needed
 80  0
                         if ( reviewTemplateId == null ) {
 81  0
                                 populateReviewTemplateInfo();
 82  
                         }
 83  0
                         ReviewResponsibility resp = (ReviewResponsibility)getBusinessObject();
 84  
                         // build the AttributeSet with the details
 85  0
                         AttributeSet details = new AttributeSet();
 86  0
                         details.put( KimAttributes.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() );
 87  0
                         details.put( KimAttributes.ROUTE_NODE_NAME, resp.getRouteNodeName() );
 88  0
                         details.put( KimAttributes.REQUIRED, resp.isRequired()?"true":"false" );
 89  0
                         details.put( KimAttributes.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" );
 90  0
                         if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) {
 91  0
                                 details.put( KimAttributes.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() );
 92  
                         }
 93  
                         
 94  0
                         KIMServiceLocator.getResponsibilityUpdateService().saveResponsibility( resp.getResponsibilityId(), 
 95  
                                         reviewTemplateId,
 96  
                                         resp.getNamespaceCode(), 
 97  
                                         resp.getName(), 
 98  
                                         resp.getDescription(), 
 99  
                                         resp.isActive(), 
 100  
                                         details );
 101  0
                 } catch ( RuntimeException ex ) {
 102  0
                         LOG.error( "Exception in saveBusinessObject()", ex );
 103  0
                         throw ex;
 104  0
                 }
 105  0
         }
 106  
         
 107  
         protected void populateReviewTemplateInfo() {
 108  0
                 KimResponsibilityTemplateInfo template = KIMServiceLocator.getResponsibilityService().getResponsibilityTemplateByName( KEWConstants.KEW_NAMESPACE, KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME);
 109  
                 
 110  0
                 reviewTemplateId = template.getResponsibilityTemplateId();
 111  0
         }
 112  
         
 113  
         /**
 114  
          * This overridden method ...
 115  
          * 
 116  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#getBoClass()
 117  
          */
 118  
         @Override
 119  
         public Class<? extends BusinessObject> getBoClass() {
 120  0
                 return ReviewResponsibility.class;
 121  
         }
 122  
         
 123  
         /**
 124  
          * This overridden method ...
 125  
          * 
 126  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#isExternalBusinessObject()
 127  
          */
 128  
         @Override
 129  
         public boolean isExternalBusinessObject() {
 130  0
                 return true;
 131  
         }
 132  
         
 133  
         /**
 134  
          * This overridden method ...
 135  
          * 
 136  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareBusinessObject(org.kuali.rice.kns.bo.BusinessObject)
 137  
          */
 138  
         @Override
 139  
         public void prepareBusinessObject(BusinessObject businessObject) {
 140  
                 try {
 141  0
                         if ( businessObject == null ) {
 142  0
                                 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityMaintainable.prepareBusinessObject passed a null object." );
 143  
                         }
 144  0
                         if ( businessObject instanceof ResponsibilityImpl ) {
 145  0
                                 KimResponsibilityImpl resp = getBusinessObjectService().findBySinglePrimaryKey(KimResponsibilityImpl.class, ((ResponsibilityImpl)businessObject).getResponsibilityId() );
 146  0
                                 businessObject = new ReviewResponsibility( resp );
 147  0
                         } else if ( businessObject instanceof ReviewResponsibility ) {
 148  
                                 // lookup the KimResponsibilityImpl and convert to a ReviewResponsibility
 149  0
                                 KimResponsibilityImpl resp = getBusinessObjectService().findBySinglePrimaryKey(KimResponsibilityImpl.class, ((ReviewResponsibility)businessObject).getResponsibilityId() );                
 150  0
                                 ((ReviewResponsibility)businessObject).loadFromKimResponsibility(resp);
 151  0
                         } else {
 152  0
                                 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityMaintainable passed an unsupported object type: " + businessObject.getClass() );
 153  
                         }
 154  0
                         if ( businessObject instanceof PersistableBusinessObject ) {
 155  0
                                 setBusinessObject( (PersistableBusinessObject)businessObject );
 156  
                         }
 157  0
                         super.prepareBusinessObject(businessObject);
 158  0
                 } catch ( RuntimeException ex ) {
 159  0
                         LOG.error( "Exception in prepareBusinessObject()", ex );
 160  0
                         throw ex;
 161  0
                 }
 162  0
         }
 163  
         
 164  
 }