Coverage Report - org.kuali.rice.krms.impl.repository.ContextBo
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextBo
0%
0/35
0%
0/14
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  
 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
 22  
 import org.kuali.rice.krms.api.repository.context.ContextDefinitionContract;
 23  
 
 24  
 
 25  
 public class ContextBo extends PersistableBusinessObjectBase implements ContextDefinitionContract {
 26  
 
 27  
         String id
 28  
         String name
 29  
         String namespace
 30  
         String typeId
 31  
     String description
 32  
 
 33  0
         List<AgendaBo> agendas = new ArrayList<AgendaBo>()
 34  
 
 35  0
         List<ContextAttributeBo> attributeBos = new ArrayList<ContextAttributeBo>()
 36  0
         List<ContextValidEventBo> validEvents = new ArrayList<ContextValidEventBo>()
 37  0
         List<ContextValidActionBo> validActions = new ArrayList<ContextValidActionBo>()
 38  
 
 39  
         Long versionNumber
 40  
 
 41  
 
 42  
         @Override
 43  
         public List<AgendaBo> getAgendas(){
 44  0
                 return agendas
 45  
         }
 46  
 
 47  
         @Override
 48  
         public Map<String, String> getAttributes() {
 49  0
                 Map<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 ContextDefinition to(ContextBo bo) {
 62  0
                 if (bo == null) { return null }
 63  0
                 return org.kuali.rice.krms.api.repository.context.ContextDefinition.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 ContextBo from(ContextDefinition im) {
 72  0
                 if (im == null) { return null }
 73  
 
 74  0
                 ContextBo bo = new ContextBo()
 75  0
                 bo.id = im.id
 76  0
                 bo.namespace = im.namespace
 77  0
                 bo.name = im.name
 78  0
                 bo.typeId = im.typeId
 79  0
         bo.description = im.description
 80  0
                 bo.agendas = new ArrayList<AgendaBo>()
 81  0
                 for (agenda in im.agendas){
 82  0
                         bo.agendas.add( AgendaBo.from(agenda) )
 83  
                 }
 84  
                 // build the list of agenda attribute BOs
 85  0
                 List<ContextAttributeBo> attrs = new ArrayList<ContextAttributeBo>();
 86  
 
 87  
                 // for each converted pair, build an AgendaAttributeBo and add it to the list
 88  0
                 ContextAttributeBo attributeBo;
 89  0
                 for (Entry<String,String> entry  : im.getAttributes().entrySet()){
 90  0
                         KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator
 91  
                         .getKrmsAttributeDefinitionService()
 92  0
                         .getKrmsAttributeBo(entry.getKey(), im.getNamespace());
 93  0
                         attributeBo = new ContextAttributeBo();
 94  0
                         attributeBo.setContextId( im.getId() );
 95  0
                         attributeBo.setAttributeDefinitionId( attrDefBo.getId() );
 96  0
                         attributeBo.setValue( entry.getValue() );
 97  0
                         attributeBo.setAttributeDefinition( attrDefBo );
 98  0
                         attrs.add( attributeBo );
 99  
                 }
 100  0
                 bo.setAttributeBos(attrs);
 101  
 
 102  0
                 bo.versionNumber = im.versionNumber
 103  0
                 return bo
 104  
         }
 105  
 }