Coverage Report - org.kuali.student.lum.program.client.core.view.CoreViewController
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreViewController
0%
0/26
0%
0/2
1.417
CoreViewController$1
0%
0/12
0%
0/4
1.417
CoreViewController$2
0%
0/3
N/A
1.417
CoreViewController$3
0%
0/3
N/A
1.417
CoreViewController$4
0%
0/3
N/A
1.417
CoreViewController$5
0%
0/6
0%
0/2
1.417
 
 1  
 package org.kuali.student.lum.program.client.core.view;
 2  
 
 3  
 import org.kuali.student.common.rice.authorization.PermissionType;
 4  
 import org.kuali.student.common.ui.client.application.Application;
 5  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 6  
 import org.kuali.student.common.ui.client.application.ViewContext;
 7  
 import org.kuali.student.common.ui.client.mvc.Callback;
 8  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 9  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 10  
 import org.kuali.student.common.ui.client.security.AuthorizationCallback;
 11  
 import org.kuali.student.common.ui.client.security.RequiresAuthorization;
 12  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 13  
 import org.kuali.student.lum.common.client.lu.LUUIPermissions;
 14  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 15  
 import org.kuali.student.lum.common.client.widgets.DropdownList;
 16  
 import org.kuali.student.lum.program.client.ProgramConstants;
 17  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 18  
 import org.kuali.student.lum.program.client.ProgramSections;
 19  
 import org.kuali.student.lum.program.client.ProgramStatus;
 20  
 import org.kuali.student.lum.program.client.core.CoreController;
 21  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 22  
 import org.kuali.student.lum.program.client.events.ProgramViewEvent;
 23  
 import org.kuali.student.lum.program.client.major.ActionType;
 24  
 
 25  
 import com.google.gwt.core.client.GWT;
 26  
 import com.google.gwt.event.dom.client.ChangeEvent;
 27  
 import com.google.gwt.event.dom.client.ChangeHandler;
 28  
 import com.google.gwt.event.shared.HandlerManager;
 29  
 
 30  
 /**
 31  
  * @author Igor
 32  
  */
 33  0
 public class CoreViewController extends CoreController implements RequiresAuthorization{
 34  
 
 35  
     /**
 36  
      * Initialize the action drop-down with a list of values.  Note that these values
 37  
      * will be changed further down in the code depending on if we are working with the latest 
 38  
      * version of the program.
 39  
      */ 
 40  0
     private final DropdownList actionBox = new DropdownList(ActionType.getValuesForCoreProgram(false));
 41  
 
 42  
     /**
 43  
      * Constructor.
 44  
      *
 45  
      * @param programModel
 46  
      */
 47  
     public CoreViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) {
 48  0
         super(programModel, viewContext, eventBus);
 49  0
         configurer = GWT.create(CoreViewConfigurer.class);
 50  0
         bind();
 51  0
     }
 52  
 
 53  
     private void bind() {
 54  0
         actionBox.addChangeHandler(new ChangeHandler() {
 55  
             @Override
 56  
             public void onChange(ChangeEvent event) {
 57  0
                 ActionType actionType = ActionType.of(actionBox.getSelectedValue());
 58  0
                 ViewContext viewContext = getViewContext();
 59  0
                 if (actionType == ActionType.MODIFY) {
 60  0
                     ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum()));
 61  0
                     HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext);
 62  0
                 } else if (actionType == ActionType.MODIFY_VERSION) {
 63  0
                     String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID);
 64  0
                     viewContext.setId(versionIndId);
 65  0
                     viewContext.setIdType(IdType.COPY_OF_OBJECT_ID);
 66  0
                     HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext);
 67  
                 }
 68  0
             }
 69  
         });
 70  0
         eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() {
 71  
             @Override
 72  
             public void onEvent(ProgramViewEvent event) {
 73  0
                 actionBox.setSelectedIndex(0);
 74  0
             }
 75  
         });
 76  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 77  
             @Override
 78  
             public void onEvent(ModelLoadedEvent event) {
 79  0
                 resetActionList();
 80  0
             }
 81  
         });
 82  0
     }
 83  
 
 84  
     @Override
 85  
     protected void configureView() {
 86  0
         super.configureView();
 87  0
         addContentWidget(actionBox);
 88  0
         initialized = true;
 89  0
     }
 90  
 
 91  
     protected void resetActionList() {
 92  
         //Only allow modify with version option for an active course that id also the latest version
 93  0
         ProgramStatus status = ProgramStatus.of(programModel.<String>get(ProgramConstants.STATE));
 94  0
         String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID);
 95  0
         Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER);
 96  
 
 97  0
         actionBox.clear();
 98  0
         if (status == ProgramStatus.ACTIVE) {
 99  0
             programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>() {
 100  
                 public void onSuccess(Boolean isLatest) {
 101  0
                     actionBox.setList(ActionType.getValuesForCoreProgram(isLatest));
 102  0
                 }
 103  
             });
 104  
         } else {
 105  0
             actionBox.setList(ActionType.getValuesForCoreProgram(false));
 106  
         }
 107  0
     }
 108  
     
 109  
     @Override
 110  
         public boolean isAuthorizationRequired() {
 111  0
                 return true;
 112  
         }
 113  
 
 114  
         @Override
 115  
         public void setAuthorizationRequired(boolean required) {
 116  0
                 throw new UnsupportedOperationException();
 117  
         }
 118  
         
 119  
         @Override
 120  
         public void checkAuthorization(final AuthorizationCallback authCallback) {
 121  0
                 Application.getApplicationContext().getSecurityContext().checkScreenPermission(LUUIPermissions.USE_VIEW_CORE_PROGRAMS_SCREEN, new Callback<Boolean>() {
 122  
                         @Override
 123  
                         public void exec(Boolean result) {
 124  
 
 125  0
                                 final boolean isAuthorized = result;
 126  
                 
 127  0
                                 if(isAuthorized){
 128  0
                                         authCallback.isAuthorized();
 129  
                                 }
 130  
                                 else
 131  0
                                         authCallback.isNotAuthorized("User is not authorized: " + LUUIPermissions.USE_VIEW_CORE_PROGRAMS_SCREEN);
 132  0
                         }        
 133  
                 });
 134  0
         }
 135  
 }