Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RegistrationViewHelperServiceImpl |
|
| 10.333333333333334;10.333 |
1 | package org.kuali.student.enrollment.class2.registration.service; | |
2 | ||
3 | import org.apache.commons.lang.StringUtils; | |
4 | import org.kuali.rice.krad.uif.UifConstants; | |
5 | import org.kuali.rice.krad.uif.component.Component; | |
6 | import org.kuali.rice.krad.uif.container.CollectionGroup; | |
7 | import org.kuali.rice.krad.uif.container.Group; | |
8 | import org.kuali.rice.krad.uif.field.ActionField; | |
9 | import org.kuali.rice.krad.uif.field.MessageField; | |
10 | import org.kuali.rice.krad.uif.layout.StackedLayoutManager; | |
11 | import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl; | |
12 | import org.kuali.rice.krad.uif.util.ComponentFactory; | |
13 | import org.kuali.student.enrollment.class2.registration.dto.RegistrationGroupWrapper; | |
14 | import org.kuali.student.enrollment.class2.registration.form.RegistrationForm; | |
15 | import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo; | |
16 | import org.kuali.student.enrollment.courseregistration.dto.RegRequestItemInfo; | |
17 | import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; | |
18 | ||
19 | import java.util.List; | |
20 | ||
21 | 0 | public class RegistrationViewHelperServiceImpl extends ViewHelperServiceImpl { |
22 | ||
23 | public void checkRegElements(CollectionGroup collGroup, RegistrationForm form){ | |
24 | 0 | List<CourseRegistrationInfo> regs = form.getCourseRegistrations(); |
25 | ||
26 | 0 | boolean courseRegistered = false; |
27 | 0 | boolean courseInCart = false; |
28 | ||
29 | 0 | for(Group group: ((StackedLayoutManager)collGroup.getLayoutManager()).getStackedGroups()){ |
30 | 0 | RegistrationGroupWrapper registrationGroupWrapper = (RegistrationGroupWrapper)group.getContext().get(UifConstants.ContextVariableNames.LINE); |
31 | 0 | boolean renderRegButtons = true; |
32 | 0 | boolean renderDropButton = false; |
33 | 0 | boolean renderRemoveFromCartButton = false; |
34 | 0 | String id = registrationGroupWrapper.getRegistrationGroup().getId(); |
35 | ||
36 | 0 | if(StringUtils.isNotBlank(id)){ |
37 | ||
38 | 0 | for (CourseRegistrationInfo reg : regs) { |
39 | 0 | if (reg.getRegGroupRegistration().getRegistrationGroup().getId().equals(id) |
40 | && reg.getRegGroupRegistration().getStateKey().equals(LuiPersonRelationServiceConstants.REGISTERED_STATE_KEY)) { | |
41 | 0 | renderDropButton = true; |
42 | 0 | courseRegistered = true; |
43 | 0 | renderRegButtons = false; |
44 | 0 | break; |
45 | } | |
46 | } | |
47 | ||
48 | 0 | if (form.getRegRequest() != null && form.getRegRequest().getRegRequestItems() != null) { |
49 | 0 | for (RegRequestItemInfo regRequestItemInfo : form.getRegRequest().getRegRequestItems()) { |
50 | 0 | String regGroupId = regRequestItemInfo.getNewRegGroupId(); |
51 | 0 | if (StringUtils.isNotBlank(regGroupId)) { |
52 | // find the regGroupWrapper that matches the id from the supplemental list | |
53 | //RegistrationGroupWrapper regGroupWrapper = form.getRegistrationGroupWrappersById().get(regGroupId); | |
54 | 0 | if (regGroupId.equals(id)) { |
55 | 0 | renderRemoveFromCartButton = true; |
56 | 0 | courseInCart = true; |
57 | 0 | renderRegButtons = false; |
58 | 0 | break; |
59 | } | |
60 | } | |
61 | 0 | } |
62 | } | |
63 | } | |
64 | 0 | for (Component c : group.getFooter().getItems()) { |
65 | ||
66 | 0 | if(c instanceof ActionField){ |
67 | 0 | if(((ActionField)c).getMethodToCall().equals("addToCart") || (((ActionField)c).getMethodToCall().equals("registerClass"))){ |
68 | 0 | c.setRender(renderRegButtons); |
69 | } | |
70 | 0 | else if(((ActionField)c).getMethodToCall().equals("removeFromCart")){ |
71 | 0 | c.setRender(renderRemoveFromCartButton); |
72 | } | |
73 | 0 | else if(((ActionField)c).getMethodToCall().equals("addDropToCart")){ |
74 | 0 | c.setRender(renderDropButton); |
75 | } | |
76 | } | |
77 | } | |
78 | 0 | if(!renderRegButtons && renderDropButton){ |
79 | 0 | MessageField message = ComponentFactory.getMessageField(); |
80 | 0 | message.setMessageText("You are currently registered for this course."); |
81 | 0 | ((List<Component>)group.getFooter().getItems()).add(0, message); |
82 | 0 | } |
83 | 0 | else if(!renderRegButtons && renderRemoveFromCartButton){ |
84 | 0 | MessageField message = ComponentFactory.getMessageField(); |
85 | 0 | message.setMessageText("This course is currently in your registration cart"); |
86 | 0 | ((List<Component>)group.getFooter().getItems()).add(0, message); |
87 | } | |
88 | 0 | } |
89 | ||
90 | // TODO: RICE=M9 UPGRADE Replace call to "getSummaryMessageField" to use one of the new ContainerBase message field widgets, I suspect this should use getErrorsField | |
91 | 0 | if(courseRegistered){ |
92 | //collGroup.getSummaryMessageField().setMessageText("You are currently registered for a version of this course."); | |
93 | //collGroup.getSummaryMessageField().addStyleClass("ks-regWarning"); | |
94 | } | |
95 | 0 | else if(courseInCart){ |
96 | //collGroup.getSummaryMessageField().setMessageText("Your cart contains a version of this course."); | |
97 | //collGroup.getSummaryMessageField().addStyleClass("ks-regWarning"); | |
98 | } | |
99 | else{ | |
100 | //collGroup.getSummaryMessageField().setMessageText("Add a course to your cart or register with a single click:"); | |
101 | //collGroup.getSummaryMessageField().getStyleClasses().remove("ks-regWarning"); | |
102 | } | |
103 | 0 | } |
104 | ||
105 | public void checkSubmitItemRender(Component component, RegistrationForm form){ | |
106 | 0 | boolean render = false; |
107 | 0 | if(form.getRegRequest() != null && form.getRegRequest().getRegRequestItems() != null |
108 | && !form.getRegRequest().getRegRequestItems().isEmpty()){ | |
109 | 0 | render = true; |
110 | } | |
111 | 0 | component.setRender(render); |
112 | 0 | } |
113 | ||
114 | public void checkRenderCartEmpty(Component component, RegistrationForm form){ | |
115 | 0 | boolean render = true; |
116 | 0 | if(form.getRegRequest() != null && form.getRegRequest().getRegRequestItems() != null |
117 | && !form.getRegRequest().getRegRequestItems().isEmpty()){ | |
118 | 0 | render = false; |
119 | } | |
120 | 0 | component.setRender(render); |
121 | 0 | } |
122 | } |