async version of getusers implementation almost finished
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/pickitem-widget@168992 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
024e218872
commit
bcc5f729ae
|
@ -29,7 +29,7 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
|
72
pom.xml
72
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.widgets</groupId>
|
<groupId>org.gcube.portlets.widgets</groupId>
|
||||||
<artifactId>pickitem-widget</artifactId>
|
<artifactId>pickitem-widget</artifactId>
|
||||||
<version>1.3.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>gCube Pick Item Widget</name>
|
<name>gCube Pick Item Widget</name>
|
||||||
<description>
|
<description>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<gwtVersion>2.7.0</gwtVersion>
|
<gwtVersion>2.7.0</gwtVersion>
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -52,6 +52,36 @@
|
||||||
<version>${gwtVersion}</version>
|
<version>${gwtVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.portlet</groupId>
|
||||||
|
<artifactId>portlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.dvos</groupId>
|
||||||
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>portal-service</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>util-java</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -66,8 +96,8 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>${maven.compiler.source}</source>
|
||||||
<target>1.7</target>
|
<target>${maven.compiler.target}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
@ -144,23 +174,23 @@
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- GWT Maven Plugin -->
|
<!-- GWT Maven Plugin -->
|
||||||
<!-- <plugin> -->
|
<!-- <plugin> -->
|
||||||
<!-- <groupId>org.codehaus.mojo</groupId> -->
|
<!-- <groupId>org.codehaus.mojo</groupId> -->
|
||||||
<!-- <artifactId>gwt-maven-plugin</artifactId> -->
|
<!-- <artifactId>gwt-maven-plugin</artifactId> -->
|
||||||
<!-- <version>2.5.1</version> -->
|
<!-- <version>2.5.1</version> -->
|
||||||
<!-- <executions> -->
|
<!-- <executions> -->
|
||||||
<!-- <execution> -->
|
<!-- <execution> -->
|
||||||
<!-- <goals> -->
|
<!-- <goals> -->
|
||||||
<!-- <goal>compile</goal> -->
|
<!-- <goal>compile</goal> -->
|
||||||
<!-- <goal>test</goal> -->
|
<!-- <goal>test</goal> -->
|
||||||
<!-- </goals> -->
|
<!-- </goals> -->
|
||||||
<!-- </execution> -->
|
<!-- </execution> -->
|
||||||
<!-- </executions> -->
|
<!-- </executions> -->
|
||||||
<!-- <configuration> -->
|
<!-- <configuration> -->
|
||||||
<!-- <runTarget>PickItem.html</runTarget> -->
|
<!-- <runTarget>PickItem.html</runTarget> -->
|
||||||
<!-- <hostedWebapp>${webappDirectory}</hostedWebapp> -->
|
<!-- <hostedWebapp>${webappDirectory}</hostedWebapp> -->
|
||||||
<!-- </configuration> -->
|
<!-- </configuration> -->
|
||||||
<!-- </plugin> -->
|
<!-- </plugin> -->
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.gcube.portlets.widgets.pickitem.client.dialog;
|
package org.gcube.portlets.widgets.pickitem.client.dialog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
|
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
|
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.oracle.UserOracle;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.oracle.UserSuggestion;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.NoPhotoTemplate;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.NoPhotoTemplate;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate;
|
||||||
|
@ -55,7 +58,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
private int itemCursorIndexStart = -1;
|
private int itemCursorIndexStart = -1;
|
||||||
boolean handleNonCharKeys = false;
|
boolean handleNonCharKeys = false;
|
||||||
|
|
||||||
private final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
|
private MultiWordSuggestOracle oracle = new UserOracle(); //by default we use the async version;
|
||||||
|
|
||||||
private int displayIndexSelected;
|
private int displayIndexSelected;
|
||||||
|
|
||||||
|
@ -70,7 +73,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
private boolean includeTriggerChar;
|
private boolean includeTriggerChar;
|
||||||
//to explain
|
//to explain
|
||||||
private boolean stopListening = true;
|
private boolean stopListening = true;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
CssAndImages.INSTANCE.css().ensureInjected();
|
CssAndImages.INSTANCE.css().ensureInjected();
|
||||||
}
|
}
|
||||||
|
@ -84,6 +87,31 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
* @param includeTriggerChar true if your suggestions start with the trigger char (e.g. #anHashTag triggered by #) false otherwise
|
* @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) {
|
public PickItemsDialog(char triggerChar, ArrayList<ItemBean> beans, final HandlerManager eventBus, int widthInPixel) {
|
||||||
|
this(triggerChar, eventBus, widthInPixel);
|
||||||
|
this.beans = beans;
|
||||||
|
oracle = new MultiWordSuggestOracle(); //not async version
|
||||||
|
GWT.log("new constructor");
|
||||||
|
//add the user fill names to the oracle
|
||||||
|
for (ItemBean bean : beans) {
|
||||||
|
oracle.add(bean.getAlternativeName());
|
||||||
|
|
||||||
|
// if it is a team, set the avatar
|
||||||
|
if(bean.isItemGroup())
|
||||||
|
bean.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getSafeUri().toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public PickItemsDialog(char triggerChar, final HandlerManager eventBus, int widthInPixel) {
|
||||||
super(true, false);
|
super(true, false);
|
||||||
if (widthInPixel < 200) {
|
if (widthInPixel < 200) {
|
||||||
throw new IllegalArgumentException("width must be greater than 199");
|
throw new IllegalArgumentException("width must be greater than 199");
|
||||||
|
@ -92,23 +120,17 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
this.triggerChar = triggerChar;
|
this.triggerChar = triggerChar;
|
||||||
this.includeTriggerChar = false;
|
this.includeTriggerChar = false;
|
||||||
this.hasPhoto = false;
|
this.hasPhoto = false;
|
||||||
this.beans = beans;
|
this.beans = new ArrayList<>();
|
||||||
focusPanel.setWidth(widthInPixel+"px");
|
focusPanel.setWidth(widthInPixel+"px");
|
||||||
mainPanel.setWidth(widthInPixel+"px");
|
mainPanel.setWidth(widthInPixel+"px");
|
||||||
setWidth(widthInPixel+"px");
|
setWidth(widthInPixel+"px");
|
||||||
focusPanel.add(mainPanel);
|
focusPanel.add(mainPanel);
|
||||||
setWidget(focusPanel);
|
setWidget(focusPanel);
|
||||||
setStyleName("pickDialog");
|
setStyleName("pickDialog");
|
||||||
|
if (oracle instanceof UserOracle) {
|
||||||
//add the user fill names to the oracle
|
UserOracle asyncOracle = (UserOracle) oracle;
|
||||||
for (ItemBean bean : beans) {
|
asyncOracle.addContacts(getAllUsers());
|
||||||
oracle.add(bean.getAlternativeName());
|
}
|
||||||
|
|
||||||
// if it is a team, set the avatar
|
|
||||||
if(bean.isItemGroup())
|
|
||||||
bean.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getURL());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//remove the first selected when hovering
|
//remove the first selected when hovering
|
||||||
focusPanel.addMouseOverHandler(new MouseOverHandler() {
|
focusPanel.addMouseOverHandler(new MouseOverHandler() {
|
||||||
|
@ -133,15 +155,21 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
handleMouseDown();
|
handleMouseDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() {
|
eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedItem(PickedItemEvent event) {
|
public void onSelectedItem(PickedItemEvent event) {
|
||||||
GWT.log("GOT @ CAZZEVENT! "+ event.getSelectedItem().getAlternativeName());
|
GWT.log("GOT EVENT "+ event.getSelectedItem().getAlternativeName());
|
||||||
stopListening = true;
|
stopListening = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//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"));
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* use if you have want to show a photo for the item or not, remember to provide it in {@link ItemBean} instances
|
* use if you have want to show a photo for the item or not, remember to provide it in {@link ItemBean} instances
|
||||||
*/
|
*/
|
||||||
|
@ -181,10 +209,10 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
this.itemCursorIndexStart = cursorPos;
|
this.itemCursorIndexStart = cursorPos;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
itemCursorIndexEnd = cursorPos;
|
itemCursorIndexEnd = cursorPos;
|
||||||
currText = currText.substring(itemCursorIndexStart, cursorPos)+ch;
|
currText = currText.substring(itemCursorIndexStart, cursorPos)+ch;
|
||||||
|
|
||||||
if (currText.contains(""+triggerChar) && currText.length() > 1 && !stopListening) {
|
if (currText.contains(""+triggerChar) && currText.length() > 1 && !stopListening) {
|
||||||
if (pickingUser(currText.substring(1))) {
|
if (pickingUser(currText.substring(1))) {
|
||||||
handleNonCharKeys = true;
|
handleNonCharKeys = true;
|
||||||
|
@ -216,6 +244,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
* @param currText the text being typed
|
* @param currText the text being typed
|
||||||
*/
|
*/
|
||||||
private boolean pickingUser(String currText) {
|
private boolean pickingUser(String currText) {
|
||||||
|
GWT.log("ci arriva");
|
||||||
if (currText.trim().length() > 0) {
|
if (currText.trim().length() > 0) {
|
||||||
if (includeTriggerChar)
|
if (includeTriggerChar)
|
||||||
showSuggestions(triggerChar+currText);
|
showSuggestions(triggerChar+currText);
|
||||||
|
@ -293,14 +322,20 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
||||||
for (ItemBean bean : beans) {
|
if (suggestion instanceof UserSuggestion) {
|
||||||
if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)
|
UserSuggestion us = (UserSuggestion) suggestion;
|
||||||
return bean;
|
return us.getUser();
|
||||||
|
} else { //the user were preloaded client side
|
||||||
|
for (ItemBean bean : beans) {
|
||||||
|
if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
return new ItemBean("no-match","no-match","no-match","no-match");
|
||||||
}
|
}
|
||||||
return new ItemBean("no-match","no-match","no-match","no-match");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.oracle;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemService;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemServiceAsync;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
|
||||||
|
|
||||||
|
public class UserOracle extends MultiWordSuggestOracle{
|
||||||
|
private final PickItemServiceAsync pickuserService = GWT.create(PickItemService.class);
|
||||||
|
|
||||||
|
private List<ItemBean> contacts = new LinkedList<>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
String text = request.getQuery();
|
||||||
|
text = text.toLowerCase();
|
||||||
|
|
||||||
|
final List<UserSuggestion> list = new ArrayList<>();
|
||||||
|
GWT.log("calling searchEntities ..." + text);
|
||||||
|
pickuserService.searchEntities(text, new AsyncCallback<ArrayList<ItemBean>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable arg0) {
|
||||||
|
GWT.log("error");
|
||||||
|
callback.onSuggestionsReady(request, resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(ArrayList<ItemBean> results) {
|
||||||
|
for (ItemBean contact : results){
|
||||||
|
list.add(new UserSuggestion(contact));
|
||||||
|
}
|
||||||
|
resp.setSuggestions(list);
|
||||||
|
callback.onSuggestionsReady(request, resp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.oracle;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||||
|
|
||||||
|
public class UserSuggestion implements SuggestOracle.Suggestion {
|
||||||
|
|
||||||
|
private ItemBean user;
|
||||||
|
|
||||||
|
public UserSuggestion(ItemBean user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayString() {
|
||||||
|
return user.getAlternativeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getReplacementString() {
|
||||||
|
return user.getAlternativeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemBean getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.rpc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.rpc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
public interface PickItemServiceAsync {
|
||||||
|
|
||||||
|
void searchEntities(String keyword, AsyncCallback<ArrayList<ItemBean>> callback);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.server;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
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.User;
|
||||||
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class PickItemServiceImpl extends RemoteServiceServlet implements PickItemService {
|
||||||
|
private static final Logger _log = LoggerFactory.getLogger(PickItemServiceImpl.class);
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return true if you're running into the portal, false if in development
|
||||||
|
*/
|
||||||
|
private boolean isWithinPortal() {
|
||||||
|
try {
|
||||||
|
UserLocalServiceUtil.getService();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
||||||
|
_log.trace("Development Mode ON");
|
||||||
|
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
|
||||||
|
@Override
|
||||||
|
public ArrayList<ItemBean> searchEntities(String keyword) {
|
||||||
|
ArrayList<ItemBean> toReturn = new ArrayList<>();
|
||||||
|
if (isWithinPortal()) {
|
||||||
|
OrderByComparator comparator = OrderByComparatorFactoryUtil.create("User_", "screenname", true);
|
||||||
|
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) {
|
||||||
|
toReturn.add(new ItemBean(""+user.getUserId(), user.getScreenName(), user.getFullName(), getUserImagePortraitUrlLocal(user.getScreenName())));
|
||||||
|
}
|
||||||
|
} catch (SystemException | PortalException 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"));
|
||||||
|
if (i % 2 == 0)
|
||||||
|
toReturn.add(new ItemBean(""+i, "username"+i, "userGetFullname()"+i, "user.getEmail()"+i));
|
||||||
|
else
|
||||||
|
toReturn.add(new ItemBean(""+i, "ciccio"+i, "ciccioNome"+i, "ciccioEMail"+i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* this method is needed because user images portrait change id depending on the portal instance
|
||||||
|
* e.g. a post made from iMarine portal would not show the avatarIMage in D4Science.org
|
||||||
|
* @param screenname
|
||||||
|
* @return the url of the image portrait for this portal instance
|
||||||
|
*/
|
||||||
|
private String getUserImagePortraitUrlLocal(String screenName) {
|
||||||
|
if (! isWithinPortal()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String thumbnailURL = "";
|
||||||
|
try {
|
||||||
|
thumbnailURL = new LiferayUserManager().getUserByUsername(screenName).getUserAvatarURL();
|
||||||
|
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return thumbnailURL;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue