Coverage Report - org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityMaintenanceDocumentRule
 
Classes in this File Line Coverage Branch Coverage Complexity
ReviewResponsibilityMaintenanceDocumentRule
0%
0/15
0%
0/6
2.5
 
 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.kuali.rice.core.api.criteria.Predicate;
 19  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 20  
 import org.kuali.rice.kew.api.KewApiConstants;
 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().getDataObject();
 50  
                         // check for creation of a duplicate node
 51  0
                         if ( resp.getDocumentTypeName() != null
 52  
                     && resp.getRouteNodeName() != null
 53  
                     && !checkForDuplicateResponsibility( resp ) ) {
 54  0
                                 GlobalVariables.getMessageMap().putError( "documentTypeName", ERROR_DUPLICATE_RESPONSIBILITY );
 55  0
                                 rulesPassed = false;
 56  
                         }
 57  
         } finally {
 58  0
                         GlobalVariables.getMessageMap().removeFromErrorPath( MAINTAINABLE_ERROR_PATH );
 59  0
                 }
 60  0
                 return rulesPassed;
 61  
         }
 62  
 
 63  
         protected boolean checkForDuplicateResponsibility( ReviewResponsibilityBo resp ) {
 64  0
         QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
 65  0
         Predicate p = and(
 66  
             equal("template.namespaceCode", KewApiConstants.KEW_NAMESPACE ),
 67  
             equal("template.name", KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME),
 68  
             equal("attributes[documentTypeName]", resp.getDocumentTypeName()),
 69  
             equal("attributes[routeNodeName]", resp.getRouteNodeName())
 70  
         );
 71  0
         builder.setPredicates(p);
 72  0
         ResponsibilityQueryResults results = KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build());
 73  0
                 return results.getResults().isEmpty();
 74  
         }
 75  
 }