Coverage Report - org.kuali.rice.krms.impl.provider.repository.CompoundPropositionTypeService
 
Classes in this File Line Coverage Branch Coverage Complexity
CompoundPropositionTypeService
92%
13/14
87%
7/8
4.5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.krms.impl.provider.repository;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.krms.api.repository.LogicalOperator;
 22  
 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
 23  
 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
 24  
 import org.kuali.rice.krms.framework.engine.CompoundProposition;
 25  
 import org.kuali.rice.krms.framework.engine.Proposition;
 26  
 import org.kuali.rice.krms.framework.type.PropositionTypeService;
 27  
 
 28  
 /**
 29  
  * An implementation of {@link PropositionTypeService} which loads a {@link CompoundProposition}
 30  
  * from the given {@link PropositionDefinition}.  A compound proposition contains one
 31  
  * or more propositions which are evaluated in conjunction with a logical operator
 32  
  * such as "AND" or "OR".
 33  
  * 
 34  
  * <p>The proposition given to the {@link #loadProposition(PropositionDefinition)}
 35  
  * method must be of type {@link PropositionType#COMPOUND}.
 36  
  * 
 37  
  * <p>The translation from a {@link PropositionDefinition} to a {@link Proposition}
 38  
  * is performed by the given {@link RepositoryToEngineTranslator}.  This must be
 39  
  * set on this class before it is used.
 40  
  * 
 41  
  * <p>This class is thread-safe and is designed to be wired as a singleton bean in
 42  
  * Spring.
 43  
  * 
 44  
  * @see CompoundProposition
 45  
  * @see RepositoryToEngineTranslator
 46  
  * 
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  *
 49  
  */
 50  4
 public class CompoundPropositionTypeService implements PropositionTypeService {
 51  
 
 52  
         private RepositoryToEngineTranslator translator;
 53  
         
 54  
         @Override
 55  
         public Proposition loadProposition(PropositionDefinition propositionDefinition) {
 56  4
                 if (translator == null) {
 57  1
                         throw new IllegalStateException("Service not configured properly, no translator available.");
 58  
                 }
 59  3
                 if (propositionDefinition == null) {
 60  1
                         throw new IllegalArgumentException("propositionDefinition was null");
 61  
                 }
 62  2
                 if (PropositionType.COMPOUND != PropositionType.fromCode(propositionDefinition.getPropositionTypeCode())) {
 63  0
                         throw new IllegalArgumentException("Given proposition definition was not compound, type code was: " + propositionDefinition.getPropositionTypeCode());
 64  
                 }
 65  2
                 List<Proposition> propositions = new ArrayList<Proposition>();
 66  2
                 for (PropositionDefinition subProp : propositionDefinition.getCompoundComponents()) {
 67  4
                         propositions.add(translator.translatePropositionDefinition(subProp));
 68  
                 }
 69  2
                 LogicalOperator operator = LogicalOperator.fromCode(propositionDefinition.getCompoundOpCode());
 70  2
                 return new CompoundProposition(operator, propositions);
 71  
         }
 72  
         
 73  
         /**
 74  
          * Sets the translator on this service to the given translator.
 75  
          * 
 76  
          * @param translator the translator to set on this service
 77  
          */
 78  
         public void setTranslator(RepositoryToEngineTranslator translator) {
 79  4
                 this.translator = translator;
 80  4
         }
 81  
 
 82  
 }