Coverage Report - org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserController
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogBrowserController
0%
0/37
0%
0/2
1.467
CatalogBrowserController$1
0%
0/3
N/A
1.467
CatalogBrowserController$2
0%
0/15
0%
0/2
1.467
CatalogBrowserController$3
0%
0/5
0%
0/2
1.467
CatalogBrowserController$4
0%
0/6
0%
0/2
1.467
CatalogBrowserController$CatalogBrowserViews
0%
0/2
N/A
1.467
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.lu.ui.tools.client.configuration;
 17  
 
 18  
 import org.kuali.student.common.assembly.data.Data;
 19  
 import org.kuali.student.common.assembly.data.Metadata;
 20  
 import org.kuali.student.common.rice.authorization.PermissionType;
 21  
 import org.kuali.student.common.ui.client.application.Application;
 22  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.TabMenuController;
 24  
 import org.kuali.student.common.ui.client.mvc.Callback;
 25  
 import org.kuali.student.common.ui.client.mvc.Controller;
 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.ModelProvider;
 29  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 30  
 import org.kuali.student.common.ui.client.security.AuthorizationCallback;
 31  
 import org.kuali.student.common.ui.client.security.RequiresAuthorization;
 32  
 import org.kuali.student.common.ui.client.service.MetadataRpcService;
 33  
 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync;
 34  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 35  
 import org.kuali.student.common.ui.client.widgets.containers.KSTitleContainerImpl;
 36  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 37  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 38  
 import org.kuali.student.lum.common.client.lu.LUUIPermissions;
 39  
 
 40  
 import com.google.gwt.core.client.GWT;
 41  
 
 42  
 
 43  0
 public class CatalogBrowserController extends TabMenuController implements RequiresAuthorization
 44  
 {
 45  0
         private MetadataRpcServiceAsync metadataService = GWT.create(MetadataRpcService.class);
 46  0
         private final DataModel dataModel = new DataModel ();
 47  0
         private boolean initialized = false;
 48  
         private Controller controller;
 49  0
         private static KSTitleContainerImpl container = new KSTitleContainerImpl("Catalog Browser");
 50  0
         private BlockingTask initializingTask = new BlockingTask("Loading");
 51  
         
 52  
         //enum is necessary for the page to be added to breadcrumbs
 53  0
         public enum CatalogBrowserViews {
 54  0
                 COURSE_CATALOG
 55  
     };
 56  
 
 57  
         public CatalogBrowserController (Controller controller)        {
 58  0
                 super(CatalogBrowserController.class.getName());
 59  0
                 this.controller = controller;
 60  
                 //sets the name of the page to be used in breadcrumbs
 61  0
                 super.setName("Course Catalog");
 62  
                 //sets enum
 63  0
                 setViewEnum(CatalogBrowserViews.COURSE_CATALOG);
 64  0
                 initialize();
 65  0
         }
 66  
 
 67  
         private void initialize ()        {
 68  0
                 dataModel.setRoot(new Data ());
 69  
                 
 70  0
                 super.setDefaultModelId (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL);
 71  0
                 super.registerModel (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL, new ModelProvider<DataModel> () {
 72  
 
 73  
                         @Override
 74  
                         public void requestModel (final ModelRequestCallback<DataModel> callback) {
 75  0
                                 callback.onModelReady (dataModel);
 76  0
                         }
 77  
                 });
 78  0
         }
 79  
 
 80  
  private static final String METADATA_OBJECT_KEY_BROWSE = "browse";
 81  
 
 82  
         private void init (final Callback<Boolean> onReadyCallback)
 83  
         {
 84  
 
 85  0
                 if (initialized) {
 86  0
                         onReadyCallback.exec (true);
 87  
                 } else        {
 88  0
                     KSBlockingProgressIndicator.addTask(initializingTask);
 89  
                     
 90  0
                         metadataService.getMetadata (METADATA_OBJECT_KEY_BROWSE, null, null, new KSAsyncCallback<Metadata> (){
 91  
 
 92  
                                 @Override
 93  
                                 public void handleFailure (Throwable caught)
 94  
                                 {
 95  0
                                         onReadyCallback.exec (false);
 96  0
                                     KSBlockingProgressIndicator.removeTask(initializingTask);
 97  0
                                         throw new RuntimeException ("Failed to get model definition for " + METADATA_OBJECT_KEY_BROWSE, caught);
 98  
                                 }
 99  
 
 100  
                                 @Override
 101  
                                 public void onSuccess (Metadata result)
 102  
                                 {
 103  0
      if (result == null)
 104  
      {
 105  0
                                          onReadyCallback.exec (false);
 106  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 107  0
                                          throw new RuntimeException ("Got null metdata for " + METADATA_OBJECT_KEY_BROWSE);
 108  
      }
 109  0
                                         DataModelDefinition def = new DataModelDefinition (result);
 110  0
                                         dataModel.setDefinition (def);
 111  0
                                         configure (def);
 112  0
                                         initialized = true;
 113  0
                                         onReadyCallback.exec (true);
 114  0
                                     KSBlockingProgressIndicator.removeTask(initializingTask);
 115  0
                                 }
 116  
                         });
 117  
                 }
 118  0
         }
 119  
 
 120  
         private void configure (DataModelDefinition modelDefinition)        {
 121  0
                 CatalogBrowserConfigurer cfg = GWT.create(CatalogBrowserConfigurer.class);
 122  0
                 cfg.setModelDefinition (modelDefinition);
 123  0
                 cfg.setController (controller);
 124  0
                 cfg.configureCatalogBrowser (this);
 125  0
         }
 126  
         
 127  
         @Override
 128  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 129  0
                 WindowTitleUtils.setContextTitle(name);
 130  0
                 dataModel.setRoot(new Data ());
 131  0
                 init (new Callback<Boolean> ()        {
 132  
 
 133  
                         @Override
 134  
                         public void exec (Boolean result)
 135  
                         {
 136  0
                                 if (result)        {
 137  0
                                         showDefaultView (onReadyCallback);
 138  
                                 } else        {
 139  0
                                         onReadyCallback.exec (false);
 140  
                                 }
 141  0
                         }
 142  
                         
 143  
                 });
 144  0
         }
 145  
 
 146  
         @Override
 147  
         public Enum<?> getViewEnumValue (String enumValue){
 148  0
                 return null;
 149  
         }
 150  
 
 151  
         @Override
 152  
         public void setParentController (Controller controller)        {
 153  0
                 super.setParentController (controller);
 154  0
         }
 155  
         
 156  
         @Override
 157  
         public boolean isAuthorizationRequired() {
 158  0
                 return true;
 159  
         }
 160  
 
 161  
         @Override
 162  
         public void setAuthorizationRequired(boolean required) {
 163  0
                 throw new UnsupportedOperationException();
 164  
         }
 165  
         
 166  
         @Override
 167  
         public void checkAuthorization(final AuthorizationCallback authCallback) {
 168  0
                 Application.getApplicationContext().getSecurityContext().checkScreenPermission(LUUIPermissions.USE_BROWSE_CATALOG_SCREEN, new Callback<Boolean>() {
 169  
                         @Override
 170  
                         public void exec(Boolean result) {
 171  
 
 172  0
                                 final boolean isAuthorized = result;
 173  
                 
 174  0
                                 if(isAuthorized){
 175  0
                                         authCallback.isAuthorized();
 176  
                                 }
 177  
                                 else
 178  0
                                         authCallback.isNotAuthorized("User is not authorized: " + LUUIPermissions.USE_BROWSE_CATALOG_SCREEN);
 179  0
                         }        
 180  
                 });
 181  0
         }
 182  
 
 183  
 }