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