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