Coverage Report - org.kuali.student.lum.lu.ui.course.client.controllers.CourseProposalController
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseProposalController
0%
0/251
0%
0/114
2.125
CourseProposalController$1
0%
0/8
0%
0/6
2.125
CourseProposalController$10
0%
0/8
N/A
2.125
CourseProposalController$11
0%
0/10
N/A
2.125
CourseProposalController$11$1
0%
0/4
0%
0/2
2.125
CourseProposalController$12
0%
0/9
0%
0/2
2.125
CourseProposalController$12$1
0%
0/7
0%
0/2
2.125
CourseProposalController$12$1$1
0%
0/4
0%
0/2
2.125
CourseProposalController$13
0%
0/16
N/A
2.125
CourseProposalController$14
0%
0/16
0%
0/4
2.125
CourseProposalController$15
0%
0/17
N/A
2.125
CourseProposalController$16
0%
0/9
0%
0/2
2.125
CourseProposalController$16$1
0%
0/9
0%
0/4
2.125
CourseProposalController$17
0%
0/45
0%
0/16
2.125
CourseProposalController$18
0%
0/9
0%
0/4
2.125
CourseProposalController$18$1
0%
0/6
N/A
2.125
CourseProposalController$19
0%
0/10
0%
0/2
2.125
CourseProposalController$2
0%
0/6
0%
0/2
2.125
CourseProposalController$2$1
0%
0/6
0%
0/4
2.125
CourseProposalController$20
0%
0/7
0%
0/4
2.125
CourseProposalController$20$1
0%
0/5
0%
0/4
2.125
CourseProposalController$20$1$1
0%
0/6
N/A
2.125
CourseProposalController$21
0%
0/12
0%
0/6
2.125
CourseProposalController$21$1
0%
0/13
0%
0/4
2.125
CourseProposalController$21$1$1
0%
0/5
0%
0/2
2.125
CourseProposalController$21$1$2
0%
0/10
0%
0/2
2.125
CourseProposalController$21$2
0%
0/5
N/A
2.125
CourseProposalController$22
0%
0/3
N/A
2.125
CourseProposalController$23
0%
0/3
N/A
2.125
CourseProposalController$24
0%
0/5
0%
0/2
2.125
CourseProposalController$25
0%
0/1
N/A
2.125
CourseProposalController$3
0%
0/5
0%
0/4
2.125
CourseProposalController$4
0%
0/3
N/A
2.125
CourseProposalController$5
0%
0/4
N/A
2.125
CourseProposalController$6
0%
0/27
0%
0/18
2.125
CourseProposalController$6$1
0%
0/14
N/A
2.125
CourseProposalController$7
0%
0/3
N/A
2.125
CourseProposalController$8
0%
0/16
0%
0/10
2.125
CourseProposalController$8$1
0%
0/15
0%
0/6
2.125
CourseProposalController$9
0%
0/5
0%
0/2
2.125
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.lu.ui.course.client.controllers;
 17  
 
 18  
 import java.text.DateFormat;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Date;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.kuali.student.common.assembly.data.Data;
 26  
 import org.kuali.student.common.assembly.data.Metadata;
 27  
 import org.kuali.student.common.assembly.data.QueryPath;
 28  
 import org.kuali.student.common.dto.DtoConstants;
 29  
 import org.kuali.student.common.rice.StudentIdentityConstants;
 30  
 import org.kuali.student.common.rice.authorization.PermissionType;
 31  
 import org.kuali.student.common.ui.client.application.Application;
 32  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 33  
 import org.kuali.student.common.ui.client.application.ViewContext;
 34  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 35  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuEditableSectionController;
 36  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
 37  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 38  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 39  
 import org.kuali.student.common.ui.client.event.ActionEvent;
 40  
 import org.kuali.student.common.ui.client.event.ContentDirtyEvent;
 41  
 import org.kuali.student.common.ui.client.event.ContentDirtyEventHandler;
 42  
 import org.kuali.student.common.ui.client.event.SaveActionEvent;
 43  
 import org.kuali.student.common.ui.client.event.SaveActionHandler;
 44  
 import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
 45  
 import org.kuali.student.common.ui.client.mvc.Callback;
 46  
 import org.kuali.student.common.ui.client.mvc.Controller;
 47  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 48  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 49  
 import org.kuali.student.common.ui.client.mvc.HasCrossConstraints;
 50  
 import org.kuali.student.common.ui.client.mvc.ModelProvider;
 51  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 52  
 import org.kuali.student.common.ui.client.mvc.View;
 53  
 import org.kuali.student.common.ui.client.mvc.WorkQueue;
 54  
 import org.kuali.student.common.ui.client.mvc.WorkQueue.WorkItem;
 55  
 import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel;
 56  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 57  
 import org.kuali.student.common.ui.client.security.AuthorizationCallback;
 58  
 import org.kuali.student.common.ui.client.security.RequiresAuthorization;
 59  
 import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcServiceAsync;
 60  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 61  
 import org.kuali.student.common.ui.client.util.ExportElement;
 62  
 import org.kuali.student.common.ui.client.util.ExportUtils;
 63  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 64  
 import org.kuali.student.common.ui.client.validator.ValidatorClientUtils;
 65  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 66  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 67  
 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
 68  
 import org.kuali.student.common.ui.client.widgets.KSDropDown;
 69  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 70  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.YesNoCancelEnum;
 71  
 import org.kuali.student.common.ui.client.widgets.dialog.ButtonMessageDialog;
 72  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup;
 73  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.YesNoCancelGroup;
 74  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 75  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 76  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 77  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 78  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 79  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 80  
 import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
 81  
 import org.kuali.student.common.ui.shared.IdAttributes;
 82  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 83  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 84  
 import org.kuali.student.core.statement.dto.StatementTypeInfo;
 85  
 import org.kuali.student.core.workflow.ui.client.widgets.WorkflowEnhancedNavController;
 86  
 import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities;
 87  
 import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper;
 88  
 import org.kuali.student.lum.common.client.lu.LUUIConstants;
 89  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 90  
 import org.kuali.student.lum.lu.LUConstants;
 91  
 import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants;
 92  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer;
 93  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer.CourseSections;
 94  
 import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel;
 95  
 import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements;
 96  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService;
 97  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync;
 98  
 import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcService;
 99  
 import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcServiceAsync;
 100  
 
 101  
 import com.google.gwt.core.client.GWT;
 102  
 import com.google.gwt.event.dom.client.ClickEvent;
 103  
 import com.google.gwt.event.dom.client.ClickHandler;
 104  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 105  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 106  
 import com.google.gwt.user.client.Window;
 107  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 108  
 
 109  
 /**
 110  
  * Controller for course proposal screens.  This controller controls all functions of the course proposal process
 111  
  * and contains the data model and is responsible for retrieving its data and metadata from the server. In
 112  
  * addition, this controller is responsible for course proposal save events and updating its ui accordingly.
 113  
  * 
 114  
  *
 115  
  * @author Kuali Student Team
 116  
  *
 117  
  */
 118  
 
 119  0
 public class CourseProposalController extends MenuEditableSectionController implements RequiresAuthorization, WorkflowEnhancedNavController, HasRequirements {
 120  
 
 121  
         //RPC Services
 122  0
         protected CreditCourseProposalRpcServiceAsync cluProposalRpcServiceAsync = GWT.create(CreditCourseProposalRpcService.class);
 123  0
         protected CourseRpcServiceAsync courseServiceAsync = GWT.create(CourseRpcService.class);
 124  
         //Models
 125  0
         protected final DataModel cluProposalModel = new DataModel("Proposal");
 126  0
         protected final DataModel comparisonModel = new DataModel("Original Course");
 127  
 
 128  
         CourseProposalConfigurer cfg;
 129  
         
 130  
         private WorkQueue modelRequestQueue;
 131  
 
 132  
     protected WorkflowUtilities workflowUtil;
 133  
 
 134  0
         private boolean initialized = false;
 135  0
         protected boolean isNew = false;
 136  
 
 137  
         private static final String UPDATED_KEY = "metaInfo/updateTime";
 138  
         private static final String VERSION_KEY  = "versionInfo/versionedFromId";
 139  
     private static final String MSG_GROUP = "course";
 140  
         
 141  0
         protected String currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_CREATE;
 142  0
         protected String proposalPath = "";
 143  
         protected String currentTitle;
 144  
 
 145  0
         private final DateFormat df = DateFormat.getInstance();
 146  
 
 147  0
         private final BlockingTask initializingTask = new BlockingTask("Loading");
 148  0
         protected final BlockingTask loadDataTask = new BlockingTask("Retrieving Data");
 149  0
         private final BlockingTask saving = new BlockingTask("Saving");
 150  
 
 151  
         protected CourseRequirementsDataModel reqDataModel;
 152  
         protected CourseRequirementsDataModel reqDataModelComp;
 153  
    
 154  
     public CourseProposalController(){
 155  0
         super();
 156  0
         initializeController();
 157  0
     }
 158  
 
 159  
     @Override
 160  
     public void setViewContext(ViewContext viewContext) {
 161  0
             super.setViewContext(viewContext);
 162  0
             if(viewContext.getId() != null && !viewContext.getId().isEmpty()){
 163  0
                     if(viewContext.getIdType() != IdType.COPY_OF_OBJECT_ID && viewContext.getIdType() != IdType.COPY_OF_KS_KEW_OBJECT_ID){
 164  0
                             viewContext.setPermissionType(PermissionType.OPEN);
 165  
                     } else{
 166  
                             //they are trying to make a modification
 167  0
                             viewContext.setPermissionType(PermissionType.INITIATE);
 168  
                     }
 169  
             }
 170  
             else{
 171  0
                     viewContext.setPermissionType(PermissionType.INITIATE);
 172  
             }
 173  0
     }
 174  
 
 175  
     protected void initializeController() {
 176  0
             cfg = GWT.create(CourseProposalConfigurer.class);
 177  0
                    proposalPath = cfg.getProposalPath();
 178  0
                    workflowUtil = new WorkflowUtilities(CourseProposalController.this, proposalPath, "Proposal Actions",
 179  
                                    CourseProposalConfigurer.CourseSections.WF_APPROVE_DIALOG,"", cfg.getModelId());//TODO make msg
 180  0
                    cfg.setState(DtoConstants.STATE_DRAFT);
 181  
                    
 182  
                    //Add an extra menu item to copy the proposal to a new proposal.
 183  0
                    workflowUtil.getAdditionalItems().add(new KSMenuItemData(this.getMessage("cluCopyItem"), new ClickHandler(){
 184  
                         @Override
 185  
                         public void onClick(ClickEvent event) {
 186  0
                             if(getViewContext() != null && getViewContext().getId() != null && !getViewContext().getId().isEmpty()){
 187  0
                                     getViewContext().setId((String)cluProposalModel.get(cfg.getProposalPath()+"/id"));
 188  0
                                     getViewContext().setIdType(IdType.COPY_OF_KS_KEW_OBJECT_ID);
 189  0
                                     getViewContext().getAttributes().remove(StudentIdentityConstants.DOCUMENT_TYPE_NAME);
 190  0
                                     cluProposalModel.resetRoot(); // Reset the root so that the model can be reloaded from the copied proposal.
 191  
                         }
 192  0
                                 HistoryManager.navigate("/HOME/CURRICULUM_HOME/COURSE_PROPOSAL/COURSE_INFO", getViewContext());
 193  0
                         }
 194  
                 }));
 195  
                    
 196  0
                    super.setDefaultModelId(cfg.getModelId());
 197  0
                    registerModelsAndHandlers();
 198  
                    
 199  0
         addStyleName("courseProposal");
 200  0
     }
 201  
     
 202  
     protected void registerModelsAndHandlers(){
 203  0
         reqDataModel = new CourseRequirementsDataModel(this);
 204  0
         reqDataModelComp = new CourseRequirementsDataModel(this);
 205  
             
 206  0
         super.registerModel(super.getDefaultModelId(), new ModelProvider<DataModel>() {
 207  
 
 208  
             @Override
 209  
             public void requestModel(final ModelRequestCallback<DataModel> callback) {
 210  0
                 if (modelRequestQueue == null){
 211  0
                     modelRequestQueue = new WorkQueue();
 212  
                 }
 213  
 
 214  0
                 WorkItem workItem = new WorkItem(){
 215  
                     @Override
 216  
                     public void exec(Callback<Boolean> workCompleteCallback) {
 217  0
                         if (cluProposalModel.getRoot() == null || initialized == false){
 218  0
                             populateModel(callback, workCompleteCallback);
 219  
                         } else {
 220  0
                             callback.onModelReady(cluProposalModel);
 221  0
                             workCompleteCallback.exec(true);
 222  
                         }
 223  0
                     }
 224  
                 };
 225  0
                 modelRequestQueue.submit(workItem);
 226  
 
 227  0
             }
 228  
 
 229  
         });
 230  0
         super.registerModel("ComparisonModel", new ModelProvider<DataModel>() {
 231  
             @Override
 232  
             public void requestModel(final ModelRequestCallback<DataModel> callback) {
 233  0
                     if(comparisonModel.getRoot() != null && comparisonModel.getRoot().size() != 0){
 234  0
                             callback.onModelReady(comparisonModel);
 235  
                             
 236  
                     }
 237  
                     else{
 238  0
                             callback.onModelReady(null);
 239  
                     }
 240  
                 
 241  0
             }
 242  
         });
 243  0
         super.addApplicationEventHandler(ContentDirtyEvent.TYPE, new ContentDirtyEventHandler(){
 244  
                         public void onContentDirty(ContentDirtyEvent event) {
 245  0
                         setContentWarning("You have unsaved changes");                                
 246  0
                         }                
 247  
         });
 248  
 
 249  0
         super.addApplicationEventHandler(SaveActionEvent.TYPE, new SaveActionHandler(){
 250  
             public void doSave(SaveActionEvent saveAction) {
 251  0
                 GWT.log("CluProposalController received save action request.", null);
 252  0
                 doSaveAction(saveAction);
 253  0
             }
 254  
         }); 
 255  0
             }
 256  
     
 257  
     /**
 258  
      * Used to populate the proposal model based on the view context.  
 259  
      * 
 260  
      * @param callback
 261  
      * @param workCompleteCallback
 262  
      */
 263  
     private void populateModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){
 264  0
             if(getViewContext().getIdType() == IdType.DOCUMENT_ID){
 265  0
             getCluProposalFromWorkflowId(callback, workCompleteCallback);
 266  0
         } else if (getViewContext().getIdType() == IdType.KS_KEW_OBJECT_ID || getViewContext().getIdType() == IdType.OBJECT_ID){
 267  0
             getCluProposalFromProposalId(getViewContext().getId(), callback, workCompleteCallback);
 268  0
         } else if (getViewContext().getIdType() == IdType.COPY_OF_OBJECT_ID){
 269  0
                 if(LUConstants.PROPOSAL_TYPE_COURSE_MODIFY.equals(getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME))||
 270  
                                LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME))){
 271  0
                         createModifyCluProposalModel("versionComment", callback, workCompleteCallback);
 272  
                 }else{
 273  0
                         createCopyCourseModel(getViewContext().getId(), callback, workCompleteCallback);
 274  
                 }
 275  0
         } else if (getViewContext().getIdType() == IdType.COPY_OF_KS_KEW_OBJECT_ID){
 276  0
                 createCopyCourseProposalModel(getViewContext().getId(), callback, workCompleteCallback);
 277  
         } else{
 278  0
             createNewCluProposalModel(callback, workCompleteCallback);
 279  
         }
 280  0
     }
 281  
 
 282  
     protected void getCurrentModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){
 283  0
             if (cluProposalModel.getRoot() != null && cluProposalModel.getRoot().size() > 0){
 284  0
                 String id = cluProposalModel.get(cfg.getProposalPath()+"/id");
 285  0
                 if(id != null){
 286  0
                         getCluProposalFromProposalId(id, callback, workCompleteCallback);
 287  
                 }
 288  
                 else{
 289  0
                         populateModel(callback, workCompleteCallback);
 290  
                 }
 291  0
             }
 292  
             else{
 293  0
                     populateModel(callback, workCompleteCallback);
 294  
             }
 295  0
     }
 296  
 
 297  
     private void intializeView(final Callback<Boolean> onReadyCallback) {
 298  0
             if (initialized) {
 299  0
                     onReadyCallback.exec(true);
 300  
             } else {
 301  0
                     initialized = true;
 302  0
                     KSBlockingProgressIndicator.addTask(initializingTask);
 303  0
                     setContentWarning("");
 304  0
             this.requestModel(new ModelRequestCallback<DataModel>(){
 305  
 
 306  
                                 @Override
 307  
                                 public void onModelReady(DataModel model) {
 308  
                                         
 309  
                                         //Setup View Context & determine id type
 310  0
                                         String idType = null;
 311  0
                                     String viewContextId = "";
 312  0
                                     if(getViewContext().getIdType() != null){
 313  0
                                 idType = getViewContext().getIdType().toString();
 314  0
                                 viewContextId = getViewContext().getId();
 315  0
                                 if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){
 316  0
                                         viewContextId = null;
 317  
                                 }
 318  
 
 319  
                                     }
 320  
 
 321  
                                     //FIXME: Something looks odd in determining currentDocType
 322  0
                                     if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("") && !LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(currentDocType)){
 323  0
                                             currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_MODIFY;
 324  
                                     }
 325  
                                     //Check for admin modify type
 326  0
                                     if(LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(cluProposalModel.get(cfg.getProposalPath()+"/type"))){
 327  0
                                             currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN;
 328  
                                     }
 329  
                                     
 330  
                                     //Get the state for save action
 331  0
                                     String dtoState = getStateforSaveAction(cluProposalModel); 
 332  
                                     
 333  
                                     //Get the current workflow node for proposal
 334  0
                                     String workflowNode = cluProposalModel.get(cfg.getProposalPath()+"/workflowNode");
 335  
                                     
 336  
                                     //Add properties to an id attributes map so metadata service can get correct metadata
 337  0
                                         HashMap<String, String> idAttributes = new HashMap<String, String>();
 338  0
                                     if(idType != null){
 339  0
                                             idAttributes.put(IdAttributes.ID_TYPE, idType);
 340  
                                     }
 341  0
                                     idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, currentDocType);                                                                        
 342  0
                                     idAttributes.put(DtoConstants.DTO_STATE, dtoState);                                    
 343  0
                                     idAttributes.put(DtoConstants.DTO_NEXT_STATE, cfg.getNextState());
 344  0
                                     if (LUConstants.PROPOSAL_TYPE_COURSE_MODIFY.equalsIgnoreCase(currentDocType) ||
 345  
                                             LUConstants.PROPOSAL_TYPE_COURSE_CREATE.equals(currentDocType)){                                            
 346  0
                                             idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, workflowNode);
 347  
                                     }
 348  
 
 349  
                                     
 350  
                                     //Get metadata and complete initializing the screen
 351  0
                                     getCourseProposalRpcService().getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){
 352  
                                                 @Override
 353  
                         public void handleTimeout(Throwable caught) {
 354  0
                                         initializeFailed(); 
 355  0
                                                 }
 356  
 
 357  
                                                 @Override
 358  
                         public void handleFailure(Throwable caught) {
 359  0
                                                         initializeFailed();
 360  0
                                     throw new RuntimeException("Failed to get model definition.", caught);
 361  
                                 }
 362  
 
 363  
                                                 public void initializeFailed(){
 364  0
                                                 initialized = false;
 365  0
                                         onReadyCallback.exec(false);
 366  0
                                         KSBlockingProgressIndicator.removeTask(initializingTask);                                                        
 367  0
                                                 }
 368  
                                                 
 369  
                                 public void onSuccess(Metadata result) {
 370  0
                                         DataModelDefinition def = new DataModelDefinition(result);
 371  0
                                     cluProposalModel.setDefinition(def);
 372  0
                                     comparisonModel.setDefinition(def);
 373  
 
 374  0
                                     configureScreens(def, onReadyCallback);
 375  
 
 376  0
                                 }
 377  
                                   });
 378  
                                         
 379  0
                                 }
 380  
 
 381  
                                 @Override
 382  
                                 public void onRequestFail(Throwable cause) {
 383  0
                                         GWT.log("Failed to get modeld for proposal controller init");
 384  0
                                         onReadyCallback.exec(false);
 385  0
                                 }
 386  
                         });
 387  
                                 
 388  
             }
 389  0
     }
 390  
 
 391  
     @Override
 392  
     public void getMetadataForFinalState(final KSAsyncCallback<Metadata> callback){
 393  
                 //Setup View Context
 394  0
                 String idType = null;
 395  0
                 String viewContextId = "";
 396  0
                 if(getViewContext().getIdType() != null){
 397  0
             idType = getViewContext().getIdType().toString();
 398  0
             viewContextId = getViewContext().getId();
 399  0
             if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){
 400  0
                     viewContextId = null;
 401  
             }
 402  
                 }
 403  0
                 HashMap<String, String> idAttributes = new HashMap<String, String>();
 404  0
                 if(idType != null){
 405  0
                         idAttributes.put(IdAttributes.ID_TYPE, idType);
 406  
                 }
 407  
 
 408  0
                 idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, currentDocType);
 409  0
                 idAttributes.put(DtoConstants.DTO_STATE, cfg.getState());                                    
 410  0
                 idAttributes.put(DtoConstants.DTO_NEXT_STATE, cfg.getNextState());
 411  0
                 idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, "Publication Review");
 412  
                 
 413  
                 //Get metadata and complete initializing the screen
 414  0
                 getCourseProposalRpcService().getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){
 415  
                         @Override
 416  
                         public void onSuccess(Metadata result) {
 417  0
                                 callback.onSuccess(result);
 418  0
                         }
 419  
                 });
 420  0
     }
 421  
     
 422  
     protected void configureScreens(final DataModelDefinition modelDefinition, final Callback<Boolean> onReadyCallback){
 423  0
             if (workflowUtil != null){
 424  0
                     workflowUtil.requestAndSetupModel();        
 425  
             }
 426  
 
 427  0
         CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() {
 428  
 
 429  
             @Override
 430  
             public void exec(List<StatementTypeInfo> stmtTypes) {
 431  0
                 List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>();
 432  0
                 if (stmtTypes != null) {
 433  0
                     for (StatementTypeInfo stmtType : stmtTypes) {
 434  0
                         if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") ||
 435  
                             stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) {
 436  0
                             continue;
 437  
                         }
 438  0
                         stmtTypesOut.add(stmtType);
 439  
                     }
 440  
                 }
 441  
 
 442  0
                 cfg.setStatementTypes(stmtTypesOut);
 443  0
                 cfg.setModelDefinition(modelDefinition);
 444  0
                 cfg.configure(CourseProposalController.this);
 445  
                 
 446  
                 //Add fields to workflow utils screens
 447  0
                 if(workflowUtil!=null){
 448  0
                         requestModel(new ModelRequestCallback<DataModel>(){
 449  
                                                 public void onModelReady(DataModel model) {
 450  
                                                         //Only display if this is a modification
 451  0
                                                         String versionedFromId = model.get("versionInfo/versionedFromId");
 452  0
                                                         if(versionedFromId!=null && !versionedFromId.isEmpty()){        
 453  0
                                                             KSLabel descLabel = new KSLabel();
 454  0
                                                             descLabel.setText(Application.getApplicationContext().getUILabel("course", LUUIConstants.FINAL_APPROVAL_DIALOG));
 455  0
                                                             if (workflowUtil.getApproveDialogue() != null) {
 456  0
                                                                 workflowUtil.getApproveDialogue().addWidget(descLabel);
 457  
                                                             }
 458  0
                                                             workflowUtil.addApproveDialogField("", "startTerm", cfg.generateMessageInfo(LUUIConstants.PROPOSAL_START_TERM), modelDefinition, true, true);
 459  0
                                                             workflowUtil.addApproveDialogField("proposal", "prevEndTerm", cfg.generateMessageInfo(LUUIConstants.PROPOSAL_PREV_END_TERM), modelDefinition, false);
 460  
                                 
 461  0
                                                             workflowUtil.updateApproveFields();                                                            
 462  0
                                                             workflowUtil.progressiveEnableFields();                                                            
 463  0
                                                         }else{
 464  
                                                                 //Ignore this field (so blanket approve works if this is a new course proposal and not modifiaction)
 465  0
                                                                 workflowUtil.addIgnoreDialogField("proposal/prevEndTerm");
 466  
                                                         }
 467  0
                                                 }
 468  
                                                 public void onRequestFail(Throwable cause) {
 469  0
                                                 }
 470  
                         });
 471  
                 }
 472  
 
 473  0
                 progressiveEnableFields();
 474  
                 
 475  0
                 onReadyCallback.exec(true);
 476  0
                 KSBlockingProgressIndicator.removeTask(initializingTask);
 477  0
             }
 478  
         });
 479  0
     }
 480  
     
 481  
     /**
 482  
      * This progressively enables/disables screen fields based on other fields present in the screens.
 483  
      *  
 484  
      * NOTE: This metod must be caled after cfg.configure() is called, otherwise path to field mappings won't exist in ApplicationContext
 485  
      */
 486  
     protected void progressiveEnableFields(){
 487  0
                 final FieldDescriptor endTerm = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.END_TERM);
 488  0
                 final FieldDescriptor pilotCourse = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.PILOT_COURSE);
 489  
                 
 490  0
                 if (pilotCourse != null && endTerm != null){
 491  
                     //Enable and require end term field based on pilot course value in model loaded                
 492  0
                 Boolean enableEndTerm = Boolean.TRUE.equals(cluProposalModel.get(CreditCourseConstants.PILOT_COURSE)) 
 493  
                         || DtoConstants.STATE_RETIRED.equalsIgnoreCase((String)cluProposalModel.get(CreditCourseConstants.STATE));
 494  0
                         BaseSection.progressiveEnableAndRequireFields(enableEndTerm, endTerm);
 495  
                     
 496  
                 //Add a click handler to pilot checkbox to toggle enabling and requiredness of end term field
 497  0
                         KSCheckBox pilotCheckbox = ((KSCheckBox)pilotCourse.getFieldWidget());
 498  0
                 pilotCheckbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
 499  
                                 @Override
 500  
                                 public void onValueChange(ValueChangeEvent<Boolean> event) {
 501  
                                         //Disable/enable end term field based on new value of pilot checkbox
 502  0
                                 BaseSection.progressiveEnableAndRequireFields(event.getValue(), endTerm);
 503  
                                 
 504  
                                 //Clear out endTerm value if pilot course unchecked (as this field is not required when not pilot course)
 505  0
                                 if (!event.getValue()){
 506  0
                                                 ((KSDropDown)((KSPicker)endTerm.getFieldWidget()).getInputWidget()).clear();                                
 507  
                                         }                                                
 508  0
                                 }
 509  
                         });
 510  
                 }
 511  0
     }
 512  
 
 513  
     @Override
 514  
     @SuppressWarnings("unchecked")
 515  
     public void requestModel(Class modelType, final ModelRequestCallback callback) {
 516  0
         if(modelType == ReferenceModel.class){
 517  0
                 if (cluProposalModel != null){
 518  0
                         ReferenceModel ref = new ReferenceModel();
 519  
 
 520  0
                         if(cluProposalModel.get(cfg.getProposalPath()) != null){
 521  0
                             ref.setReferenceId((String)cluProposalModel.get(cfg.getProposalPath()+"/id"));
 522  
                         } else {
 523  0
                                 ref.setReferenceId(null);
 524  
                         }
 525  
                         
 526  
                         //Use the referenceAttribute to store misc data from the parent model like reference name, etc
 527  0
                         if(cluProposalModel.get(cfg.getProposalPath()) != null){
 528  0
                                 Map<String, String> attributes = new HashMap<String, String>();
 529  0
                                 attributes.put("name", (String)cluProposalModel.get(cfg.getProposalPath()+"/name"));
 530  0
                                 ref.setReferenceAttributes(attributes);
 531  0
                         } else {
 532  0
                                 ref.setReferenceAttributes(null);
 533  
                         }
 534  
 
 535  0
                         ref.setReferenceTypeKey(cfg.getProposalReferenceTypeKey());
 536  0
                         ref.setReferenceType(cfg.getProposalReferenceObjectType());
 537  0
                         ref.setReferenceState(getViewContext().getState());
 538  
 
 539  0
                         callback.onModelReady(ref);
 540  0
                 }
 541  0
         } else if (modelType == Data.class){
 542  0
                 requestModel(cfg.getModelId(), callback);
 543  
         } else {
 544  0
             super.requestModel(modelType, callback);
 545  
         }
 546  
 
 547  0
     }
 548  
 
 549  
     private void getCluProposalFromWorkflowId(@SuppressWarnings("rawtypes") final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 550  0
         KSBlockingProgressIndicator.addTask(loadDataTask);
 551  0
         workflowUtil.getDataIdFromWorkflowId(getViewContext().getId(), new KSAsyncCallback<String>(){
 552  
                         @Override
 553  
                         public void handleFailure(Throwable caught) {
 554  0
                 Window.alert("Error loading Proposal from Workflow Document: "+caught.getMessage());
 555  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 556  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 557  0
                         }
 558  
 
 559  
                         @Override
 560  
                         public void onSuccess(String proposalId) {
 561  0
                                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 562  0
                                 getCluProposalFromProposalId(proposalId, callback, workCompleteCallback);
 563  0
                         }
 564  
         });
 565  0
     }
 566  
 
 567  
     protected void getCluProposalFromProposalId(String id, @SuppressWarnings("rawtypes") final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 568  0
             KSBlockingProgressIndicator.addTask(loadDataTask);
 569  0
             getCourseProposalRpcService().getData(id, new KSAsyncCallback<Data>(){
 570  
 
 571  
                         @Override
 572  
                         public void handleFailure(Throwable caught) {
 573  0
                 Window.alert("Error loading Proposal: "+caught.getMessage());
 574  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 575  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 576  0
                         }
 577  
 
 578  
                         @Override
 579  
                         public void onSuccess(Data result) {
 580  0
                                 cluProposalModel.setRoot(result);
 581  0
                         setHeaderTitle();
 582  0
                         setLastUpdated();
 583  0
                 reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() {
 584  
                     @Override
 585  
                     public void exec(Boolean result) {
 586  0
                        if(result){
 587  0
                           getCourseComparisonModelAndReqs(callback, workCompleteCallback);
 588  
                        }
 589  0
                     }
 590  
                 });
 591  0
                         }
 592  
 
 593  
             });
 594  0
     }
 595  
 
 596  
     @SuppressWarnings("unchecked")
 597  
         protected void getCourseComparisonModelAndReqs(final ModelRequestCallback proposalModelRequestCallback, final Callback<Boolean> workCompleteCallback){
 598  0
                 if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("")){
 599  0
                         courseServiceAsync.getData((String)cluProposalModel.get(VERSION_KEY), new KSAsyncCallback<Data>(){
 600  
         
 601  
                             @Override
 602  
                     public void handleFailure(Throwable caught) {
 603  0
                         Window.alert("Error loading Proposal: "+caught.getMessage());
 604  0
                         createNewCluProposalModel(proposalModelRequestCallback, workCompleteCallback);
 605  0
                         KSBlockingProgressIndicator.removeTask(loadDataTask);
 606  0
                     }
 607  
 
 608  
                 @Override
 609  
                 public void onSuccess(Data result) {
 610  
                         // ??? why result would be null ever?
 611  0
                     if (result != null) 
 612  0
                         comparisonModel.setRoot(result);
 613  
 
 614  0
                     reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() {
 615  
                                    @Override
 616  
                                    public void exec(Boolean result) {
 617  0
                                            if (result) {
 618  0
                                                    KSBlockingProgressIndicator.removeTask(loadDataTask);
 619  0
                                 reqDataModelComp.retrieveStatementTypes(comparisonModel.<String>get("id"), new Callback<Boolean>() {
 620  
                                     @Override
 621  
                                     public void exec(Boolean result) {
 622  0
                                         if (result) {
 623  0
                                             KSBlockingProgressIndicator.removeTask(loadDataTask);
 624  
                                          }
 625  0
                                     }
 626  
                                 });
 627  0
                                 proposalModelRequestCallback.onModelReady(cluProposalModel);
 628  0
                                 workCompleteCallback.exec(true);
 629  
                                           }
 630  0
                                    }
 631  
                            });
 632  0
                }
 633  
             });
 634  
         } else {
 635  0
             proposalModelRequestCallback.onModelReady(cluProposalModel);
 636  0
             workCompleteCallback.exec(true);
 637  0
             KSBlockingProgressIndicator.removeTask(loadDataTask);
 638  
         }
 639  0
     }
 640  
 
 641  
     @SuppressWarnings("unchecked")
 642  
     protected void createNewCluProposalModel(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 643  0
         Data data = new Data();
 644  0
             cluProposalModel.setRoot(data);
 645  
         
 646  0
         Data proposalData = new Data();
 647  0
         proposalData.set(new Data.StringKey("type"), currentDocType);
 648  0
         data.set(new Data.StringKey("proposal"), proposalData);                
 649  0
         if (cfg.getNextState() == null || cfg.getNextState().isEmpty()){
 650  0
                 proposalData.set(new Data.StringKey("workflowNode"), "PreRoute");
 651  
         }
 652  
         
 653  0
         isNew = true;
 654  0
         setHeaderTitle();
 655  0
         setLastUpdated();
 656  0
         callback.onModelReady(cluProposalModel);
 657  0
         workCompleteCallback.exec(true);
 658  0
     }
 659  
 
 660  
     private void createModifyCluProposalModel(String versionComment, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 661  0
         Data data = new Data();
 662  0
         cluProposalModel.setRoot(data);        
 663  
         
 664  0
         this.currentDocType = getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME);
 665  0
         Data proposalData = new Data();
 666  0
         proposalData.set(new Data.StringKey("type"), currentDocType);
 667  0
         data.set(new Data.StringKey("proposal"), proposalData);
 668  0
         if (cfg.getNextState() == null && cfg.getNextState().isEmpty()){
 669  0
                 proposalData.set(new Data.StringKey("workflowNode"), "PreRoute");
 670  
         }
 671  
                 
 672  0
         Data versionData = new Data();
 673  0
         versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId());
 674  0
         versionData.set(new Data.StringKey("versionComment"), versionComment);
 675  0
         data.set(new Data.StringKey("versionInfo"), versionData);
 676  
         
 677  0
         cluProposalRpcServiceAsync.saveData(cluProposalModel.getRoot(), new AsyncCallback<DataSaveResult>() {
 678  
                         public void onSuccess(DataSaveResult result) {
 679  0
                                 cluProposalModel.setRoot(result.getValue());
 680  0
                                 setHeaderTitle();
 681  0
                         setLastUpdated();
 682  
                         //add to recently viewed now that we know the id of proposal
 683  0
                         ViewContext docContext = new ViewContext();
 684  0
                         docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id"));
 685  0
                         docContext.setIdType(IdType.KS_KEW_OBJECT_ID);
 686  0
                         RecentlyViewedHelper.addDocument(getProposalTitle(), 
 687  
                                         HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), docContext)
 688  
                                         + "/SUMMARY");
 689  0
                         getCourseComparisonModelAndReqs(callback, workCompleteCallback);
 690  
                         
 691  
                         // We need to update the current view context so that if the user clicks the back button it doesn't 
 692  
                         // create a duplicate course proposal. 
 693  0
                         getViewContext().setIdType(docContext.getIdType());
 694  0
                         getViewContext().setId(docContext.getId());
 695  
                         
 696  0
                         }
 697  
                         
 698  
                         public void onFailure(Throwable caught) {
 699  0
                 Window.alert("Error loading Proposal: "+caught.getMessage());
 700  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 701  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 702  0
                         }
 703  
                 });
 704  0
     }
 705  
 
 706  
     @SuppressWarnings("unchecked")
 707  
     private void createCopyCourseModel(String originalCluId, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 708  
 
 709  0
             cluProposalRpcServiceAsync.createCopyCourse(originalCluId, new AsyncCallback<DataSaveResult>() {
 710  
                         public void onSuccess(DataSaveResult result) {
 711  0
                                 cluProposalModel.setRoot(result.getValue());
 712  
                                 
 713  
                                 //Add in a blank proposal placeholder
 714  0
                         Data proposalData = new Data();
 715  0
                         cluProposalModel.getRoot().set(new Data.StringKey("proposal"), proposalData);
 716  0
                         if (cfg.getNextState() == null || cfg.getNextState().isEmpty()){
 717  0
                             proposalData.set(new Data.StringKey("workflowNode"), "PreRoute");
 718  
                         }
 719  
                         
 720  0
                         isNew = true;
 721  0
                                 setHeaderTitle();
 722  0
                         setLastUpdated();
 723  
 
 724  0
                         callback.onModelReady(cluProposalModel);
 725  0
                         workCompleteCallback.exec(true);
 726  0
                         }
 727  
                         
 728  
                         public void onFailure(Throwable caught) {
 729  0
                 Window.alert("Error loading Proposal: "+caught.getMessage());
 730  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 731  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 732  0
                         }
 733  
                 });
 734  0
     }
 735  
     
 736  
     @SuppressWarnings("unchecked")
 737  
     private void createCopyCourseProposalModel(String originalProposalId, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){
 738  
 
 739  0
             cluProposalRpcServiceAsync.createCopyCourseProposal(originalProposalId, new AsyncCallback<DataSaveResult>() {
 740  
                         public void onSuccess(DataSaveResult result) {
 741  0
                                 cluProposalModel.setRoot(result.getValue());
 742  0
                         setHeaderTitle();
 743  0
                         setLastUpdated();
 744  
                         //add to recently viewed now that we know the id of proposal
 745  0
                         ViewContext docContext = new ViewContext();
 746  0
                         docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id"));
 747  0
                         docContext.setIdType(IdType.KS_KEW_OBJECT_ID);
 748  0
                         RecentlyViewedHelper.addDocument(getProposalTitle(), 
 749  
                                         HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), docContext)
 750  
                                         + "/COURSE_INFO");
 751  
                         
 752  
                         // We need to update the current view context so that if the user clicks the back button it doesn't 
 753  
                         // create a duplicate course proposal. 
 754  0
                         getViewContext().setIdType(docContext.getIdType());
 755  0
                         getViewContext().setId(docContext.getId());
 756  
                         
 757  0
                         callback.onModelReady(cluProposalModel);
 758  0
                         workCompleteCallback.exec(true);
 759  0
                         }
 760  
                         
 761  
                         public void onFailure(Throwable caught) {
 762  0
                 Window.alert("Error loading Proposal: "+caught.getMessage());
 763  0
                 createNewCluProposalModel(callback, workCompleteCallback);
 764  0
                 KSBlockingProgressIndicator.removeTask(loadDataTask);
 765  0
                         }
 766  
                 });
 767  0
     }
 768  
     
 769  
     public void doSaveAction(final SaveActionEvent saveActionEvent){
 770  0
         requestModel(new ModelRequestCallback<DataModel>() {
 771  
             @Override
 772  
             public void onModelReady(DataModel model) {
 773  0
                 CourseProposalController.this.updateModelFromCurrentView();
 774  
 
 775  0
                 if (isStartViewShowing()){
 776  
                         //This call required so fields in start section, which also appear in
 777  
                         //other sections don't get overridden from updateModel call above.
 778  0
                         getStartPopupView().updateModel();
 779  
                 }
 780  
 
 781  0
                     model.validate(new Callback<List<ValidationResultInfo>>() {
 782  
                     @Override
 783  
                     public void exec(List<ValidationResultInfo> result) {
 784  
 
 785  0
                             boolean isSectionValid = isValid(result, true);
 786  
 
 787  0
                             if(isSectionValid){
 788  0
                             if (startSectionRequired()){
 789  0
                                 showStartPopup(NO_OP_CALLBACK);
 790  0
                                 saveActionEvent.doActionComplete();
 791  
                             }
 792  
                             else{
 793  0
                                     saveProposalClu(saveActionEvent);
 794  
                             }
 795  
                             }
 796  
                             else{
 797  
                                     //saveActionEvent.doActionComplete();
 798  0
                                     KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 799  
                             }
 800  
 
 801  0
                     }
 802  
                 });
 803  0
             }
 804  
 
 805  
             @Override
 806  
             public void onRequestFail(Throwable cause) {
 807  0
                     saveActionEvent.doActionComplete();
 808  0
                 GWT.log("Unable to retrieve model for validation and save", cause);
 809  0
             }
 810  
 
 811  
         });
 812  
 
 813  0
     }
 814  
 
 815  
     public boolean startSectionRequired(){
 816  0
         String proposalId = cluProposalModel.get(cfg.getProposalPath()+"/id");
 817  
         
 818  
         //Defaulting the proposalTitle to courseTitle, this way course data gets set and assembler doesn't
 819  
         //complain. This may not be the correct approach.
 820  0
         String proposalTitle = cluProposalModel.get(cfg.getProposalTitlePath());
 821  0
         String courseTitle = cluProposalModel.get(cfg.getCourseTitlePath());
 822  0
         if (proposalTitle == null || proposalTitle.isEmpty()){
 823  0
             cluProposalModel.set(QueryPath.parse(cfg.getProposalTitlePath()), courseTitle);
 824  
         }
 825  
         
 826  0
             return proposalId==null && !CourseProposalController.this.isStartViewShowing() && !hasTitles(proposalTitle, courseTitle);
 827  
     }
 828  
 
 829  
     private boolean hasTitles(String proposalTitle, String courseTitle){
 830  0
             return (proposalTitle != null && !proposalTitle.isEmpty()) && (courseTitle != null && !courseTitle.isEmpty());
 831  
     }
 832  
     
 833  
     public void saveProposalClu(final SaveActionEvent saveActionEvent){
 834  0
             KSBlockingProgressIndicator.addTask(saving);
 835  0
         getCourseProposalRpcService().saveData(cluProposalModel.getRoot(), new KSAsyncCallback<DataSaveResult>(){
 836  
 
 837  
             @Override
 838  
             public void handleFailure(Throwable caught) {
 839  0
                 GWT.log("Save Failed.", caught);
 840  0
                 KSBlockingProgressIndicator.removeTask(saving);
 841  0
                 KSNotifier.add(new KSNotification("Save Failed on server. Please try again.", false, true, 5000));
 842  0
             }
 843  
                 
 844  
             @Override
 845  
             public void handleVersionMismatch(Throwable caught) {
 846  0
                 super.handleVersionMismatch(caught);
 847  0
                 KSBlockingProgressIndicator.removeTask(saving);
 848  0
             }
 849  
 
 850  
             public void onSuccess(DataSaveResult result) {
 851  0
                 KSBlockingProgressIndicator.removeTask(saving);
 852  
 
 853  0
                                 Application.getApplicationContext().clearValidationWarnings();
 854  0
                                 Application.getApplicationContext().addValidationWarnings(result.getValidationResults());
 855  
                         
 856  0
                                 if(ValidatorClientUtils.hasErrors(result.getValidationResults())){
 857  0
                         isValid(result.getValidationResults(), false, true);
 858  0
                     saveActionEvent.setGotoNextView(false);
 859  0
                     saveActionEvent.doActionComplete();
 860  0
                     KSNotifier.add(new KSNotification("Save Failed. There were validation errors.", false, true, 5000));
 861  
                 }else{
 862  
                                 
 863  0
                         saveActionEvent.setSaveSuccessful(true);
 864  0
                         cluProposalModel.setRoot(result.getValue());
 865  0
                         String title = getProposalTitle();
 866  0
                         View currentView = getCurrentView();
 867  0
                                     if (currentView instanceof SectionView){
 868  0
                                             ((SectionView)currentView).updateView(cluProposalModel);
 869  0
                                             ((SectionView) currentView).resetDirtyFlags();
 870  
                         }
 871  0
                     saveActionEvent.doActionComplete();
 872  
                             
 873  0
                                     ViewContext context = CourseProposalController.this.getViewContext();
 874  0
                                     context.setId((String)cluProposalModel.get(proposalPath+"/id"));
 875  0
                                     context.setIdType(IdType.KS_KEW_OBJECT_ID);
 876  
                                     
 877  
                                     //Always update the status after a save.
 878  0
                                     if(workflowUtil != null){
 879  0
                                             workflowUtil.refresh();
 880  
                                     }
 881  
                                             
 882  0
                                     setHeaderTitle();
 883  0
                                     setLastUpdated();
 884  0
                                     HistoryManager.logHistoryChange();
 885  0
                                if(isNew){
 886  0
                                        RecentlyViewedHelper.addCurrentDocument(title);
 887  
                                }
 888  0
                                else if(!currentTitle.equals(title)){
 889  0
                                        RecentlyViewedHelper.updateTitle(currentTitle, title, (String)cluProposalModel.get(proposalPath+"/id"));
 890  
                                }
 891  0
                                isNew = false;
 892  
                                             
 893  0
                                     if(saveActionEvent.gotoNextView()){
 894  0
                                             CourseProposalController.this.showNextViewOnMenu();
 895  
                                     }
 896  
                                             
 897  0
                                     if (ValidatorClientUtils.hasWarnings(result.getValidationResults())){
 898  0
                                             if (!saveActionEvent.gotoNextView()){
 899  
                                                     //Need to display warnings when view has not changed.
 900  0
                                                     isValid(result.getValidationResults(), false, true);
 901  
                                             }
 902  0
                                             KSNotifier.show("Saved with Warnings");
 903  
                                     } else {
 904  0
                                             KSNotifier.show("Save Successful");
 905  
                                     }                                  
 906  
                        }
 907  0
             }
 908  
         });
 909  
 
 910  0
     }
 911  
 
 912  
     public void setLastUpdated(){
 913  0
             Date lastUpdated = (Date)cluProposalModel.get(UPDATED_KEY);
 914  0
             if(lastUpdated != null){
 915  0
                     setContentInfo("Last Updated: " + df.format(lastUpdated));
 916  
             }
 917  
             else{
 918  0
                     setContentInfo("");
 919  
             }
 920  0
     }
 921  
 
 922  
     @Override
 923  
         public void beforeShow(final Callback<Boolean> onReadyCallback){
 924  0
             Application.getApplicationContext().clearCrossConstraintMap(null);
 925  0
             Application.getApplicationContext().clearPathToFieldMapping(null);
 926  0
             Application.getApplicationContext().clearValidationWarnings();
 927  0
             Application.getApplicationContext().setParentPath("");
 928  
                        
 929  0
             intializeView(onReadyCallback);
 930  0
         }
 931  
 
 932  
     //Before show is called before the model is bound to the widgets. We need to update cross constraints and re-display 
 933  
     // validation warnings after widget binding
 934  
     //This gets called twice which is not optimal
 935  
         @Override
 936  
         public <V extends Enum<?>> void showView(final V viewType,
 937  
                         final Callback<Boolean> onReadyCallback) {
 938  0
                 Callback<Boolean> finalizeView = new Callback<Boolean>(){
 939  
                         public void exec(Boolean result) {
 940  
                                 //Update cross constraints
 941  0
                                 for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){
 942  0
                                 crossConstraint.reprocessWithUpdatedConstraints();
 943  
                         }
 944  
                                 
 945  
                                 //When showing summary section make sure data gets validated in case there are warnings.
 946  
                                 //TODO: Is it possible to cut down on this validation so it doesn't have to validate every time.
 947  0
                                 if (viewType == CourseSections.SUMMARY){
 948  0
                                         KSBlockingProgressIndicator.addTask(initializingTask);
 949  0
                                         courseServiceAsync.validate(cluProposalModel.getRoot(), new KSAsyncCallback<List<ValidationResultInfo>>(){
 950  
                                                 @Override
 951  
                                                 public void onSuccess(List<ValidationResultInfo> result) {
 952  0
                                                         Application.getApplicationContext().clearValidationWarnings();
 953  0
                                                         Application.getApplicationContext().addValidationWarnings(result);
 954  0
                                                         showWarnings();
 955  0
                                                         KSBlockingProgressIndicator.removeTask(initializingTask);
 956  0
                                                 }                                                
 957  
                                         });                                        
 958  
                                 } else {
 959  0
                                         showWarnings();                                        
 960  
                                 }
 961  
                                 
 962  0
                                 onReadyCallback.exec(result);
 963  0
                         }
 964  
         };
 965  0
                 super.showView(viewType, finalizeView);
 966  0
         }
 967  
  
 968  
 
 969  
    @Override
 970  
    public void showDefaultView(Callback<Boolean> onReadyCallback) {
 971  0
            if(isNew){
 972  0
                    super.showFirstView(onReadyCallback);
 973  
            }
 974  
            else{
 975  0
                    super.showDefaultView(onReadyCallback);
 976  
            }
 977  0
    }
 978  
 
 979  
         @Override
 980  
     public void setParentController(Controller controller) {
 981  0
         super.setParentController(controller);
 982  0
     }
 983  
 
 984  
         @Override
 985  
         public void checkAuthorization(final PermissionType permissionType, final AuthorizationCallback authCallback) {
 986  0
                 Map<String,String> attributes = new HashMap<String,String>();
 987  
 //                if (StringUtils.isNotBlank(getViewContext().getId())) {
 988  0
                 GWT.log("Attempting Auth Check.", null);
 989  0
                 if ( (getViewContext().getId() != null) && (!"".equals(getViewContext().getId())) ) {
 990  0
                         attributes.put(getViewContext().getIdType().toString(), getViewContext().getId());
 991  
                 }
 992  
 
 993  0
                 cluProposalRpcServiceAsync.isAuthorized(permissionType, attributes, new KSAsyncCallback<Boolean>(){
 994  
 
 995  
                         @Override
 996  
                         public void handleFailure(Throwable caught) {
 997  0
                                 authCallback.isNotAuthorized("Error checking authorization.");
 998  0
                                 GWT.log("Error checking proposal authorization.", caught);
 999  0
                 Window.alert("Error Checking Proposal Authorization: "+caught.getMessage());
 1000  0
                         }
 1001  
 
 1002  
                         @Override
 1003  
                         public void onSuccess(Boolean result) {
 1004  0
                                 GWT.log("Succeeded checking auth for permission type '" + permissionType + "' with result: " + result, null);
 1005  0
                                 if (Boolean.TRUE.equals(result)) {
 1006  0
                                         authCallback.isAuthorized();
 1007  
                                 }
 1008  
                                 else {
 1009  0
                                         authCallback.isNotAuthorized("User is not authorized: " + permissionType);
 1010  
                                 }
 1011  0
                         }
 1012  
             });
 1013  0
         }
 1014  
 
 1015  
         @Override
 1016  
         public boolean isAuthorizationRequired() {
 1017  0
                 return true;
 1018  
         }
 1019  
 
 1020  
         @Override
 1021  
         public void setAuthorizationRequired(boolean required) {
 1022  0
                 throw new UnsupportedOperationException();
 1023  
         }
 1024  
 
 1025  
     protected void setHeaderTitle(){
 1026  
             String title;
 1027  0
             if (cluProposalModel.get(cfg.getProposalTitlePath()) != null){
 1028  0
                     title = getProposalTitle();
 1029  
             }
 1030  
             else{
 1031  0
                     title = "New Course (Proposal)";
 1032  
             }
 1033  0
             this.setContentTitle(title);
 1034  0
             this.setName(title);
 1035  0
             WindowTitleUtils.setContextTitle(title);
 1036  0
                 currentTitle = title;
 1037  0
     }
 1038  
 
 1039  
         @Override
 1040  
         public WorkflowUtilities getWfUtilities() {
 1041  0
                 return workflowUtil;
 1042  
         }
 1043  
 
 1044  
         @Override
 1045  
         public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChange) {
 1046  
                 //Make sure the course information data is bound before viewing any other sections for cross field constraints
 1047  0
                 final Callback<Boolean> reallyOkToChange = new Callback<Boolean>(){
 1048  
                         @Override
 1049  
                         public void exec(Boolean result) {
 1050  0
                                 if(result){
 1051  0
                                         if(CourseSections.GOVERNANCE.equals(viewChangingTo)){
 1052  0
                                                 getView(CourseSections.COURSE_INFO, new Callback<View>(){
 1053  
                                                         @Override
 1054  
                                                         public void exec(final View view) {
 1055  0
                                                                 if(view!=null && view instanceof SectionView){
 1056  0
                                                                         requestModel(new ModelRequestCallback<DataModel>(){
 1057  
                                                                                 public void onModelReady(DataModel model) {
 1058  0
                                                                                         ((SectionView)view).updateWidgetData(model);
 1059  0
                                                                                         okToChange.exec(true);
 1060  0
                                                                                 }
 1061  
                                                                                 public void onRequestFail(Throwable cause) {
 1062  0
                                                                                         okToChange.exec(false);
 1063  0
                                                                                 }
 1064  
                                                                         });
 1065  
                                                                 }else{
 1066  0
                                                                         okToChange.exec(true);
 1067  
                                                                 }
 1068  0
                                                         }});
 1069  
                                         } else
 1070  0
                                                 okToChange.exec(true);                                        
 1071  
                                 } else         
 1072  0
                                         okToChange.exec(false);
 1073  0
                         }
 1074  
                 };
 1075  
                 
 1076  
                 //We do this check here because theoretically the subcontroller views
 1077  
                 //will display their own messages to the user to give them a reason why the view
 1078  
                 //change has been cancelled, otherwise continue to check for reasons not to change
 1079  
                 //with this controller
 1080  0
                 super.beforeViewChange(viewChangingTo, new Callback<Boolean>(){
 1081  
 
 1082  
                         @Override
 1083  
                         public void exec(Boolean result) {
 1084  0
                                 if(result){
 1085  0
                                         if(getCurrentView() instanceof SectionView && ((SectionView)getCurrentView()).isDirty()){
 1086  0
                                                 ButtonGroup<YesNoCancelEnum> buttonGroup = new YesNoCancelGroup();
 1087  0
                                                 final ButtonMessageDialog<YesNoCancelEnum> dialog = new ButtonMessageDialog<YesNoCancelEnum>("Warning", "You may have unsaved changes.  Save changes?", buttonGroup);
 1088  0
                                                 buttonGroup.addCallback(new Callback<YesNoCancelEnum>(){
 1089  
 
 1090  
                                                         @Override
 1091  
                                                         public void exec(YesNoCancelEnum result) {
 1092  0
                                                                 switch(result){
 1093  
                                                                         case YES:
 1094  0
                                                                                 dialog.hide();
 1095  0
                                                                                 final SaveActionEvent e = new SaveActionEvent();
 1096  0
                                                                                 e.setActionCompleteCallback(new ActionCompleteCallback(){
 1097  
 
 1098  
                                                                                         @Override
 1099  
                                                                                         public void onActionComplete(ActionEvent action) {
 1100  0
                                                                                                 if(e.isSaveSuccessful()){
 1101  0
                                                                                                         reallyOkToChange.exec(true);
 1102  
                                                                                                 }
 1103  
                                                                                                 else{
 1104  0
                                                                                                         reallyOkToChange.exec(false);
 1105  
                                                                                                 }
 1106  0
                                                                                         }
 1107  
                                                                                         
 1108  
                                                                                 });
 1109  0
                                                                                 fireApplicationEvent(e);
 1110  0
                                                                                 break;
 1111  
                                                                         case NO:
 1112  
                                                                                 //Force a model request from server
 1113  0
                                                                                 getCurrentModel(new ModelRequestCallback<DataModel>(){
 1114  
 
 1115  
                                                                                         @Override
 1116  
                                                                                         public void onModelReady(DataModel model) {
 1117  0
                                                                                                 if (getCurrentView()instanceof Section){
 1118  0
                                                                                                     ((Section) getCurrentView()).resetFieldInteractionFlags();
 1119  
                                                                                                 }
 1120  0
                                                                                                 reallyOkToChange.exec(true);
 1121  0
                                                                                                 dialog.hide();
 1122  0
                                                                                         }
 1123  
 
 1124  
                                                                                         @Override
 1125  
                                                                                         public void onRequestFail(Throwable cause) {
 1126  
                                                                                                 //TODO Is this correct... do we want to stop view change if we can't restore the data?  Possibly traps the user
 1127  
                                                                                                 //if we don't it messes up saves, possibly warn the user that it failed and continue?
 1128  0
                                                                                                 reallyOkToChange.exec(false);
 1129  0
                                                                                                 dialog.hide();
 1130  0
                                                                                                 GWT.log("Unable to retrieve model for data restore on view change with no save", cause);
 1131  0
                                                                                         }},
 1132  
                                                                                         NO_OP_CALLBACK);
 1133  
 
 1134  0
                                                                                 break;
 1135  
                                                                         case CANCEL:
 1136  0
                                                                                 reallyOkToChange.exec(false);
 1137  0
                                                                                 dialog.hide();
 1138  
                                                                                 // Because this event fires after the history change event we need to "undo" the history events. 
 1139  0
                                                                                 HistoryManager.logHistoryChange();  
 1140  
                                                                                 break;
 1141  
                                                                 }
 1142  0
                                                         }
 1143  
                                                 });
 1144  0
                                                 dialog.addCloseLinkClickHandler(new ClickHandler() {
 1145  
                             
 1146  
                             @Override
 1147  
                             public void onClick(ClickEvent event) {
 1148  0
                                 okToChange.exec(false);
 1149  0
                                 dialog.hide();
 1150  
                                 // Because this event fires after the history change event we need to "undo" the history events. 
 1151  0
                                 HistoryManager.logHistoryChange();  
 1152  0
                             }
 1153  
                         });
 1154  0
                                                 dialog.show();
 1155  0
                                         }
 1156  
                                         else{
 1157  0
                                                 reallyOkToChange.exec(true);
 1158  
                                         }
 1159  
                                 }
 1160  
                                 else{
 1161  0
                                         reallyOkToChange.exec(false);
 1162  
                                 }
 1163  0
                         }
 1164  
                 });
 1165  0
         }
 1166  
         
 1167  
     public KSButton getSaveButton(){
 1168  0
             if(currentDocType != LUConstants.PROPOSAL_TYPE_COURSE_MODIFY && currentDocType != LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN){
 1169  0
                 return new KSButton("Save and Continue", new ClickHandler(){
 1170  
                             public void onClick(ClickEvent event) {
 1171  0
                                     CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(true));
 1172  0
                             }
 1173  
                         });
 1174  
             }
 1175  
             else{
 1176  0
                     return new KSButton("Save", new ClickHandler(){
 1177  
                 public void onClick(ClickEvent event) {
 1178  0
                     CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(false));
 1179  0
                 }
 1180  
             });
 1181  
             }
 1182  
     }
 1183  
     
 1184  
     public KSButton getCancelButton(final Enum<?> summaryView){
 1185  
             
 1186  0
         return new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){
 1187  
                     public void onClick(ClickEvent event) {
 1188  0
                             if(!isNew){
 1189  0
                                     CourseProposalController.this.showView(summaryView);
 1190  
                             }
 1191  
                             else{
 1192  0
                                     Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());
 1193  
                             }
 1194  0
                     }
 1195  
                 });
 1196  
 
 1197  
     }
 1198  
         
 1199  
         @Override
 1200  
         public void onHistoryEvent(String historyStack) {
 1201  0
                 super.onHistoryEvent(historyStack);
 1202  
                 //we dont want to add proposals that are brand new before saving, or copy addresses (as they will initiate
 1203  
                 //the modify/copy logic again if called)
 1204  0
                 if(cluProposalModel.get(cfg.getProposalTitlePath()) != null && 
 1205  
                                 this.getViewContext().getIdType() != IdType.COPY_OF_OBJECT_ID){
 1206  0
                         RecentlyViewedHelper.addCurrentDocument(getProposalTitle());
 1207  
                 }
 1208  0
         }
 1209  
         
 1210  
         private String getProposalTitle(){
 1211  0
                 StringBuffer sb = new StringBuffer();
 1212  0
                 sb.append(cluProposalModel.get(cfg.getProposalTitlePath()));
 1213  0
                 sb.append(" (Proposal)");
 1214  0
                 return sb.toString();
 1215  
         }
 1216  
 
 1217  
     public String getCourseId(){
 1218  0
         return cluProposalModel.<String>get("id");
 1219  
     }
 1220  
 
 1221  
     public String getCourseState(){
 1222  0
         return cluProposalModel.<String>get("state");
 1223  
     }
 1224  
 
 1225  
     public boolean isNew() {
 1226  0
         return isNew;
 1227  
     }
 1228  
 
 1229  
     public CourseRequirementsDataModel getReqDataModel() {
 1230  0
         return reqDataModel;
 1231  
     }
 1232  
 
 1233  
     public CourseRequirementsDataModel getReqDataModelComp() {
 1234  0
         return reqDataModelComp;
 1235  
     }
 1236  
 
 1237  
     @Override
 1238  
     public DataModel getExportDataModel() {
 1239  0
         return cluProposalModel;
 1240  
     }
 1241  
     
 1242  
     /**
 1243  
      * 
 1244  
      * @see org.kuali.student.common.ui.client.reporting.ReportExport#getExportTemplateName()
 1245  
      */
 1246  
     @Override
 1247  
     public String getExportTemplateName() {
 1248  0
         return "proposal.template";
 1249  
     }
 1250  
     
 1251  
     @Override
 1252  
     public ArrayList<ExportElement> getExportElementsFromView() {
 1253  0
         ArrayList<ExportElement> exportElements = new ArrayList<ExportElement>();
 1254  0
         if (this.getCurrentViewEnum().equals(CourseSections.SUMMARY)) {      
 1255  0
             SummaryTableSection tableSection = this.cfg.getSummaryConfigurer().getTableSection();
 1256  0
             ExportElement heading = new ExportElement();
 1257  0
             heading.setFieldLabel("");
 1258  0
             heading.setFieldValue(cluProposalModel.getModelName());
 1259  0
             heading.setFieldValue2(comparisonModel.getModelName());
 1260  0
             exportElements.add(heading);
 1261  0
             exportElements = ExportUtils.getDetailsForWidget(tableSection, exportElements);
 1262  
         }
 1263  0
         return exportElements;
 1264  
     }
 1265  
     
 1266  
     @Override
 1267  
     public boolean isExportButtonActive() {
 1268  0
         if (this.getCurrentViewEnum() != null && this.getCurrentViewEnum().equals(CourseSections.SUMMARY)) {   
 1269  0
             return true;
 1270  
         } else {
 1271  0
             return false;
 1272  
         }
 1273  
             
 1274  
     }
 1275  
     
 1276  
     /**
 1277  
      * This method is used to determine which state the dto will be when making the save call. The information
 1278  
      * is used by the metadata service (along with workflow node) to determine the appropriate required indicators
 1279  
      * for field elements.
 1280  
      */
 1281  
     protected String getStateforSaveAction(DataModel model){
 1282  
                 //The state for existing course proposal will be the state set on existing course
 1283  0
             String state = (String)model.get(CreditCourseConstants.STATE);
 1284  
                 
 1285  
             //If null, this means it is a new course proposal, in which case we will default to configurer state
 1286  
             //which should be DRAFT
 1287  0
             if (state == null){
 1288  0
                         state = cfg.getState();
 1289  
                 }
 1290  
             
 1291  0
                 return state;
 1292  
     }
 1293  
     
 1294  
     public String getMessage(String courseMessageKey) {
 1295  0
             String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey);
 1296  0
             if (msg == null) {
 1297  0
                     msg = courseMessageKey;
 1298  
             }
 1299  0
             return msg;
 1300  
     }
 1301  
 
 1302  
     /**
 1303  
      * This method exists to allow the save/get implementations defined in this CourseProposalController
 1304  
      * in this controller to be reused in the CourseAdminWithoutVersion controller. This is in an attempt
 1305  
      * prevent duplication of a large chunk of code in the CourseAdminWithoutVersion controller. Rather than
 1306  
      * have a save wrapped with proposal information, the  CourseAdminWithoutVersion will override this method
 1307  
      * and return the standard course rpc service which does not use filters for proposal data. 
 1308  
      * 
 1309  
      * @return the course rpc service to use
 1310  
      */
 1311  
     protected  BaseDataOrchestrationRpcServiceAsync getCourseProposalRpcService(){
 1312  0
             return cluProposalRpcServiceAsync;
 1313  
     }
 1314  
 }