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