Coverage Report - org.kuali.student.lum.program.client.major.edit.MajorEditController
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorEditController
0%
0/92
0%
0/20
1.816
MajorEditController$1
0%
0/3
N/A
1.816
MajorEditController$10
0%
0/6
N/A
1.816
MajorEditController$10$1
0%
0/7
0%
0/2
1.816
MajorEditController$11
0%
0/42
0%
0/8
1.816
MajorEditController$12
0%
0/6
0%
0/2
1.816
MajorEditController$13
0%
0/5
0%
0/4
1.816
MajorEditController$13$1
0%
0/6
N/A
1.816
MajorEditController$2
0%
0/3
N/A
1.816
MajorEditController$3
0%
0/6
0%
0/2
1.816
MajorEditController$4
0%
0/3
N/A
1.816
MajorEditController$4$1
0%
0/3
N/A
1.816
MajorEditController$4$1$1
0%
0/11
0%
0/6
1.816
MajorEditController$4$1$1$1
0%
0/6
0%
0/2
1.816
MajorEditController$4$1$1$1$1
0%
0/5
0%
0/2
1.816
MajorEditController$5
0%
0/27
0%
0/10
1.816
MajorEditController$6
0%
0/9
N/A
1.816
MajorEditController$7
0%
0/12
0%
0/4
1.816
MajorEditController$8
0%
0/3
N/A
1.816
MajorEditController$9
0%
0/11
N/A
1.816
 
 1  
 package org.kuali.student.lum.program.client.major.edit;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Iterator;
 5  
 import java.util.List;
 6  
 import java.util.Set;
 7  
 import java.util.TreeSet;
 8  
 
 9  
 import org.kuali.student.common.assembly.data.Data;
 10  
 import org.kuali.student.common.assembly.data.Data.Property;
 11  
 import org.kuali.student.common.assembly.data.QueryPath;
 12  
 import org.kuali.student.common.ui.client.application.Application;
 13  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 14  
 import org.kuali.student.common.ui.client.application.ViewContext;
 15  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 16  
 import org.kuali.student.common.ui.client.mvc.Callback;
 17  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 18  
 import org.kuali.student.common.ui.client.mvc.HasCrossConstraints;
 19  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 20  
 import org.kuali.student.common.ui.client.mvc.View;
 21  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 22  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 23  
 import org.kuali.student.common.ui.client.validator.ValidatorClientUtils;
 24  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 25  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
 26  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 27  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 28  
 import org.kuali.student.common.ui.shared.IdAttributes;
 29  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 30  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 31  
 import org.kuali.student.lum.common.client.configuration.LUMViews;
 32  
 import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper;
 33  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 34  
 import org.kuali.student.lum.program.client.ProgramConstants;
 35  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 36  
 import org.kuali.student.lum.program.client.ProgramSections;
 37  
 import org.kuali.student.lum.program.client.ProgramStatus;
 38  
 import org.kuali.student.lum.program.client.ProgramUtils;
 39  
 import org.kuali.student.lum.program.client.events.AddSpecializationEvent;
 40  
 import org.kuali.student.lum.program.client.events.AfterSaveEvent;
 41  
 import org.kuali.student.lum.program.client.events.ChangeViewEvent;
 42  
 import org.kuali.student.lum.program.client.events.MetadataLoadedEvent;
 43  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 44  
 import org.kuali.student.lum.program.client.events.SpecializationCreatedEvent;
 45  
 import org.kuali.student.lum.program.client.events.SpecializationSaveEvent;
 46  
 import org.kuali.student.lum.program.client.events.SpecializationUpdateEvent;
 47  
 import org.kuali.student.lum.program.client.events.StateChangeEvent;
 48  
 import org.kuali.student.lum.program.client.events.StoreRequirementIDsEvent;
 49  
 import org.kuali.student.lum.program.client.events.UpdateEvent;
 50  
 import org.kuali.student.lum.program.client.major.MajorController;
 51  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 52  
 import org.kuali.student.lum.program.client.rpc.AbstractCallback;
 53  
 import org.kuali.student.lum.program.client.widgets.ProgramSideBar;
 54  
 
 55  
 import com.google.gwt.core.client.GWT;
 56  
 import com.google.gwt.event.dom.client.ClickEvent;
 57  
 import com.google.gwt.event.dom.client.ClickHandler;
 58  
 import com.google.gwt.event.shared.HandlerManager;
 59  
 import com.google.gwt.user.client.Window;
 60  
 
 61  
 /**
 62  
  * @author Igor
 63  
  */
 64  0
 public class MajorEditController extends MajorController {
 65  
 
 66  0
     private final KSButton saveButton = new KSButton(ProgramProperties.get().common_save());
 67  0
     private final KSButton cancelButton = new KSButton(ProgramProperties.get().common_cancel(), KSButtonAbstract.ButtonStyle.ANCHOR_LARGE_CENTERED);
 68  0
     private final Set<String> existingVariationIds = new TreeSet<String>();
 69  
 
 70  
  
 71  
     /**
 72  
      * Constructor.
 73  
      *
 74  
      * @param programModel
 75  
      */
 76  
     public MajorEditController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) {
 77  0
         super(programModel, viewContext, eventBus);
 78  0
         configurer = GWT.create(MajorEditConfigurer.class);
 79  0
         sideBar.setState(ProgramSideBar.State.EDIT);
 80  0
         initHandlers();
 81  0
     }
 82  
 
 83  
     @Override
 84  
     protected void configureView() {
 85  0
         super.configureView();
 86  0
         if (!initialized) {
 87  0
             eventBus.fireEvent(new MetadataLoadedEvent(programModel.getDefinition(), this));
 88  0
             List<Enum<?>> excludedViews = new ArrayList<Enum<?>>();
 89  0
             excludedViews.add(ProgramSections.PROGRAM_REQUIREMENTS_EDIT);
 90  0
             excludedViews.add(ProgramSections.SUPPORTING_DOCUMENTS_EDIT);
 91  0
             excludedViews.add(ProgramSections.SUMMARY);
 92  0
             addCommonButton(ProgramProperties.get().program_menu_sections(), saveButton, excludedViews);
 93  0
             addCommonButton(ProgramProperties.get().program_menu_sections(), cancelButton, excludedViews);
 94  0
             initialized = true;
 95  
         }
 96  0
     }
 97  
 
 98  
     private void initHandlers() {
 99  0
         saveButton.addClickHandler(new ClickHandler() {
 100  
 
 101  
             @Override
 102  
             public void onClick(ClickEvent event) {
 103  0
                 doSave();
 104  0
             }
 105  
         });
 106  0
         cancelButton.addClickHandler(new ClickHandler() {
 107  
 
 108  
             @Override
 109  
             public void onClick(ClickEvent event) {
 110  0
                 doCancel();
 111  0
             }
 112  
         });
 113  0
         eventBus.addHandler(UpdateEvent.TYPE, new UpdateEvent.Handler() {
 114  
             @Override
 115  
             public void onEvent(UpdateEvent event) {
 116  0
                 Enum<?> view = event.getCurrentView();
 117  0
                 if (view != null) {
 118  0
                     setCurrentViewEnum(view);
 119  
                 }
 120  0
                 doSave(event.getOkCallback());
 121  
 
 122  0
             }
 123  
         });
 124  0
         eventBus.addHandler(StateChangeEvent.TYPE, new StateChangeEvent.Handler() {
 125  
             @Override
 126  
             public void onEvent(final StateChangeEvent event) {
 127  
                     //FIXME: The proper way of doing this would be a single server side call to validate next state
 128  
                     //which would retrieve warnings & required for next state, instead of re-validating warnings for
 129  
                     //current state server side and validating required for next state client side.
 130  0
                     programRemoteService.validate(programModel.getRoot(), new KSAsyncCallback<List<ValidationResultInfo>>(){
 131  
                                         @Override
 132  
                                         public void onSuccess(final List<ValidationResultInfo> currentStateResults) {
 133  0
                                 programModel.validateNextState(new Callback<List<ValidationResultInfo>>() {
 134  
                                     @Override
 135  
                                     public void exec(List<ValidationResultInfo> nextStateResults) {
 136  
                                             //Update validation warnings and process for all screens
 137  0
                                             Application.getApplicationContext().clearValidationWarnings();
 138  0
                                             Application.getApplicationContext().addValidationWarnings(currentStateResults);
 139  0
                                             isValid(Application.getApplicationContext().getValidationWarnings(), false);
 140  
                                         
 141  0
                                             boolean isSectionValid = isValid(nextStateResults, true) 
 142  
                                                 && Application.getApplicationContext().getValidationWarnings().isEmpty();
 143  0
                                         if (isSectionValid) {
 144  0
                                             Callback<Boolean> callback = new Callback<Boolean>() {
 145  
                                                 @Override
 146  
                                                 public void exec(Boolean result) {
 147  0
                                                     if (result) {
 148  0
                                                         reloadMetadata = true;
 149  0
                                                         loadMetadata(new Callback<Boolean>() {
 150  
                                                             @Override
 151  
                                                             public void exec(Boolean result) {
 152  0
                                                                 if (result) {
 153  0
                                                                     ProgramUtils.syncMetadata(configurer, programModel.getDefinition());
 154  0
                                                                     HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), context);
 155  
                                                                 }
 156  0
                                                             }
 157  
                                                         });
 158  
                                                     }else{
 159  0
                                                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 160  
                                                     }
 161  0
                                                 }
 162  
                                             };
 163  0
                                             updateState(event.getProgramStatus().getValue(), callback);
 164  0
                                         } else {
 165  0
                                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 166  
                                         }
 167  0
                                     }
 168  
                                 });
 169  
 
 170  
                                                 
 171  0
                                         }
 172  
                             
 173  
                     });                
 174  0
             }
 175  
         });
 176  
 
 177  0
         eventBus.addHandler(SpecializationSaveEvent.TYPE, new SpecializationSaveEvent.Handler() {
 178  
             @Override
 179  
             public void onEvent(SpecializationSaveEvent event) {
 180  
 
 181  0
                 Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);
 182  
 
 183  0
                 existingVariationIds.clear();
 184  
 
 185  0
                 for (Data.Property prop : currentVariations) {
 186  0
                     String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 187  0
                     existingVariationIds.add(existingId);
 188  0
                 }
 189  0
                 String updatedId = event.getData().get(ProgramConstants.ID);
 190  0
                 Integer updatedKey = null;
 191  
 
 192  
                 //FIXME: This is ugly but gets us past a  blocker issue. 
 193  
                 // Theres something wrong with the way the models are
 194  
                 // handled in the major and variation controllers  so they get out of sync.
 195  
                 // This is a temporary workaround
 196  0
                 if (updatedId != null) { // this is an update of an existing variation
 197  0
                     for (Data.Property prop : currentVariations) {
 198  0
                         String id = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 199  0
                         if (updatedId.equals(id)) {
 200  0
                             updatedKey = prop.getKey();
 201  0
                             Data currentMetaInfo = ((Data) prop.getValue()).get("metaInfo");
 202  0
                             String latestVersionInd = currentMetaInfo.get("versionInd");
 203  0
                             Data newMetaInfo = event.getData().get("metaInfo");
 204  0
                             if (newMetaInfo == null) {
 205  0
                                 newMetaInfo = new Data();
 206  0
                                 event.getData().set("metaInfo", newMetaInfo);
 207  
                             }
 208  0
                             newMetaInfo.set("versionInd", latestVersionInd);
 209  0
                             break;
 210  
                         }
 211  0
                     }
 212  
 
 213  0
                     currentVariations.set(updatedKey, event.getData());
 214  
                 } else {
 215  0
                     currentVariations.add(event.getData());
 216  
 
 217  
                 }
 218  0
                 doSave();
 219  0
             }
 220  
         });
 221  0
         eventBus.addHandler(AddSpecializationEvent.TYPE, new AddSpecializationEvent.Handler() {
 222  
             @Override
 223  
             public void onEvent(AddSpecializationEvent event) {
 224  0
                 String id = getStringProperty(ProgramConstants.ID);
 225  0
                 ProgramRegistry.setRow((getDataProperty(ProgramConstants.VARIATIONS)).size());
 226  0
                 ProgramRegistry.setData(ProgramUtils.createNewSpecializationBasedOnMajor(programModel));
 227  0
                 ViewContext viewContext = new ViewContext();
 228  0
                 viewContext.setId(id);
 229  0
                 viewContext.setIdType(IdAttributes.IdType.OBJECT_ID);
 230  0
                 HistoryManager.navigate(AppLocations.Locations.EDIT_VARIATION.getLocation(), viewContext);
 231  
 
 232  0
             }
 233  
         });
 234  
 
 235  0
         eventBus.addHandler(StoreRequirementIDsEvent.TYPE, new StoreRequirementIDsEvent.Handler() {
 236  
             @Override
 237  
             public void onEvent(StoreRequirementIDsEvent event) {
 238  0
                 List<String> ids = event.getProgramRequirementIds();
 239  
 
 240  0
                 programModel.set(QueryPath.parse(ProgramConstants.PROGRAM_REQUIREMENTS), new Data());
 241  0
                 Data programRequirements = programModel.get(ProgramConstants.PROGRAM_REQUIREMENTS);
 242  
 
 243  0
                 if (programRequirements == null) {
 244  0
                     Window.alert("Cannot find program requirements in data model.");
 245  0
                     GWT.log("Cannot find program requirements in data model", null);
 246  0
                     return;
 247  
                 }
 248  
 
 249  0
                 for (String id : ids) {
 250  0
                     programRequirements.add(id);
 251  
                 }
 252  0
                 doSave();
 253  0
             }
 254  
         });
 255  0
         eventBus.addHandler(ChangeViewEvent.TYPE, new ChangeViewEvent.Handler() {
 256  
             @Override
 257  
             public void onEvent(ChangeViewEvent event) {
 258  0
                 showView(event.getViewToken());
 259  0
             }
 260  
         });
 261  0
     }
 262  
 
 263  
     @Override
 264  
     protected void loadModel(ModelRequestCallback<DataModel> callback) {
 265  0
         ViewContext viewContext = getViewContext();
 266  0
         if (viewContext.getIdType() == IdType.COPY_OF_OBJECT_ID) {
 267  0
             createNewVersionAndLoadModel(callback, viewContext);
 268  
         } else {
 269  0
             super.loadModel(callback);
 270  
         }
 271  0
     }
 272  
 
 273  
     protected void createNewVersionAndLoadModel(final ModelRequestCallback<DataModel> callback, final ViewContext viewContext) {
 274  0
         Data data = new Data();
 275  0
         Data versionData = new Data();
 276  0
         versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId());
 277  0
         versionData.set(new Data.StringKey("versionComment"), "Major Disicpline Version");
 278  0
         data.set(new Data.StringKey("versionInfo"), versionData);
 279  
 
 280  0
         programRemoteService.saveData(data, new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_retrievingData()) {
 281  
             @Override
 282  
             public void onSuccess(DataSaveResult result) {
 283  0
                 super.onSuccess(result);
 284  0
                 refreshModelAndView(result);
 285  0
                 viewContext.setId(ProgramUtils.getProgramId(programModel));
 286  0
                 viewContext.setIdType(IdType.OBJECT_ID);                
 287  0
                 callback.onModelReady(programModel);
 288  0
                 eventBus.fireEvent(new ModelLoadedEvent(programModel));
 289  0
             }
 290  
 
 291  
             @Override
 292  
             public void onFailure(Throwable caught) {
 293  0
                 super.onFailure(caught);
 294  0
                 callback.onRequestFail(caught);
 295  0
             }
 296  
         });
 297  
 
 298  0
     }
 299  
 
 300  
     private void doSave(final Callback<Boolean> okCallback) {
 301  0
         requestModel(new ModelRequestCallback<DataModel>() {
 302  
             @Override
 303  
             public void onModelReady(DataModel model) {
 304  0
                 MajorEditController.this.updateModelFromCurrentView();
 305  0
                 model.validate(new Callback<List<ValidationResultInfo>>() {
 306  
                     @Override
 307  
                     public void exec(List<ValidationResultInfo> result) {
 308  0
                         boolean isSectionValid = isValid(result, true);
 309  0
                         if (isSectionValid) {
 310  0
                             saveData(okCallback);
 311  
                         } else {
 312  0
                             okCallback.exec(false);
 313  0
                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 314  
                         }
 315  0
                     }
 316  
                 });
 317  
 
 318  0
             }
 319  
 
 320  
             @Override
 321  
             public void onRequestFail(Throwable cause) {
 322  0
                 GWT.log("Unable to retrieve model for validation and save", cause);
 323  0
             }
 324  
         });
 325  0
     }
 326  
 
 327  
     private void doCancel() {
 328  0
         showView(ProgramSections.SUMMARY);
 329  0
     }
 330  
 
 331  
     @Override
 332  
     protected void doSave() {
 333  0
         doSave(NO_OP_CALLBACK);
 334  0
     }
 335  
 
 336  
     private void saveData(final Callback<Boolean> okCallback) {
 337  0
         programRemoteService.saveData(programModel.getRoot(), new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_savingData()) {
 338  
             @Override
 339  
             public void onSuccess(DataSaveResult result) {
 340  0
                 super.onSuccess(result);
 341  
 
 342  
                 //Clear warning states on field and any warnings stored in ApplicationContext;
 343  0
                 clearAllWarnings();
 344  0
                 Application.getApplicationContext().clearValidationWarnings();
 345  
                 
 346  0
                 List<ValidationResultInfo> validationResults = result.getValidationResults();
 347  0
                 Application.getApplicationContext().addValidationWarnings(validationResults);
 348  0
                 if (ValidatorClientUtils.hasErrors(validationResults)) {
 349  0
                     ProgramUtils.retrofitValidationResults(validationResults);
 350  0
                     isValid(validationResults, false, true);
 351  0
                     ProgramUtils.handleValidationErrorsForSpecializations(validationResults, programModel);
 352  
                     
 353  
                     //Clean up anything created by earlier code
 354  0
                     Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);
 355  
 
 356  0
                     existingVariationIds.clear();
 357  
 
 358  0
                     for (Iterator<Property> iter = currentVariations.iterator();iter.hasNext();) {
 359  0
                             Property prop = iter.next();
 360  0
                         String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 361  0
                         if(existingId==null){
 362  0
                                 iter.remove();
 363  
                         }else{
 364  0
                                 existingVariationIds.add(existingId);
 365  
                         }
 366  0
                     }
 367  
                     
 368  0
                     okCallback.exec(false);
 369  0
                 } else {
 370  0
                     refreshModelAndView(result);
 371  0
                     resetFieldInteractionFlag();
 372  0
                     configurer.applyPermissions();
 373  0
                     handleSpecializations();
 374  0
                     throwAfterSaveEvent();
 375  0
                     HistoryManager.logHistoryChange();
 376  0
                     ViewContext viewContext = getViewContext();
 377  0
                     viewContext.setId(getStringProperty(ProgramConstants.ID));
 378  0
                     viewContext.setIdType(IdType.OBJECT_ID);
 379  
 
 380  0
                                     if (ValidatorClientUtils.hasWarnings(validationResults)){
 381  
                                             //Show validation warnings for major
 382  0
                                             isValid(result.getValidationResults(), false, true);                                            
 383  0
                                             KSNotifier.show("Saved with Warnings");
 384  
                                     } else {
 385  0
                         KSNotifier.show(ProgramProperties.get().common_successfulSave());
 386  
                                     }                                  
 387  
                     
 388  
                     // add to recently viewed now that we're sure to know the program's id
 389  0
                     ViewContext docContext = new ViewContext();
 390  0
                     docContext.setId(getStringProperty(ProgramConstants.ID));
 391  0
                     docContext.setIdType(IdType.OBJECT_ID);
 392  0
                     docContext.setAttribute(ProgramConstants.TYPE, ProgramConstants.MAJOR_LU_TYPE_ID + '/' + ProgramSections.PROGRAM_DETAILS_VIEW);
 393  0
                     RecentlyViewedHelper.addDocument(getProgramName(),
 394  
                             HistoryManager.appendContext(AppLocations.Locations.VIEW_PROGRAM.getLocation(), docContext));
 395  
                    
 396  0
                     okCallback.exec(true);
 397  0
                     processCurrentView();
 398  
                 }
 399  0
             }
 400  
         });
 401  0
     }
 402  
 
 403  
     private void processCurrentView() {
 404  0
         Enum<?> currentView = getCurrentViewEnum();
 405  0
         if (currentView.name().equals(ProgramSections.VIEW_ALL.name())) {
 406  0
             HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), getViewContext());
 407  
         } else {
 408  0
             showView(currentView);
 409  
         }
 410  0
     }
 411  
 
 412  
     /**
 413  
      * Handles after save work for specializations.
 414  
      */
 415  
     private void handleSpecializations() {
 416  0
         String newVariationId = null;
 417  0
         Data variations = programModel.get(ProgramConstants.VARIATIONS);
 418  0
         for (Data.Property prop : variations) {
 419  0
             String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 420  0
             if (!existingVariationIds.contains(varId)) {
 421  0
                 newVariationId = varId;
 422  0
                 existingVariationIds.add(newVariationId);
 423  0
                 break;
 424  
             }
 425  0
         }
 426  0
         if (newVariationId != null) {
 427  0
             eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId));
 428  
         } else {
 429  0
             eventBus.fireEvent(new SpecializationUpdateEvent(variations));
 430  
         }
 431  0
     }
 432  
 
 433  
     private void throwAfterSaveEvent() {
 434  0
         eventBus.fireEvent(new AfterSaveEvent(programModel, this));
 435  0
     }
 436  
 
 437  
     @Override
 438  
     public void onModelLoadedEvent() {
 439  0
         Enum<?> changeSection = ProgramRegistry.getSection();
 440  0
         if (changeSection != null) {
 441  0
             showView(changeSection);
 442  0
             ProgramRegistry.setSection(null);
 443  
         } else {
 444  0
             String id = getStringProperty(ProgramConstants.ID);
 445  0
             if (id == null) {
 446  0
                 showView(ProgramSections.PROGRAM_DETAILS_EDIT);
 447  
             } else {
 448  0
                 showView(ProgramSections.SUMMARY);
 449  
             }
 450  
         }
 451  
 
 452  0
     }
 453  
 
 454  
         @Override
 455  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 456  0
                 if(!initialized){
 457  0
                         Application.getApplicationContext().clearCrossConstraintMap(null);
 458  0
                         Application.getApplicationContext().clearPathToFieldMapping(null);
 459  
                 }
 460  
                 //Clear the parent path again
 461  0
                 Application.getApplicationContext().setParentPath("");
 462  0
                 super.beforeShow(onReadyCallback);
 463  0
         }
 464  
 
 465  
         //Before show is called before the model is bound to the widgets. We need to update cross constraints after widget binding
 466  
         //This gets called twice which is not optimal
 467  
         @Override
 468  
         public <V extends Enum<?>> void showView(V viewType,
 469  
                         final Callback<Boolean> onReadyCallback) {
 470  0
                 Callback<Boolean> updateCrossConstraintsCallback = new Callback<Boolean>(){
 471  
                         public void exec(Boolean result) {
 472  0
                                 onReadyCallback.exec(result);
 473  0
                         for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){
 474  0
                                 crossConstraint.reprocessWithUpdatedConstraints();
 475  
                         }
 476  0
                         showWarnings();        
 477  0
                         }
 478  
         };
 479  0
                 super.showView(viewType, updateCrossConstraintsCallback);
 480  0
         }
 481  
 
 482  
         //Ensure that the managing bodies section view is updated before the user edits specializations
 483  
         @Override
 484  
         public void beforeViewChange(Enum<?> viewChangingTo, final Callback<Boolean> okToChangeCallback){
 485  0
                 if(LUMViews.VARIATION_EDIT.equals(viewChangingTo)){
 486  0
                         getView(ProgramSections.MANAGE_BODIES_EDIT, new Callback<View>(){
 487  
                                 @Override
 488  
                                 public void exec(final View view) {
 489  0
                                         if(view!=null && view instanceof SectionView){
 490  0
                                                 requestModel(new ModelRequestCallback<DataModel>(){
 491  
                                                         public void onModelReady(DataModel model) {
 492  0
                                                                 ((SectionView)view).updateWidgetData(model);
 493  0
                                                                 okToChangeCallback.exec(true);
 494  0
                                                         }
 495  
                                                         public void onRequestFail(Throwable cause) {
 496  0
                                                                 okToChangeCallback.exec(false);
 497  0
                                                         }
 498  
                                                 });
 499  
                                         }else{
 500  0
                                                 okToChangeCallback.exec(true);
 501  
                                         }
 502  0
                                 }});
 503  
                 }else{
 504  0
                         okToChangeCallback.exec(true);
 505  
                 }
 506  0
                 this.showExport(isExportButtonActive());        // KSLAB-1916
 507  0
         }
 508  
 }