1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.social.service.rest.api.models;
18
19 import java.util.HashMap;
20
21 import org.exoplatform.social.core.activity.model.ActivityStream;
22 import org.exoplatform.social.core.identity.model.Identity;
23 import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
24 import org.exoplatform.social.core.manager.IdentityManager;
25 import org.exoplatform.social.core.space.model.Space;
26 import org.exoplatform.social.core.space.spi.SpaceService;
27 import org.exoplatform.social.service.rest.Util;
28
29
30
31
32
33
34
35
36 public class ActivityStreamRestOut extends HashMap<String, Object> {
37
38
39
40
41 public static enum Field {
42 TYPE("type"),
43 PRETTY_ID("prettyId"),
44 FULL_NAME("fullName"),
45 FAVICON_URL("faviconUrl"),
46 TITLE("title"),
47 PERMA_LINK("permaLink");
48
49
50
51
52 private final String fieldName;
53
54
55
56
57
58
59 private Field(final String str) {
60 fieldName = str;
61 }
62
63
64
65
66
67
68 @Override
69 public String toString() {
70 return fieldName;
71 }
72 }
73
74
75
76
77 public ActivityStreamRestOut() {
78 initialize();
79 }
80
81
82
83
84
85
86 public ActivityStreamRestOut(final ActivityStream activityStream, String portalContainerName) {
87 initialize();
88 this.setType(activityStream.getType().toString());
89 this.setPrettyId(activityStream.getPrettyId());
90 this.setFaviconUrl(activityStream.getFaviconUrl());
91 this.setTitle(activityStream.getTitle());
92 this.setPermaLink(activityStream.getPermaLink());
93
94 if(activityStream.getType() != null){
95 ActivityStream.Type activityStreamType = activityStream.getType();
96 if(activityStreamType.equals(ActivityStream.Type.SPACE)){
97 SpaceService spaceService = Util.getSpaceService(portalContainerName);
98 Space space = spaceService.getSpaceByPrettyName(activityStream.getPrettyId());
99 if(space != null && space.getDisplayName() != null){
100 this.setFullName(space.getDisplayName());
101 }
102 } else if(activityStreamType.equals(ActivityStream.Type.USER)) {
103 IdentityManager identityManager = Util.getIdentityManager(portalContainerName);
104 Identity identity = identityManager.getOrCreateIdentity(
105 OrganizationIdentityProvider.NAME, activityStream.getPrettyId(), true);
106 if(identity != null && identity.getProfile() != null && identity.getProfile().getFullName() != null){
107 this.setFullName(identity.getProfile().getFullName());
108 }
109 }
110 }
111 }
112
113
114
115
116
117
118 public String getType() {
119 return (String) get(Field.TYPE.toString());
120 }
121
122
123
124
125
126
127 public void setType(String type) {
128 if (type == null) {
129 put(Field.TYPE.toString(), "");
130 } else {
131 put(Field.TYPE.toString(), type);
132 }
133 }
134
135
136
137
138
139
140 public String getPrettyId() {
141 return (String) get(Field.PRETTY_ID.toString());
142 }
143
144
145
146
147
148
149 public void setPrettyId(final String prettyId) {
150 if (prettyId == null) {
151 put(Field.PRETTY_ID.toString(), "");
152 } else {
153 put(Field.PRETTY_ID.toString(), prettyId);
154 }
155 }
156
157
158
159
160
161
162
163 public String getFullName() {
164 return (String) get(Field.FULL_NAME.toString());
165 }
166
167
168
169
170
171
172 public void setFullName(final String fullName) {
173 if (fullName == null) {
174 put(Field.FULL_NAME.toString(), "");
175 } else {
176 put(Field.FULL_NAME.toString(), fullName);
177 }
178 }
179
180
181
182
183
184
185 public String getTitle() {
186 return (String) get(Field.TITLE.toString());
187 }
188
189
190
191
192
193
194 public void setTitle(final String title) {
195 if (title == null) {
196 put(Field.TITLE.toString(), "");
197 } else {
198 put(Field.TITLE.toString(), title);
199 }
200 }
201
202
203
204
205
206
207 public String getPermaLink() {
208 return (String) get(Field.PERMA_LINK.toString());
209 }
210
211
212
213
214
215
216 public void setPermaLink(final String permalink) {
217 if (permalink == null) {
218 put(Field.PERMA_LINK.toString(), "");
219 } else {
220 put(Field.PERMA_LINK.toString(), Util.getBaseUrl() + permalink);
221 }
222 }
223
224
225
226
227
228
229 public String getFaviconUrl() {
230 return (String) get(Field.FAVICON_URL.toString());
231 }
232
233
234
235
236
237
238 public void setFaviconUrl(String faviconUrl) {
239 if (faviconUrl == null) {
240 put(Field.FAVICON_URL.toString(), "");
241 } else {
242 put(Field.FAVICON_URL.toString(), Util.getBaseUrl() + faviconUrl);
243 }
244 }
245
246
247
248
249
250 private void initialize() {
251 setType("");
252 setPrettyId("");
253 setFullName(null);
254 setFaviconUrl(null);
255 setTitle("");
256 setPermaLink(null);
257 }
258
259 }