1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class ApplicationContext { |
40 | 0 | private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class); |
41 | |
|
42 | 0 | private boolean loggedIn = true; |
43 | 0 | private String userId = "testuser"; |
44 | 0 | private String version = "KS"; |
45 | 0 | private List<String> roles = new ArrayList<String>(); |
46 | |
|
47 | 0 | private Map<String, Map<String, String>> messages = new HashMap<String, Map<String,String>>(); |
48 | 0 | private Map<String, String> flatMessages = new HashMap<String, String>(); |
49 | 0 | private List<Message> messagesList = new ArrayList<Message>(); |
50 | |
|
51 | |
private SecurityContext securityContext; |
52 | |
private String applicationContextUrl; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | protected ApplicationContext() { |
59 | 0 | roles.add("role1"); |
60 | 0 | roles.add("role2"); |
61 | |
|
62 | 0 | serverPropertiesRpcService.getContextPath(new AsyncCallback<String>(){ |
63 | |
|
64 | |
@Override |
65 | |
public void onFailure(Throwable caught) { |
66 | 0 | throw new RuntimeException("Fatal - Unable to initialze application context"); |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
public void onSuccess(String result) { |
71 | 0 | applicationContextUrl = result; |
72 | 0 | } |
73 | |
}); |
74 | 0 | } |
75 | |
|
76 | |
public void setLoggedIn(boolean loggedIn) { |
77 | 0 | this.loggedIn = loggedIn; |
78 | 0 | } |
79 | |
|
80 | |
public void setUserId(String userId) { |
81 | 0 | this.userId = userId; |
82 | 0 | } |
83 | |
|
84 | |
public void setRoles(List<String> roles) { |
85 | 0 | this.roles = roles; |
86 | 0 | } |
87 | |
|
88 | |
public boolean isLoggedIn() { |
89 | 0 | return loggedIn; |
90 | |
} |
91 | |
|
92 | |
public String getUserId() { |
93 | 0 | return userId; |
94 | |
} |
95 | |
|
96 | |
public List<String> getRoles() { |
97 | 0 | return roles; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public void addMessages(List<Message> messages) { |
105 | 0 | messagesList.addAll(messages); |
106 | 0 | for (Message m : messages) { |
107 | 0 | String groupName = m.getGroupName(); |
108 | 0 | Map<String, String> group = this.messages.get(groupName); |
109 | 0 | if (group == null) { |
110 | 0 | group = new HashMap<String, String>(); |
111 | 0 | this.messages.put(groupName, group); |
112 | |
} |
113 | 0 | group.put(m.getId(), m.getValue()); |
114 | 0 | flatMessages.put(m.getId(), m.getValue()); |
115 | 0 | } |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public String getMessage(String messageId) { |
122 | 0 | return flatMessages.get(messageId); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public List<Message> getMessages() { |
129 | 0 | return messagesList; |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public String getMessage(String groupName, String messageId) { |
137 | |
|
138 | 0 | String result = null; |
139 | |
|
140 | 0 | Map<String, String> group = this.messages.get(groupName); |
141 | 0 | if (group != null) { |
142 | 0 | result = group.get(messageId); |
143 | |
} |
144 | |
|
145 | 0 | return result; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public String getUILabel(String groupName, String type, String state, String fieldId) { |
163 | |
|
164 | 0 | String label = getMessage(groupName, type + ":" + state + ":" + fieldId); |
165 | |
|
166 | 0 | if (label == null) |
167 | 0 | label = getMessage(groupName, fieldId); |
168 | |
|
169 | 0 | if (label == null) |
170 | 0 | label = fieldId; |
171 | |
|
172 | 0 | return label; |
173 | |
|
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public String getUILabel(String groupName, String fieldId) { |
181 | |
|
182 | 0 | String label = getMessage(groupName, fieldId); |
183 | |
|
184 | 0 | if (label == null) |
185 | 0 | label = fieldId; |
186 | |
|
187 | 0 | return label; |
188 | |
|
189 | |
} |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
public SecurityContext getSecurityContext() { |
196 | 0 | return securityContext; |
197 | |
} |
198 | |
|
199 | |
public void setSecurityContext(SecurityContext securityContext) { |
200 | 0 | this.securityContext = securityContext; |
201 | 0 | } |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public String getApplicationContextUrl() { |
207 | 0 | return applicationContextUrl; |
208 | |
} |
209 | |
|
210 | |
public void setVersion(String version) { |
211 | 0 | this.version = version; |
212 | 0 | } |
213 | |
|
214 | |
public String getVersion() { |
215 | 0 | return version; |
216 | |
} |
217 | |
|
218 | |
} |