Coverage Report - org.kuali.student.lum.lu.ui.course.client.controllers.VersionsController
 
Classes in this File Line Coverage Branch Coverage Complexity
VersionsController
0%
0/92
0%
0/12
1.667
VersionsController$1
0%
0/3
N/A
1.667
VersionsController$2
0%
0/5
0%
0/4
1.667
VersionsController$3
0%
0/5
0%
0/4
1.667
VersionsController$4
0%
0/33
0%
0/6
1.667
VersionsController$4$1
0%
0/4
0%
0/2
1.667
VersionsController$4$2
0%
0/4
0%
0/2
1.667
VersionsController$5
0%
0/6
0%
0/2
1.667
VersionsController$5$1
0%
0/4
N/A
1.667
VersionsController$6
0%
0/9
N/A
1.667
VersionsController$7
0%
0/19
0%
0/8
1.667
VersionsController$8
0%
0/6
0%
0/2
1.667
VersionsController$Views
0%
0/1
N/A
1.667
 
 1  
 package org.kuali.student.lum.lu.ui.course.client.controllers;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.kuali.student.common.assembly.data.Data;
 7  
 import org.kuali.student.common.assembly.data.Metadata;
 8  
 import org.kuali.student.common.dto.DtoConstants;
 9  
 import org.kuali.student.common.ui.client.application.Application;
 10  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 11  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.BasicLayoutWithContentHeader;
 12  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
 13  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 14  
 import org.kuali.student.common.ui.client.mvc.Callback;
 15  
 import org.kuali.student.common.ui.client.mvc.Controller;
 16  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 17  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 18  
 import org.kuali.student.common.ui.client.mvc.ModelProvider;
 19  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 20  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 21  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 22  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 23  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 24  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 25  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 26  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 27  
 import org.kuali.student.core.statement.dto.StatementTypeInfo;
 28  
 import org.kuali.student.lum.common.client.lu.LUUIConstants;
 29  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseSummaryConfigurer;
 30  
 import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel;
 31  
 import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements;
 32  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService;
 33  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync;
 34  
 import org.kuali.student.lum.lu.ui.course.client.views.SelectVersionsView;
 35  
 import org.kuali.student.lum.lu.ui.course.client.views.ShowVersionView;
 36  
 import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList;
 37  
 
 38  
 import com.google.gwt.core.client.GWT;
 39  
 import com.google.gwt.event.dom.client.ClickEvent;
 40  
 import com.google.gwt.event.dom.client.ClickHandler;
 41  
 import com.google.gwt.user.client.Window;
 42  
 import com.google.gwt.user.client.ui.Widget;
 43  
 
 44  0
 public class VersionsController extends BasicLayoutWithContentHeader implements HasRequirements{
 45  
         
 46  0
         public static enum Views{VERSION_SELECT, VERSION_VIEW, VERSION_COMPARE}
 47  
         
 48  0
         private SelectVersionsView select = new SelectVersionsView(this, "", Views.VERSION_SELECT);
 49  
         private ShowVersionView view;
 50  
         private VerticalSectionView compare;
 51  
     private static final String MSG_GROUP = "course";
 52  0
     private String type = "course";
 53  0
     private String state = DtoConstants.STATE_DRAFT;
 54  0
     private String groupName = LUUIConstants.COURSE_GROUP_NAME;
 55  
         CourseSummaryConfigurer summaryConfigurer;
 56  0
         CourseRpcServiceAsync rpcServiceAsync = GWT.create(CourseRpcService.class);
 57  
         DataModelDefinition definition;
 58  
         
 59  
         private DataModel cluModel1;
 60  
         private DataModel cluModel2;
 61  
         
 62  0
         private String lastId1 = "";
 63  0
         private String lastId2 = "";
 64  0
         private HorizontalSection workflowVersionInfoSection = new HorizontalSection();
 65  
         
 66  
     private final CourseRequirementsDataModel reqDataModel1;
 67  
     private final CourseRequirementsDataModel reqDataModel2;
 68  
         
 69  0
         private boolean initialized = false;
 70  0
         private String versionIndId = "";
 71  0
         private String currentVersionId = "";
 72  0
         private final BlockingTask loadDataTask = new BlockingTask("Retrieving Data....");
 73  
         
 74  0
         private List<CourseWorkflowActionList> actionDropDownWidgets = new ArrayList<CourseWorkflowActionList>();
 75  0
         private KSLabel statusLabel = new KSLabel("");
 76  
         
 77  
         public VersionsController(Enum<?> viewType) {
 78  0
                 super(VersionsController.class.toString());
 79  0
                 this.addView(select);
 80  0
         this.setDefaultView(Views.VERSION_SELECT);
 81  0
         this.setName("Versions");
 82  0
         this.setViewEnum(viewType);
 83  0
         KSButton versionHistoryButton = new KSButton("Version History", ButtonStyle.DEFAULT_ANCHOR, new ClickHandler(){
 84  
 
 85  
                     @Override
 86  
                     public void onClick(ClickEvent event) {
 87  0
                             VersionsController.this.showDefaultView(Controller.NO_OP_CALLBACK);
 88  0
                     }
 89  
             });
 90  0
         versionHistoryButton.addStyleName("versionHistoryLink");
 91  
 
 92  0
         reqDataModel1 = new CourseRequirementsDataModel(this);
 93  0
         reqDataModel2 = new CourseRequirementsDataModel(this);
 94  
 
 95  0
         workflowVersionInfoSection.addWidget(this.getStatusLabel());
 96  0
         workflowVersionInfoSection.addWidget(this.generateActionDropDown());
 97  0
         workflowVersionInfoSection.addWidget(versionHistoryButton);
 98  
                 
 99  0
         this.getHeader().addWidget(workflowVersionInfoSection);
 100  0
         this.viewContainer.addStyleName("standard-content-padding");
 101  0
         initialize();
 102  0
     }        
 103  
 
 104  
         public void setVersionIndId(String versionIndId) {
 105  0
                 this.versionIndId = versionIndId;
 106  0
         }
 107  
         
 108  
         private void initialize() {
 109  0
         super.setDefaultModelId("Model");
 110  0
         super.registerModel("Model", new ModelProvider<DataModel>() {
 111  
 
 112  
             @Override
 113  
             public void requestModel(final ModelRequestCallback<DataModel> callback) {
 114  0
                 if(getViewContext().getId() != null && !getViewContext().getId().isEmpty()){
 115  0
                             getCourseFromCluId(getViewContext().getId(), 1, callback, true);
 116  
                 }
 117  
                 else{
 118  0
                         callback.onModelReady(null);
 119  
                 }
 120  0
             }
 121  
         });
 122  
         
 123  0
         super.registerModel("ComparisonModel", new ModelProvider<DataModel>() {
 124  
             @Override
 125  
             public void requestModel(final ModelRequestCallback<DataModel> callback) {
 126  0
                     if(getViewContext().getAttribute("docId2") != null && !getViewContext().getAttribute("docId2").isEmpty()){
 127  0
                             getCourseFromCluId(getViewContext().getAttribute("docId2"), 2, callback, false);        
 128  
                     }
 129  
                     else{
 130  0
                             callback.onModelReady(null);
 131  
                     }
 132  0
             }
 133  
         });
 134  0
         }
 135  
          
 136  
         @SuppressWarnings("unchecked")    
 137  
         private void getCourseFromCluId(final String courseId, final int modelNum, final ModelRequestCallback callback, final boolean id1Model){
 138  0
                 KSBlockingProgressIndicator.addTask(loadDataTask);
 139  
         
 140  0
             rpcServiceAsync.getData(courseId, new KSAsyncCallback<Data>(){
 141  
         
 142  
                 @Override
 143  
                 public void handleFailure(Throwable caught) {
 144  0
                     Window.alert("Error loading Course: "+caught.getMessage());
 145  0
                     callback.onRequestFail(caught);
 146  0
                     KSBlockingProgressIndicator.removeTask(loadDataTask);
 147  0
                 }
 148  
         
 149  
                 @Override
 150  
                 public void onSuccess(Data result) {
 151  0
                         if(modelNum == 1){
 152  0
                                 cluModel1 = new DataModel();
 153  0
                                 cluModel1.setDefinition(definition);
 154  0
                                 cluModel1.setRoot(result);
 155  0
                                 if(courseId.equals(currentVersionId)){
 156  0
                                         String name = "Version " + cluModel1.get("versionInfo/sequenceNumber") + " (current version)";
 157  0
                                         cluModel1.setModelName(name);
 158  0
                                         view.setName(name);
 159  0
                                         view.showWarningMessage(false);
 160  0
                                 }
 161  
                                 else{
 162  0
                                         String name = "Version " + cluModel1.get("versionInfo/sequenceNumber");
 163  0
                                         cluModel1.setModelName(name);
 164  0
                                         view.setName(name);
 165  0
                                         view.showWarningMessage(true);
 166  
                                 }
 167  0
                                 updateState(cluModel1);
 168  0
                              callback.onModelReady(cluModel1);
 169  0
                              lastId1 = courseId;
 170  
 
 171  0
                              reqDataModel1.retrieveStatementTypes(cluModel1.<String>get("id"), new Callback<Boolean>() {
 172  
                             @Override
 173  
                             public void exec(Boolean result) {
 174  0
                                 if (result) {
 175  0
                                     KSBlockingProgressIndicator.removeTask(loadDataTask);
 176  
                                 }
 177  0
                             }
 178  
                         }); 
 179  
                         }
 180  
                         else{
 181  0
                                 cluModel2 = new DataModel();
 182  0
                                 cluModel2.setDefinition(definition);
 183  0
                                 cluModel2.setRoot(result);
 184  0
                                 if(courseId.equals(currentVersionId)){
 185  0
                                         cluModel2.setModelName("Version " + cluModel2.get("versionInfo/sequenceNumber") + " (current version)");
 186  
                                 }
 187  
                                 else{
 188  0
                                         cluModel2.setModelName("Version " + cluModel2.get("versionInfo/sequenceNumber"));
 189  
                                 }
 190  0
                              callback.onModelReady(cluModel2);
 191  0
                              lastId2 = courseId;
 192  
 
 193  0
                              reqDataModel2.retrieveStatementTypes(cluModel2.<String>get("id"), new Callback<Boolean>() {
 194  
                             @Override
 195  
                             public void exec(Boolean result) {
 196  0
                                 if (result) {
 197  0
                                     KSBlockingProgressIndicator.removeTask(loadDataTask);
 198  
                                 }
 199  0
                             }
 200  
                         });
 201  
                         }                    
 202  0
                 }        
 203  
             });
 204  0
         }
 205  
         
 206  
     @Override
 207  
     public void showDefaultView(final Callback<Boolean> onReadyCallback) {
 208  0
             KSBlockingProgressIndicator.addTask(loadDataTask);
 209  
             
 210  0
         init(new Callback<Boolean>() {
 211  
 
 212  
             @Override
 213  
             public void exec(Boolean result) {
 214  0
                 if (result) {
 215  0
                         VersionsController.super.showDefaultView(new Callback<Boolean>() {
 216  
                                 
 217  
                                 @Override
 218  
                                 public void exec(Boolean result) {
 219  0
                                         onReadyCallback.exec(result);
 220  0
                                         KSBlockingProgressIndicator.removeTask(loadDataTask);
 221  0
                                 }
 222  
                         });
 223  
                 } else {
 224  0
                     onReadyCallback.exec(false);
 225  0
                     KSBlockingProgressIndicator.removeTask(loadDataTask);
 226  
                 }
 227  
                 
 228  0
             }
 229  
         });
 230  0
     }
 231  
     
 232  
     @Override
 233  
     public void beforeShow(Callback<Boolean> onReadyCallback) {
 234  0
             workflowVersionInfoSection.setVisible(false);
 235  0
             this.getHeader().showPrint(false);
 236  0
             this.getHeader().showExport(false);
 237  0
             showDefaultView(onReadyCallback);
 238  0
     }
 239  
     
 240  
     private void init(final Callback<Boolean> onReadyCallback) {
 241  
 
 242  0
         if (initialized) {
 243  0
             onReadyCallback.exec(true);
 244  
         } else {
 245  0
                 KSBlockingProgressIndicator.addTask(loadDataTask);
 246  
                     
 247  0
                 rpcServiceAsync.getMetadata("", null, new KSAsyncCallback<Metadata>(){
 248  
 
 249  
                         public void handleFailure(Throwable caught) {
 250  0
                                 initialized = false;
 251  0
                         onReadyCallback.exec(false);
 252  0
                         KSBlockingProgressIndicator.removeTask(loadDataTask);
 253  0
                     throw new RuntimeException("Failed to get model definition.", caught);
 254  
                 }
 255  
 
 256  
                 public void onSuccess(Metadata result) {
 257  0
                         definition = new DataModelDefinition(result);
 258  0
                     KSBlockingProgressIndicator.removeTask(loadDataTask);
 259  0
                     configureScreens(onReadyCallback);
 260  0
                 }
 261  
                   });
 262  
             
 263  
         }
 264  0
     }
 265  
 
 266  
     private void configureScreens(final Callback<Boolean> onReadyCallback) {
 267  0
         CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() {
 268  
 
 269  
             @Override
 270  
             public void exec(List<StatementTypeInfo> stmtTypes) {
 271  0
                 List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>();
 272  0
                 if (stmtTypes != null) {
 273  0
                     for (StatementTypeInfo stmtType : stmtTypes) {
 274  0
                         if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") ||
 275  
                             stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) {
 276  0
                             continue;
 277  
                         }
 278  0
                         stmtTypesOut.add(stmtType);
 279  
                     }
 280  
                 }
 281  
 
 282  0
                 summaryConfigurer = new CourseSummaryConfigurer(type, state, groupName, definition, stmtTypesOut, VersionsController.this, "Model");
 283  0
                 view = new ShowVersionView(Views.VERSION_VIEW, "Version", "Model", VersionsController.this, stmtTypesOut);
 284  0
                 compare = summaryConfigurer.generateCourseSummarySection();
 285  0
                 compare.setLayoutController(VersionsController.this);
 286  0
                 compare.setSectionTitle("Compare Versions");
 287  0
                 compare.setName("Compare Versions");
 288  0
                 compare.setViewEnum(Views.VERSION_COMPARE);
 289  0
                 VersionsController.this.addView(view);
 290  0
                 VersionsController.this.addView(compare);
 291  0
                 initialized = true;
 292  0
                 onReadyCallback.exec(true);
 293  0
             }
 294  
         });
 295  0
     }
 296  
     
 297  
     public Widget generateActionDropDown(){
 298  0
             CourseWorkflowActionList actionList = new CourseWorkflowActionList(this.getMessage("cluActionsLabel"));
 299  
 
 300  0
             actionDropDownWidgets.add(actionList);
 301  
         
 302  0
             return actionList;
 303  
     }
 304  
     
 305  
     private void updateState(final DataModel cluModel) {
 306  0
             if(cluModel.get("state") != null){
 307  0
                     statusLabel.setText("Status: " + cluModel.get("state"));
 308  
                     
 309  0
                     for(CourseWorkflowActionList widget: actionDropDownWidgets){
 310  0
                                 widget.init(getViewContext(), "/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", cluModel, new Callback<String>() {
 311  
                                         @Override
 312  
                                 public void exec(String newState) {
 313  0
                                     if (newState != null) {
 314  0
                                         KSNotifier.add(new KSNotification(getMessage("cluStateChangeNotification" + newState), false, 5000));
 315  
                                         // FIXME: this is not updating the cluModel so state will not be updated in the model.  May not be a problem.
 316  0
                                         statusLabel.setText("Status: " + newState);
 317  
                                     } else {
 318  0
                                             KSNotifier.add(new KSNotification(getMessage("cluStateChangeFailedNotification"), false, 5000));
 319  
                                     }
 320  0
                                 }
 321  
                                 });
 322  0
                                 widget.updateCourseActionItems(cluModel);
 323  0
                                 widget.setEnabled(true);
 324  0
                                 if(widget.isEmpty()) {
 325  0
                                         widget.setVisible(false);
 326  
                                 }
 327  
                                 else{
 328  0
                                         widget.setVisible(true);
 329  
                                 }
 330  
                         }
 331  
             }
 332  0
     }
 333  
     
 334  
         public Widget getStatusLabel() {
 335  0
                 statusLabel.setStyleName("courseStatusLabel");
 336  0
                 return statusLabel;
 337  
         }
 338  
     
 339  
     public DataModelDefinition getDefinition(){
 340  0
             return definition;
 341  
     }
 342  
 
 343  
         public void setCurrentVersionId(String id) {
 344  0
                 this.currentVersionId = id;
 345  0
         }
 346  
 
 347  
         public String getCurrentVersionId() {
 348  0
                 return currentVersionId;
 349  
         }
 350  
         
 351  
         public String getVersionIndId() {
 352  0
                 return versionIndId;
 353  
         }
 354  
         
 355  
     public String getMessage(String courseMessageKey) {
 356  0
             String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey);
 357  0
             if (msg == null) {
 358  0
                     msg = courseMessageKey;
 359  
             }
 360  0
             return msg;
 361  
     }
 362  
         
 363  
         
 364  
         @Override
 365  
         public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback) {
 366  0
                 if(viewType != Views.VERSION_SELECT){
 367  0
                         workflowVersionInfoSection.setVisible(true);
 368  0
                         this.getHeader().showPrint(true);
 369  0
                         this.getHeader().showExport(true);
 370  
                 }
 371  
                 else{
 372  0
                         workflowVersionInfoSection.setVisible(false);
 373  0
                         this.getHeader().showPrint(false);
 374  0
                         this.getHeader().showExport(false);
 375  
                 }
 376  0
                 super.showView(viewType, onReadyCallback);
 377  0
         }
 378  
 
 379  
 
 380  
 
 381  
         public void setCurrentTitle(String currentTitle) {
 382  0
             this.getHeader().setTitle(currentTitle);
 383  0
         }
 384  
         
 385  
         
 386  
         @Override
 387  
         public CourseRequirementsDataModel getReqDataModel() {
 388  0
                 return reqDataModel1;
 389  
         }
 390  
 
 391  
         public CourseRequirementsDataModel getReqDataModelComp() {
 392  0
                 return reqDataModel2;
 393  
         } 
 394  
 }