|  1 |     | 
   package org.kuali.student.lum.program.client.major.proposal;  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import java.util.ArrayList;  | 
  |  4 |     | 
   import java.util.HashMap;  | 
  |  5 |     | 
   import java.util.Iterator;  | 
  |  6 |     | 
   import java.util.List;  | 
  |  7 |     | 
   import java.util.Map;  | 
  |  8 |     | 
   import java.util.Set;  | 
  |  9 |     | 
   import java.util.TreeSet;  | 
  |  10 |     | 
     | 
  |  11 |     | 
   import org.kuali.student.common.assembly.data.Data;  | 
  |  12 |     | 
   import org.kuali.student.common.assembly.data.Data.Property;  | 
  |  13 |     | 
   import org.kuali.student.common.assembly.data.Metadata;  | 
  |  14 |     | 
   import org.kuali.student.common.assembly.data.QueryPath;  | 
  |  15 |     | 
   import org.kuali.student.common.dto.DtoConstants;  | 
  |  16 |     | 
   import org.kuali.student.common.rice.StudentIdentityConstants;  | 
  |  17 |     | 
   import org.kuali.student.common.rice.authorization.PermissionType;  | 
  |  18 |     | 
   import org.kuali.student.common.ui.client.application.Application;  | 
  |  19 |     | 
   import org.kuali.student.common.ui.client.application.KSAsyncCallback;  | 
  |  20 |     | 
   import org.kuali.student.common.ui.client.application.ViewContext;  | 
  |  21 |     | 
   import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;  | 
  |  22 |     | 
   import org.kuali.student.common.ui.client.event.SaveActionEvent;  | 
  |  23 |     | 
   import org.kuali.student.common.ui.client.event.SaveActionHandler;  | 
  |  24 |     | 
   import org.kuali.student.common.ui.client.mvc.ApplicationEvent;  | 
  |  25 |     | 
   import org.kuali.student.common.ui.client.mvc.Callback;  | 
  |  26 |     | 
   import org.kuali.student.common.ui.client.mvc.DataModel;  | 
  |  27 |     | 
   import org.kuali.student.common.ui.client.mvc.DataModelDefinition;  | 
  |  28 |     | 
   import org.kuali.student.common.ui.client.mvc.HasCrossConstraints;  | 
  |  29 |     | 
   import org.kuali.student.common.ui.client.mvc.ModelProvider;  | 
  |  30 |     | 
   import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;  | 
  |  31 |     | 
   import org.kuali.student.common.ui.client.mvc.View;  | 
  |  32 |     | 
   import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel;  | 
  |  33 |     | 
   import org.kuali.student.common.ui.client.mvc.history.HistoryManager;  | 
  |  34 |     | 
   import org.kuali.student.common.ui.client.security.AuthorizationCallback;  | 
  |  35 |     | 
   import org.kuali.student.common.ui.client.security.RequiresAuthorization;  | 
  |  36 |     | 
   import org.kuali.student.common.ui.client.service.DataSaveResult;  | 
  |  37 |     | 
   import org.kuali.student.common.ui.client.validator.ValidatorClientUtils;  | 
  |  38 |     | 
   import org.kuali.student.common.ui.client.widgets.KSButton;  | 
  |  39 |     | 
   import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;  | 
  |  40 |     | 
   import org.kuali.student.common.ui.client.widgets.notification.KSNotification;  | 
  |  41 |     | 
   import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;  | 
  |  42 |     | 
   import org.kuali.student.common.ui.shared.IdAttributes;  | 
  |  43 |     | 
   import org.kuali.student.common.ui.shared.IdAttributes.IdType;  | 
  |  44 |     | 
   import org.kuali.student.common.validation.dto.ValidationResultInfo;  | 
  |  45 |     | 
   import org.kuali.student.core.proposal.dto.ProposalInfo;  | 
  |  46 |     | 
   import org.kuali.student.core.proposal.ui.client.service.ProposalRpcService;  | 
  |  47 |     | 
   import org.kuali.student.core.proposal.ui.client.service.ProposalRpcServiceAsync;  | 
  |  48 |     | 
   import org.kuali.student.core.workflow.ui.client.widgets.WorkflowEnhancedNavController;  | 
  |  49 |     | 
   import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities;  | 
  |  50 |     | 
   import org.kuali.student.lum.common.client.configuration.LUMViews;  | 
  |  51 |     | 
   import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper;  | 
  |  52 |     | 
   import org.kuali.student.lum.common.client.widgets.AppLocations;  | 
  |  53 |     | 
   import org.kuali.student.lum.lu.LUConstants;  | 
  |  54 |     | 
   import org.kuali.student.lum.program.client.ProgramConstants;  | 
  |  55 |     | 
   import org.kuali.student.lum.program.client.ProgramRegistry;  | 
  |  56 |     | 
   import org.kuali.student.lum.program.client.ProgramSections;  | 
  |  57 |     | 
   import org.kuali.student.lum.program.client.ProgramStatus;  | 
  |  58 |     | 
   import org.kuali.student.lum.program.client.ProgramUtils;  | 
  |  59 |     | 
   import org.kuali.student.lum.program.client.events.AddSpecializationEvent;  | 
  |  60 |     | 
   import org.kuali.student.lum.program.client.events.AfterSaveEvent;  | 
  |  61 |     | 
   import org.kuali.student.lum.program.client.events.ChangeViewEvent;  | 
  |  62 |     | 
   import org.kuali.student.lum.program.client.events.MetadataLoadedEvent;  | 
  |  63 |     | 
   import org.kuali.student.lum.program.client.events.ModelLoadedEvent;  | 
  |  64 |     | 
   import org.kuali.student.lum.program.client.events.SpecializationCreatedEvent;  | 
  |  65 |     | 
   import org.kuali.student.lum.program.client.events.SpecializationSaveEvent;  | 
  |  66 |     | 
   import org.kuali.student.lum.program.client.events.SpecializationUpdateEvent;  | 
  |  67 |     | 
   import org.kuali.student.lum.program.client.events.StateChangeEvent;  | 
  |  68 |     | 
   import org.kuali.student.lum.program.client.events.StoreRequirementIDsEvent;  | 
  |  69 |     | 
   import org.kuali.student.lum.program.client.events.UpdateEvent;  | 
  |  70 |     | 
   import org.kuali.student.lum.program.client.major.MajorController;  | 
  |  71 |     | 
   import org.kuali.student.lum.program.client.properties.ProgramProperties;  | 
  |  72 |     | 
   import org.kuali.student.lum.program.client.requirements.ProgramRequirementsDataModel;  | 
  |  73 |     | 
   import org.kuali.student.lum.program.client.rpc.AbstractCallback;  | 
  |  74 |     | 
   import org.kuali.student.lum.program.client.rpc.MajorDisciplineProposalRpcService;  | 
  |  75 |     | 
   import org.kuali.student.lum.program.client.rpc.MajorDisciplineRpcService;  | 
  |  76 |     | 
   import org.kuali.student.lum.program.client.rpc.MajorDisciplineRpcServiceAsync;  | 
  |  77 |     | 
   import org.kuali.student.lum.program.client.widgets.ProgramSideBar;  | 
  |  78 |     | 
     | 
  |  79 |     | 
   import com.google.gwt.core.client.GWT;  | 
  |  80 |     | 
   import com.google.gwt.event.dom.client.ClickEvent;  | 
  |  81 |     | 
   import com.google.gwt.event.dom.client.ClickHandler;  | 
  |  82 |     | 
   import com.google.gwt.event.shared.HandlerManager;  | 
  |  83 |     | 
   import com.google.gwt.user.client.Window;  | 
  |  84 |     | 
     | 
  |  85 |     | 
     | 
  |  86 |     | 
     | 
  |  87 |     | 
     | 
  |  88 |    0 |    public class MajorProposalController extends MajorController implements WorkflowEnhancedNavController, RequiresAuthorization{ | 
  |  89 |     | 
     | 
  |  90 |    0 |            private final KSButton saveButton = new KSButton(ProgramProperties.get().common_save());  | 
  |  91 |    0 |        private final KSButton cancelButton = new KSButton(ProgramProperties.get().common_cancel(), KSButtonAbstract.ButtonStyle.ANCHOR_LARGE_CENTERED);  | 
  |  92 |    0 |        private final Set<String> existingVariationIds = new TreeSet<String>();  | 
  |  93 |    0 |        protected String proposalPath = "";  | 
  |  94 |     | 
       protected WorkflowUtilities workflowUtil;   | 
  |  95 |    0 |        private final ProposalRpcServiceAsync proposalServiceAsync = GWT.create(ProposalRpcService.class);  | 
  |  96 |     | 
     | 
  |  97 |    0 |            protected final DataModel comparisonModel = new DataModel("Original Program"); | 
  |  98 |    0 |            private String comparisonModelId = "ComparisonModel";  | 
  |  99 |     | 
     | 
  |  100 |    0 |            protected final DataModel reqModel = new DataModel(""); | 
  |  101 |    0 |            private String reqModelId = "reqModel";  | 
  |  102 |     | 
     | 
  |  103 |     | 
       private ProgramRequirementsDataModel reqDataModel;  | 
  |  104 |     | 
       private ProgramRequirementsDataModel reqDataModelComp;  | 
  |  105 |     | 
     | 
  |  106 |     | 
       protected MajorDisciplineRpcServiceAsync majorDisciplineService;  | 
  |  107 |     | 
     | 
  |  108 |     | 
         | 
  |  109 |     | 
     | 
  |  110 |     | 
     | 
  |  111 |     | 
     | 
  |  112 |     | 
     | 
  |  113 |     | 
       public MajorProposalController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { | 
  |  114 |    0 |            super(programModel, viewContext, eventBus);   | 
  |  115 |    0 |            majorDisciplineService = createMajorDisciplineService();  | 
  |  116 |    0 |            programModel.setModelName("Proposal"); | 
  |  117 |    0 |            initializeComparisonModel();  | 
  |  118 |    0 |            configurer = GWT.create(MajorProposalConfigurer.class);  | 
  |  119 |    0 |            proposalPath = configurer.getProposalPath();  | 
  |  120 |    0 |            workflowUtil = new WorkflowUtilities(MajorProposalController.this, proposalPath, "Proposal Actions",  | 
  |  121 |     | 
                                      ProgramSections.WF_APPROVE_DIALOG,"Required Fields", ProgramConstants.PROGRAM_MODEL_ID);  | 
  |  122 |     | 
     | 
  |  123 |    0 |            sideBar.setState(ProgramSideBar.State.EDIT);  | 
  |  124 |    0 |            initHandlers();  | 
  |  125 |     | 
             | 
  |  126 |    0 |            reqDataModel = new ProgramRequirementsDataModel(eventBus);  | 
  |  127 |    0 |            reqDataModelComp = new ProgramRequirementsDataModel(eventBus);  | 
  |  128 |    0 |        }  | 
  |  129 |     | 
           | 
  |  130 |     | 
         | 
  |  131 |     | 
     | 
  |  132 |     | 
     | 
  |  133 |     | 
     | 
  |  134 |     | 
     | 
  |  135 |     | 
     | 
  |  136 |     | 
     | 
  |  137 |     | 
       @Override  | 
  |  138 |     | 
       public void requestModel(Class modelType, ModelRequestCallback callback) { | 
  |  139 |    0 |            if (modelType == ReferenceModel.class) { | 
  |  140 |    0 |                ReferenceModel referenceModel = new ReferenceModel();  | 
  |  141 |     | 
                 | 
  |  142 |     | 
                 | 
  |  143 |     | 
                 | 
  |  144 |     | 
                 | 
  |  145 |    0 |                referenceModel.setReferenceId(ProgramUtils.getProposalId(programModel));  | 
  |  146 |     | 
                | 
  |  147 |     | 
                 | 
  |  148 |     | 
                 | 
  |  149 |    0 |                referenceModel.setReferenceTypeKey(ProgramConstants.PROPOSAL_REFERENCE_TYPE_ID);  | 
  |  150 |     | 
                 | 
  |  151 |     | 
                 | 
  |  152 |     | 
                 | 
  |  153 |     | 
                 | 
  |  154 |    0 |                referenceModel.setReferenceType(ProgramConstants.MAJOR_LU_TYPE_ID);  | 
  |  155 |     | 
                | 
  |  156 |    0 |                Map<String, String> attributes = new HashMap<String, String>();  | 
  |  157 |    0 |                attributes.put("name", getStringProperty("name")); | 
  |  158 |    0 |                referenceModel.setReferenceAttributes(attributes);  | 
  |  159 |    0 |                callback.onModelReady(referenceModel);  | 
  |  160 |    0 |            } else { | 
  |  161 |    0 |                super.requestModel(modelType, callback);  | 
  |  162 |     | 
           }  | 
  |  163 |    0 |        }  | 
  |  164 |     | 
         | 
  |  165 |     | 
         | 
  |  166 |     | 
     | 
  |  167 |     | 
     | 
  |  168 |     | 
     | 
  |  169 |     | 
     | 
  |  170 |     | 
       @Override  | 
  |  171 |     | 
       protected MajorDisciplineRpcServiceAsync createProgramRemoteService() { | 
  |  172 |    0 |            return GWT.create(MajorDisciplineProposalRpcService.class);  | 
  |  173 |     | 
       }  | 
  |  174 |     | 
     | 
  |  175 |     | 
         | 
  |  176 |     | 
     | 
  |  177 |     | 
     | 
  |  178 |     | 
       protected MajorDisciplineRpcServiceAsync createMajorDisciplineService() { | 
  |  179 |    0 |            return GWT.create(MajorDisciplineRpcService.class);  | 
  |  180 |     | 
       }  | 
  |  181 |     | 
     | 
  |  182 |     | 
       @Override  | 
  |  183 |     | 
       protected void configureView() { | 
  |  184 |    0 |            super.configureView();  | 
  |  185 |    0 |            if (!initialized) { | 
  |  186 |    0 |                eventBus.fireEvent(new MetadataLoadedEvent(programModel.getDefinition(), this));  | 
  |  187 |    0 |                List<Enum<?>> excludedViews = new ArrayList<Enum<?>>();  | 
  |  188 |    0 |                excludedViews.add(ProgramSections.PROGRAM_REQUIREMENTS_EDIT);  | 
  |  189 |    0 |                excludedViews.add(ProgramSections.SUPPORTING_DOCUMENTS_EDIT);  | 
  |  190 |    0 |                excludedViews.add(ProgramSections.SUMMARY);  | 
  |  191 |    0 |                addCommonButton(ProgramProperties.get().program_menu_sections(), saveButton, excludedViews);  | 
  |  192 |    0 |                addCommonButton(ProgramProperties.get().program_menu_sections(), cancelButton, excludedViews);  | 
  |  193 |    0 |                initialized = true;  | 
  |  194 |     | 
           }  | 
  |  195 |    0 |        }  | 
  |  196 |     | 
     | 
  |  197 |     | 
         | 
  |  198 |     | 
     | 
  |  199 |     | 
     | 
  |  200 |     | 
     | 
  |  201 |     | 
     | 
  |  202 |     | 
     | 
  |  203 |     | 
     | 
  |  204 |     | 
     | 
  |  205 |     | 
     | 
  |  206 |     | 
       @Override  | 
  |  207 |     | 
       public void setViewContext(ViewContext viewContext) { | 
  |  208 |    0 |            super.setViewContext(viewContext);  | 
  |  209 |    0 |            if(viewContext.getId() != null && !viewContext.getId().isEmpty()){ | 
  |  210 |    0 |                if(viewContext.getIdType() != IdType.COPY_OF_OBJECT_ID && viewContext.getIdType() != IdType.COPY_OF_KS_KEW_OBJECT_ID){ | 
  |  211 |     | 
                     | 
  |  212 |    0 |                    viewContext.setPermissionType(PermissionType.OPEN);  | 
  |  213 |     | 
               } else{ | 
  |  214 |     | 
                     | 
  |  215 |     | 
                     | 
  |  216 |     | 
                     | 
  |  217 |     | 
                     | 
  |  218 |    0 |                    resetModel();  | 
  |  219 |     | 
                     | 
  |  220 |    0 |                    viewContext.setPermissionType(PermissionType.INITIATE);  | 
  |  221 |     | 
               }  | 
  |  222 |     | 
           }  | 
  |  223 |     | 
           else{ | 
  |  224 |    0 |                viewContext.setPermissionType(PermissionType.INITIATE);  | 
  |  225 |     | 
           }  | 
  |  226 |    0 |        }  | 
  |  227 |     | 
     | 
  |  228 |     | 
         | 
  |  229 |     | 
     | 
  |  230 |     | 
     | 
  |  231 |     | 
     | 
  |  232 |     | 
     | 
  |  233 |     | 
     | 
  |  234 |     | 
       public WorkflowUtilities getWfUtilities(){ | 
  |  235 |    0 |            return workflowUtil;  | 
  |  236 |     | 
       }  | 
  |  237 |     | 
         | 
  |  238 |     | 
       private void initHandlers() { | 
  |  239 |    0 |            saveButton.addClickHandler(new ClickHandler() { | 
  |  240 |     | 
     | 
  |  241 |     | 
               @Override  | 
  |  242 |     | 
               public void onClick(ClickEvent event) { | 
  |  243 |    0 |                    doSave();  | 
  |  244 |    0 |                }  | 
  |  245 |     | 
           });  | 
  |  246 |    0 |            cancelButton.addClickHandler(new ClickHandler() { | 
  |  247 |     | 
     | 
  |  248 |     | 
               @Override  | 
  |  249 |     | 
               public void onClick(ClickEvent event) { | 
  |  250 |    0 |                    doCancel();  | 
  |  251 |    0 |                }  | 
  |  252 |     | 
           });  | 
  |  253 |    0 |            eventBus.addHandler(UpdateEvent.TYPE, new UpdateEvent.Handler() { | 
  |  254 |     | 
               @Override  | 
  |  255 |     | 
               public void onEvent(UpdateEvent event) { | 
  |  256 |    0 |                    Enum<?> view = event.getCurrentView();  | 
  |  257 |    0 |                    if (view != null) { | 
  |  258 |    0 |                        setCurrentViewEnum(view);  | 
  |  259 |     | 
                   }  | 
  |  260 |    0 |                    doSave(event.getOkCallback());  | 
  |  261 |     | 
     | 
  |  262 |    0 |                }  | 
  |  263 |     | 
           });  | 
  |  264 |    0 |            eventBus.addHandler(StateChangeEvent.TYPE, new StateChangeEvent.Handler() { | 
  |  265 |     | 
               @Override  | 
  |  266 |     | 
               public void onEvent(final StateChangeEvent event) { | 
  |  267 |     | 
                         | 
  |  268 |     | 
                         | 
  |  269 |     | 
                         | 
  |  270 |    0 |                        programRemoteService.validate(programModel.getRoot(), new KSAsyncCallback<List<ValidationResultInfo>>(){ | 
  |  271 |     | 
                                           @Override  | 
  |  272 |     | 
                                           public void onSuccess(final List<ValidationResultInfo> currentStateResults) { | 
  |  273 |    0 |                                    programModel.validateNextState(new Callback<List<ValidationResultInfo>>() { | 
  |  274 |     | 
                                       @Override  | 
  |  275 |     | 
                                       public void exec(List<ValidationResultInfo> nextStateResults) { | 
  |  276 |     | 
                                                 | 
  |  277 |    0 |                                                Application.getApplicationContext().clearValidationWarnings();  | 
  |  278 |    0 |                                                Application.getApplicationContext().addValidationWarnings(currentStateResults);  | 
  |  279 |    0 |                                                isValid(Application.getApplicationContext().getValidationWarnings(), false);  | 
  |  280 |     | 
                                             | 
  |  281 |    0 |                                                boolean isSectionValid = isValid(nextStateResults, true)   | 
  |  282 |     | 
                                                   && Application.getApplicationContext().getValidationWarnings().isEmpty();  | 
  |  283 |    0 |                                            if (isSectionValid) { | 
  |  284 |    0 |                                                Callback<Boolean> callback = new Callback<Boolean>() { | 
  |  285 |     | 
                                                   @Override  | 
  |  286 |     | 
                                                   public void exec(Boolean result) { | 
  |  287 |    0 |                                                        if (result) { | 
  |  288 |    0 |                                                            reloadMetadata = true;  | 
  |  289 |    0 |                                                            loadMetadata(new Callback<Boolean>() { | 
  |  290 |     | 
                                                               @Override  | 
  |  291 |     | 
                                                               public void exec(Boolean result) { | 
  |  292 |    0 |                                                                    if (result) { | 
  |  293 |    0 |                                                                        ProgramUtils.syncMetadata(configurer, programModel.getDefinition());  | 
  |  294 |    0 |                                                                        HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), context);  | 
  |  295 |     | 
                                                                   }  | 
  |  296 |    0 |                                                                }  | 
  |  297 |     | 
                                                           });  | 
  |  298 |     | 
                                                       }  | 
  |  299 |    0 |                                                    }  | 
  |  300 |     | 
                                               };  | 
  |  301 |    0 |                                                updateState(event.getProgramStatus().getValue(), callback);  | 
  |  302 |    0 |                                            } else { | 
  |  303 |    0 |                                                KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); | 
  |  304 |     | 
                                           }  | 
  |  305 |    0 |                                        }  | 
  |  306 |     | 
                                   });                                                  | 
  |  307 |    0 |                                            }                              | 
  |  308 |     | 
                       });                  | 
  |  309 |    0 |                }  | 
  |  310 |     | 
           });  | 
  |  311 |     | 
     | 
  |  312 |    0 |            eventBus.addHandler(SpecializationSaveEvent.TYPE, new SpecializationSaveEvent.Handler() { | 
  |  313 |     | 
               @Override  | 
  |  314 |     | 
               public void onEvent(SpecializationSaveEvent event) { | 
  |  315 |     | 
     | 
  |  316 |    0 |                    Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);  | 
  |  317 |     | 
     | 
  |  318 |    0 |                    existingVariationIds.clear();  | 
  |  319 |     | 
     | 
  |  320 |    0 |                    for (Data.Property prop : currentVariations) { | 
  |  321 |    0 |                        String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);  | 
  |  322 |    0 |                        existingVariationIds.add(existingId);  | 
  |  323 |    0 |                    }  | 
  |  324 |    0 |                    String updatedId = event.getData().get(ProgramConstants.ID);  | 
  |  325 |    0 |                    Integer updatedKey = null;  | 
  |  326 |     | 
     | 
  |  327 |     | 
                     | 
  |  328 |     | 
                     | 
  |  329 |     | 
                     | 
  |  330 |     | 
                     | 
  |  331 |    0 |                    if (updatedId != null) {  | 
  |  332 |    0 |                        for (Data.Property prop : currentVariations) { | 
  |  333 |    0 |                            String id = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);  | 
  |  334 |    0 |                            if (updatedId.equals(id)) { | 
  |  335 |    0 |                                updatedKey = prop.getKey();  | 
  |  336 |    0 |                                Data currentMetaInfo = ((Data) prop.getValue()).get("metaInfo"); | 
  |  337 |    0 |                                String latestVersionInd = currentMetaInfo.get("versionInd"); | 
  |  338 |    0 |                                Data newMetaInfo = event.getData().get("metaInfo"); | 
  |  339 |    0 |                                if (newMetaInfo == null) { | 
  |  340 |    0 |                                    newMetaInfo = new Data();  | 
  |  341 |    0 |                                    event.getData().set("metaInfo", newMetaInfo); | 
  |  342 |     | 
                               }  | 
  |  343 |    0 |                                newMetaInfo.set("versionInd", latestVersionInd); | 
  |  344 |    0 |                                break;  | 
  |  345 |     | 
                           }  | 
  |  346 |    0 |                        }  | 
  |  347 |     | 
     | 
  |  348 |    0 |                        currentVariations.set(updatedKey, event.getData());  | 
  |  349 |     | 
                   } else { | 
  |  350 |    0 |                        currentVariations.add(event.getData());  | 
  |  351 |     | 
     | 
  |  352 |     | 
                   }  | 
  |  353 |    0 |                    doSave();  | 
  |  354 |    0 |                }  | 
  |  355 |     | 
           });  | 
  |  356 |    0 |            eventBus.addHandler(AddSpecializationEvent.TYPE, new AddSpecializationEvent.Handler() { | 
  |  357 |     | 
               @Override  | 
  |  358 |     | 
               public void onEvent(AddSpecializationEvent event) { | 
  |  359 |    0 |                    String id = getStringProperty(ProgramConstants.ID);  | 
  |  360 |    0 |                    ProgramRegistry.setRow((getDataProperty(ProgramConstants.VARIATIONS)).size());  | 
  |  361 |    0 |                    Data variationData = ProgramUtils.createNewSpecializationBasedOnMajor(programModel);  | 
  |  362 |    0 |                    ProgramRegistry.setData(variationData);  | 
  |  363 |    0 |                    ViewContext viewContext = new ViewContext();  | 
  |  364 |    0 |                    viewContext.setId(id);  | 
  |  365 |    0 |                    viewContext.setIdType(IdAttributes.IdType.OBJECT_ID);  | 
  |  366 |    0 |                    if(programModel.get("proposal/id") != null){ | 
  |  367 |     | 
                         | 
  |  368 |    0 |                        variationData.set("isProposal", true); | 
  |  369 |     | 
                   }  | 
  |  370 |    0 |                    HistoryManager.navigate(AppLocations.Locations.EDIT_VARIATION.getLocation(), viewContext);  | 
  |  371 |     | 
     | 
  |  372 |    0 |                }  | 
  |  373 |     | 
           });  | 
  |  374 |     | 
     | 
  |  375 |    0 |            eventBus.addHandler(StoreRequirementIDsEvent.TYPE, new StoreRequirementIDsEvent.Handler() { | 
  |  376 |     | 
               @Override  | 
  |  377 |     | 
               public void onEvent(StoreRequirementIDsEvent event) { | 
  |  378 |    0 |                    List<String> ids = event.getProgramRequirementIds();  | 
  |  379 |     | 
     | 
  |  380 |    0 |                    programModel.set(QueryPath.parse(ProgramConstants.PROGRAM_REQUIREMENTS), new Data());  | 
  |  381 |    0 |                    Data programRequirements = programModel.get(ProgramConstants.PROGRAM_REQUIREMENTS);  | 
  |  382 |     | 
     | 
  |  383 |    0 |                    if (programRequirements == null) { | 
  |  384 |    0 |                        Window.alert("Cannot find program requirements in data model."); | 
  |  385 |    0 |                        GWT.log("Cannot find program requirements in data model", null); | 
  |  386 |    0 |                        return;  | 
  |  387 |     | 
                   }  | 
  |  388 |     | 
     | 
  |  389 |    0 |                    for (String id : ids) { | 
  |  390 |    0 |                        programRequirements.add(id);  | 
  |  391 |     | 
                   }  | 
  |  392 |     | 
                     | 
  |  393 |    0 |                        Callback<Boolean> reqCallback = new Callback<Boolean>() { | 
  |  394 |     | 
                               @Override  | 
  |  395 |     | 
                               public void exec(Boolean result) { | 
  |  396 |    0 |                                        majorDisciplineService.getData(getViewContext().getId(), new AbstractCallback<Data>(ProgramProperties.get().common_retrievingData()) { | 
  |  397 |     | 
                               @Override  | 
  |  398 |     | 
                               public void onSuccess(Data result) { | 
  |  399 |    0 |                                    super.onSuccess(result);  | 
  |  400 |    0 |                                    reqModel.setRoot(result);  | 
  |  401 |    0 |                                    reqDataModel.retrieveProgramRequirements(MajorProposalController.this, reqModelId, new Callback<Boolean>() { | 
  |  402 |     | 
                                       @Override  | 
  |  403 |    0 |                                        public void exec(Boolean result) {} | 
  |  404 |     | 
                                   });                      | 
  |  405 |    0 |                                }  | 
  |  406 |     | 
                                 | 
  |  407 |     | 
                               @Override  | 
  |  408 |     | 
                               public void onFailure(Throwable caught) { | 
  |  409 |    0 |                                    super.onFailure(caught);  | 
  |  410 |    0 |                                }  | 
  |  411 |     | 
                           });  | 
  |  412 |    0 |                                }  | 
  |  413 |     | 
                       };  | 
  |  414 |     | 
     | 
  |  415 |    0 |                    doSave(reqCallback);  | 
  |  416 |    0 |                }  | 
  |  417 |     | 
           });  | 
  |  418 |    0 |            eventBus.addHandler(ChangeViewEvent.TYPE, new ChangeViewEvent.Handler() { | 
  |  419 |     | 
               @Override  | 
  |  420 |     | 
               public void onEvent(ChangeViewEvent event) { | 
  |  421 |    0 |                    showView(event.getViewToken());  | 
  |  422 |    0 |                }  | 
  |  423 |     | 
           });  | 
  |  424 |    0 |            eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler(){ | 
  |  425 |     | 
                           @Override  | 
  |  426 |     | 
                           public void onEvent(ModelLoadedEvent event) { | 
  |  427 |    0 |                                    if (workflowUtil != null){ | 
  |  428 |    0 |                                            workflowUtil.requestAndSetupModel(NO_OP_CALLBACK);  | 
  |  429 |     | 
                                             | 
  |  430 |     | 
                                   }  | 
  |  431 |    0 |                            }                  | 
  |  432 |     | 
           });  | 
  |  433 |     | 
             | 
  |  434 |    0 |            addApplicationEventHandler(SaveActionEvent.TYPE, new SaveActionHandler(){ | 
  |  435 |     | 
                           @Override  | 
  |  436 |     | 
                           public void doSave(final SaveActionEvent saveAction) { | 
  |  437 |    0 |                                    MajorProposalController.this.doSave(new Callback<Boolean>(){ | 
  |  438 |     | 
                                           @Override  | 
  |  439 |     | 
                                           public void exec(Boolean result) { | 
  |  440 |    0 |                                                    saveAction.doActionComplete();  | 
  |  441 |    0 |                                            }  | 
  |  442 |     | 
                                   });  | 
  |  443 |    0 |                            }  | 
  |  444 |     | 
           });  | 
  |  445 |    0 |       }  | 
  |  446 |     | 
     | 
  |  447 |     | 
         | 
  |  448 |     | 
     | 
  |  449 |     | 
     | 
  |  450 |     | 
       @Override  | 
  |  451 |     | 
           public void fireApplicationEvent(ApplicationEvent event) { | 
  |  452 |     | 
                 | 
  |  453 |    0 |                    if(event instanceof SaveActionEvent){ | 
  |  454 |    0 |                            eventBus.fireEvent(event);  | 
  |  455 |     | 
                   }  | 
  |  456 |    0 |                    super.fireApplicationEvent(event);  | 
  |  457 |    0 |            }  | 
  |  458 |     | 
     | 
  |  459 |     | 
         | 
  |  460 |     | 
         | 
  |  461 |     | 
     | 
  |  462 |     | 
     | 
  |  463 |     | 
       private void initializeComparisonModel() { | 
  |  464 |    0 |            super.registerModel(comparisonModelId, new ModelProvider<DataModel>() { | 
  |  465 |     | 
               @Override  | 
  |  466 |     | 
               public void requestModel(final ModelRequestCallback<DataModel> callback) { | 
  |  467 |    0 |                        if(comparisonModel.getRoot() != null && comparisonModel.getRoot().size() != 0){ | 
  |  468 |    0 |                                callback.onModelReady(comparisonModel);                              | 
  |  469 |     | 
                       }  | 
  |  470 |     | 
                       else{ | 
  |  471 |    0 |                                callback.onModelReady(null);  | 
  |  472 |     | 
                       }                  | 
  |  473 |    0 |                 }  | 
  |  474 |     | 
           });  | 
  |  475 |     | 
                     | 
  |  476 |    0 |            super.registerModel(reqModelId, new ModelProvider<DataModel>() { | 
  |  477 |     | 
               @Override  | 
  |  478 |     | 
               public void requestModel(final ModelRequestCallback<DataModel> callback) { | 
  |  479 |    0 |                        if(reqModel.getRoot() != null && reqModel.getRoot().size() != 0){ | 
  |  480 |    0 |                                callback.onModelReady(reqModel);                              | 
  |  481 |     | 
                       }  | 
  |  482 |     | 
                       else{ | 
  |  483 |    0 |                                callback.onModelReady(null);  | 
  |  484 |     | 
                       }                  | 
  |  485 |    0 |                 }  | 
  |  486 |     | 
           });  | 
  |  487 |    0 |        }  | 
  |  488 |     | 
     | 
  |  489 |     | 
       @Override  | 
  |  490 |     | 
       protected void loadMetadata(final Callback<Boolean> onReadyCallback) { | 
  |  491 |    0 |            Map<String, String> idAttributes = new HashMap<String, String>();  | 
  |  492 |    0 |            ViewContext viewContext = getViewContext();  | 
  |  493 |    0 |            IdType idType = viewContext.getIdType();  | 
  |  494 |    0 |            String viewContextId = null;  | 
  |  495 |    0 |            if (idType != null) { | 
  |  496 |    0 |                idAttributes.put(IdAttributes.ID_TYPE, idType.toString());  | 
  |  497 |    0 |                viewContextId = viewContext.getId();  | 
  |  498 |    0 |                if (idType == IdType.COPY_OF_OBJECT_ID) { | 
  |  499 |    0 |                    viewContextId = null;  | 
  |  500 |     | 
               }  | 
  |  501 |     | 
           }  | 
  |  502 |    0 |            idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_MAJOR_DISCIPLINE_MODIFY);         | 
  |  503 |    0 |            if (programModel.getRoot() != null) { | 
  |  504 |    0 |                ProgramStatus programStatus = ProgramStatus.of(programModel);  | 
  |  505 |    0 |                idAttributes.put(DtoConstants.DTO_STATE, programStatus.getValue());  | 
  |  506 |    0 |                String workflowNode = programModel.get("proposal/workflowNode"); | 
  |  507 |    0 |                if(workflowNode!=null){ | 
  |  508 |    0 |                        idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, workflowNode);  | 
  |  509 |     | 
               }  | 
  |  510 |     | 
           }  | 
  |  511 |    0 |            programRemoteService.getMetadata(viewContextId, idAttributes, new AbstractCallback<Metadata>() { | 
  |  512 |     | 
     | 
  |  513 |     | 
               @Override  | 
  |  514 |     | 
               public void onSuccess(Metadata result) { | 
  |  515 |    0 |                    super.onSuccess(result);  | 
  |  516 |    0 |                    DataModelDefinition def = new DataModelDefinition(result);  | 
  |  517 |    0 |                    programModel.setDefinition(def);  | 
  |  518 |    0 |                    comparisonModel.setDefinition(def);  | 
  |  519 |    0 |                    lastLoadedStatus = ProgramStatus.of(programModel);  | 
  |  520 |    0 |                    afterMetadataLoaded(onReadyCallback);  | 
  |  521 |    0 |                    if (result.isCanEdit()){ | 
  |  522 |    0 |                        sideBar.setState(ProgramSideBar.State.EDIT);  | 
  |  523 |     | 
                   }else { | 
  |  524 |    0 |                            sideBar.setState(ProgramSideBar.State.VIEW);  | 
  |  525 |     | 
                   }  | 
  |  526 |    0 |                }  | 
  |  527 |     | 
     | 
  |  528 |     | 
               @Override  | 
  |  529 |     | 
               public void onFailure(Throwable caught) { | 
  |  530 |    0 |                    super.onFailure(caught);  | 
  |  531 |    0 |                    onReadyCallback.exec(false);  | 
  |  532 |    0 |                }  | 
  |  533 |     | 
           });  | 
  |  534 |    0 |        }  | 
  |  535 |     | 
     | 
  |  536 |     | 
       @Override  | 
  |  537 |     | 
       protected void loadModel(final ModelRequestCallback<DataModel> callback) {             | 
  |  538 |    0 |                ViewContext viewContext = getViewContext();  | 
  |  539 |    0 |            if (viewContext.getIdType() == IdType.COPY_OF_OBJECT_ID)   | 
  |  540 |     | 
           {         | 
  |  541 |    0 |                    ModelRequestCallback<DataModel> comparisonModelCallback = new ModelRequestCallback<DataModel>() { | 
  |  542 |     | 
                               @Override  | 
  |  543 |     | 
                               public void onModelReady(DataModel model) { | 
  |  544 |    0 |                                        majorDisciplineService.getData((String)model.get("versionInfo/versionedFromId"), new AbstractCallback<Data>(ProgramProperties.get().common_retrievingData()) { | 
  |  545 |     | 
                           @Override  | 
  |  546 |     | 
                           public void onSuccess(Data result) { | 
  |  547 |    0 |                                super.onSuccess(result);  | 
  |  548 |    0 |                                comparisonModel.setRoot(result);  | 
  |  549 |    0 |                                reqDataModel.retrieveProgramRequirements(MajorProposalController.this, ProgramConstants.PROGRAM_MODEL_ID, new Callback<Boolean>() { | 
  |  550 |     | 
                                   @Override  | 
  |  551 |     | 
                                   public void exec(Boolean result) { | 
  |  552 |    0 |                                        if (result) { | 
  |  553 |    0 |                                                reqDataModelComp.retrieveProgramRequirements(MajorProposalController.this, comparisonModelId, new Callback<Boolean>() { | 
  |  554 |     | 
                                               @Override  | 
  |  555 |     | 
                                               public void exec(Boolean result) { | 
  |  556 |    0 |                                                    if (result) { | 
  |  557 |    0 |                                                        callback.onModelReady(comparisonModel);  | 
  |  558 |     | 
                                                   }  | 
  |  559 |    0 |                                                }  | 
  |  560 |     | 
                                           });  | 
  |  561 |     | 
                                       }  | 
  |  562 |    0 |                                    }  | 
  |  563 |     | 
                               });                      | 
  |  564 |    0 |                            }  | 
  |  565 |     | 
                             | 
  |  566 |     | 
                           @Override  | 
  |  567 |     | 
                           public void onFailure(Throwable caught) { | 
  |  568 |    0 |                                super.onFailure(caught);  | 
  |  569 |    0 |                                callback.onRequestFail(caught);  | 
  |  570 |    0 |                            }  | 
  |  571 |     | 
                       });  | 
  |  572 |    0 |                            }  | 
  |  573 |     | 
     | 
  |  574 |     | 
                               @Override  | 
  |  575 |     | 
                               public void onRequestFail(Throwable cause) { | 
  |  576 |    0 |                        GWT.log("Unable to retrieve comparison model", cause); | 
  |  577 |    0 |                                }  | 
  |  578 |     | 
                   };          | 
  |  579 |     | 
                     | 
  |  580 |    0 |                               createNewVersionAndLoadModel(comparisonModelCallback, viewContext);                             | 
  |  581 |    0 |            }          | 
  |  582 |     | 
           else  | 
  |  583 |     | 
           { | 
  |  584 |    0 |                    ModelRequestCallback<DataModel> comparisonModelCallback = new ModelRequestCallback<DataModel>() { | 
  |  585 |     | 
                               @Override  | 
  |  586 |     | 
                               public void onModelReady(DataModel model) { | 
  |  587 |    0 |                                        majorDisciplineService.getData((String)model.get("versionInfo/versionedFromId"), new AbstractCallback<Data>(ProgramProperties.get().common_retrievingData()) { | 
  |  588 |     | 
                           @Override  | 
  |  589 |     | 
                           public void onSuccess(Data result) { | 
  |  590 |    0 |                                super.onSuccess(result);  | 
  |  591 |    0 |                                comparisonModel.setRoot(result);  | 
  |  592 |    0 |                                reqDataModel.retrieveProgramRequirements(MajorProposalController.this, ProgramConstants.PROGRAM_MODEL_ID, new Callback<Boolean>() { | 
  |  593 |     | 
                                   @Override  | 
  |  594 |     | 
                                   public void exec(Boolean result) { | 
  |  595 |    0 |                                        if (result) { | 
  |  596 |    0 |                                                reqDataModelComp.retrieveProgramRequirements(MajorProposalController.this, comparisonModelId, new Callback<Boolean>() { | 
  |  597 |     | 
                                               @Override  | 
  |  598 |     | 
                                               public void exec(Boolean result) { | 
  |  599 |    0 |                                                    if (result) { | 
  |  600 |    0 |                                                        callback.onModelReady(comparisonModel);  | 
  |  601 |     | 
                                                   }  | 
  |  602 |    0 |                                                }  | 
  |  603 |     | 
                                           });  | 
  |  604 |     | 
                                       }  | 
  |  605 |    0 |                                    }  | 
  |  606 |     | 
                               });                      | 
  |  607 |    0 |                            }  | 
  |  608 |     | 
                             | 
  |  609 |     | 
                           @Override  | 
  |  610 |     | 
                           public void onFailure(Throwable caught) { | 
  |  611 |    0 |                                super.onFailure(caught);  | 
  |  612 |    0 |                                callback.onRequestFail(caught);  | 
  |  613 |    0 |                            }  | 
  |  614 |     | 
                       });  | 
  |  615 |    0 |                            }  | 
  |  616 |     | 
     | 
  |  617 |     | 
                               @Override  | 
  |  618 |     | 
                               public void onRequestFail(Throwable cause) { | 
  |  619 |    0 |                        GWT.log("Unable to retrieve comparison model", cause); | 
  |  620 |    0 |                                }  | 
  |  621 |     | 
                   };          | 
  |  622 |     | 
     | 
  |  623 |    0 |                    if (viewContext.getIdType() == IdType.DOCUMENT_ID)  | 
  |  624 |    0 |                            loadProgramModelFromWorkflowId(comparisonModelCallback);   | 
  |  625 |     | 
                   else   | 
  |  626 |    0 |                            super.loadModel(comparisonModelCallback);  | 
  |  627 |     | 
           }          | 
  |  628 |    0 |        }  | 
  |  629 |     | 
     | 
  |  630 |     | 
       protected void createNewVersionAndLoadModel(final ModelRequestCallback<DataModel> callback, final ViewContext viewContext) { | 
  |  631 |    0 |            Data data = new Data();                  | 
  |  632 |    0 |            Data versionData = new Data();  | 
  |  633 |    0 |            versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId()); | 
  |  634 |    0 |            versionData.set(new Data.StringKey("versionComment"), "Major Disicpline Version"); | 
  |  635 |    0 |            data.set(new Data.StringKey("versionInfo"), versionData); | 
  |  636 |     | 
     | 
  |  637 |    0 |            programRemoteService.saveData(data, new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_retrievingData()) { | 
  |  638 |     | 
               @Override  | 
  |  639 |     | 
               public void onSuccess(DataSaveResult result) { | 
  |  640 |    0 |                    super.onSuccess(result);  | 
  |  641 |    0 |                    refreshModelAndView(result);  | 
  |  642 |     | 
                     | 
  |  643 |    0 |                    viewContext.setId(ProgramUtils.getProposalId(programModel));  | 
  |  644 |    0 |                    viewContext.setIdType(IdType.KS_KEW_OBJECT_ID);  | 
  |  645 |    0 |                    callback.onModelReady(programModel);  | 
  |  646 |    0 |                    eventBus.fireEvent(new ModelLoadedEvent(programModel));  | 
  |  647 |    0 |                }  | 
  |  648 |     | 
     | 
  |  649 |     | 
               @Override  | 
  |  650 |     | 
               public void onFailure(Throwable caught) { | 
  |  651 |    0 |                    super.onFailure(caught);  | 
  |  652 |    0 |                    callback.onRequestFail(caught);  | 
  |  653 |    0 |                }  | 
  |  654 |     | 
           });  | 
  |  655 |     | 
     | 
  |  656 |    0 |        }  | 
  |  657 |     | 
     | 
  |  658 |     | 
       protected void loadProgramModelFromWorkflowId(final ModelRequestCallback<DataModel> callback){ | 
  |  659 |    0 |            workflowUtil.getDataIdFromWorkflowId(getViewContext().getId(), new KSAsyncCallback<String>(){ | 
  |  660 |     | 
                           @Override  | 
  |  661 |     | 
                           public void handleFailure(Throwable caught) { | 
  |  662 |    0 |                    Window.alert("Error loading Proposal from Workflow Document: "+caught.getMessage()); | 
  |  663 |    0 |                            }  | 
  |  664 |     | 
     | 
  |  665 |     | 
                           @Override  | 
  |  666 |     | 
                           public void onSuccess(String proposalId) { | 
  |  667 |     | 
                                     | 
  |  668 |    0 |                            ViewContext viewContext = new ViewContext();  | 
  |  669 |    0 |                    viewContext.setId(proposalId);  | 
  |  670 |    0 |                    getViewContext().setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_MAJOR_DISCIPLINE_MODIFY);  | 
  |  671 |    0 |                    viewContext.setIdType(IdType.KS_KEW_OBJECT_ID);  | 
  |  672 |    0 |                    Application.navigate(AppLocations.Locations.PROGRAM_PROPOSAL.getLocation(), viewContext);  | 
  |  673 |    0 |                            }  | 
  |  674 |     | 
           });              | 
  |  675 |    0 |        }  | 
  |  676 |     | 
         | 
  |  677 |     | 
       private void doSave(final Callback<Boolean> okCallback) { | 
  |  678 |    0 |            requestModel(new ModelRequestCallback<DataModel>() { | 
  |  679 |     | 
               @Override  | 
  |  680 |     | 
               public void onModelReady(DataModel model) { | 
  |  681 |    0 |                    MajorProposalController.this.updateModelFromCurrentView();  | 
  |  682 |    0 |                    model.validate(new Callback<List<ValidationResultInfo>>() { | 
  |  683 |     | 
                       @Override  | 
  |  684 |     | 
                       public void exec(List<ValidationResultInfo> result) { | 
  |  685 |    0 |                            boolean isSectionValid = isValid(result, true);  | 
  |  686 |    0 |                            if (isSectionValid) { | 
  |  687 |    0 |                                saveData(okCallback);  | 
  |  688 |     | 
                           } else { | 
  |  689 |    0 |                                okCallback.exec(false);  | 
  |  690 |    0 |                                KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); | 
  |  691 |     | 
                           }  | 
  |  692 |    0 |                        }  | 
  |  693 |     | 
                   });  | 
  |  694 |     | 
     | 
  |  695 |    0 |                }  | 
  |  696 |     | 
     | 
  |  697 |     | 
               @Override  | 
  |  698 |     | 
               public void onRequestFail(Throwable cause) { | 
  |  699 |    0 |                    GWT.log("Unable to retrieve model for validation and save", cause); | 
  |  700 |    0 |                }  | 
  |  701 |     | 
           });  | 
  |  702 |    0 |        }  | 
  |  703 |     | 
     | 
  |  704 |     | 
       private void doCancel() { | 
  |  705 |    0 |            showView(ProgramSections.SUMMARY);  | 
  |  706 |    0 |        }  | 
  |  707 |     | 
     | 
  |  708 |     | 
       @Override  | 
  |  709 |     | 
       protected void doSave() { | 
  |  710 |    0 |            doSave(NO_OP_CALLBACK);  | 
  |  711 |    0 |        }  | 
  |  712 |     | 
     | 
  |  713 |     | 
       private void saveData(final Callback<Boolean> okCallback) { | 
  |  714 |    0 |            programRemoteService.saveData(programModel.getRoot(), new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_savingData()) { | 
  |  715 |     | 
               @Override  | 
  |  716 |     | 
               public void onSuccess(DataSaveResult result) { | 
  |  717 |    0 |                    super.onSuccess(result);  | 
  |  718 |     | 
     | 
  |  719 |     | 
                     | 
  |  720 |    0 |                    clearAllWarnings();  | 
  |  721 |    0 |                    Application.getApplicationContext().clearValidationWarnings();  | 
  |  722 |     | 
                     | 
  |  723 |    0 |                    List<ValidationResultInfo> validationResults = result.getValidationResults();  | 
  |  724 |    0 |                    Application.getApplicationContext().addValidationWarnings(validationResults);  | 
  |  725 |    0 |                    if (ValidatorClientUtils.hasErrors(validationResults)) { | 
  |  726 |    0 |                        ProgramUtils.retrofitValidationResults(validationResults);  | 
  |  727 |    0 |                        isValid(validationResults, false, true);  | 
  |  728 |    0 |                        ProgramUtils.handleValidationErrorsForSpecializations(validationResults, programModel);  | 
  |  729 |     | 
                         | 
  |  730 |     | 
                         | 
  |  731 |    0 |                        Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);  | 
  |  732 |     | 
     | 
  |  733 |    0 |                        existingVariationIds.clear();  | 
  |  734 |     | 
     | 
  |  735 |    0 |                        for (Iterator<Property> iter = currentVariations.iterator();iter.hasNext();) { | 
  |  736 |    0 |                                Property prop = iter.next();  | 
  |  737 |    0 |                            String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);  | 
  |  738 |    0 |                            if(existingId==null){ | 
  |  739 |    0 |                                    iter.remove();  | 
  |  740 |     | 
                           }else{ | 
  |  741 |    0 |                                    existingVariationIds.add(existingId);  | 
  |  742 |     | 
                           }  | 
  |  743 |    0 |                        }  | 
  |  744 |     | 
                         | 
  |  745 |    0 |                        okCallback.exec(false);  | 
  |  746 |    0 |                    } else { | 
  |  747 |    0 |                            refreshModelAndView(result);  | 
  |  748 |    0 |                        if(workflowUtil != null){ | 
  |  749 |    0 |                            workflowUtil.refresh();  | 
  |  750 |     | 
                       }                          | 
  |  751 |    0 |                        resetFieldInteractionFlag();  | 
  |  752 |    0 |                        configurer.applyPermissions();  | 
  |  753 |    0 |                        handleSpecializations();  | 
  |  754 |    0 |                        throwAfterSaveEvent();  | 
  |  755 |    0 |                        HistoryManager.logHistoryChange();  | 
  |  756 |    0 |                        ViewContext viewContext = getViewContext();  | 
  |  757 |    0 |                        viewContext.setId(getStringProperty(ProgramConstants.ID));  | 
  |  758 |    0 |                        viewContext.setIdType(IdType.OBJECT_ID);  | 
  |  759 |     | 
     | 
  |  760 |    0 |                                        if (ValidatorClientUtils.hasWarnings(validationResults)){ | 
  |  761 |     | 
                                                 | 
  |  762 |    0 |                                                isValid(result.getValidationResults(), false, true);                                              | 
  |  763 |    0 |                                                KSNotifier.show("Saved with Warnings"); | 
  |  764 |     | 
                                       } else { | 
  |  765 |    0 |                            KSNotifier.show(ProgramProperties.get().common_successfulSave());  | 
  |  766 |     | 
                                       }                                    | 
  |  767 |     | 
                         | 
  |  768 |     | 
                         | 
  |  769 |    0 |                        ViewContext docContext = new ViewContext();  | 
  |  770 |    0 |                        docContext.setId(getStringProperty(ProgramConstants.ID));  | 
  |  771 |    0 |                        docContext.setIdType(IdType.OBJECT_ID);  | 
  |  772 |    0 |                        docContext.setAttribute(ProgramConstants.TYPE, ProgramConstants.MAJOR_LU_TYPE_ID + '/' + ProgramSections.PROGRAM_DETAILS_VIEW);  | 
  |  773 |    0 |                        RecentlyViewedHelper.addDocument(getProgramName(),  | 
  |  774 |     | 
                       HistoryManager.appendContext(AppLocations.Locations.VIEW_PROGRAM.getLocation(), docContext));  | 
  |  775 |    0 |                            okCallback.exec(true);  | 
  |  776 |    0 |                            processCurrentView();                              | 
  |  777 |     | 
                   }  | 
  |  778 |    0 |                }  | 
  |  779 |     | 
           });   | 
  |  780 |    0 |        }  | 
  |  781 |     | 
     | 
  |  782 |     | 
       private void processCurrentView() { | 
  |  783 |    0 |            Enum<?> currentView = getCurrentViewEnum();  | 
  |  784 |    0 |            if (currentView.name().equals(ProgramSections.VIEW_ALL.name())) { | 
  |  785 |    0 |                HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), getViewContext());  | 
  |  786 |     | 
           } else { | 
  |  787 |    0 |                showView(currentView);  | 
  |  788 |     | 
           }  | 
  |  789 |    0 |        }  | 
  |  790 |     | 
     | 
  |  791 |     | 
         | 
  |  792 |     | 
     | 
  |  793 |     | 
     | 
  |  794 |     | 
       private void handleSpecializations() { | 
  |  795 |    0 |            String newVariationId = null;  | 
  |  796 |    0 |            Data variations = programModel.get(ProgramConstants.VARIATIONS);  | 
  |  797 |    0 |            for (Data.Property prop : variations) { | 
  |  798 |    0 |                String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);  | 
  |  799 |    0 |                if (!existingVariationIds.contains(varId)) { | 
  |  800 |    0 |                    newVariationId = varId;  | 
  |  801 |    0 |                    existingVariationIds.add(newVariationId);  | 
  |  802 |    0 |                    break;  | 
  |  803 |     | 
               }  | 
  |  804 |    0 |            }  | 
  |  805 |    0 |            if (newVariationId != null) { | 
  |  806 |    0 |                eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId));  | 
  |  807 |     | 
           } else { | 
  |  808 |    0 |                eventBus.fireEvent(new SpecializationUpdateEvent(variations));  | 
  |  809 |     | 
           }  | 
  |  810 |    0 |        }  | 
  |  811 |     | 
     | 
  |  812 |     | 
       private void throwAfterSaveEvent() { | 
  |  813 |    0 |            eventBus.fireEvent(new AfterSaveEvent(programModel, this));  | 
  |  814 |    0 |        }  | 
  |  815 |     | 
     | 
  |  816 |     | 
       @Override  | 
  |  817 |     | 
       public void onModelLoadedEvent() { | 
  |  818 |    0 |            Enum<?> changeSection = ProgramRegistry.getSection();  | 
  |  819 |    0 |            if (changeSection != null) { | 
  |  820 |    0 |                showView(changeSection);  | 
  |  821 |    0 |                ProgramRegistry.setSection(null);  | 
  |  822 |     | 
           } else { | 
  |  823 |    0 |                String id = getStringProperty(ProgramConstants.ID);  | 
  |  824 |    0 |                if (id == null) { | 
  |  825 |    0 |                    showView(ProgramSections.PROGRAM_DETAILS_EDIT);  | 
  |  826 |     | 
               } else { | 
  |  827 |    0 |                    showView(ProgramSections.PROGRAM_PROPOSAL_EDIT);  | 
  |  828 |     | 
               }  | 
  |  829 |     | 
           }  | 
  |  830 |     | 
     | 
  |  831 |    0 |        }  | 
  |  832 |     | 
     | 
  |  833 |     | 
           @Override  | 
  |  834 |     | 
           public void beforeShow(final Callback<Boolean> onReadyCallback) { | 
  |  835 |    0 |                    if(!initialized){ | 
  |  836 |    0 |                            Application.getApplicationContext().clearCrossConstraintMap(null);  | 
  |  837 |    0 |                            Application.getApplicationContext().clearPathToFieldMapping(null);  | 
  |  838 |     | 
                   }  | 
  |  839 |     | 
                     | 
  |  840 |    0 |                    Application.getApplicationContext().setParentPath(""); | 
  |  841 |    0 |                    super.beforeShow(onReadyCallback);                                                  | 
  |  842 |    0 |            }  | 
  |  843 |     | 
     | 
  |  844 |     | 
             | 
  |  845 |     | 
             | 
  |  846 |     | 
           @Override  | 
  |  847 |     | 
           public <V extends Enum<?>> void showView(V viewType,  | 
  |  848 |     | 
                           final Callback<Boolean> onReadyCallback) { | 
  |  849 |    0 |                    Callback<Boolean> updateCrossConstraintsCallback = new Callback<Boolean>(){ | 
  |  850 |     | 
                           public void exec(Boolean result) { | 
  |  851 |    0 |                                    onReadyCallback.exec(result);  | 
  |  852 |    0 |                            for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){ | 
  |  853 |    0 |                                    crossConstraint.reprocessWithUpdatedConstraints();  | 
  |  854 |     | 
                           }  | 
  |  855 |    0 |                            showWarnings();          | 
  |  856 |    0 |                            }  | 
  |  857 |     | 
           };  | 
  |  858 |    0 |                    super.showView(viewType, updateCrossConstraintsCallback);  | 
  |  859 |    0 |            }  | 
  |  860 |     | 
     | 
  |  861 |     | 
             | 
  |  862 |     | 
           @Override  | 
  |  863 |     | 
           public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChangeCallback){ | 
  |  864 |    0 |                final Callback<Boolean> reallyOkToChange = new Callback<Boolean>() { | 
  |  865 |     | 
     | 
  |  866 |     | 
               @Override  | 
  |  867 |     | 
               public void exec(Boolean result) { | 
  |  868 |    0 |                    if (result) { | 
  |  869 |    0 |                        if (LUMViews.VARIATION_EDIT.equals(viewChangingTo)) { | 
  |  870 |    0 |                            getView(ProgramSections.MANAGE_BODIES_EDIT, new Callback<View>() { | 
  |  871 |     | 
                               @Override  | 
  |  872 |     | 
                               public void exec(final View view) { | 
  |  873 |    0 |                                    if (view != null && view instanceof SectionView) { | 
  |  874 |    0 |                                        requestModel(new ModelRequestCallback<DataModel>() { | 
  |  875 |     | 
                                           public void onModelReady(DataModel model) { | 
  |  876 |    0 |                                                ((SectionView) view).updateWidgetData(model);  | 
  |  877 |    0 |                                                okToChangeCallback.exec(true);  | 
  |  878 |    0 |                                            }  | 
  |  879 |     | 
     | 
  |  880 |     | 
                                           public void onRequestFail(Throwable cause) { | 
  |  881 |    0 |                                                okToChangeCallback.exec(false);  | 
  |  882 |    0 |                                            }  | 
  |  883 |     | 
                                       });  | 
  |  884 |     | 
                                   } else { | 
  |  885 |    0 |                                        okToChangeCallback.exec(true);  | 
  |  886 |     | 
                                   }  | 
  |  887 |    0 |                                }  | 
  |  888 |     | 
                           });  | 
  |  889 |     | 
                       } else { | 
  |  890 |    0 |                            okToChangeCallback.exec(true);  | 
  |  891 |     | 
                       }  | 
  |  892 |     | 
                   }  | 
  |  893 |    0 |                }  | 
  |  894 |     | 
           };  | 
  |  895 |    0 |            super.beforeViewChange(viewChangingTo, reallyOkToChange);  | 
  |  896 |    0 |            this.showExport(isExportButtonActive());   | 
  |  897 |    0 |            }  | 
  |  898 |     | 
     | 
  |  899 |     | 
       protected void setStatus() { | 
  |  900 |    0 |            String modelProposalId = programModel.get(QueryPath.parse(proposalPath + "/id"));  | 
  |  901 |     | 
     | 
  |  902 |    0 |            if (modelProposalId != null && !modelProposalId.isEmpty()) { | 
  |  903 |    0 |                String workflowId = programModel.get(QueryPath.parse(proposalPath + "/workflowId"));  | 
  |  904 |    0 |                proposalServiceAsync.getProposalByWorkflowId(workflowId, new KSAsyncCallback<ProposalInfo>() { | 
  |  905 |     | 
                   @Override  | 
  |  906 |     | 
                   public void handleFailure(Throwable caught) { | 
  |  907 |    0 |                        statusLabel.setText("Proposal status: Unknown"); | 
  |  908 |    0 |                    }  | 
  |  909 |     | 
     | 
  |  910 |     | 
                   @Override  | 
  |  911 |     | 
                   public void onSuccess(ProposalInfo result) { | 
  |  912 |    0 |                        statusLabel.setText("Proposal status: " + result.getState()); | 
  |  913 |    0 |                    }  | 
  |  914 |     | 
               });  | 
  |  915 |     | 
           }  | 
  |  916 |    0 |        }  | 
  |  917 |     | 
             | 
  |  918 |     | 
       public ProgramRequirementsDataModel getReqDataModel() { | 
  |  919 |    0 |            return reqDataModel;  | 
  |  920 |     | 
       }  | 
  |  921 |     | 
     | 
  |  922 |     | 
       public ProgramRequirementsDataModel getReqDataModelComp() { | 
  |  923 |    0 |            return reqDataModelComp;  | 
  |  924 |     | 
       }  | 
  |  925 |     | 
     | 
  |  926 |     | 
           @Override  | 
  |  927 |     | 
           public void getMetadataForFinalState(final KSAsyncCallback<Metadata> callback) { | 
  |  928 |     | 
                     | 
  |  929 |    0 |                    String idType = null;  | 
  |  930 |    0 |                    String viewContextId = "";  | 
  |  931 |    0 |                    if(getViewContext().getIdType() != null){ | 
  |  932 |    0 |                idType = getViewContext().getIdType().toString();  | 
  |  933 |    0 |                viewContextId = getViewContext().getId();  | 
  |  934 |    0 |                if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){ | 
  |  935 |    0 |                        viewContextId = null;  | 
  |  936 |     | 
               }  | 
  |  937 |     | 
                   }  | 
  |  938 |    0 |                    HashMap<String, String> idAttributes = new HashMap<String, String>();  | 
  |  939 |    0 |                    if(idType != null){ | 
  |  940 |    0 |                            idAttributes.put(IdAttributes.ID_TYPE, idType);  | 
  |  941 |     | 
                   }  | 
  |  942 |     | 
     | 
  |  943 |    0 |                    idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, "kuali.proposal.type.majorDiscipline.modify");  | 
  |  944 |    0 |                    idAttributes.put(DtoConstants.DTO_STATE, "Draft");                                      | 
  |  945 |    0 |                    idAttributes.put(DtoConstants.DTO_NEXT_STATE, "Active");  | 
  |  946 |    0 |                    idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, "Publication Review");  | 
  |  947 |     | 
                     | 
  |  948 |     | 
                     | 
  |  949 |    0 |                    programRemoteService.getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){ | 
  |  950 |     | 
                           @Override  | 
  |  951 |     | 
                           public void onSuccess(Metadata metadata) { | 
  |  952 |     | 
                                     | 
  |  953 |    0 |                                    metadata.getProperties().remove("orgCoreProgram");  | 
  |  954 |    0 |                                    callback.onSuccess(metadata);  | 
  |  955 |    0 |                            }  | 
  |  956 |     | 
                   });  | 
  |  957 |    0 |            }  | 
  |  958 |     | 
     | 
  |  959 |     | 
           @Override  | 
  |  960 |     | 
           public void checkAuthorization(final PermissionType permissionType,        final AuthorizationCallback callbackLocatedOnBaseControllerClass) { | 
  |  961 |     | 
                     | 
  |  962 |    0 |                    Map<String,String> attributes = new HashMap<String,String>();  | 
  |  963 |    0 |                    GWT.log("Attempting Auth Check.", null); | 
  |  964 |    0 |                    if (programModel != null && programModel.getRoot() != null) { | 
  |  965 |     | 
                             | 
  |  966 |     | 
                             | 
  |  967 |    0 |                            attributes.put(IdType.KS_KEW_OBJECT_ID.toString(), ProgramUtils.getProposalId(programModel));  | 
  |  968 |    0 |                        attributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_MAJOR_DISCIPLINE_MODIFY);  | 
  |  969 |    0 |                    } else if ( (getViewContext().getId() != null) && (!"".equals(getViewContext().getId())) && getViewContext().getIdType() != null ) { | 
  |  970 |    0 |                            if (getViewContext().getIdType() == IdType.KS_KEW_OBJECT_ID || getViewContext().getIdType() == IdType.DOCUMENT_ID){ | 
  |  971 |    0 |                                    attributes.put(getViewContext().getIdType().toString(), getViewContext().getId());  | 
  |  972 |     | 
                           }  | 
  |  973 |     | 
                   }  | 
  |  974 |    0 |                    programRemoteService.isAuthorized(permissionType, attributes, new KSAsyncCallback<Boolean>(){ | 
  |  975 |     | 
     | 
  |  976 |     | 
                           @Override  | 
  |  977 |     | 
                           public void handleFailure(Throwable caught) { | 
  |  978 |    0 |                                    callbackLocatedOnBaseControllerClass.isNotAuthorized("Error checking authorization."); | 
  |  979 |    0 |                                    GWT.log("Error checking proposal authorization.", caught); | 
  |  980 |    0 |                    Window.alert("Error Checking Proposal Authorization: "+caught.getMessage()); | 
  |  981 |    0 |                            }  | 
  |  982 |     | 
     | 
  |  983 |     | 
                           @Override  | 
  |  984 |     | 
                           public void onSuccess(Boolean result) { | 
  |  985 |    0 |                                    GWT.log("Succeeded checking auth for permission type '" + permissionType + "' with result: " + result, null); | 
  |  986 |    0 |                                    if (Boolean.TRUE.equals(result)) { | 
  |  987 |    0 |                                            callbackLocatedOnBaseControllerClass.isAuthorized();  | 
  |  988 |     | 
                                   }  | 
  |  989 |     | 
                                   else { | 
  |  990 |    0 |                                            callbackLocatedOnBaseControllerClass.isNotAuthorized("User is not authorized: " + permissionType); | 
  |  991 |     | 
                                   }  | 
  |  992 |    0 |                            }  | 
  |  993 |     | 
               });  | 
  |  994 |    0 |            }  | 
  |  995 |     | 
     | 
  |  996 |     | 
     | 
  |  997 |     | 
           @Override  | 
  |  998 |     | 
           public boolean isAuthorizationRequired() { | 
  |  999 |    0 |                    return true;  | 
  |  1000 |     | 
           }  | 
  |  1001 |     | 
     | 
  |  1002 |     | 
     | 
  |  1003 |     | 
           @Override  | 
  |  1004 |     | 
           public void setAuthorizationRequired(boolean required) { | 
  |  1005 |     | 
                     | 
  |  1006 |    0 |            }  | 
  |  1007 |     | 
     | 
  |  1008 |     | 
   }  |