Coverage Report - org.kuali.rice.krms.impl.repository.TermResolverBo
 
Classes in this File Line Coverage Branch Coverage Complexity
TermResolverBo
0%
0/49
0%
0/24
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.term.TermResolverDefinition;
 8  
 import org.kuali.rice.krms.api.repository.term.TermResolverDefinitionContract;
 9  
 
 10  
 public class TermResolverBo extends PersistableBusinessObjectBase implements TermResolverDefinitionContract {
 11  
     
 12  
     def String id
 13  
     def String namespaceCode
 14  
     def String name
 15  
     def String contextId
 16  
     def String typeId
 17  
     def String outputId
 18  
 
 19  
     def TermSpecificationBo output
 20  
     def Set<TermSpecificationBo> prerequisites
 21  
     def Set<TermResolverParameterSpecificationBo> parameterSpecifications;
 22  
     def Set<TermResolverAttributeBo> attributeBos
 23  
 
 24  
     public void setParameterNames(Set<String> pns) {
 25  0
         if (pns != null) {
 26  0
             parameterSpecifications = new HashSet<TermResolverParameterSpecificationBo>();
 27  0
             for (String pn : pns) {
 28  0
                 TermResolverParameterSpecificationBo paramSpecBo = new TermResolverParameterSpecificationBo();
 29  0
                 paramSpecBo.setName(pn);
 30  0
                 paramSpecBo.setTermResolverId(id);
 31  0
                 parameterSpecifications.add(paramSpecBo);
 32  
             }
 33  
         }
 34  
     }
 35  
 
 36  
     public Set<String> getParameterNames() {
 37  0
         Set<String> results = Collections.emptySet();
 38  
 
 39  0
         if (parameterSpecifications != null && parameterSpecifications.size() > 0) {
 40  0
             results = new HashSet<String>();
 41  0
             for (parmSpec in parameterSpecifications) {
 42  0
                 results.add( parmSpec.name );
 43  
             }
 44  
         }
 45  0
         return results;
 46  
     }
 47  
     
 48  
         public Map<String, String> getAttributes() {
 49  0
                 HashMap<String, String> attributes = new HashMap<String, String>();
 50  0
                 for (attr in attributeBos) {
 51  0
                         attributes.put( attr.attributeDefinition.name, attr.value )
 52  
                 }
 53  0
                 return attributes;
 54  
         }
 55  
 
 56  
     /**
 57  
      * Converts a mutable bo to it's immutable counterpart
 58  
      * @param bo the mutable business object
 59  
      * @return the immutable object
 60  
      */
 61  
     static TermResolverDefinition to(TermResolverBo bo) {
 62  0
         if (bo == null) { return null }
 63  0
         return org.kuali.rice.krms.api.repository.term.TermResolverDefinition.Builder.create(bo).build()
 64  
     }
 65  
 
 66  
     /**
 67  
      * Converts a immutable object to it's mutable bo counterpart
 68  
      * @param im immutable object
 69  
      * @return the mutable bo
 70  
      */
 71  
     static TermResolverBo from(TermResolverDefinition im) {
 72  0
         if (im == null) { return null }
 73  
 
 74  0
         TermResolverBo bo = new TermResolverBo()
 75  0
         bo.id = im.id
 76  0
         bo.namespaceCode = im.namespaceCode
 77  0
         bo.name = im.name
 78  0
         bo.contextId = im.contextId
 79  0
         bo.typeId = im.typeId
 80  0
         bo.output = TermSpecificationBo.from(im.output)
 81  0
         bo.outputId = im.output.id
 82  0
         bo.parameterNames = new HashSet<String>()
 83  0
                 for (paramName in im.parameterNames) {
 84  0
                         bo.parameterSpecifications.add(TermResolverParameterSpecificationBo.from(im, paramName))
 85  
                 }
 86  0
                 bo.prerequisites = new HashSet<TermSpecificationBo>()
 87  0
                 for (prereq in im.prerequisites){
 88  0
                         bo.prerequisites.add (TermSpecificationBo.from(prereq))
 89  
                 }
 90  
                 
 91  
                 // build the set of term resolver attribute BOs
 92  0
                 Set<TermResolverAttributeBo> attrs = new HashSet<TermResolverAttributeBo>();
 93  
 
 94  
                 // for each converted pair, build an TermResolverAttributeBo and add it to the set
 95  0
                 TermResolverAttributeBo attributeBo;
 96  0
                 for (Entry<String,String> entry  : im.getAttributes().entrySet()){
 97  0
                         KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator
 98  
                                         .getKrmsAttributeDefinitionService()
 99  0
                                         .getKrmsAttributeBo(entry.getKey(), im.getNamespaceCode());
 100  0
                         attributeBo = new TermResolverAttributeBo();
 101  0
                         attributeBo.setTermResolverId( im.getId() );
 102  0
                         attributeBo.setAttributeDefinitionId( attrDefBo.getId() );
 103  0
                         attributeBo.setValue( entry.getValue() );
 104  0
                         attributeBo.setAttributeDefinition( attrDefBo );
 105  0
                         attrs.add( attributeBo );
 106  
                 }
 107  0
                 bo.setAttributeBos(attrs);
 108  0
                 bo.versionNumber = im.versionNumber
 109  0
                 return bo
 110  
         }
 111  
         public TermSpecificationBo getOutput(){
 112  0
                 return output;
 113  
     }
 114  
 
 115  
 }