Coverage Report - org.kuali.rice.krms.impl.repository.RuleBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleBo
68%
22/32
60%
6/10
0
 
 1  
 package org.kuali.rice.krms.impl.repository
 2  
 
 3  
 import java.util.Map;
 4  
 import java.util.Map.Entry;
 5  
 
 6  
 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase
 7  
 
 8  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
 9  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
 10  
 
 11  
 
 12  
 public class RuleBo extends PersistableBusinessObjectBase implements RuleDefinitionContract {
 13  
 
 14  
         def String id
 15  
         def String namespace
 16  
         def String name
 17  
         def String typeId
 18  
         def String propId
 19  
 
 20  
         def PropositionBo proposition
 21  
         def List<ActionBo> actions        
 22  
         def Set<RuleAttributeBo> attributeBos
 23  
     //def List<PropositionBo> allChildPropositions
 24  
         
 25  
    public PropositionBo getProposition(){
 26  12
            return proposition
 27  
    }
 28  
    
 29  
         public Map<String, String> getAttributes() {
 30  12
                 HashMap<String, String> attributes = new HashMap<String, String>();
 31  12
                 for (attr in attributeBos) {
 32  0
                         attributes.put( attr.attributeDefinition.name, attr.value )
 33  
                 }
 34  12
                 return attributes;
 35  
         }
 36  
         
 37  
         /**
 38  
         * Converts a mutable bo to it's immutable counterpart
 39  
         * @param bo the mutable business object
 40  
         * @return the immutable object
 41  
         */
 42  
    static RuleDefinition to(RuleBo bo) {
 43  9
            if (bo == null) { return null }
 44  6
            return org.kuali.rice.krms.api.repository.rule.RuleDefinition.Builder.create(bo).build()
 45  
    }
 46  
 
 47  
    /**
 48  
         * Converts a immutable object to it's mutable bo counterpart
 49  
         * @param im immutable object
 50  
         * @return the mutable bo
 51  
         */
 52  
    static RuleBo from(RuleDefinition im) {
 53  3
            if (im == null) { return null }
 54  
 
 55  3
            RuleBo bo = new RuleBo()
 56  3
            bo.id = im.id
 57  3
            bo.namespace = im.namespace
 58  3
            bo.name = im.name
 59  3
            bo.typeId = im.typeId
 60  3
            bo.propId = im.propId
 61  3
            bo.proposition = PropositionBo.from(im.proposition)
 62  3
            bo.versionNumber = im.versionNumber
 63  
            
 64  3
            bo.actions = new ArrayList<ActionBo>()
 65  3
            for (action in im.actions){
 66  0
                    bo.actions.add( ActionBo.from(action) )
 67  
            }
 68  
 
 69  
            // build the set of agenda attribute BOs
 70  3
            Set<RuleAttributeBo> attrs = new HashSet<RuleAttributeBo>();
 71  
 
 72  
            // for each converted pair, build an AgendaAttributeBo and add it to the set
 73  3
            RuleAttributeBo attributeBo;
 74  3
            for (Entry<String,String> entry  : im.getAttributes().entrySet()){
 75  0
                    KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator
 76  
                                    .getKrmsAttributeDefinitionService()
 77  0
                                    .getKrmsAttributeBo(entry.getKey(), im.getNamespace());
 78  0
                    attributeBo = new ActionAttributeBo();
 79  0
                    attributeBo.setActionId( im.getId() );
 80  0
                    attributeBo.setAttributeDefinitionId( attrDefBo.getId() );
 81  0
                    attributeBo.setValue( entry.getValue() );
 82  0
                    attributeBo.setAttributeDefinition( attrDefBo );
 83  0
                    attrs.add( attributeBo );
 84  
            }
 85  3
            bo.setAttributeBos(attrs);
 86  
 
 87  3
            return bo
 88  
    }
 89  
 }