Skip to content
This repository was archived by the owner on Jan 15, 2022. It is now read-only.

Commit e4c18b9

Browse files
authored
PLF-8554 : Suggestions should be continuously filled from last registered users and shared connections (#411) (#601)
* PLF-8554 : Suggestions should be continuously filled from last registered users and shared connections
1 parent 959f689 commit e4c18b9

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

component/common/src/main/java/org/exoplatform/platform/common/rest/services/SuggestPeoplePortlet/PeopleRestServices.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
import javax.ws.rs.core.SecurityContext;
2828
import javax.ws.rs.core.UriInfo;
2929
import javax.ws.rs.ext.RuntimeDelegate;
30-
import java.util.Collections;
31-
import java.util.LinkedHashMap;
32-
import java.util.List;
33-
import java.util.Map;
30+
import java.util.*;
3431
import java.util.Map.Entry;
3532

3633
@Path("/homepage/intranet/people/")
3734
@Produces("application/json")
3835
public class PeopleRestServices implements ResourceContainer {
3936

37+
private static final int NUMBER_OF_SUGGESTIONS = 10;
4038
private static Log log = ExoLogger.getLogger(PeopleRestServices.class);
4139

4240
private static final CacheControl cacheControl;
@@ -232,27 +230,27 @@ public Response getSuggestions(@Context SecurityContext sc, @Context UriInfo uri
232230

233231
ListAccess<Identity> connectionList = relationshipManager.getConnections(identity);
234232
int size = connectionList.getSize();
235-
Map<Identity, Integer> suggestions;
233+
Map<Identity, Integer> connectionsSuggestions;
236234
if (size > 0) {
237-
suggestions = relationshipManager.getSuggestions(identity, 20, 50, 10);
238-
if (suggestions.size() == 1 && suggestions.keySet().iterator().next().getRemoteId().equals(userACL.getSuperUser())) {
235+
connectionsSuggestions = relationshipManager.getSuggestions(identity, 20, 50, 10);
236+
if (connectionsSuggestions.size() == 1 && connectionsSuggestions.keySet().iterator().next().getRemoteId().equals(userACL.getSuperUser())) {
239237
// The only suggestion is the super user so we clear the suggestion list
240-
suggestions = Collections.emptyMap();
238+
connectionsSuggestions = Collections.emptyMap();
241239
}
242240
} else {
243-
suggestions = Collections.emptyMap();
241+
connectionsSuggestions = Collections.emptyMap();
244242
}
245243

246244
JSONObject jsonGlobal = new JSONObject();
247245
JSONArray jsonArray = new JSONArray();
248-
if (suggestions.isEmpty()) {
246+
Map<Identity, Integer> suggestions = new HashMap<>(connectionsSuggestions);
247+
if (connectionsSuggestions.size() < NUMBER_OF_SUGGESTIONS) {
249248
// Returns the last users
250-
List<Identity> identities = identityManager.getLastIdentities(10);
251-
suggestions = new LinkedHashMap<Identity, Integer>();
249+
List<Identity> identities = identityManager.getLastIdentities(NUMBER_OF_SUGGESTIONS - suggestions.size());
252250
for (Identity id : identities) {
253251
if (identity.equals(id) || relationshipManager.get(identity, id) != null)
254252
continue;
255-
suggestions.put(id, new Integer(0));
253+
suggestions.put(id, 0);
256254
}
257255
}
258256
for (Entry<Identity, Integer> suggestion : suggestions.entrySet()) {

component/common/src/test/java/org/exoplatform/platform/common/rest/services/SuggestPeoplePortlet/TestPeopleRestServices.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public void testSuggestions() throws Exception {
4747
idFoo.setId("foo");
4848
Identity idBar = new Identity(OrganizationIdentityProvider.NAME, "bar");
4949
idBar.setId("bar");
50+
Identity idBaz = new Identity(OrganizationIdentityProvider.NAME, "baz");
51+
idBaz.setId("baz");
52+
Identity idQux = new Identity(OrganizationIdentityProvider.NAME, "qux");
53+
idBaz.setId("qux");
5054
envctx.put(SecurityContext.class, new MockSecurityContext(idFoo.getRemoteId()));
5155

5256
Map<String, Object> imResults = new HashMap<String, Object>();
@@ -84,7 +88,7 @@ public void testSuggestions() throws Exception {
8488
assertTrue(json.has("items"));
8589
assertTrue(json.getJSONArray("items").length() == 0);
8690

87-
// The only suggestion is demo
91+
// The only suggestion is bar
8892
rmResults.put("getConnections", new MockListAccess<Identity>(new Identity[]{idBar}));
8993
rmResults.put("getSuggestions", Collections.singletonMap(idRoot, 1));
9094
rmResults.remove("get");
@@ -94,9 +98,25 @@ public void testSuggestions() throws Exception {
9498
assertEquals("application/json", resp.getContentType().toString());
9599
json = new JSONObject(resp.getEntity().toString());
96100
assertTrue(json.has("items"));
97-
assertTrue(json.getJSONArray("items").length() == 1);
101+
assertEquals(1, json.getJSONArray("items").length());
98102
assertEquals(json.getJSONArray("items").getJSONObject(0).getString("username"), idBar.getRemoteId());
99103

104+
// There is one suggestion and one connection to a contact
105+
// bar is the suggestion since he is a connection
106+
// baz is a new suggestion as he is a new registered user
107+
Map<Identity, Integer> suggestions = new HashMap<>();
108+
suggestions.put(idRoot, 1);
109+
suggestions.put(idBar, 2);
110+
imResults.put("getLastIdentities", Arrays.asList(idRoot, idFoo, idBaz));
111+
rmResults.put("getConnections", new MockListAccess<Identity>(new Identity[]{idQux}));
112+
rmResults.put("getSuggestions", suggestions);
113+
resp = launcher.service("GET", path, "", null, null, envctx);
114+
assertEquals(200, resp.getStatus());
115+
assertEquals("application/json", resp.getContentType().toString());
116+
json = new JSONObject(resp.getEntity().toString());
117+
assertTrue(json.has("items"));
118+
assertEquals(2, json.getJSONArray("items").length());
119+
100120
getContainer().unregisterComponent("UserACL");
101121
getContainer().unregisterComponent("RelationshipManager");
102122
getContainer().unregisterComponent("IdentityManager");

0 commit comments

Comments
 (0)