Skip to content

Commit 1e71a22

Browse files
committed
Feature #3934 - upgrading UserProfile REST WebService to get, if requested, more data about a user & adding the technical possibility to use the UserProfile JavaScript API by a synchronous way
2 parents 7e2ca47 + a080cf8 commit 1e71a22

File tree

5 files changed

+252
-76
lines changed

5 files changed

+252
-76
lines changed

war-core/src/main/webapp/util/javaScript/silverpeas-profile.js

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2000 - 2012 Silverpeas
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -36,16 +36,19 @@ function isAUserGroup(object) {
3636
}
3737

3838
function UserProfile(user) {
39-
4039
var self = this;
40+
41+
var userProfileManagementParams = $.extend({extended: false, async:true}, user);
4142
var usermgt = new UserProfileManagement({
42-
id: user.id
43+
id: userProfileManagementParams.id,
44+
extended : userProfileManagementParams.extended,
45+
async : userProfileManagementParams.async
4346
});
44-
47+
4548
if (user != null)
4649
for (var prop in user)
4750
this[prop] = user[prop];
48-
51+
4952
/**
5053
* Loads the attributes of the profile of this user.
5154
* Whether a callback is passed as argument, invokes the callback with this user profile once its
@@ -67,7 +70,7 @@ function UserProfile(user) {
6770
});
6871
return self;
6972
}
70-
73+
7174
/**
7275
* Sets this user as having access priviledges in the specified component instance
7376
* (the unique identifier of the component instance).
@@ -131,7 +134,7 @@ function UserProfile(user) {
131134
var callback = arguments[arg];
132135
if (usermgt.users == null) {
133136
toload = true;
134-
}
137+
}
135138
if (usermgt.filter.name != name) {
136139
usermgt.filter.name = name;
137140
toload = true;
@@ -140,7 +143,7 @@ function UserProfile(user) {
140143
if (usermgt.filter.pagination == null || usermgt.filter.pagination.page != page ||
141144
usermgt.filter.pagination.count != pagesize) {
142145
usermgt.filter.pagination = {
143-
page: page,
146+
page: page,
144147
count: pagesize
145148
};
146149
toload = true;
@@ -154,11 +157,11 @@ function UserProfile(user) {
154157
usermgt.get({
155158
contacts: true
156159
}, callback);
157-
else
160+
else
158161
callback(usermgt.users);
159162
return self;
160163
}
161-
164+
162165
/**
163166
* Gets the loaded relationships.
164167
* Returns null if the relationships were not loaded.
@@ -173,15 +176,15 @@ function UserProfile(user) {
173176
* It provides additional methods.
174177
*/
175178
function UserGroup(group) {
176-
179+
177180
var self = this;
178181
var subgroupmgt = new UserGroupManagement();
179182
var usermgt = new UserProfileManagement();
180-
183+
181184
if (group != null)
182185
for (var prop in group)
183186
this[prop] = group[prop];
184-
187+
185188
/**
186189
* Sets this user group as having access priviledges in the specified component instance
187190
* (the unique identifier of the component instance).
@@ -241,7 +244,7 @@ function UserGroup(group) {
241244
});
242245
return self;
243246
}
244-
247+
245248
/**
246249
* Loads the children (subgroups) of this user group, and calls the specified callback operation
247250
* by passing it the fetched subgroups.
@@ -259,11 +262,11 @@ function UserGroup(group) {
259262
name: name,
260263
url: self.childrenUri
261264
},callback);
262-
} else
265+
} else
263266
callback(subgroupmgt.groups);
264267
return self;
265268
}
266-
269+
267270
/**
268271
* Loads the nth page of the users that belong to this group (and its subgroups), and calls the
269272
* specified callback operation by passing it the fetched users.
@@ -292,7 +295,7 @@ function UserGroup(group) {
292295
if (usermgt.users == null) {
293296
usermgt.filter.group = self.id;
294297
toload = true;
295-
}
298+
}
296299
if (usermgt.filter.name != name) {
297300
usermgt.filter.name = name;
298301
toload = true;
@@ -301,7 +304,7 @@ function UserGroup(group) {
301304
if (usermgt.filter.pagination == null || usermgt.filter.pagination.page != page ||
302305
usermgt.filter.pagination.count != pagesize) {
303306
usermgt.filter.pagination = {
304-
page: page,
307+
page: page,
305308
count: pagesize
306309
};
307310
toload = true;
@@ -313,19 +316,19 @@ function UserGroup(group) {
313316
}
314317
if (toload)
315318
usermgt.get(callback);
316-
else
319+
else
317320
callback(usermgt.users);
318321
return self;
319322
}
320-
323+
321324
/**
322325
* Gets the loaded subgroups of this user group.
323326
* Null is returned if the subgroups are not loaded.
324327
*/
325328
this.children = function() {
326329
return subgroupmgt.groups;
327330
}
328-
331+
329332
/**
330333
* Gets the loaded users in this user group.
331334
* Null is returned if the users are not loaded.
@@ -351,11 +354,12 @@ var rootUserGroup = new UserGroup({
351354
* You can give some parameters to filter the users on which this object works.
352355
*/
353356
function UserProfileManagement(params) {
354-
357+
355358
var self = this;
356-
359+
357360
this.filter = {
358361
id: null, // the unique identifier of a user to get
362+
extended: false, // a flag to load user full details
359363
contacts: false, // the contacts of the refered user. The id must be set to be taken into account
360364
group: null, // a user group unique identifier
361365
name: null, // a pattern about a user name (* is a wildcard)
@@ -364,10 +368,10 @@ function UserProfileManagement(params) {
364368
resource: null, // an identifier of a resource belonging to a component instance (the identifier
365369
// must be set the resource type following by resource identifier in Silverpeas).
366370
roles: null, // a string with a comma-separated role names
367-
pagination: null // pagination data in the form of
371+
pagination: null // pagination data in the form of
368372
// { page: <number of the page>, count: <count of users to fetch> }
369373
};
370-
374+
371375
/**
372376
* The filtering parameters about the user profiles to get.
373377
*/
@@ -376,7 +380,7 @@ function UserProfileManagement(params) {
376380
for(var prop in params)
377381
self.filter[prop] = params[prop];
378382
}
379-
383+
380384
/**
381385
* Decorates the user profiles with usefull method to improve the usability.
382386
*/
@@ -390,12 +394,12 @@ function UserProfileManagement(params) {
390394
}
391395
return decoratedUsers;
392396
}
393-
397+
394398
setUpFilter(params);
395-
399+
396400
// the users it manages
397401
this.users = null;
398-
402+
399403
/**
400404
* Gets the user profiles matching the filters (if any) and passes them to the
401405
* specified callback 'loaded'.
@@ -412,6 +416,10 @@ function UserProfileManagement(params) {
412416
urlOfUsers += '/' + self.filter.id;
413417
if (self.filter.contacts)
414418
urlOfUsers += '/contacts';
419+
if (self.filter.extended) {
420+
urlOfUsers += separator + 'extended=' + self.filter.extended;
421+
separator = '&';
422+
}
415423
application = separator + 'application=';
416424
if (self.filter.component)
417425
separator = '&';
@@ -441,12 +449,13 @@ function UserProfileManagement(params) {
441449
}
442450
if (self.filter.pagination) {
443451
urlOfUsers += separator + 'page=' + self.filter.pagination.page + ';' + self.filter.pagination.count;
444-
}
452+
}
445453
$.ajax({
446454
url: urlOfUsers,
447455
type: 'GET',
448456
dataType: 'json',
449457
cache: false,
458+
async: params.async,
450459
success: function(users, status, jqXHR) {
451460
self.users = decorate(users);
452461
self.users.maxlength = jqXHR.getResponseHeader('X-Silverpeas-UserSize');
@@ -466,9 +475,9 @@ function UserProfileManagement(params) {
466475
* You can give some parameters to contraints the user groups on which this object should work.
467476
*/
468477
function UserGroupManagement(params) {
469-
478+
470479
var self = this;
471-
480+
472481
this.filter = {
473482
id: null, // the unique identifier of a user group to get.
474483
url: null, // the URL at which the groups have to be get. If not set, the URL of the root groups
@@ -481,7 +490,7 @@ function UserGroupManagement(params) {
481490
resource: null // an identifier of a resource belonging to a component instance (the identifier
482491
// must be set the resource type following by resource identifier in Silverpeas).
483492
};
484-
493+
485494
/**
486495
* The filtering parameters about the user groups to get.
487496
*/
@@ -490,7 +499,7 @@ function UserGroupManagement(params) {
490499
for(var prop in params)
491500
self.filter[prop] = params[prop];
492501
}
493-
502+
494503
/**
495504
* Decorates the user groups with usefull method to improve the usability:
496505
* - children(loaded) with loaded a callback called with as argument the loaded groups,
@@ -507,12 +516,12 @@ function UserGroupManagement(params) {
507516
}
508517
return decoratedGroups;
509518
}
510-
519+
511520
setUpFilter(params);
512-
521+
513522
// the groups it manages.
514523
this.groups = null;
515-
524+
516525
/**
517526
* Gets the user profiles matching the filters (if any) and passes them to the specified callback
518527
* 'loaded'.

web-core/src/main/java/com/silverpeas/profile/web/UserProfileEntity.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static UserProfileEntity[] fromUsers(final List<? extends UserDetail> use
100100
@XmlElement(defaultValue="false")
101101
private boolean anonymous = false;
102102

103-
private UserProfileEntity(UserDetail user) {
103+
protected UserProfileEntity(UserDetail user) {
104104
this.user = user;
105105
UserPreferences prefs = getUserPreferences();
106106
if (prefs != null) {
@@ -112,7 +112,7 @@ private UserProfileEntity(UserDetail user) {
112112
this.domainName = UserDetail.getOrganizationController().getDomain(this.user.getDomainId()).
113113
getName();
114114
} catch (Exception e) {
115-
// Potential errors during getting domain should not break service
115+
// Potential errors during getting domain should not break service
116116
SilverTrace.warn("util", "UserProfileEntity.constructor", "root.EX_IGNORED", e);
117117
}
118118
this.fullName = user.getDisplayedName();
@@ -121,7 +121,6 @@ private UserProfileEntity(UserDetail user) {
121121
this.webPage = getUserProfileWebPageURI();
122122
this.tchatPage = getTchatWebPageURI();
123123
this.anonymous = user.isAnonymous();
124-
125124
}
126125

127126
@Override
@@ -167,7 +166,7 @@ public String geteMail() {
167166
public String getLanguage() {
168167
return language;
169168
}
170-
169+
171170
@Override
172171
public void setAccessLevel(String sAccessLevel) {
173172
this.user.setAccessLevel(sAccessLevel);
@@ -203,7 +202,7 @@ public String getAvatar() {
203202
}
204203
return avatar;
205204
}
206-
205+
207206
/**
208207
* Gets the URL of the WEB page in which is presented the profile of this user.
209208
* @return the URL of the user profile WEB page.
@@ -214,7 +213,7 @@ public String getWebPage() {
214213
}
215214
return webPage;
216215
}
217-
216+
218217
/**
219218
* Gets the URL of the tchat WEB page opened to discuss with this user.
220219
* @return the URL of the user tchat page.
@@ -233,7 +232,7 @@ public String getTchatPage() {
233232
public String getFullName() {
234233
return fullName;
235234
}
236-
235+
237236
/**
238237
* Is this user connected to Silverpeas?
239238
* @return true if the user is connected, false otherwise.
@@ -270,15 +269,15 @@ public void setLogin(String sLogin) {
270269
public String getStatus() {
271270
return user.getStatus();
272271
}
273-
272+
274273
public void setStatus(String newStatus) {
275-
274+
276275
}
277276

278277
public String getDomainName() {
279278
return this.domainName;
280279
}
281-
280+
282281
@Override
283282
public boolean isAnonymous() {
284283
return this.anonymous;
@@ -320,7 +319,7 @@ public int hashCode() {
320319
public URI getURI() {
321320
return this.uri;
322321
}
323-
322+
324323
private String getAvatarURI() {
325324
String avatarURI = this.user.getAvatar();
326325
WebApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
@@ -329,7 +328,7 @@ private String getAvatarURI() {
329328
}
330329
return avatarURI;
331330
}
332-
331+
333332
private String getUserProfileWebPageURI() {
334333
String pageUri = "/Rprofil/jsp/Main?userId=" + this.user.getId();
335334
WebApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
@@ -340,7 +339,7 @@ private String getUserProfileWebPageURI() {
340339
}
341340
return pageUri;
342341
}
343-
342+
344343
private String getTchatWebPageURI() {
345344
String pageUri = "/RcommunicationUser/jsp/OpenDiscussion?userId=" + this.user.getId();
346345
WebApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();

0 commit comments

Comments
 (0)