Coverage Report - org.kuali.student.lum.lu.ui.course.client.controllers.CourseRetireByProposalController
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseRetireByProposalController
0%
0/53
0%
0/16
1.615
CourseRetireByProposalController$1
0%
0/16
N/A
1.615
 
 1  
 /**
 2  
  * 
 3  
  */
 4  
 package org.kuali.student.lum.lu.ui.course.client.controllers;
 5  
 
 6  
 import java.util.ArrayList;
 7  
 import java.util.List;
 8  
 
 9  
 import org.kuali.student.common.assembly.data.Data;
 10  
 import org.kuali.student.common.dto.DtoConstants;
 11  
 import org.kuali.student.common.rice.StudentIdentityConstants;
 12  
 import org.kuali.student.common.ui.client.application.Application;
 13  
 import org.kuali.student.common.ui.client.application.ViewContext;
 14  
 import org.kuali.student.common.ui.client.event.ActionEvent;
 15  
 import org.kuali.student.common.ui.client.event.SaveActionEvent;
 16  
 import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
 17  
 import org.kuali.student.common.ui.client.mvc.Callback;
 18  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 19  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 20  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 21  
 import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcServiceAsync;
 22  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 23  
 import org.kuali.student.common.ui.client.util.ExportElement;
 24  
 import org.kuali.student.common.ui.client.util.ExportUtils;
 25  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 26  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 27  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 28  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 29  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 30  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 31  
 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
 32  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 33  
 import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities;
 34  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 35  
 import org.kuali.student.lum.lu.LUConstants;
 36  
 import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants;
 37  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer;
 38  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseRetireByProposalConfigurer;
 39  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer.CourseSections;
 40  
 import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseRetireProposalRpcService;
 41  
 import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList;
 42  
 
 43  
 import com.google.gwt.core.client.GWT;
 44  
 import com.google.gwt.event.dom.client.ClickEvent;
 45  
 import com.google.gwt.event.dom.client.ClickHandler;
 46  
 import com.google.gwt.user.client.Window;
 47  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 48  
 
 49  
 /**
 50  
  * New controller for Retire Course screen.
 51  
  * 
 52  
  *
 53  
  */
 54  
 
 55  0
 public class CourseRetireByProposalController extends CourseProposalController {
 56  
 
 57  
         /**
 58  
          * Override the intitailzeController method to use CourseAdminConfigurer 
 59  
          */
 60  
         @Override
 61  
         protected void initializeController() {
 62  0
                 cluProposalRpcServiceAsync = GWT.create(CreditCourseRetireProposalRpcService.class);                   
 63  0
                 super.cfg = GWT.create(CourseRetireByProposalConfigurer.class);        
 64  0
                 proposalPath = cfg.getProposalPath();
 65  0
                 workflowUtil = new WorkflowUtilities(CourseRetireByProposalController.this, proposalPath, "Proposal Actions",
 66  
                                    CourseProposalConfigurer.CourseSections.WF_APPROVE_DIALOG,"", cfg.getModelId());//TODO make msg
 67  0
                    cfg.setState(DtoConstants.STATE_DRAFT);                   
 68  0
                    cfg.setNextState(DtoConstants.STATE_RETIRED);
 69  
                    
 70  
                    /* - Having navigation problems where the copied proposal does not come up
 71  
                     *   MPG pointed out this is backlogged and wouldn't really do what the user wants anyway
 72  
                     *   so moving on to other tasks for now. - KSCM-1775
 73  
                     *
 74  
                     *    
 75  
                    
 76  
                    //Add an extra menu item to copy the proposal to a new proposal.
 77  
                    workflowUtil.getAdditionalItems().add(new KSMenuItemData(this.getMessage("cluCopyItem"), new ClickHandler(){
 78  
                         @Override
 79  
                         public void onClick(ClickEvent event) {
 80  
                             if(getViewContext() != null && getViewContext().getId() != null && !getViewContext().getId().isEmpty()){
 81  
                                     getViewContext().setId((String)cluProposalModel.get(cfg.getProposalPath()+"/id"));
 82  
                                     getViewContext().setIdType(IdType.COPY_OF_KS_KEW_OBJECT_ID);
 83  
                                     getViewContext().getAttributes().remove(StudentIdentityConstants.DOCUMENT_TYPE_NAME);
 84  
                                     cluProposalModel.resetRoot(); // Reset the root so that the model can be reloaded from the copied proposal.
 85  
                         }
 86  
                 HistoryManager.navigate("/HOME/CURRICULUM_HOME/COURSE_RETIRE_BY_PROPOSAL", getViewContext());
 87  
                         }
 88  
                 }));
 89  
                    */
 90  
                    
 91  0
                    super.setDefaultModelId(cfg.getModelId());
 92  0
                    super.registerModelsAndHandlers();
 93  0
                    super.addStyleName("ks-course-admin");  
 94  0
                    currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_RETIRE;         
 95  
 
 96  0
     }
 97  
         
 98  
         // Overriding this method to make things a little cleaner.
 99  
         @Override
 100  
     protected void populateModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){
 101  0
             if(getViewContext().getIdType() == IdType.DOCUMENT_ID){
 102  0
             getCluProposalFromWorkflowId(callback, workCompleteCallback);
 103  0
         } else if (getViewContext().getIdType() == IdType.KS_KEW_OBJECT_ID || getViewContext().getIdType() == IdType.OBJECT_ID){
 104  
                 // Admin Retire goes here
 105  0
             getCluProposalFromProposalId(getViewContext().getId(), callback, workCompleteCallback);
 106  0
         } else if (getViewContext().getIdType() == IdType.COPY_OF_OBJECT_ID){                
 107  0
                  if (LUConstants.PROPOSAL_TYPE_COURSE_RETIRE.equals(getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME)))
 108  
                     { // Retire By Proposal
 109  0
                         createRetireCluProposalModel(callback, workCompleteCallback);
 110  
                 }
 111  
       }
 112  0
         }
 113  
         
 114  
         protected void createRetireCluProposalModel(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 115  0
         Data data = new Data();
 116  0
         cluProposalModel.setRoot(data);        
 117  
        
 118  0
         Data proposalData = new Data();
 119  0
         proposalData.set(new Data.StringKey("type"), LUConstants.PROPOSAL_TYPE_COURSE_RETIRE);
 120  0
         data.set(new Data.StringKey("proposal"), proposalData);
 121  0
         if (cfg.getNextState() == null && cfg.getNextState().isEmpty()){
 122  0
                 proposalData.set(new Data.StringKey("workflowNode"), "PreRoute");
 123  
         }
 124  
                 
 125  0
         data.set(new Data.StringKey("id"), getViewContext().getId());
 126  
         
 127  0
         cluProposalRpcServiceAsync.saveData(cluProposalModel.getRoot(), new AsyncCallback<DataSaveResult>() {
 128  
                         public void onSuccess(DataSaveResult result) {
 129  
                                 
 130  0
                                 cluProposalModel.setRoot(result.getValue());
 131  0
                                 setHeaderTitle();
 132  0
                         setLastUpdated();
 133  
                         //add to recently viewed now that we know the id of proposal
 134  0
                         ViewContext docContext = new ViewContext();
 135  0
                         docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id"));
 136  0
                         docContext.setIdType(IdType.KS_KEW_OBJECT_ID);
 137  
                         //RecentlyViewedHelper.addDocument(getProposalTitle(), 
 138  
                         //        HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), docContext)
 139  
                         //                + "/SUMMARY");
 140  
                         //getCourseComparisonModelAndReqs(callback, workCompleteCallback);
 141  
                         
 142  
                         // We need to update the current view context so that if the user clicks the back button it doesn't 
 143  
                         // create a duplicate course proposal. 
 144  0
                         getViewContext().setIdType(docContext.getIdType());
 145  0
                         getViewContext().setId(docContext.getId());
 146  0
                         callback.onModelReady(cluProposalModel);
 147  0
                         workCompleteCallback.exec(true);
 148  
                         
 149  0
                         }
 150  
                         
 151  
                         public void onFailure(Throwable caught) {
 152  0
                 Window.alert("Error loading Proposal: "+caught.getMessage());
 153  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 154  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 155  0
                         }
 156  
                 });        
 157  
             
 158  
             
 159  
 
 160  0
     }
 161  
         
 162  
         
 163  
         
 164  
         /**
 165  
      * Override the setHeaderTitle to display proper header title for admin screens
 166  
      */
 167  
         @Override
 168  
         protected void setHeaderTitle(){
 169  0
                 StringBuffer sb = new StringBuffer();
 170  0
                 sb.append(cluProposalModel.get(cfg.getCourseTitlePath()));
 171  0
                 sb.append(" (Proposed Retirement)");
 172  
                                 
 173  0
                 currentTitle = sb.toString();
 174  
                 
 175  0
                 this.setContentTitle(currentTitle);
 176  0
             this.setName(currentTitle);
 177  0
             WindowTitleUtils.setContextTitle(currentTitle);                
 178  0
     }
 179  
 
 180  
         @Override
 181  
         protected  BaseDataOrchestrationRpcServiceAsync getCourseProposalRpcService(){
 182  0
             return cluProposalRpcServiceAsync;
 183  
     }
 184  
             
 185  
     public boolean startSectionRequired(){
 186  
             //There is no start section for retire screen
 187  0
             return false;
 188  
     }
 189  
 
 190  
     @Override
 191  
         public boolean isAuthorizationRequired() {
 192  
                 //FIXME: Need to add proper authorization checks for admin modify.
 193  0
                 return true;
 194  
         }
 195  
 
 196  
         @Override
 197  
         protected void progressiveEnableFields() {
 198  
                 //Does nothing, there are no progressive enabled fields on retire screens.
 199  0
         }
 200  
         
 201  
         /**
 202  
          * Override the getStateforSaveAction since the save action for retire course will change state to 
 203  
          * retired.  
 204  
          */
 205  
         @Override
 206  
     protected String getStateforSaveAction(DataModel model){
 207  0
             return cfg.getState();
 208  
     }
 209  
         
 210  
         // KSLAB-2585: export Summary to PDF and DOC
 211  
     @Override
 212  
     public String getExportTemplateName() {
 213  0
         return "base.template";
 214  
     }
 215  
     
 216  
     @Override
 217  
     public List<ExportElement> getExportElementsFromView() {
 218  0
         List<ExportElement> exportElements = new ArrayList<ExportElement>();
 219  0
         if (this.getCurrentViewEnum().equals(CourseSections.SUMMARY)) {      
 220  0
             SummaryTableSection tableSection = this.cfg.getSummaryConfigurer().getTableSection();
 221  0
             ExportElement heading = new ExportElement();
 222  0
             heading.setFieldLabel("");
 223  0
             heading.setFieldValue("Retire Proposal");
 224  0
             exportElements.add(heading);
 225  0
             exportElements.addAll(ExportUtils.getDetailsForWidget(tableSection.getSummaryTable()));
 226  
         }
 227  0
         return exportElements;
 228  
     }
 229  
 
 230  
 }