View Javadoc

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