Coverage Report - org.kuali.student.enrollment.class2.registration.service.RegistrationViewHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RegistrationViewHelperServiceImpl
0%
0/53
0%
0/52
9.667
 
 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.RegistrationRequestItemInfo;
 17  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 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  
                     /*
 40  
                     if (reg.getRegGroupRegistration().getRegistrationGroup().getId().equals(id)
 41  
                             && reg.getRegGroupRegistration().getStateKey().equals(LprServiceConstants.REGISTERED_STATE_KEY)) {
 42  
                         renderDropButton = true;
 43  
                         courseRegistered = true;
 44  
                         renderRegButtons = false;
 45  
                         break;
 46  
                     }
 47  
                     */
 48  
                 }
 49  
 
 50  0
                 if (form.getRegRequest() != null && form.getRegRequest().getRegistrationRequestItems() != null) {
 51  0
                     for (RegistrationRequestItemInfo regRequestItemInfo : form.getRegRequest().getRegistrationRequestItems()) {
 52  0
                         String regGroupId = regRequestItemInfo.getNewRegistrationGroupId();
 53  0
                         if (StringUtils.isNotBlank(regGroupId)) {
 54  
                             // find the regGroupWrapper that matches the id from the supplemental list
 55  
                             //RegistrationGroupWrapper regGroupWrapper = form.getRegistrationGroupWrappersById().get(regGroupId);
 56  0
                             if (regGroupId.equals(id)) {
 57  0
                                 renderRemoveFromCartButton = true;
 58  0
                                 courseInCart = true;
 59  0
                                 renderRegButtons = false;
 60  0
                                 break;
 61  
                             }
 62  
                         }
 63  0
                     }
 64  
                 }
 65  
             }
 66  0
             for (Component c : group.getFooter().getItems()) {
 67  
 
 68  0
                 if(c instanceof ActionField){
 69  0
                     if(((ActionField)c).getMethodToCall().equals("addToCart") || (((ActionField)c).getMethodToCall().equals("registerClass"))){
 70  0
                         c.setRender(renderRegButtons);
 71  
                     }
 72  0
                     else if(((ActionField)c).getMethodToCall().equals("removeFromCart")){
 73  0
                         c.setRender(renderRemoveFromCartButton);
 74  
                     }
 75  0
                     else if(((ActionField)c).getMethodToCall().equals("addDropToCart")){
 76  0
                         c.setRender(renderDropButton);
 77  
                     }
 78  
                 }
 79  
             }
 80  0
             if(!renderRegButtons && renderDropButton){
 81  0
                 MessageField message = ComponentFactory.getMessageField();
 82  0
                 message.setMessageText("You are currently registered for this course.");
 83  0
                 ((List<Component>)group.getFooter().getItems()).add(0, message);
 84  0
             }
 85  0
             else if(!renderRegButtons && renderRemoveFromCartButton){
 86  0
                 MessageField message = ComponentFactory.getMessageField();
 87  0
                 message.setMessageText("This course is currently in your registration cart");
 88  0
                 ((List<Component>)group.getFooter().getItems()).add(0, message);
 89  
             }
 90  0
         }
 91  
 
 92  
         // TODO: RICE=M9 UPGRADE Replace call to "getSummaryMessageField" to use one of the new ContainerBase message field widgets, I suspect this should use getErrorsField
 93  0
         if(courseRegistered){
 94  
            //collGroup.getSummaryMessageField().setMessageText("You are currently registered for a version of this course.");
 95  
            //collGroup.getSummaryMessageField().addStyleClass("ks-regWarning");
 96  
         }
 97  0
         else if(courseInCart){
 98  
            //collGroup.getSummaryMessageField().setMessageText("Your cart contains a version of this course.");
 99  
            //collGroup.getSummaryMessageField().addStyleClass("ks-regWarning");
 100  
         }
 101  
         else{
 102  
            //collGroup.getSummaryMessageField().setMessageText("Add a course to your cart or register with a single click:");
 103  
            //collGroup.getSummaryMessageField().getStyleClasses().remove("ks-regWarning");
 104  
         }
 105  0
     }
 106  
 
 107  
     public void checkSubmitItemRender(Component component, RegistrationForm form){
 108  0
         boolean render = false;
 109  0
         if(form.getRegRequest() != null && form.getRegRequest().getRegistrationRequestItems() != null
 110  
                 && !form.getRegRequest().getRegistrationRequestItems().isEmpty()){
 111  0
             render = true;
 112  
         }
 113  0
         component.setRender(render);
 114  0
     }
 115  
 
 116  
     public void checkRenderCartEmpty(Component component, RegistrationForm form){
 117  0
         boolean render = true;
 118  0
         if(form.getRegRequest() != null && form.getRegRequest().getRegistrationRequestItems() != null
 119  
                 && !form.getRegRequest().getRegistrationRequestItems().isEmpty()){
 120  0
             render = false;
 121  
         }
 122  0
         component.setRender(render);
 123  0
     }
 124  
 }