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.action.ActionDefinition; |
22 | |
import org.kuali.rice.krms.framework.type.ValidationActionService; |
23 | |
import org.kuali.rice.krms.framework.engine.Action; |
24 | |
import org.kuali.rice.krms.framework.type.ActionTypeService; |
25 | |
import org.kuali.rice.krms.framework.type.ValidationActionType; |
26 | |
import org.kuali.rice.krms.framework.type.ValidationActionTypeService; |
27 | |
import org.kuali.rice.krms.impl.type.KrmsTypeServiceBase; |
28 | |
|
29 | |
import javax.jws.WebParam; |
30 | |
import java.util.List; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class ValidationActionTypeServiceImpl extends KrmsTypeServiceBase implements ValidationActionTypeService { |
36 | |
private ValidationActionService validationService; |
37 | |
|
38 | 0 | private ValidationActionTypeServiceImpl() {} |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public static ActionTypeService getInstance() { |
45 | 0 | return new ValidationActionTypeServiceImpl(); |
46 | |
} |
47 | |
|
48 | |
@Override |
49 | |
public Action loadAction(ActionDefinition validationActionDefinition) { |
50 | |
|
51 | 0 | if (validationActionDefinition == null) { throw new RiceIllegalArgumentException("validationActionDefinition must not be null"); } |
52 | 0 | if (validationActionDefinition.getAttributes() == null) { throw new RiceIllegalArgumentException("validationActionDefinition must not be null");} |
53 | 0 | if (!validationActionDefinition.getAttributes().containsKey(ValidationActionTypeService.VALIDATIONS_ACTION_TYPE_CODE_ATTRIBUTE)) { |
54 | 0 | throw new RiceIllegalArgumentException("validationActionDefinition does not contain an " + |
55 | |
ValidationActionTypeService.VALIDATIONS_ACTION_TYPE_CODE_ATTRIBUTE + " attribute"); |
56 | |
} |
57 | 0 | String validationActionTypeCode = validationActionDefinition.getAttributes().get(ValidationActionTypeService.VALIDATIONS_ACTION_TYPE_CODE_ATTRIBUTE); |
58 | |
|
59 | 0 | if (StringUtils.isBlank(validationActionTypeCode)) { |
60 | 0 | throw new RiceIllegalArgumentException(ValidationActionTypeService.VALIDATIONS_ACTION_TYPE_CODE_ATTRIBUTE + " attribute must not be null or blank"); |
61 | |
} |
62 | |
|
63 | 0 | if (ValidationActionType.WARNING.getCode().equals(validationActionTypeCode)) { |
64 | 0 | return new ValidationAction(ValidationActionType.WARNING, validationActionDefinition.getDescription()); |
65 | |
} |
66 | 0 | if (ValidationActionType.ERROR.getCode().equals(validationActionTypeCode)) { |
67 | 0 | return new ValidationAction(ValidationActionType.ERROR, validationActionDefinition.getDescription()); |
68 | |
} |
69 | 0 | return null; |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public List<RemotableAttributeField> getAttributeFields(@WebParam(name = "krmsTypeId") String krmsTypeId) throws RiceIllegalArgumentException { |
74 | 0 | RadioButtonTypeServiceUtil radioButtonTypeServiceUtil = new RadioButtonTypeServiceUtil(); |
75 | 0 | return radioButtonTypeServiceUtil.getAttributeFields(krmsTypeId); |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public void setValidationService(ValidationActionService mockValidationService) { |
80 | 0 | if (mockValidationService == null) { |
81 | 0 | throw new RiceIllegalArgumentException("validationService must not be null"); |
82 | |
} |
83 | 0 | this.validationService = mockValidationService; |
84 | 0 | } |
85 | |
} |