| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 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 | |
|
| 56 | |
|
| 57 | |
|
| 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 | |
|
| 83 | |
|
| 84 | |
|
| 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 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 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 | |
|
| 118 | |
|
| 119 | |
|
| 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 | |
|
| 146 | |
|
| 147 | |
|
| 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 | |
|
| 162 | |
|
| 163 | |
|
| 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 | |
|
| 176 | |
|
| 177 | |
|
| 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 | |
} |