1 package org.kuali.student.r2.common.util;
2
3 import org.kuali.rice.krad.UserSession;
4 import org.kuali.rice.krad.util.GlobalVariables;
5 import org.kuali.student.r2.common.dto.ContextInfo;
6 import org.kuali.student.r2.common.dto.LocaleInfo;
7
8 import java.util.Date;
9 import java.util.Locale;
10
11
12
13
14
15
16
17
18 public class ContextUtils {
19
20
21
22
23
24
25
26 public static ContextInfo getContextInfo(){
27 ContextInfo contextInfo = new ContextInfo();
28 UserSession userSession = GlobalVariables.getUserSession();
29 if (userSession != null) {
30 contextInfo.setPrincipalId(userSession.getPrincipalId());
31 }
32
33 return contextInfo;
34 }
35
36
37
38
39
40 public static ContextInfo createDefaultContextInfo(){
41 ContextInfo contextInfo = new ContextInfo();
42 UserSession userSession = GlobalVariables.getUserSession();
43 if (userSession != null) {
44 contextInfo.setAuthenticatedPrincipalId(userSession.getPrincipalId());
45 contextInfo.setPrincipalId(userSession.getPrincipalId());
46 }
47 contextInfo.setCurrentDate(new Date());
48 LocaleInfo localeInfo = new LocaleInfo();
49 localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
50 localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
51 contextInfo.setLocale(localeInfo);
52 return contextInfo;
53 }
54 }