| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | 29 | public final class PropositionBoServiceImpl implements PropositionBoService { |
| 29 | |
|
| 30 | |
private BusinessObjectService businessObjectService; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
@Override |
| 39 | |
public PropositionDefinition createProposition(PropositionDefinition prop) { |
| 40 | 4 | if (prop == null){ |
| 41 | 1 | throw new IllegalArgumentException("proposition is null"); |
| 42 | |
} |
| 43 | 3 | if (null != prop.getId()) { |
| 44 | 1 | throw new IllegalStateException("for creation, PropositionDefinition.id must be null"); |
| 45 | |
} |
| 46 | |
|
| 47 | 2 | PropositionBo propositionBo = PropositionBo.from(prop); |
| 48 | 2 | businessObjectService.save(propositionBo); |
| 49 | 2 | return PropositionBo.to(propositionBo); |
| 50 | |
} |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public void updateProposition(PropositionDefinition prop) { |
| 59 | 3 | if (prop == null) { |
| 60 | 1 | throw new IllegalArgumentException("proposition is null"); |
| 61 | |
} |
| 62 | 2 | final String propIdKey = prop.getId(); |
| 63 | 2 | final PropositionDefinition existing = getPropositionById(propIdKey); |
| 64 | 2 | if (existing == null) { |
| 65 | 1 | throw new IllegalStateException("the proposition does not exist: " + prop); |
| 66 | |
} |
| 67 | |
final PropositionDefinition toUpdate; |
| 68 | 1 | 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 | 1 | toUpdate = prop; |
| 74 | |
} |
| 75 | |
|
| 76 | 1 | businessObjectService.save(PropositionBo.from(toUpdate)); |
| 77 | 1 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public PropositionDefinition getPropositionById(String propId) { |
| 86 | 5 | if (StringUtils.isBlank(propId)){ |
| 87 | 1 | throw new IllegalArgumentException("propId is null or blank"); |
| 88 | |
} |
| 89 | 4 | PropositionBo bo = businessObjectService.findBySinglePrimaryKey(PropositionBo.class, propId); |
| 90 | 4 | return PropositionBo.to(bo); |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public void createParameter(PropositionParameter parameter) { |
| 101 | 3 | if (parameter == null){ |
| 102 | 1 | throw new IllegalArgumentException("parameter is null"); |
| 103 | |
} |
| 104 | 2 | final String propIdKey = parameter.getPropId(); |
| 105 | 2 | final Integer seqNoKey = parameter.getSequenceNumber(); |
| 106 | 2 | final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey); |
| 107 | 2 | if (existing != null && existing.getPropId().equals(propIdKey) && existing.getSequenceNumber().equals(seqNoKey)){ |
| 108 | 1 | throw new IllegalStateException("the parameter to create already exists: " + parameter); |
| 109 | |
} |
| 110 | |
|
| 111 | 1 | businessObjectService.save(PropositionParameterBo.from(parameter)); |
| 112 | 1 | } |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
@Override |
| 120 | |
public void updateParameter(PropositionParameter parameter) { |
| 121 | 3 | if (parameter == null) { |
| 122 | 1 | throw new IllegalArgumentException("parameter is null"); |
| 123 | |
} |
| 124 | 2 | final String propIdKey = parameter.getPropId(); |
| 125 | 2 | final Integer seqNoKey = parameter.getSequenceNumber(); |
| 126 | 2 | final PropositionParameter existing = getParameterByPropIdAndSequenceNumber(propIdKey, seqNoKey); |
| 127 | 2 | if (existing == null) { |
| 128 | 1 | throw new IllegalStateException("the parameter does not exist: " + parameter); |
| 129 | |
} |
| 130 | |
final PropositionParameter toUpdate; |
| 131 | 1 | 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 | 1 | toUpdate = parameter; |
| 137 | |
} |
| 138 | |
|
| 139 | 1 | businessObjectService.save(PropositionParameterBo.from(toUpdate)); |
| 140 | 1 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
@Override |
| 148 | |
public List<PropositionParameter> getParameters(String propId) { |
| 149 | 4 | if (StringUtils.isBlank(propId)) { |
| 150 | 2 | throw new IllegalArgumentException("propId is null or blank"); |
| 151 | |
} |
| 152 | 2 | final Map<String, Object> map = new HashMap<String, Object>(); |
| 153 | 2 | map.put("propId", propId); |
| 154 | 2 | List<PropositionParameterBo> bos = (List<PropositionParameterBo>) businessObjectService.findMatchingOrderBy(PropositionParameterBo.class, map, "sequenceNumber", true); |
| 155 | 2 | return PropositionParameterBo.to(bos); |
| 156 | |
} |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
@Override |
| 164 | |
public PropositionParameter getParameterById(String id) { |
| 165 | 4 | if (StringUtils.isBlank(id)) { |
| 166 | 2 | throw new IllegalArgumentException("id is null or blank"); |
| 167 | |
} |
| 168 | 2 | PropositionParameterBo bo = businessObjectService.findBySinglePrimaryKey(PropositionParameterBo.class, id); |
| 169 | 2 | return PropositionParameterBo.to(bo); |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
@Override |
| 178 | |
public PropositionParameter getParameterByPropIdAndSequenceNumber( |
| 179 | |
String propId, Integer sequenceNumber) { |
| 180 | 9 | if (StringUtils.isBlank(propId)) { |
| 181 | 2 | throw new IllegalArgumentException("propId is null or blank"); |
| 182 | |
} |
| 183 | 7 | if (sequenceNumber == null) { |
| 184 | 1 | throw new IllegalArgumentException("sequenceNumber is null"); |
| 185 | |
} |
| 186 | 6 | final Map<String, Object> map = new HashMap<String, Object>(); |
| 187 | 6 | map.put("propId", propId); |
| 188 | 6 | map.put("sequenceNumber", sequenceNumber); |
| 189 | 6 | PropositionParameterBo bo = businessObjectService.findByPrimaryKey(PropositionParameterBo.class, map); |
| 190 | 6 | return PropositionParameterBo.to(bo); |
| 191 | |
} |
| 192 | |
|
| 193 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
| 194 | 29 | this.businessObjectService = businessObjectService; |
| 195 | 29 | } |
| 196 | |
|
| 197 | |
} |