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 | 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 | |
|
47 | |
|
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 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
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 | |
} |