Coverage Report - org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintainable
0%
0/49
0%
0/36
4.167
 
 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.kim.impl.responsibility;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.kew.api.KewApiConstants;
 21  
 import org.kuali.rice.kim.api.KimConstants;
 22  
 import org.kuali.rice.kim.api.common.template.Template;
 23  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 24  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 25  
 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
 26  
 import org.kuali.rice.kim.impl.permission.PermissionTemplateBo;
 27  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 28  
 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
 29  
 import org.kuali.rice.kns.maintenance.Maintainable;
 30  
 import org.kuali.rice.kns.web.ui.Field;
 31  
 import org.kuali.rice.kns.web.ui.Row;
 32  
 import org.kuali.rice.kns.web.ui.Section;
 33  
 import org.kuali.rice.krad.bo.BusinessObject;
 34  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 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.kns.maintenance.KualiMaintainableImpl#saveDataObject()
 67  
          */
 68  
         @Override
 69  
         public void saveDataObject() {
 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)getDataObject();
 76  
         // build the Map<String, String> 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  
         //ResponsibilityBo bo = ReviewResponsibilityBo.toResponsibilityBo(resp);
 87  0
         if (resp.getTemplateId() == null) {
 88  0
             resp.setTemplateId(REVIEW_TEMPLATE.getId());
 89  0
             resp.setTemplate(ResponsibilityTemplateBo.from(REVIEW_TEMPLATE));
 90  
         }
 91  0
         if (resp.getTemplateId() != null && resp.getTemplate() == null) {
 92  0
                 resp.setTemplate(
 93  
                         ResponsibilityTemplateBo.from(KimApiServiceLocator.getResponsibilityService().getResponsibilityTemplate(
 94  
                                 resp.getTemplateId())));
 95  
         }
 96  
         //set attributes
 97  0
         resp.setAttributes(details);
 98  
         //resp.setAttributeDetails(KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.class, details, resp.getTemplate().getKimTypeId()));
 99  
 
 100  0
         boolean responsibilityExists = false;
 101  0
         if (resp.getId() != null) {
 102  0
             responsibilityExists = KimApiServiceLocator.getResponsibilityService().getResponsibility(resp.getId()) != null;
 103  
         }
 104  
 
 105  0
         if (responsibilityExists) {
 106  0
             KimApiServiceLocator.getResponsibilityService().updateResponsibility(ResponsibilityBo.to(resp));
 107  
         } else {
 108  0
             KimApiServiceLocator.getResponsibilityService().createResponsibility(ResponsibilityBo.to(resp));
 109  
         }
 110  0
         }
 111  
         
 112  
         private static synchronized void populateReviewTemplateInfo() {
 113  0
                 if ( REVIEW_TEMPLATE == null ) {
 114  0
                     REVIEW_TEMPLATE = KimApiServiceLocator.getResponsibilityService().findRespTemplateByNamespaceCodeAndName(KewApiConstants.KEW_NAMESPACE, KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME);
 115  
         }
 116  0
         }
 117  
 
 118  
         @Override
 119  
         public Class<? extends BusinessObject> getBoClass() {
 120  0
                 return ReviewResponsibilityBo.class;
 121  
         }
 122  
 
 123  
         @Override
 124  
         public void prepareBusinessObject(BusinessObject businessObject) {
 125  0
         if ( businessObject == null ) {
 126  0
             throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." );
 127  
         }
 128  0
         if ( businessObject instanceof ResponsibilityBo ) {
 129  0
             ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() );
 130  0
             businessObject = new ReviewResponsibilityBo( resp );
 131  0
             setBusinessObject( (PersistableBusinessObject)businessObject );
 132  0
         } else {
 133  0
             throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() );
 134  
         }
 135  0
         super.prepareBusinessObject(businessObject);
 136  0
         }
 137  
 
 138  
     /**
 139  
          * This overridden method ...
 140  
          *
 141  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#isExternalBusinessObject()
 142  
          */
 143  
         @Override
 144  
         public boolean isExternalBusinessObject() {
 145  0
                 return true;
 146  
         }
 147  
 
 148  
 }