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