Coverage Report - org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintainable
0%
0/52
0%
0/28
4
 
 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.impl.responsibility;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.core.api.mo.common.Attributes;
 21  
 import org.kuali.rice.core.util.AttributeSet;
 22  
 import org.kuali.rice.kew.util.KEWConstants;
 23  
 import org.kuali.rice.kim.api.common.template.Template;
 24  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 25  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 26  
 import org.kuali.rice.kim.util.KimConstants;
 27  
 import org.kuali.rice.kns.bo.BusinessObject;
 28  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 29  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 30  
 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
 31  
 import org.kuali.rice.kns.maintenance.Maintainable;
 32  
 import org.kuali.rice.kns.web.ui.Field;
 33  
 import org.kuali.rice.kns.web.ui.Row;
 34  
 import org.kuali.rice.kns.web.ui.Section;
 35  
 
 36  
 import java.util.List;
 37  
 
 38  
 /**
 39  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  *
 43  
  */
 44  0
 public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl {
 45  
 
 46  0
         private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class );
 47  
         private static final long serialVersionUID = -8102504656976243468L;
 48  
 
 49  
     //FIXME: this seems really dubious
 50  0
         protected static Template reviewTemplate = 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(ReviewResponsibilityBo.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  0
         if ( LOG.isInfoEnabled() ) {
 76  0
             LOG.info( "Attempting to save ReviewResponsibilityBo BO via ResponsibilityService:" + getBusinessObject() );
 77  
         }
 78  
         // find the template ID if needed
 79  0
         if ( reviewTemplate == null ) {
 80  0
             populateReviewTemplateInfo();
 81  
         }
 82  0
         ReviewResponsibilityBo resp = (ReviewResponsibilityBo)getBusinessObject();
 83  
         // build the AttributeSet with the details
 84  0
         AttributeSet details = new AttributeSet();
 85  0
         details.put( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() );
 86  0
         details.put( KimConstants.AttributeConstants.ROUTE_NODE_NAME, resp.getRouteNodeName() );
 87  0
         details.put( KimConstants.AttributeConstants.REQUIRED, resp.isRequired()?"true":"false" );
 88  0
         details.put( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" );
 89  0
         if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) {
 90  0
             details.put( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() );
 91  
         }
 92  
 
 93  0
         Responsibility.Builder b = Responsibility.Builder.create(resp.getResponsibilityId(), resp.getNamespaceCode(), resp.getName(), Template.Builder.create(reviewTemplate));
 94  0
         b.setActive(resp.isActive());
 95  0
         b.setDescription(resp.getDescription());
 96  0
         b.setAttributes(Attributes.fromMap(details));
 97  
 
 98  0
         KimApiServiceLocator.getResponsibilityService().updateResponsibility(b.build());
 99  0
         }
 100  
         
 101  
         protected void populateReviewTemplateInfo() {
 102  0
                 List<Template> template = KimApiServiceLocator.getResponsibilityService().findRespTemplatesByNamespaceCodeAndName(KEWConstants.KEW_NAMESPACE, KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME);
 103  
                 
 104  0
                 reviewTemplate = template.get(0);
 105  0
         }
 106  
         
 107  
         /**
 108  
          * This overridden method ...
 109  
          * 
 110  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#getBoClass()
 111  
          */
 112  
         @Override
 113  
         public Class<? extends BusinessObject> getBoClass() {
 114  0
                 return ReviewResponsibilityBo.class;
 115  
         }
 116  
         
 117  
         /**
 118  
          * This overridden method ...
 119  
          * 
 120  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#isExternalBusinessObject()
 121  
          */
 122  
         @Override
 123  
         public boolean isExternalBusinessObject() {
 124  0
                 return true;
 125  
         }
 126  
         
 127  
         /**
 128  
          * This overridden method ...
 129  
          * 
 130  
          * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareBusinessObject(org.kuali.rice.kns.bo.BusinessObject)
 131  
          */
 132  
         @Override
 133  
         public void prepareBusinessObject(BusinessObject businessObject) {
 134  
                 try {
 135  0
                         if ( businessObject == null ) {
 136  0
                                 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." );
 137  
                         }
 138  0
                         if ( businessObject instanceof ResponsibilityBo ) {
 139  0
                                 ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() );
 140  0
                                 businessObject = new ReviewResponsibilityBo( resp );
 141  0
                         } else if ( businessObject instanceof ReviewResponsibilityBo ) {
 142  
                                 // lookup the KimResponsibilityImpl and convert to a ReviewResponsibilityBo
 143  0
                                 ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ReviewResponsibilityBo)businessObject).getResponsibilityId() );
 144  0
                                 ((ReviewResponsibilityBo)businessObject).loadFromKimResponsibility(resp);
 145  0
                         } else {
 146  0
                                 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() );
 147  
                         }
 148  0
                         if ( businessObject instanceof PersistableBusinessObject ) {
 149  0
                                 setBusinessObject( (PersistableBusinessObject)businessObject );
 150  
                         }
 151  0
                         super.prepareBusinessObject(businessObject);
 152  0
                 } catch ( RuntimeException ex ) {
 153  0
                         LOG.error( "Exception in prepareBusinessObject()", ex );
 154  0
                         throw ex;
 155  0
                 }
 156  0
         }
 157  
         
 158  
 }