Coverage Report - org.kuali.rice.krms.impl.repository.RuleBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleBo
69%
23/33
60%
6/10
0
 
 1  
 package org.kuali.rice.krms.impl.repository
 2  
 
 3  
 import java.util.Map.Entry;
 4  
 
 5  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 6  
 
 7  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
 8  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
 9  
 
 10  
 
 11  
 public class RuleBo extends PersistableBusinessObjectBase implements RuleDefinitionContract {
 12  
 
 13  
         def String id
 14  
         def String namespace
 15  
     def String description
 16  
         def String name
 17  
         def String typeId
 18  
         def String propId
 19  
 
 20  
     def PropositionBo proposition
 21  
     def List<ActionBo> actions
 22  
     def List<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.description = im.description
 60  3
            bo.typeId = im.typeId
 61  3
            bo.propId = im.propId
 62  3
            bo.proposition = PropositionBo.from(im.proposition)
 63  3
            bo.versionNumber = im.versionNumber
 64  
            
 65  3
            bo.actions = new ArrayList<ActionBo>()
 66  3
            for (action in im.actions){
 67  0
                    bo.actions.add( ActionBo.from(action) )
 68  
            }
 69  
 
 70  
            // build the set of agenda attribute BOs
 71  3
            List<RuleAttributeBo> attrs = new ArrayList<RuleAttributeBo>();
 72  
 
 73  
            // for each converted pair, build an AgendaAttributeBo and add it to the set
 74  3
            RuleAttributeBo attributeBo;
 75  3
            for (Entry<String,String> entry  : im.getAttributes().entrySet()){
 76  0
                    KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator
 77  
                                    .getKrmsAttributeDefinitionService()
 78  0
                                    .getKrmsAttributeBo(entry.getKey(), im.getNamespace());
 79  0
                    attributeBo = new ActionAttributeBo();
 80  0
                    attributeBo.setActionId( im.getId() );
 81  0
                    attributeBo.setAttributeDefinitionId( attrDefBo.getId() );
 82  0
                    attributeBo.setValue( entry.getValue() );
 83  0
                    attributeBo.setAttributeDefinition( attrDefBo );
 84  0
                    attrs.add( attributeBo );
 85  
            }
 86  3
            bo.setAttributeBos(attrs);
 87  
 
 88  3
            return bo
 89  
    }
 90  
 }