Coverage Report - org.kuali.student.common.ui.client.application.ApplicationContext
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationContext
0%
0/54
0%
0/12
1.389
ApplicationContext$1
0%
0/4
N/A
1.389
 
 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.common.ui.client.application;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.student.common.ui.client.security.SecurityContext;
 24  
 import org.kuali.student.common.ui.client.service.ServerPropertiesRpcService;
 25  
 import org.kuali.student.common.ui.client.service.ServerPropertiesRpcServiceAsync;
 26  
 import org.kuali.student.core.messages.dto.Message;
 27  
 
 28  
 import com.google.gwt.core.client.GWT;
 29  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 30  
 
 31  0
 public class ApplicationContext {
 32  0
         private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class);
 33  
         
 34  0
         private boolean loggedIn = true;
 35  0
         private String userId = "testuser";
 36  0
         private List<String> roles = new ArrayList<String>();
 37  
         
 38  0
         private Map<String, Map<String, String>> messages = new HashMap<String, Map<String,String>>();
 39  0
         private Map<String, String> flatMessages = new HashMap<String, String>();
 40  0
         private List<Message> messagesList = new ArrayList<Message>();
 41  
         
 42  
         private SecurityContext securityContext;
 43  
         private String applicationContextUrl;
 44  
         
 45  
         /**
 46  
          * This constructor should only be visible to the common application package. If ApplicationContext is 
 47  
          * required outside this package do Application.getApplicationContext();
 48  
          */
 49  0
         protected ApplicationContext() {
 50  0
                 roles.add("role1");
 51  0
                 roles.add("role2");
 52  
                 
 53  0
                 serverPropertiesRpcService.getContextPath(new AsyncCallback<String>(){
 54  
 
 55  
                         @Override
 56  
                         public void onFailure(Throwable caught) {
 57  0
                                 throw new RuntimeException("Fatal - Unable to initialze application context");
 58  
                         }
 59  
 
 60  
                         @Override
 61  
                         public void onSuccess(String result) {
 62  0
                                 applicationContextUrl = result;
 63  0
                         }                        
 64  
                 });
 65  0
         }
 66  
 
 67  
         public void setLoggedIn(boolean loggedIn) {
 68  0
                 this.loggedIn = loggedIn;
 69  0
         }
 70  
 
 71  
         public void setUserId(String userId) {
 72  0
                 this.userId = userId;
 73  0
         }
 74  
 
 75  
         public void setRoles(List<String> roles) {
 76  0
                 this.roles = roles;
 77  0
         }
 78  
 
 79  
         public boolean isLoggedIn() {
 80  0
                 return loggedIn;
 81  
         }
 82  
 
 83  
         public String getUserId() {
 84  0
                 return userId;
 85  
         }
 86  
 
 87  
         public List<String> getRoles() {
 88  0
                 return roles;
 89  
         }
 90  
 
 91  
     public void addMessages(List<Message> messages) {
 92  0
                 messagesList.addAll(messages);
 93  0
             for (Message m : messages) {
 94  0
                 String groupName = m.getGroupName();
 95  0
                 Map<String, String> group = this.messages.get(groupName);
 96  0
                 if (group == null) {
 97  0
                     group = new HashMap<String, String>();
 98  0
                     this.messages.put(groupName, group);
 99  
                 }
 100  0
                 group.put(m.getId(), m.getValue());
 101  0
                 flatMessages.put(m.getId(), m.getValue());
 102  0
             }
 103  0
         }
 104  
         
 105  
         public String getMessage(String messageId) {
 106  0
             return flatMessages.get(messageId);
 107  
     }
 108  
     
 109  
         public List<Message> getMessages() {
 110  0
             return messagesList;
 111  
     }
 112  
     
 113  
         
 114  
         public String getMessage(String groupName, String messageId) {
 115  
                         
 116  0
             String result = null;
 117  
             
 118  0
             Map<String, String> group = this.messages.get(groupName);
 119  0
             if (group != null) {
 120  0
                 result = group.get(messageId);
 121  
             }
 122  
             
 123  0
             return result;
 124  
         }
 125  
         
 126  
     /**
 127  
      * 
 128  
      * This method looks up a UI Label in the messages cache.  
 129  
      * First looks for a label specific to the type and state of the field.
 130  
      * If none found try for a generalized label.
 131  
      * Otherwise return the supplied fieldId
 132  
      * Groups provide namespace for same label ids within different LUs
 133  
      * 
 134  
      * @param groupName - for example 'course' or 'program'
 135  
      * @param type
 136  
      * @param state
 137  
      * @param fieldId
 138  
      * @return
 139  
      */
 140  
          public String getUILabel(String groupName, String type, String state, String fieldId) {
 141  
 
 142  0
         String label = getMessage(groupName, type + ":" + state + ":" + fieldId);
 143  
         
 144  0
         if (label == null)
 145  0
             label = getMessage(groupName, fieldId);
 146  
         
 147  0
         if (label == null)
 148  0
             label =  fieldId;
 149  
         
 150  0
         return label;
 151  
         
 152  
     }
 153  
          
 154  
         public String getUILabel(String groupName, String fieldId) {
 155  
 
 156  0
                 String label = getMessage(groupName, fieldId);
 157  
                 
 158  0
                 if (label == null)
 159  0
                     label =  fieldId;
 160  
                 
 161  0
                 return label;
 162  
                 
 163  
         }
 164  
 
 165  
     public SecurityContext getSecurityContext() {
 166  0
         return securityContext;
 167  
     }
 168  
 
 169  
     public void setSecurityContext(SecurityContext securityContext) {
 170  0
         this.securityContext = securityContext;
 171  0
     }
 172  
         
 173  
         public String getApplicationContextUrl() {
 174  0
                 return applicationContextUrl;
 175  
         }
 176  
         
 177  
 }