Coverage Report - org.kuali.rice.krms.impl.repository.PropositionBoServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PropositionBoServiceImpl
0%
0/71
0%
0/34
4.333
 
 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  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.krad.service.BusinessObjectService;
 25  
 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
 26  
 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
 27  
 
 28  0
 public final class PropositionBoServiceImpl implements PropositionBoService {
 29  
 
 30  
     private BusinessObjectService businessObjectService;
 31  
 
 32  
         /**
 33  
          * This overridden method creates a Proposition if it does not 
 34  
          * already exist in the repository.
 35  
          * 
 36  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#createProposition(org.kuali.rice.krms.api.repository.proposition.PropositionDefinition)
 37  
          */
 38  
         @Override
 39  
         public PropositionDefinition createProposition(PropositionDefinition prop) {
 40  0
                 if (prop == null){
 41  0
                 throw new IllegalArgumentException("proposition is null");
 42  
                 }
 43  0
                 if (null != prop.getId()) {
 44  0
                     throw new IllegalStateException("for creation, PropositionDefinition.id must be null");
 45  
             }
 46  
                 
 47  0
                 PropositionBo propositionBo = PropositionBo.from(prop);
 48  0
                 businessObjectService.save(propositionBo);
 49  0
                 return PropositionBo.to(propositionBo);
 50  
         }
 51  
 
 52  
         /**
 53  
          * This overridden method updates an existing proposition
 54  
          * 
 55  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#updateProposition(org.kuali.rice.krms.api.repository.proposition.PropositionDefinition)
 56  
          */
 57  
         @Override
 58  
         public void updateProposition(PropositionDefinition prop) {
 59  0
         if (prop == null) {
 60  0
             throw new IllegalArgumentException("proposition is null");
 61  
         }
 62  0
                 final String propIdKey = prop.getId();
 63  0
                 final PropositionDefinition existing = getPropositionById(propIdKey);
 64  0
         if (existing == null) {
 65  0
             throw new IllegalStateException("the proposition does not exist: " + prop);
 66  
         }
 67  
         final PropositionDefinition toUpdate;
 68  0
         if (!existing.getId().equals(prop.getId())){
 69  0
                 final PropositionDefinition.Builder builder = PropositionDefinition.Builder.create(prop);
 70  0
                 builder.setId(existing.getId());
 71  0
                 toUpdate = builder.build();
 72  0
         } else {
 73  0
                 toUpdate = prop;
 74  
         }
 75  
         
 76  0
         businessObjectService.save(PropositionBo.from(toUpdate));
 77  0
         }
 78  
 
 79  
         /**
 80  
          * This overridden method retrieves a proposition by the give proposition id.
 81  
          * 
 82  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#getPropositionById(java.lang.String)
 83  
          */
 84  
         @Override
 85  
         public PropositionDefinition getPropositionById(String propId) {
 86  0
                 if (StringUtils.isBlank(propId)){
 87  0
             throw new IllegalArgumentException("propId is null or blank");                        
 88  
                 }
 89  0
                 PropositionBo bo = businessObjectService.findBySinglePrimaryKey(PropositionBo.class, propId);
 90  0
                 return PropositionBo.to(bo);
 91  
         }
 92  
 
 93  
         /**
 94  
          * This overridden method creates a PropositionParameter if it does not 
 95  
          * already exist in the repository.
 96  
          * 
 97  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#createParameter(org.kuali.rice.krms.api.repository.proposition.PropositionParameter)
 98  
          */
 99  
         @Override
 100  
         public void createParameter(PropositionParameter parameter) {
 101  0
                 if (parameter == null){
 102  0
                 throw new IllegalArgumentException("parameter is null");
 103  
                 }
 104  0
                 final String propIdKey = parameter.getPropId();
 105  0
                 final Integer seqNoKey = parameter.getSequenceNumber();
 106  0
                 final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey);
 107  0
                 if (existing != null && existing.getPropId().equals(propIdKey) && existing.getSequenceNumber().equals(seqNoKey)){
 108  0
             throw new IllegalStateException("the parameter to create already exists: " + parameter);                        
 109  
                 }
 110  
                 
 111  0
                 businessObjectService.save(PropositionParameterBo.from(parameter));
 112  0
         }
 113  
 
 114  
         /**
 115  
          * This overridden method updates an existing proposition parameter
 116  
          * 
 117  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#updateParameter(org.kuali.rice.krms.api.repository.proposition.PropositionParameter)
 118  
          */
 119  
         @Override
 120  
         public void updateParameter(PropositionParameter parameter) {
 121  0
         if (parameter == null) {
 122  0
             throw new IllegalArgumentException("parameter is null");
 123  
         }
 124  0
                 final String propIdKey = parameter.getPropId();
 125  0
                 final Integer seqNoKey = parameter.getSequenceNumber();
 126  0
                 final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey);
 127  0
         if (existing == null) {
 128  0
             throw new IllegalStateException("the parameter does not exist: " + parameter);
 129  
         }
 130  
         final PropositionParameter toUpdate;
 131  0
         if (!existing.getId().equals(parameter.getId())){
 132  0
                 final PropositionParameter.Builder builder = PropositionParameter.Builder.create(parameter);
 133  0
                 builder.setId(existing.getId());
 134  0
                 toUpdate = builder.build();
 135  0
         } else {
 136  0
                 toUpdate = parameter;
 137  
         }
 138  
         
 139  0
         businessObjectService.save(PropositionParameterBo.from(toUpdate));
 140  0
         }
 141  
 
 142  
         /**
 143  
          * This overridden method retrieves a list of parameters for a given proposition
 144  
          * 
 145  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#getParameters(java.lang.Long)
 146  
          */
 147  
         @Override
 148  
         public List<PropositionParameter> getParameters(String propId) {
 149  0
                 if (StringUtils.isBlank(propId)) {
 150  0
             throw new IllegalArgumentException("propId is null or blank");
 151  
                 }
 152  0
         final Map<String, Object> map = new HashMap<String, Object>();
 153  0
         map.put("propId", propId);
 154  0
                 List<PropositionParameterBo> bos = (List<PropositionParameterBo>) businessObjectService.findMatchingOrderBy(PropositionParameterBo.class, map, "sequenceNumber", true);
 155  0
                 return PropositionParameterBo.to(bos);
 156  
         }
 157  
 
 158  
         /**
 159  
          * This overridden method gets a parameter by the parameter id
 160  
          * 
 161  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#getParameterById(java.lang.String)
 162  
          */
 163  
         @Override
 164  
         public PropositionParameter getParameterById(String id) {
 165  0
                 if (StringUtils.isBlank(id)) {
 166  0
             throw new IllegalArgumentException("id is null or blank");
 167  
                 }
 168  0
                 PropositionParameterBo bo = businessObjectService.findBySinglePrimaryKey(PropositionParameterBo.class, id);
 169  0
                 return PropositionParameterBo.to(bo);
 170  
         }
 171  
 
 172  
         /**
 173  
          * This overridden method gets a parameter by the Proposition Id and Sequence Number
 174  
          * 
 175  
          * @see org.kuali.rice.krms.impl.repository.PropositionBoService#getParameterByPropIdAndSequenceNumber(java.lang.String, java.lang.String)
 176  
          */
 177  
         @Override
 178  
         public PropositionParameter getParameterByPropIdAndSequenceNumber(
 179  
                         String propId, Integer sequenceNumber) {
 180  0
                 if (StringUtils.isBlank(propId)) {
 181  0
             throw new IllegalArgumentException("propId is null or blank");
 182  
                 }
 183  0
                 if (sequenceNumber == null) {
 184  0
             throw new IllegalArgumentException("sequenceNumber is null");
 185  
                 }
 186  0
         final Map<String, Object> map = new HashMap<String, Object>();
 187  0
         map.put("propId", propId);
 188  0
         map.put("sequenceNumber", sequenceNumber);
 189  0
                 PropositionParameterBo bo = businessObjectService.findByPrimaryKey(PropositionParameterBo.class, map);
 190  0
                 return PropositionParameterBo.to(bo);
 191  
         }
 192  
         
 193  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 194  0
         this.businessObjectService = businessObjectService;
 195  0
     }
 196  
 
 197  
 }