git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/pickitem-widget@169023 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bcc5f729ae
commit
7115d7675e
|
@ -58,7 +58,7 @@ public class PickItemsDialog extends PopupPanel {
|
|||
private int itemCursorIndexStart = -1;
|
||||
boolean handleNonCharKeys = false;
|
||||
|
||||
private MultiWordSuggestOracle oracle = new UserOracle(); //by default we use the async version;
|
||||
private MultiWordSuggestOracle oracle;
|
||||
|
||||
private int displayIndexSelected;
|
||||
|
||||
|
@ -67,6 +67,8 @@ public class PickItemsDialog extends PopupPanel {
|
|||
private char triggerChar;
|
||||
private ArrayList<ItemBean> beans;
|
||||
|
||||
private String context; //e.g. /gcube/devNext/NextNext
|
||||
|
||||
//needed because is selected when it popups
|
||||
private Widget first;
|
||||
private boolean hasPhoto;
|
||||
|
@ -80,14 +82,12 @@ public class PickItemsDialog extends PopupPanel {
|
|||
|
||||
/**
|
||||
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
||||
* @param the list of user to pick
|
||||
* @param the list of user to pick as {@link ArrayList} of {@link ItemBean}
|
||||
* @param eventBus the event bus on where the widget will fire the selected user event
|
||||
* @param widthInPixel the desired width (grater than 199 pixel)
|
||||
* @param hasPhoto tell of you have want to show photo for the item or not
|
||||
* @param includeTriggerChar true if your suggestions start with the trigger char (e.g. #anHashTag triggered by #) false otherwise
|
||||
*/
|
||||
public PickItemsDialog(char triggerChar, ArrayList<ItemBean> beans, final HandlerManager eventBus, int widthInPixel) {
|
||||
this(triggerChar, eventBus, widthInPixel);
|
||||
this(triggerChar, eventBus, widthInPixel, null);
|
||||
this.beans = beans;
|
||||
oracle = new MultiWordSuggestOracle(); //not async version
|
||||
GWT.log("new constructor");
|
||||
|
@ -103,19 +103,20 @@ public class PickItemsDialog extends PopupPanel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use this constructor for users, the list of the users is automatically loaded form the VRE members if in a VRE or from the union of the current's user VRE members if at root level
|
||||
* Use this constructor for users, the list of the users is automatically loaded from the VRE passed in the context param
|
||||
* Note that you must declare the pick item widget servlet in this case
|
||||
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
||||
* @param eventBus the event bus on where the widget will fire the selected user event
|
||||
* @param widthInPixel the desired width (grater than 199 pixel)
|
||||
* @param hasPhoto tell of you have want to show photo for the item or not
|
||||
* @param includeTriggerChar true if your suggestions start with the trigger char (e.g. #anHashTag triggered by #) false otherwise
|
||||
* @param context the context (VRE scope e.g. /gcube/devNext/NextNext) from where to load the users and groups
|
||||
*/
|
||||
public PickItemsDialog(char triggerChar, final HandlerManager eventBus, int widthInPixel) {
|
||||
public PickItemsDialog(char triggerChar, final HandlerManager eventBus, int widthInPixel, String context) {
|
||||
super(true, false);
|
||||
if (widthInPixel < 200) {
|
||||
throw new IllegalArgumentException("width must be greater than 199");
|
||||
}
|
||||
this.context = context;
|
||||
oracle = new UserOracle(context); //by default we use the async version;
|
||||
this.eventBus = eventBus;
|
||||
this.triggerChar = triggerChar;
|
||||
this.includeTriggerChar = false;
|
||||
|
@ -167,7 +168,7 @@ public class PickItemsDialog extends PopupPanel {
|
|||
//just used in devlopment
|
||||
private List<ItemBean> getAllUsers() {
|
||||
List<ItemBean> toReturn = new ArrayList<>();
|
||||
toReturn.add(new ItemBean("andrea.rossi", "andrea.rossi", "Andrea Rossi", "m.assante@gmail.com"));
|
||||
toReturn.add(new ItemBean("id", "username", "Andrea Rossi Dev", "email"));
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -15,21 +15,20 @@ public class UserOracle extends MultiWordSuggestOracle{
|
|||
private final PickItemServiceAsync pickuserService = GWT.create(PickItemService.class);
|
||||
|
||||
private List<ItemBean> contacts = new LinkedList<>();
|
||||
private String context;
|
||||
|
||||
public UserOracle(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void addContacts(List<ItemBean> users) {
|
||||
contacts.addAll(users);
|
||||
}
|
||||
|
||||
public UserOracle() {
|
||||
//((ServiceDefTarget) pickuserService).setServiceEntryPoint(Utils.getServiceEntryPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestSuggestions(final Request request, final Callback callback) {
|
||||
GWT.log("UserOracl requestSuggestions");
|
||||
final Response resp = new Response();
|
||||
if(contacts.isEmpty()){
|
||||
GWT.log("callback.onSuggestionsReady");
|
||||
callback.onSuggestionsReady(request, resp);
|
||||
return;
|
||||
}
|
||||
|
@ -37,8 +36,7 @@ public class UserOracle extends MultiWordSuggestOracle{
|
|||
text = text.toLowerCase();
|
||||
|
||||
final List<UserSuggestion> list = new ArrayList<>();
|
||||
GWT.log("calling searchEntities ..." + text);
|
||||
pickuserService.searchEntities(text, new AsyncCallback<ArrayList<ItemBean>>() {
|
||||
pickuserService.searchEntities(text, context, new AsyncCallback<ArrayList<ItemBean>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable arg0) {
|
||||
|
|
|
@ -8,5 +8,5 @@ import com.google.gwt.user.client.rpc.RemoteService;
|
|||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
@RemoteServiceRelativePath("pickItemServlet")
|
||||
public interface PickItemService extends RemoteService {
|
||||
ArrayList<ItemBean> searchEntities(String keyword);
|
||||
ArrayList<ItemBean> searchEntities(String keyword, String vreContext);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||
|
||||
public interface PickItemServiceAsync {
|
||||
|
||||
void searchEntities(String keyword, AsyncCallback<ArrayList<ItemBean>> callback);
|
||||
void searchEntities(String keyword, String vreContext, AsyncCallback<ArrayList<ItemBean>> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,16 @@ package org.gcube.portlets.widgets.pickitem.server;
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemService;
|
||||
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -15,16 +19,18 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.kernel.dao.orm.QueryUtil;
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.util.OrderByComparator;
|
||||
import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
|
||||
import com.liferay.portal.model.Team;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.service.TeamLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PickItemServiceImpl extends RemoteServiceServlet implements PickItemService {
|
||||
private static final Logger _log = LoggerFactory.getLogger(PickItemServiceImpl.class);
|
||||
//this map is used as cache containing the association between a context and a GroupId so that we don't ask everytime.
|
||||
private static HashMap<String, Long> contextToGroupIdMap = new HashMap<>();
|
||||
/**
|
||||
*
|
||||
* @return true if you're running into the portal, false if in development
|
||||
|
@ -39,25 +45,47 @@ public class PickItemServiceImpl extends RemoteServiceServlet implements PickIte
|
|||
return false;
|
||||
}
|
||||
}
|
||||
//TODO: Questo metodo lunedì va modificato per fargli cercare non tutti gli utenti ma dipdende dallo scope i VRE Members oppure l'unione se è root, e poi vanno gestiti i gruppi stessa cosa.
|
||||
//anzi dovresti farti passare come parametro la VRE dove è stato postato il post allora sarebbe semplicissimo, niente union non serve
|
||||
|
||||
private long getGroupIdFromContext(String context) {
|
||||
if (contextToGroupIdMap.containsKey(context))
|
||||
return contextToGroupIdMap.get(context);
|
||||
try {
|
||||
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(context);
|
||||
contextToGroupIdMap.put(context, new Long(groupId));
|
||||
return groupId;
|
||||
} catch (IllegalArgumentException | UserManagementSystemException | GroupRetrievalFault e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemBean> searchEntities(String keyword) {
|
||||
public ArrayList<ItemBean> searchEntities(String keyword, String context) {
|
||||
ArrayList<ItemBean> toReturn = new ArrayList<>();
|
||||
if (isWithinPortal()) {
|
||||
OrderByComparator comparator = OrderByComparatorFactoryUtil.create("User_", "screenname", true);
|
||||
LinkedHashMap<String, Object> params = new LinkedHashMap<>();
|
||||
long currentGroupId = getGroupIdFromContext(context);
|
||||
params.put("usersGroups", currentGroupId);
|
||||
try {
|
||||
_log.debug("Searching " + keyword);
|
||||
List<User> lrUsers = UserLocalServiceUtil.search(ManagementUtils.getCompany().getCompanyId(), keyword, 0, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, comparator);
|
||||
for (User user : lrUsers) {
|
||||
_log.debug("Searching " + keyword + " on " + context);
|
||||
List<User> usersByGroup = UserLocalServiceUtil.search(
|
||||
ManagementUtils.getCompany().getCompanyId(), keyword, 0, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, comparator);
|
||||
for (User user : usersByGroup) {
|
||||
toReturn.add(new ItemBean(""+user.getUserId(), user.getScreenName(), user.getFullName(), getUserImagePortraitUrlLocal(user.getScreenName())));
|
||||
}
|
||||
} catch (SystemException | PortalException e) {
|
||||
|
||||
OrderByComparator teamComparator = OrderByComparatorFactoryUtil.create("team", "name", true);
|
||||
List<Team> teams = TeamLocalServiceUtil.search(currentGroupId, keyword, "", null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, teamComparator);
|
||||
for (Team team : teams) {
|
||||
toReturn.add(new ItemBean(team.getTeamId()+"", team.getName()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else { //development
|
||||
for (int i = 0; i < 10; i++) {
|
||||
toReturn.add(new ItemBean("andrea.rossi", "andrea.rossi", "Andrea Rossi", "m.assante@gmail.com"));
|
||||
toReturn.add(new ItemBean("id", "andrea.rossi", "Andrea Rossi", "email"));
|
||||
if (i % 2 == 0)
|
||||
toReturn.add(new ItemBean(""+i, "username"+i, "userGetFullname()"+i, "user.getEmail()"+i));
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue