Coverage Report - org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintainable
0%
0/42
0%
0/24
3.8
 
 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.krad.bo.BusinessObject;
 28  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 29  
 import org.kuali.rice.krad.document.MaintenanceDocument;
 30  
 import org.kuali.rice.krad.maintenance.KualiMaintainableImpl;
 31  
 import org.kuali.rice.krad.maintenance.Maintainable;
 32  
 import org.kuali.rice.krad.web.ui.Field;
 33  
 import org.kuali.rice.krad.web.ui.Row;
 34  
 import org.kuali.rice.krad.web.ui.Section;
 35  
 
 36  
 import java.util.HashMap;
 37  
 import java.util.List;
 38  
 import java.util.Map;
 39  
 
 40  0
 public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl {
 41  
 
 42  0
         private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class );
 43  
         private static final long serialVersionUID = -8102504656976243468L;
 44  
 
 45  
         private static Template REVIEW_TEMPLATE;
 46  
 
 47  
     public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
 48  0
         List<Section> sections = super.getSections(document, oldMaintainable);
 49  0
         if(document.isEdit()){
 50  0
                 for (Section section : sections) {
 51  0
                 for (Row row : section.getRows()) {
 52  0
                     for (Field field : row.getFields()) {
 53  0
                             if(ReviewResponsibilityBo.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL_FIELD_NAME.equals(field.getPropertyName())){
 54  0
                                     field.setReadOnly(true);
 55  
                             }
 56  
                     }
 57  
                 }
 58  
                 }
 59  
         }
 60  0
         return sections;
 61  
     }
 62  
                 
 63  
         /**
 64  
          * Saves the responsibility via the responsibility service
 65  
          * 
 66  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#saveBusinessObject()
 67  
          */
 68  
         @Override
 69  
         public void saveBusinessObject() {
 70  0
         if ( LOG.isInfoEnabled() ) {
 71  0
             LOG.info( "Attempting to save ReviewResponsibilityBo BO via ResponsibilityService:" + getBusinessObject() );
 72  
         }
 73  0
         populateReviewTemplateInfo();
 74  
 
 75  0
         ReviewResponsibilityBo resp = (ReviewResponsibilityBo)getBusinessObject();
 76  
         // build the AttributeSet with the details
 77  0
         Map<String, String> details = new HashMap<String, String>();
 78  0
         details.put( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() );
 79  0
         details.put( KimConstants.AttributeConstants.ROUTE_NODE_NAME, resp.getRouteNodeName() );
 80  0
         details.put( KimConstants.AttributeConstants.REQUIRED, resp.isRequired()?"true":"false" );
 81  0
         details.put( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" );
 82  0
         if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) {
 83  0
             details.put( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() );
 84  
         }
 85  
 
 86  0
         Responsibility.Builder b = Responsibility.Builder.create(resp.getNamespaceCode(), resp.getName(), Template.Builder.create(REVIEW_TEMPLATE));
 87  0
         b.setDescription(resp.getDescription());
 88  0
         b.setAttributes(Attributes.fromMap(details));
 89  0
         b.setActive(resp.isActive());
 90  
 
 91  0
         KimApiServiceLocator.getResponsibilityService().createResponsibility(b.build());
 92  0
         }
 93  
         
 94  
         private static synchronized void populateReviewTemplateInfo() {
 95  0
                 if ( REVIEW_TEMPLATE == null ) {
 96  0
             List<Template> template = KimApiServiceLocator.getResponsibilityService().findRespTemplatesByNamespaceCodeAndName(KEWConstants.KEW_NAMESPACE, KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME);
 97  
                 
 98  0
                     REVIEW_TEMPLATE = template.get(0);
 99  
         }
 100  0
         }
 101  
 
 102  
         @Override
 103  
         public Class<? extends BusinessObject> getBoClass() {
 104  0
                 return ReviewResponsibilityBo.class;
 105  
         }
 106  
 
 107  
         @Override
 108  
         public void prepareBusinessObject(BusinessObject businessObject) {
 109  0
         if ( businessObject == null ) {
 110  0
             throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." );
 111  
         }
 112  0
         if ( businessObject instanceof ResponsibilityBo ) {
 113  0
             ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() );
 114  0
             businessObject = new ReviewResponsibilityBo( resp );
 115  0
             setBusinessObject( (PersistableBusinessObject)businessObject );
 116  0
         } else {
 117  0
             throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() );
 118  
         }
 119  0
         super.prepareBusinessObject(businessObject);
 120  0
         }
 121  
         
 122  
 }