Coverage Report - org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityMaintenanceDocumentRule
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintenanceDocumentRule
0%
0/15
0%
0/2
1.5
 
 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.kuali.rice.core.api.criteria.Predicate;
 19  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 20  
 import org.kuali.rice.kew.util.KEWConstants;
 21  
 import org.kuali.rice.kim.api.responsibility.ResponsibilityQueryResults;
 22  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 23  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 24  
 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
 25  
 import org.kuali.rice.krad.util.GlobalVariables;
 26  
 
 27  
 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
 28  
 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
 29  
 
 30  
 /**
 31  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public class ReviewResponsibilityMaintenanceDocumentRule extends MaintenanceDocumentRuleBase {
 37  
 
 38  
         protected static final String ERROR_MESSAGE_PREFIX = "error.document.kim.reviewresponsibility.";
 39  
         protected static final String ERROR_DUPLICATE_RESPONSIBILITY = ERROR_MESSAGE_PREFIX + "duplicateresponsibility";
 40  
 
 41  
         /**
 42  
          * @see org.kuali.rice.krad.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.krad.document.MaintenanceDocument)
 43  
          */
 44  
         @Override
 45  
         protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
 46  0
                 boolean rulesPassed = true;
 47  0
                 GlobalVariables.getMessageMap().addToErrorPath( MAINTAINABLE_ERROR_PATH );
 48  
                 try {
 49  0
                         ReviewResponsibilityBo resp = (ReviewResponsibilityBo)document.getNewMaintainableObject().getBusinessObject();
 50  
                         // check for creation of a duplicate node
 51  0
                         if ( !checkForDuplicateResponsibility( resp ) ) {
 52  0
                                 GlobalVariables.getMessageMap().putError( "documentTypeName", ERROR_DUPLICATE_RESPONSIBILITY );
 53  0
                                 rulesPassed = false;
 54  
                         }
 55  
         } finally {
 56  0
                         GlobalVariables.getMessageMap().removeFromErrorPath( MAINTAINABLE_ERROR_PATH );
 57  0
                 }
 58  0
                 return rulesPassed;
 59  
         }
 60  
 
 61  
         protected boolean checkForDuplicateResponsibility( ReviewResponsibilityBo resp ) {
 62  0
         QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
 63  0
         Predicate p = and(
 64  
             equal("template.namespaceCode", KEWConstants.KEW_NAMESPACE ),
 65  
             equal("template.name", KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME),
 66  
             equal("attributes[documentTypeName]", resp.getDocumentTypeName()),
 67  
             equal("attributes[routeNodeName]", resp.getRouteNodeName())
 68  
         );
 69  0
         builder.setPredicates(p);
 70  0
         ResponsibilityQueryResults results = KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build());
 71  0
                 return results.getResults().isEmpty();
 72  
         }
 73  
 }