1
2
3
4
5 package com.hack23.cia.model.application.dto.common;
6
7 import gnu.trove.THashMap;
8
9 import java.util.Map;
10
11 import com.hack23.cia.model.application.impl.common.Agency;
12 import com.hack23.cia.model.application.impl.common.LanguageContent;
13 import com.hack23.cia.model.application.impl.common.Portal;
14 import com.hack23.cia.model.application.impl.common.UserSession;
15 import com.hack23.cia.model.sweden.impl.Vote.Position;
16
17 /***
18 * The Class UserSessionDTO.
19 */
20 public class UserSessionDTO {
21
22 /*** The agency language content values. */
23 private final Map<Agency.LanguageContentKey, String> agencyLanguageContentValues = new THashMap<Agency.LanguageContentKey, String>();
24
25 /*** The portal language content values. */
26 private final Map<Portal.LanguageContentKey, String> portalLanguageContentValues = new THashMap<Portal.LanguageContentKey, String>();
27
28 /*** The user session. */
29 private final UserSession userSession;
30
31 /***
32 * Instantiates a new user session dto.
33 *
34 * @param userSession the user session
35 */
36 public UserSessionDTO(final UserSession userSession) {
37 super();
38 this.userSession = userSession;
39 if (userSession != null) {
40
41 if (userSession.getPortal() != null) {
42 for (final LanguageContent languageContent : userSession
43 .getPortal()
44 .getLanguageContentByLanguage(userSession.getLanguage())) {
45 portalLanguageContentValues.put(Portal.LanguageContentKey
46 .valueOf(languageContent.getContentPropertyName()),
47 languageContent.getContent());
48 }
49
50 if (userSession.getPortal().getAgency() != null) {
51
52 for (final LanguageContent languageContent : userSession.getPortal()
53 .getAgency().getLanguageContentByLanguage(
54 userSession.getLanguage())) {
55 agencyLanguageContentValues.put(Agency.LanguageContentKey
56 .valueOf(languageContent.getContentPropertyName()),
57 languageContent.getContent());
58 }
59 }
60 }
61 }
62 }
63
64 /***
65 * Gets the language resource.
66 *
67 * @param key the key
68 * @return the language resource
69 */
70 public final String getLanguageResource(final Agency.LanguageContentKey key) {
71 return agencyLanguageContentValues.get(key);
72
73 }
74
75 /***
76 * Gets the language resource.
77 *
78 * @param key the key
79 * @return the language resource
80 */
81 public final String getLanguageResource(final Portal.LanguageContentKey key) {
82 return portalLanguageContentValues.get(key);
83 }
84
85 /***
86 * Gets the language resource.
87 *
88 * @param position the position
89 * @return the language resource
90 */
91 public final String getLanguageResource(final Position position) {
92 final Agency.LanguageContentKey key = Agency.LanguageContentKey.valueOf(position.toString().toUpperCase());
93 return getLanguageResource(key);
94 }
95
96 /***
97 * Gets the user session.
98 *
99 * @return the user session
100 */
101 public final UserSession getUserSession() {
102 return userSession;
103 }
104 }