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