From 600dddc376fa8d3b43a31dfc001f5eae1ef76e10 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 23 Jul 2019 12:08:12 +0000 Subject: [PATCH] ref 17169: Selection of users in the Sharing panel https://support.d4science.org/issues/17169 Added users discovery by keyword search git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@181296 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/view/sharing/ContactFetcher.java | 11 +- .../client/view/sharing/DialogShareWItem.java | 6 +- .../client/view/sharing/SmartShare.java | 8 +- .../client/view/sharing/UserStore.java | 19 +- .../InfoContactModelSuggestion.java | 49 +++++ .../sharing/multisuggest/MultiValuePanel.java | 196 +++++++++--------- .../ServerMultiWordSuggestOracle.java | 91 ++++++++ .../server/GWTWorkspaceSharingBuilder.java | 71 ++++--- .../server/WorkspaceSharingServiceImpl.java | 31 ++- .../shared/InfoContactModel.java | 95 ++++----- 10 files changed, 378 insertions(+), 199 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/InfoContactModelSuggestion.java create mode 100644 src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/ServerMultiWordSuggestOracle.java diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/ContactFetcher.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/ContactFetcher.java index 4be0c69..8784aa0 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/ContactFetcher.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/ContactFetcher.java @@ -8,17 +8,18 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel import com.google.gwt.user.client.rpc.AsyncCallback; public interface ContactFetcher { - + public void getListContact(AsyncCallback> callback, boolean reloadList); + public void getListSharedUserByFolderId(String sharedFolderId, AsyncCallback> callback); + public List getExclusiveContactsFromAllContact(List listSharedUser); + public void getOwner(String sharedFolderId, AsyncCallback callback); - - public void getInfoContactModelsFromCredential( - List listAlreadySharedContact, + public void getInfoContactModelsFromCredential(List listAlreadySharedContact, AsyncCallback> callback); - + public void getAdministratorsByFolderId(String sharedFolderId, AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java index 65781d1..43d5619 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java @@ -190,7 +190,7 @@ public class DialogShareWItem extends Dialog { for (InfoContactModel infoContactModel : result) { if (infoContactModel.getName() != null) { listAlreadyShared.add(infoContactModel); - suggestPanel.addRecipient(infoContactModel.getName(), false); + suggestPanel.addRecipient(infoContactModel, false); } } @@ -348,7 +348,7 @@ public class DialogShareWItem extends Dialog { initSuggestContacts(); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { - suggestPanel.addRecipient(infoContactModel.getName(), true); + suggestPanel.addRecipient(infoContactModel, true); } // for (InfoContactModel infoContactModel : @@ -398,7 +398,7 @@ public class DialogShareWItem extends Dialog { suggestPanel.resetItemSelected(); for (InfoContactModel contact : listAlreadyShared) { - suggestPanel.addRecipient(contact.getName(), false); + suggestPanel.addRecipient(contact, false); } } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java index cc4dfb1..9a1a16e 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java @@ -155,9 +155,9 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ @Override public void onSuccess(List result) { for (InfoContactModel infoContactModel : result) { - String name = infoContactModel.getName()!=null && !infoContactModel.getName().isEmpty()?infoContactModel.getName():infoContactModel.getLogin(); + //String name = infoContactModel.getName()!=null && !infoContactModel.getName().isEmpty()?infoContactModel.getName():infoContactModel.getLogin(); listAlreadyShared.add(infoContactModel); - suggestPanel.addRecipient(name,false); + suggestPanel.addRecipient(infoContactModel,false); layout(); } lc.unmask(); @@ -317,7 +317,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ initSuggestContacts(); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { - suggestPanel.addRecipient(infoContactModel.getName(),true); + suggestPanel.addRecipient(infoContactModel,true); } // for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { @@ -371,7 +371,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ suggestPanel.resetItemSelected(); for (InfoContactModel contact : listAlreadyShared) { - suggestPanel.addRecipient(contact.getName(), false); + suggestPanel.addRecipient(contact, false); } } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/UserStore.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/UserStore.java index 3c32775..b5220f9 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/UserStore.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/UserStore.java @@ -23,6 +23,8 @@ public class UserStore implements ContactFetcher{ // public boolean syncronizeCleanSharedUser = false; public UserStore() { + loadAllUsersFromServer(); + } @Override @@ -30,7 +32,7 @@ public class UserStore implements ContactFetcher{ loadSharedUserBySharedFolderId(sharedFolderId, callback); } - private void loadAllUsersFromServer(final AsyncCallback> callback){ + private void loadAllUsersFromServer(){ listAllContact = new ArrayList(); @@ -40,13 +42,11 @@ public class UserStore implements ContactFetcher{ public void onSuccess(List result) { GWT.log("Get all contacts loaded "+result.size() + " contacts from server"); listAllContact = result; - callback.onSuccess(listAllContact); } @Override public void onFailure(Throwable caught) { MessageBox.alert("Error", ConstantsSharing.SERVER_ERROR +" retrieving user " + ConstantsSharing.TRY_AGAIN, null); - callback.onFailure(caught); } }); } @@ -128,10 +128,15 @@ public class UserStore implements ContactFetcher{ @Override public void getListContact(AsyncCallback> callback,boolean reloadList) { - if(reloadList || listAllContact==null) - loadAllUsersFromServer(callback); - else - callback.onSuccess(listAllContact); + if(listAllContact==null||listAllContact.isEmpty()){ + callback.onFailure(new Throwable("Error retrieving all users!")); + } else { + callback.onSuccess(listAllContact); + } + //if(reloadList || listAllContact==null) + // loadAllUsersFromServer(callback); + // else + // callback.onSuccess(listAllContact); } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/InfoContactModelSuggestion.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/InfoContactModelSuggestion.java new file mode 100644 index 0000000..5cf310e --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/InfoContactModelSuggestion.java @@ -0,0 +1,49 @@ +package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest; + +import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; + +import com.google.gwt.user.client.ui.SuggestOracle; + +/** + * + * @author Giancarlo Panichi + * + */ +public class InfoContactModelSuggestion implements SuggestOracle.Suggestion { + + private InfoContactModel infoContactModel; + + public InfoContactModelSuggestion(InfoContactModel infoContactModel) { + this.infoContactModel = infoContactModel; + } + + @Override + public String getDisplayString() { + return getReplacementString(); + } + + @Override + public String getReplacementString() { + if (infoContactModel != null && infoContactModel.getName() != null && !infoContactModel.getName().isEmpty()) { + if (infoContactModel.getEmailDomain() == null || infoContactModel.getEmailDomain().isEmpty()) { + return infoContactModel.getName(); + } else { + return infoContactModel.getName() + " (" + infoContactModel.getEmailDomain() + ")"; + + } + } else { + return ""; + } + + } + + public InfoContactModel getInfoContactModel() { + return infoContactModel; + } + + @Override + public String toString() { + return "InfoContactModelSuggestion [infoContactModel=" + infoContactModel + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java index 9795988..4672c4e 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java @@ -7,7 +7,6 @@ import java.util.List; import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.ContactFetcher; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; -import com.extjs.gxt.ui.client.widget.MessageBox; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -16,7 +15,6 @@ import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.MultiWordSuggestOracle; @@ -27,56 +25,66 @@ import com.google.gwt.user.client.ui.TextBox; /** * The Class MultiValuePanel. * - * @author Francesco Mangiacrapa - * Feb 25, 2014 + * @author Francesco Mangiacrapa Feb 25, 2014 */ public class MultiValuePanel extends Composite { -// private final WsMailServiceAsync mailingService = GWT.create(WsMailService.class); - private List itemsSelected = new ArrayList(); + // private final WsMailServiceAsync mailingService = + // GWT.create(WsMailService.class); + // private List itemsSelected = new ArrayList<>(); FlowPanel panel = new FlowPanel(); -// private HandlerManager eventBus; - private HashMap users = new HashMap(); //AN HAST FULLNAME - INFOCONTACTMODEL + // private HandlerManager eventBus; + private HashMap users = new HashMap(); // AN + // HAST + // FULLNAME + // - + // INFOCONTACTMODEL private BulletList listBullet = new BulletList(); private SuggestBox box; - private ContactFetcher userFetch; - private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); //ORACLE OF FULL NAMES - + // private ContactFetcher userFetch; + private ServerMultiWordSuggestOracle oracle = new ServerMultiWordSuggestOracle(); // ORACLE + + /** * Instantiates a new multi value panel. * - * @param userFetch the ContactFetcher - * @param readGroupsFromHL the read groups from hl - * @param readGroupsFromPortal the read groups from portal + * @param userFetch + * the ContactFetcher + * @param readGroupsFromHL + * the read groups from hl + * @param readGroupsFromPortal + * the read groups from portal */ public MultiValuePanel(ContactFetcher userFetch) { - this.userFetch = userFetch; + // this.userFetch = userFetch; initWidget(panel); panel.setWidth("100%"); listBullet.setStyleName("multivalue-panel-suggest"); final ListItem item = new ListItem(); final TextBox itemBox = new TextBox(); - itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium; border: none;"); - box = new SuggestBox(getSuggestions(), itemBox); + itemBox.getElement().setAttribute("style", + "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium; border: none;"); + box = new SuggestBox(oracle, itemBox); item.add(box); listBullet.add(item); - // needed to be set on the itemBox instead of the box, otherwise backspace gets executed twice + // needed to be set on the itemBox instead of the box, otherwise + // backspace gets executed twice itemBox.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { // handle backspace if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) { if ("".equals(itemBox.getValue().trim())) { - if(listBullet.getWidgetCount()>2){ + if (listBullet.getWidgetCount() > 2) { ListItem li = (ListItem) listBullet.getWidget(listBullet.getWidgetCount() - 2); - if(li.getWidget(0) instanceof Paragraph){ + if (li.getWidget(0) instanceof Paragraph) { Paragraph p = (Paragraph) li.getWidget(0); - GWT.log("p "+p.getText() +" is removable : " + p.isRemovable()); - if (itemsSelected.contains(p.getText()) && p.isRemovable()==true) { - itemsSelected.remove(p.getText()); + GWT.log("p " + p.getText() + " is removable : " + p.isRemovable()); + if (users.containsKey(p.getText()) && p.isRemovable() == true) { + users.remove(p.getText()); GWT.log("Removing selected item: " + p.getText() + "'"); listBullet.remove(li); } @@ -90,20 +98,23 @@ public class MultiValuePanel extends Composite { }); box.addSelectionHandler(new SelectionHandler() { + public void onSelection(SelectionEvent selectionEvent) { - chosenContactItem(itemBox, listBullet); + InfoContactModelSuggestion suggest = (InfoContactModelSuggestion) selectionEvent.getSelectedItem(); + chosenContactItem(suggest, itemBox, listBullet); } }); panel.add(listBullet); - box.getElement().setId("suggestion_box"); //needed for the focus on click + box.getElement().setId("suggestion_box"); // needed for the focus on + // click panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()"); } /** * Box set focus. */ - public void boxSetFocus(){ + public void boxSetFocus() { box.getElement().focus(); box.setFocus(true); } @@ -113,17 +124,19 @@ public class MultiValuePanel extends Composite { * * @return the flow panel */ - public FlowPanel getFlowPanel(){ + public FlowPanel getFlowPanel() { return panel; } /** * actually insert the contact in the flow panel. * - * @param itemBox the item box - * @param list the list + * @param itemBox + * the item box + * @param list + * the list */ - private void chosenContactItem(final TextBox itemBox, final BulletList list) { + private void chosenContactItem(InfoContactModelSuggestion suggest, final TextBox itemBox, final BulletList list) { if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) { final ListItem displayItem = new ListItem(); displayItem.setStyleName("multivalue-panel-token-ws"); @@ -139,10 +152,11 @@ public class MultiValuePanel extends Composite { displayItem.add(p); displayItem.add(span); - //original value of the item selected + // original value of the item selected GWT.log("Adding selected item '" + itemBox.getValue()); - itemsSelected.add(itemBox.getValue()); - GWT.log("Total: " + itemsSelected); + // itemsSelected.add(itemBox.getValue()); + // GWT.log("Total: " + itemsSelected); + users.put(itemBox.getValue(), suggest.getInfoContactModel()); list.insert(displayItem, list.getWidgetCount() - 1); itemBox.setValue(""); @@ -160,11 +174,11 @@ public class MultiValuePanel extends Composite { return new ArrayList(); else { List toReturn = new ArrayList(); -// GWT.log("Selected User: "+itemsSelected); -// GWT.log("users: "+users); - for (String fullName : itemsSelected) { + // GWT.log("Selected User: "+itemsSelected); + // GWT.log("users: "+users); + for (String fullName : users.keySet()) { InfoContactModel wsuser = users.get(fullName); - if(wsuser!= null && !toReturn.contains(wsuser)) + if (wsuser != null && !toReturn.contains(wsuser)) toReturn.add(wsuser); } return toReturn; @@ -174,12 +188,15 @@ public class MultiValuePanel extends Composite { /** * Removes the list item. * - * @param displayItem the display item - * @param list the list + * @param displayItem + * the display item + * @param list + * the list */ private void removeListItem(ListItem displayItem, BulletList list) { GWT.log("Removing: " + displayItem.getWidget(0).getElement().getInnerHTML(), null); - itemsSelected.remove(displayItem.getWidget(0).getElement().getInnerHTML()); + // itemsSelected.remove(displayItem.getWidget(0).getElement().getInnerHTML()); + users.remove(displayItem.getWidget(0).getElement().getInnerHTML()); list.remove(displayItem); } @@ -189,83 +206,74 @@ public class MultiValuePanel extends Composite { * @return names of possible contacts */ private MultiWordSuggestOracle getSuggestions() { - userFetch.getListContact(contacts, false); + // userFetch.getListContact(contacts, false); return oracle; } - - /** - * Update suggestions. + /* + * /** Update suggestions. * * @param result the result + * + * public void updateSuggestions(List result) { + * + * oracle.clear(); + * + * for (InfoContactModel wsUser : result) { oracle.add(wsUser.getName()); + * + * } } + * + * + * private AsyncCallback> contacts = new + * AsyncCallback>() { + * + * @Override public void onFailure(Throwable caught) { + * GWT.log("Error on loading contacts"); MessageBox.alert("Error", + * caught.getMessage(), null); } + * + * @Override public void onSuccess(List result) { + * users.clear(); for (InfoContactModel wsUser : result) { String fullName = + * wsUser.getName(); if(users.containsKey(fullName)){ //case of homonimy + * fullName = fullName+"_"; users.put(fullName, wsUser); }else + * users.put(fullName, wsUser); + * + * oracle.add(fullName); } } }; */ - public void updateSuggestions(List result) { - - oracle.clear(); - - for (InfoContactModel wsUser : result) { - oracle.add(wsUser.getName()); - - } - } - - - private AsyncCallback> contacts = new AsyncCallback>() { - - @Override - public void onFailure(Throwable caught) { - GWT.log("Error on loading contacts"); - MessageBox.alert("Error", caught.getMessage(), null); - } - - @Override - public void onSuccess(List result) { - users.clear(); - for (InfoContactModel wsUser : result) { - String fullName = wsUser.getName(); - if(users.containsKey(fullName)){ //case of homonimy - fullName = fullName+"_"; - users.put(fullName, wsUser); - }else - users.put(fullName, wsUser); - - oracle.add(fullName); - } - } - }; /** * Reset item selected. */ - public void resetItemSelected(){ + public void resetItemSelected() { listBullet.clear(); - itemsSelected.clear(); + // itemsSelected.clear(); + users.clear(); ListItem item = new ListItem(); item.add(box); listBullet.add(item); } - /** * Adds the recipient. * - * @param fullName the full name - * @param displayRemoveItem the display remove item + * @param fullName + * the full name + * @param displayRemoveItem + * the display remove item */ - public void addRecipient(String fullName, boolean displayRemoveItem) { + public void addRecipient(InfoContactModel infoContactModel, boolean displayRemoveItem) { - if (fullName != null) { + if (infoContactModel != null) { TextBox itemBox = new TextBox(); - itemBox.setText(fullName); - itemBox.setValue(fullName); + itemBox.setText(infoContactModel.getName()); + itemBox.setValue(infoContactModel.getName()); final ListItem displayItem = new ListItem(); - Paragraph p = new Paragraph(fullName); + Paragraph p = new Paragraph(infoContactModel.getName()); displayItem.add(p); - if(displayRemoveItem){ + if (displayRemoveItem) { displayItem.setStyleName("multivalue-panel-token-ws"); p.setRemovable(true); Span span = new Span("x"); @@ -276,17 +284,17 @@ public class MultiValuePanel extends Composite { }); displayItem.add(span); - } - else{ + } else { displayItem.setStyleName("multivalue-panel-token-ws-notselectable"); p.setRemovable(false); } GWT.log("Adding selected wp item '" + itemBox.getValue()); - itemsSelected.add(itemBox.getValue()); - GWT.log("Total: " + itemsSelected); + // itemsSelected.add(itemBox.getValue()); + // GWT.log("Total: " + itemsSelected); + users.put(infoContactModel.getName(), infoContactModel); - listBullet.insert(displayItem, listBullet.getWidgetCount()-1); + listBullet.insert(displayItem, listBullet.getWidgetCount() - 1); itemBox.setValue(""); itemBox.setFocus(true); } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/ServerMultiWordSuggestOracle.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/ServerMultiWordSuggestOracle.java new file mode 100644 index 0000000..28e7302 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/ServerMultiWordSuggestOracle.java @@ -0,0 +1,91 @@ +package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync; +import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; + +import com.google.gwt.core.shared.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.MultiWordSuggestOracle; + +/** + * + * @author Giancarlo Panichi + * + */ +public class ServerMultiWordSuggestOracle extends MultiWordSuggestOracle { + + private static final int DEFAULT_QUERY_LENGHT = 1; + //private int startQueryLength; + private ArrayList suggestions = new ArrayList<>(); + //private boolean isMoreSuggestions = false; + //private int previousQueryLength = 0; + + public ServerMultiWordSuggestOracle() { + this(DEFAULT_QUERY_LENGHT); + } + + public ServerMultiWordSuggestOracle(int startQueryLength) { + super(); + //this.startQueryLength = startQueryLength; + } + + + @Override + public void requestSuggestions(final Request request, final Callback callback) { + // start the backend call only if the user types in more than + // startQueryLength characters. + //if (request.getQuery().length() < startQueryLength) + // return; + // if the user expands the search or a search hasn't been carried out, + // call the backend. Otherwise use the existing list + //if (isMoreSuggestions || previousQueryLength > request.getQuery().length() || suggestions.size() == 0) { + String keyword = request.getQuery(); + keyword = keyword.toLowerCase(); + + WorkspaceSharingServiceAsync.INSTANCE.getUsersByKeyword(keyword, + new AsyncCallback>() { + + @Override + public void onSuccess(List result) { + suggestions.clear(); + for (int i = 0; i < result.size(); i++) { + InfoContactModelSuggestion suggestion = new InfoContactModelSuggestion(result.get(i)); + suggestions.add(suggestion); + } + + MultiWordSuggestOracle.Response response = new MultiWordSuggestOracle.Response(suggestions); + // isMoreSuggestions = isMore; + + /*if (result == null || result.isEmpty()) { + response.setMoreSuggestions(false); + } else { + + int count = result.size() - request.getLimit(); + if (count > 0) { + response.setMoreSuggestionsCount(count); + } else { + response.setMoreSuggestions(false); + } + }*/ + //previousQueryLength = request.getQuery().length(); + callback.onSuggestionsReady(request, response); + + } + + @Override + public void onFailure(Throwable caught) { + GWT.log("Error retrieving users in ServerMultiWordSuggest", caught); + } + }); + + //} else { + // super.requestSuggestions(request, callback); + //} + } + + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java index 5848cbc..92f9680 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java @@ -67,31 +67,31 @@ public class GWTWorkspaceSharingBuilder { if (hashTestUser == null) { hashTestUser = new HashMap(); - hashTestUser.put("federico.defaveri", - new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri", false)); + hashTestUser.put("federico.defaveri", new InfoContactModel("federico.defaveri", "federico.defaveri", + "Federico de Faveri", "@isti.cnr.it", false)); hashTestUser.put("antonio.gioia", - new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia", false)); + new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia", "@isti.cnr.it", false)); - hashTestUser.put("fabio.sinibaldi", - new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi", false)); + hashTestUser.put("fabio.sinibaldi", new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", + "Fabio Sinibaldi", "@isti.cnr.it", false)); - hashTestUser.put("pasquale.pagano", - new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano", false)); + hashTestUser.put("pasquale.pagano", new InfoContactModel("pasquale.pagano", "pasquale.pagano", + "Pasquale Pagano", "@isti.cnr.it", false)); hashTestUser.put("francesco.mangiacrapa", new InfoContactModel("francesco.mangiacrapa", - "francesco.mangiacrapa", "Francesco Mangiacrapa", false)); + "francesco.mangiacrapa", "Francesco Mangiacrapa", "@isti.cnr.it", false)); hashTestUser.put("massimiliano.assante", new InfoContactModel("massimiliano.assante", - "massimiliano.assante", "Massimiliano Assante", false)); + "massimiliano.assante", "Massimiliano Assante", "@isti.cnr.it", false)); - hashTestUser.put("leonardo.candela", - new InfoContactModel("leonardo.candela", "leonardo.candela", "Leonardo Candela", false)); + hashTestUser.put("leonardo.candela", new InfoContactModel("leonardo.candela", "leonardo.candela", + "Leonardo Candela", "@isti.cnr.it", false)); - hashTestUser.put("valentina.marioli", - new InfoContactModel("valentina.marioli", "valentina.marioli", "Valentina Marioli", false)); + hashTestUser.put("valentina.marioli", new InfoContactModel("valentina.marioli", "valentina.marioli", + "Valentina Marioli", "@isti.cnr.it", false)); - hashTestUser.put("devVRE", new InfoContactModel("devVRE", "devVRE", "devVRE", true)); + hashTestUser.put("devVRE", new InfoContactModel("devVRE", "devVRE", "devVRE", "", true)); // hashTestUser.put(WsUtil.TEST_USER.toString(), // new InfoContactModel( @@ -166,7 +166,7 @@ public class GWTWorkspaceSharingBuilder { logger.warn("Skipping group with null or empty name " + group); else { InfoContactModel contact = new InfoContactModel(group.getGroupName(), group.getGroupName(), groupDN, - true); + "", true); logger.trace("Adding group " + contact); listContactsModel.add(contact); } @@ -178,7 +178,7 @@ public class GWTWorkspaceSharingBuilder { logger.warn("Skipping group with null or empty name " + group); else listContactsModel.add(new InfoContactModel(group.getGroupName(), group.getGroupName(), - group.getGroupName(), true)); + group.getGroupName(), "", true)); } } @@ -249,6 +249,18 @@ public class GWTWorkspaceSharingBuilder { return listContactsModel; } + /** + * utility method extract the @domain.com from an email address + * return @unknown-domain in case of no emails + */ + private String extractDomainFromEmail(String email) { + int index = email.indexOf('@'); + if (index > 0) + return email.substring(index); + else + return "@unknown-domain"; + } + /** * * @param info @@ -275,8 +287,8 @@ public class GWTWorkspaceSharingBuilder { String fullName = userModel.getFullname(); if (fullName != null && !fullName.isEmpty()) - listContactsModel.add( - new InfoContactModel(userModel.getUserId() + "", userModel.getUsername(), fullName, false)); + listContactsModel.add(new InfoContactModel(userModel.getUserId() + "", userModel.getUsername(), + fullName, extractDomainFromEmail(userModel.getEmail()), false)); else logger.trace("buildGXTListContactsModel is not returning user: " + userModel.getUsername() + "because name is null or empty"); @@ -285,8 +297,7 @@ public class GWTWorkspaceSharingBuilder { return listContactsModel; } - - + /** * * @param info @@ -295,7 +306,8 @@ public class GWTWorkspaceSharingBuilder { * @throws Exception * Error */ - public List buildGXTListContactsModelFromUserModel(PortalContextInfo info,GGroup gGroup) throws Exception { + public List buildGXTListContactsModelFromUserModel(PortalContextInfo info, GGroup gGroup) + throws Exception { List listUsers = new LiferayUserManager().listUsersByGroup(gGroup.getGroupId()); @@ -313,8 +325,8 @@ public class GWTWorkspaceSharingBuilder { String fullName = userModel.getFullname(); if (fullName != null && !fullName.isEmpty()) - listContactsModel.add( - new InfoContactModel(userModel.getUserId() + "", userModel.getUsername(), fullName, false)); + listContactsModel.add(new InfoContactModel(userModel.getUserId() + "", userModel.getUsername(), + fullName, extractDomainFromEmail(userModel.getEmail()), false)); else logger.trace("buildGXTListContactsModel is not returning user: " + userModel.getUsername() + "because name is null or empty"); @@ -324,7 +336,6 @@ public class GWTWorkspaceSharingBuilder { return listContactsModel; } - public ArrayList getVREList(PortalContextInfo info) throws Exception { try { @@ -362,14 +373,16 @@ public class GWTWorkspaceSharingBuilder { List listInfoContactModel = new ArrayList<>(); UserManager userManager = new LiferayUserManager(); List users = userManager.searchUsersByGroup(keyword, info.getCurrGroupId()); - for (GCubeUser user : users) { + + for (int i = 0; i < users.size() && i < 30; i++) { + GCubeUser user = users.get(i); InfoContactModel icm = new InfoContactModel(String.valueOf(user.getUserId()), user.getUsername(), - user.getFullname(), false); + user.getFullname(), extractDomainFromEmail(user.getEmail()), false); listInfoContactModel.add(icm); } return listInfoContactModel; } catch (Exception e) { - logger.error("Error retrieving the users by keyword: "+e.getLocalizedMessage(), e); + logger.error("Error retrieving the users by keyword: " + e.getLocalizedMessage(), e); throw e; } } @@ -408,7 +421,7 @@ public class GWTWorkspaceSharingBuilder { logger.warn("Contact login is null, return empty"); portalLogin = ""; } - return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin), false); + return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin), "", false); } /** @@ -436,7 +449,7 @@ public class GWTWorkspaceSharingBuilder { groupName = groupLogin; } - return new InfoContactModel(groupLogin, groupLogin, groupName, true); + return new InfoContactModel(groupLogin, groupLogin, groupName, "", true); } /** diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java index 60b99f0..a01022d 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java @@ -176,7 +176,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements public List getUsersByKeyword(String keyword) throws Exception { try { - logger.info("Call getUsersByKeyword(): keyword="+keyword); + logger.info("Call getUsersByKeyword(): keyword=" + keyword); PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest()); @@ -192,7 +192,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception("Error retrieving list of contacts!", e); } } - + @Override public List getVREList() throws Exception { try { @@ -208,13 +208,12 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception("Error retrieving VRE List!", e); } } - - + @Override public List getAllContactsByVRE(GGroup gGroup) throws Exception { try { - logger.info("Call getAllContactsByVRE(): "+gGroup); + logger.info("Call getAllContactsByVRE(): " + gGroup); if (isTestMode()) { logger.debug("WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS AND GROUPS"); @@ -231,7 +230,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); - List listContactsModel = builder.buildGXTListContactsModelFromUserModel(info,gGroup); + List listContactsModel = builder.buildGXTListContactsModelFromUserModel(info, gGroup); // listContactsModel.addAll(builder.getGXTListContactsModelFromVOs(info)); @@ -244,7 +243,6 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } - /* * (non-Javadoc) * @@ -294,6 +292,18 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } + /** + * utility method extract the @domain.com from an email address + * return @unknown-domain in case of no emails + */ + private String extractDomainFromEmail(String email) { + int index = email.indexOf('@'); + if (index > 0) + return email.substring(index); + else + return "@unknown-domain"; + } + private List retrieveUsersListFromSharedFolder(SharedFolder sharedFolder) throws Exception { Metadata metadata = sharedFolder.getUsers(); if (metadata != null) { @@ -311,7 +321,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements logger.warn("Invalid info for user " + username, e); } if (curr != null && curr.getFullname() != null && !curr.getFullname().isEmpty()) { - InfoContactModel userInfo = new InfoContactModel(username, username, curr.getFullname(), false); + InfoContactModel userInfo = new InfoContactModel(username, username, curr.getFullname(), + extractDomainFromEmail(curr.getEmail()), false); listShared.add(userInfo); } } @@ -362,7 +373,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } logger.debug("Owner not found from user model!"); - return new InfoContactModel(item.getOwner(), item.getOwner(), item.getOwner(), false); + return new InfoContactModel(item.getOwner(), item.getOwner(), item.getOwner(), "", false); } else { logger.debug("Owner not found from item"); return new InfoContactModel(); @@ -1114,7 +1125,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements logger.info("Unshared folded for users: " + users); ArrayList listContacts = new ArrayList<>(); for (String key : users) { - InfoContactModel contact = new InfoContactModel(key, key, key, false); + InfoContactModel contact = new InfoContactModel(key, key, key, "",false); listContacts.add(contact); } NotificationsProducer np = getNotificationProducer( diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/InfoContactModel.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/InfoContactModel.java index 77f2396..29169f5 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/InfoContactModel.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/InfoContactModel.java @@ -6,50 +6,34 @@ import java.util.Comparator; import com.extjs.gxt.ui.client.data.BaseModelData; /** - * @author Francesco Mangiacrapa + * @author Francesco Mangiacrapa * */ public class InfoContactModel extends BaseModelData implements Serializable, Comparable { - /** * */ private static final long serialVersionUID = -6158514541724213534L; - + protected static final String ID = "id"; public static final String FULLNAME = "fullname"; public static final String LOGIN = "login"; + public static final String EMAIL_DOMAIN = "emailDomain"; public static final String ISGROUP = "isgroup"; - + private CredentialModel referenceCredential; + public InfoContactModel() { + } - public InfoContactModel() {} - - public InfoContactModel(String id, String login, String fullName, boolean isGroup) { + public InfoContactModel(String id, String login, String fullName, String emailDomain, boolean isGroup) { setId(id); setLogin(login); setName(fullName); + setEmailDomain(emailDomain); setIsGroup(isGroup); } - - public void setIsGroup(boolean isGroup){ - set(ISGROUP, isGroup); - } - - public Boolean isGroup(){ - return (Boolean) get(ISGROUP); - } - - public void setName(String name) { - set(FULLNAME,name); - - } - - public String getName(){ - return get(FULLNAME); - } public String getId() { return get(ID); @@ -67,7 +51,31 @@ public class InfoContactModel extends BaseModelData implements Serializable, Com set(LOGIN, login); } - + public String getName() { + return get(FULLNAME); + } + + public void setName(String name) { + set(FULLNAME, name); + + } + + public String getEmailDomain() { + return (String) get(EMAIL_DOMAIN); + } + + public void setEmailDomain(String emailDomain) { + set(EMAIL_DOMAIN, emailDomain); + } + + public Boolean isGroup() { + return (Boolean) get(ISGROUP); + } + + public void setIsGroup(boolean isGroup) { + set(ISGROUP, isGroup); + } + public static Comparator COMPARATORLOGINS = new Comparator() { // This is where the sorting happens. public int compare(InfoContactModel o1, InfoContactModel o2) { @@ -75,7 +83,6 @@ public class InfoContactModel extends BaseModelData implements Serializable, Com } }; - /** * @return the referenceCredential */ @@ -84,45 +91,39 @@ public class InfoContactModel extends BaseModelData implements Serializable, Com } /** - * @param referenceCredential the referenceCredential to set + * @param referenceCredential + * the referenceCredential to set */ public void setReferenceCredential(CredentialModel referenceCredential) { this.referenceCredential = referenceCredential; } - - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(InfoContactModel o) { return InfoContactModel.COMPARATORLOGINS.compare(this, o); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { int compare = compareTo((InfoContactModel) obj); - return compare == 0? true:false; + return compare == 0 ? true : false; } - + @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("InfoContactModel [isGroup()="); - builder.append(isGroup()); - builder.append(", getName()="); - builder.append(getName()); - builder.append(", getId()="); - builder.append(getId()); - builder.append(", getLogin()="); - builder.append(getLogin()); - builder.append(", getReferenceCredential()="); - builder.append(getReferenceCredential()); - builder.append("]"); - return builder.toString(); + return "InfoContactModel [getId()=" + getId() + ", getLogin()=" + getLogin() + ", getName()=" + getName() + + ", getEmailDomain()=" + getEmailDomain() + ", isGroup()=" + isGroup() + ", getReferenceCredential()=" + + getReferenceCredential() + "]"; } + } \ No newline at end of file