1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.impl.validation; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.core.api.uif.RemotableAttributeField; |
21 | |
import org.kuali.rice.krms.api.repository.rule.RuleDefinition; |
22 | |
import org.kuali.rice.krms.framework.engine.Rule; |
23 | |
import org.kuali.rice.krms.framework.type.ValidationRuleType; |
24 | |
import org.kuali.rice.krms.framework.type.ValidationRuleTypeService; |
25 | |
import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslator; |
26 | |
import org.kuali.rice.krms.impl.type.KrmsTypeServiceBase; |
27 | |
|
28 | |
import javax.jws.WebParam; |
29 | |
import java.util.List; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public final class ValidationRuleTypeServiceImpl extends KrmsTypeServiceBase implements ValidationRuleTypeService { |
35 | |
|
36 | |
private RepositoryToEngineTranslator translator; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
private ValidationRuleTypeServiceImpl(){ |
42 | 0 | super(); |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public static ValidationRuleTypeService getInstance() { |
50 | 0 | return new ValidationRuleTypeServiceImpl(); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public Rule loadRule(RuleDefinition validationRuleDefinition) { |
55 | 0 | if (validationRuleDefinition == null) { throw new RiceIllegalArgumentException("validationRuleDefinition must not be null"); } |
56 | 0 | if (validationRuleDefinition.getAttributes() == null) { throw new RiceIllegalArgumentException("validationRuleDefinition must not be null");} |
57 | |
|
58 | 0 | if (!validationRuleDefinition.getAttributes().containsKey(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE)) { |
59 | |
|
60 | 0 | throw new RiceIllegalArgumentException("validationRuleDefinition does not contain an " + |
61 | |
ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE + " attribute"); |
62 | |
} |
63 | 0 | String validationRuleTypeCode = validationRuleDefinition.getAttributes().get(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE); |
64 | |
|
65 | 0 | if (StringUtils.isBlank(validationRuleTypeCode)) { |
66 | 0 | throw new RiceIllegalArgumentException(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE + " attribute must not be null or blank"); |
67 | |
} |
68 | |
|
69 | 0 | if (ValidationRuleType.VALID.getCode().equals(validationRuleTypeCode)) { |
70 | 0 | return new ValidationRule(ValidationRuleType.VALID, validationRuleDefinition.getName(), |
71 | |
translator.translatePropositionDefinition(validationRuleDefinition.getProposition()), |
72 | |
translator.translateActionDefinitions(validationRuleDefinition.getActions())); |
73 | |
} |
74 | 0 | if (ValidationRuleType.INVALID.getCode().equals(validationRuleTypeCode)) { |
75 | 0 | return new ValidationRule(ValidationRuleType.INVALID, validationRuleDefinition.getName(), |
76 | |
translator.translatePropositionDefinition(validationRuleDefinition.getProposition()), |
77 | |
translator.translateActionDefinitions(validationRuleDefinition.getActions())); |
78 | |
} |
79 | 0 | return null; |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public List<RemotableAttributeField> getAttributeFields(@WebParam(name = "krmsTypeId") String krmsTypeId) throws RiceIllegalArgumentException { |
84 | 0 | RadioButtonTypeServiceUtil radioButtonTypeServiceUtil = new RadioButtonTypeServiceUtil(); |
85 | 0 | return radioButtonTypeServiceUtil.getAttributeFields(krmsTypeId); |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void setRepositoryToEngineTranslator(RepositoryToEngineTranslator translator) { |
92 | 0 | this.translator = translator; |
93 | 0 | } |
94 | |
} |
95 | |
|