Massimiliano Assante 9 years ago
parent 6fba7de7ab
commit b22106cb38

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="${webappDirectory}/WEB-INF/classes"/>
</classpath>

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>invite-friends-widget</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

@ -0,0 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/Users/massi/Documents/workspace/invite-friends-wdiget/target/session-checker-0.1.0-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

@ -0,0 +1,5 @@
#Thu Jun 16 11:14:17 CEST 2011
eclipse.preferences.version=1
entryPointModules=
filesCopiedToWebInfLib=gwt-servlet.jar
gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBWy13YXIgc3JjL21haW4vd2ViYXBwXV0+PC9leHRyYS1hcmdzPjx2bS1hcmdzPjwhW0NEQVRBWy1YbXg1MTJtXV0+PC92bS1hcmdzPjxlbnRyeS1wb2ludC1tb2R1bGU+Y29tLmNvbXBhbnkuU29tZU1vZHVsZTwvZW50cnktcG9pbnQtbW9kdWxlPjwvZ3d0LWNvbXBpbGUtc2V0dGluZ3M+

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="invite-friends-widget">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="invites-common-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/invites-common-library/invites-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="invite-friends-widget"/>
<property name="java-output-path" value="/invite-friends-widget/target/invite-friends-widget-0.0.1-SNAPSHOT/WEB-INF/classes"/>
</wb-module>
</project-modules>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

@ -0,0 +1,244 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>invite-friends-widget</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>gCube Invites widget</name>
<description>
gCube Session Checker Widget is a GWT Widget that can be used to automatically check if the session expired.
</description>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId}</developerConnection>
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId}</url>
</scm>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.7.0</gwtVersion>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>${gwtVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Google Web Toolkit (GWT) -->
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>invites-common-library</artifactId>
<version>[0.1.0-SNAPSHOT,)</version>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-jsonmaker</artifactId>
</dependency>
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
<version>2.3.2.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<executions>
<execution>
<configuration>
<module>org.gcube.portlets.widgets.inviteswidget.InvitesWidget</module>
</configuration>
<goals>
<!-- <goal>compile</goal> -->
<!-- <goal>test</goal> -->
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>InvitesWidget.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- SA Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,14 @@
package org.gcube.portlets.widgets.inviteswidget.client;
import org.gcube.portal.databook.shared.InviteOperationResult;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
@RemoteServiceRelativePath("greet")
public interface InviteService extends RemoteService {
InviteOperationResult sendInvite(String name, String lastName, String email) throws IllegalArgumentException;
}

@ -0,0 +1,12 @@
package org.gcube.portlets.widgets.inviteswidget.client;
import org.gcube.portal.databook.shared.InviteOperationResult;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface InviteServiceAsync {
void sendInvite(String name, String lastName, String email,
AsyncCallback<InviteOperationResult> callback);
}

@ -0,0 +1,18 @@
package org.gcube.portlets.widgets.inviteswidget.client;
import org.gcube.portlets.widgets.inviteswidget.client.ui.InviteWidget;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class InvitesWidget implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
RootPanel.get("invite-friends-DIV").add(new InviteWidget());
}
}

@ -0,0 +1,164 @@
/**
*
*/
package org.gcube.portlets.widgets.inviteswidget.client.ui;
import org.gcube.portal.databook.shared.InviteOperationResult;
import org.gcube.portlets.widgets.inviteswidget.client.InviteService;
import org.gcube.portlets.widgets.inviteswidget.client.InviteServiceAsync;
import org.gcube.portlets.widgets.inviteswidget.client.validation.FormView;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.HelpBlock;
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorDriver;
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author Massimiliano Assante, ISTI-CNR
*
*/
public class FormViewImpl extends Composite implements FormView, Editor<FormView.UserDetails> {
/**
* Create a remote service proxy to talk to the server-side service
*/
private final InviteServiceAsync service = GWT.create(InviteService.class);
interface Binder extends UiBinder<Widget, FormViewImpl> {}
private static Binder uiBinder = GWT.create(Binder.class);
interface Driver extends SimpleBeanEditorDriver<FormView.UserDetails, FormViewImpl> { }
private Driver driver = GWT.create(Driver.class);
private final Delegate delegate;
@UiField TextBox email;
@UiField TextBox name;
@UiField Button openModal;
@UiField Button cancelInvite;
@UiField Button sendInvite;
@UiField Modal modalWindow;
@UiField HelpBlock nameErrors;
@UiField HelpBlock feedback;
@UiField
ControlGroup nameGroup;
@UiField
ControlGroup feedbackGroup;
public FormViewImpl(Delegate delegate) {
super();
this.delegate = delegate;
initWidget(uiBinder.createAndBindUi(this));
driver.initialize(this);
driver.edit(new UserDetails());
email.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
openModal.click();
}
});
name.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
sendInvite.click();
}
});
sendInvite.setEnabled(true);
}
@UiHandler("openModal")
void onUserClick(ClickEvent event) {
if (!delegate.onSendClick()) {
sendInvite.setEnabled(true);
feedback.setText("We will send the invitation email to: "+email.getText() + " and put you in cc, we'll never email your contacts without your say so.");
name.setText("");
modalWindow.show();
Timer t = new Timer() {
@Override
public void run() {
name.setFocus(true);
}
};
t.schedule(1000);
}
}
@UiHandler("sendInvite")
void onSendInviteClick(ClickEvent event) {
if (delegate.onEmailSendInviteClick()) {
nameGroup.setType(ControlGroupType.ERROR);
nameErrors.setText("Name must not be null");
} else {
nameGroup.setType(ControlGroupType.NONE);
nameErrors.setText("");
service.sendInvite(name.getText(), "", email.getText(), new AsyncCallback<InviteOperationResult>() {
@Override
public void onSuccess(InviteOperationResult result) {
switch (result) {
case SUCCESS:
feedback.setText("Thanks for inviting, we sent the email correctly.");
feedbackGroup.setType(ControlGroupType.SUCCESS);
break;
case ALREADY_INVITED:
feedback.setText("Thanks for inviting, however the user was already invited.");
feedbackGroup.setType(ControlGroupType.WARNING);
break;
case FAILED:
feedback.setText("Sorry, an error occurred in the server and we could not send the invite, please try again later.");
feedbackGroup.setType(ControlGroupType.ERROR);
break;
}
sendInvite.setEnabled(false);
cancelInvite.setText("Close");
email.setText("");
}
@Override
public void onFailure(Throwable caught) {
feedback.setText("Sorry, an error occurred and we could not send the invite, please try again later.");
feedbackGroup.setType(ControlGroupType.ERROR);
sendInvite.setEnabled(false);
email.setText("");
}
});
}
}
@UiHandler("cancelInvite")
public void onCancelClick(ClickEvent e) {
modalWindow.hide();
email.setText("");
}
@Override
public EditorDriver<FormView.UserDetails> getEditorDriver() {
return driver;
}
}

@ -0,0 +1,30 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<b:Form type="VERTICAL">
<b:ControlGroup ui:field="emailGroup">
<b:TextBox placeholder="e-mail address" ui:field="email"
controlGroup="{emailGroup}" errorLabel="{emailErrors}" />
<b:HelpBlock ui:field="emailErrors"></b:HelpBlock>
</b:ControlGroup>
<b:Button ui:field="openModal">Send Invite</b:Button>
<b:Modal ui:field="modalWindow" title="Invite whoever's missing"
backdrop="STATIC" keyboard="true" animation="true">
<b:Form type="VERTICAL">
<b:ControlGroup ui:field="nameGroup">
<b:TextBox placeholder="enter your friend's name" ui:field="name"></b:TextBox>
<b:HelpBlock ui:field="nameErrors"></b:HelpBlock>
</b:ControlGroup>
<b:ControlGroup ui:field="feedbackGroup">
<b:HelpBlock ui:field="feedback"></b:HelpBlock>
</b:ControlGroup>
</b:Form>
<b:ModalFooter>
<b:Button ui:field="cancelInvite">Cancel</b:Button>
<b:Button ui:field="sendInvite" type="PRIMARY">Send Invite</b:Button>
</b:ModalFooter>
</b:Modal>
</b:Form>
</ui:UiBinder>

@ -0,0 +1,35 @@
package org.gcube.portlets.widgets.inviteswidget.client.ui;
import org.gcube.portlets.widgets.inviteswidget.client.validation.FormErrorsValidation;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author Massimiliano Assante, ISTI-CNR
*
*/
public class InviteWidget extends Composite{
public static final String DISPLAY_NAME = "Invite whoever's missing";
private static InviteWidgetUiBinder uiBinder = GWT.create(InviteWidgetUiBinder.class);
interface InviteWidgetUiBinder extends UiBinder<Widget, InviteWidget> { }
@UiField HTML header;
@UiField SimplePanel validationErrorsFormPanel;
public InviteWidget() {
super();
initWidget(uiBinder.createAndBindUi(this));
header.setText(DISPLAY_NAME);
new FormErrorsValidation().start(validationErrorsFormPanel, null);
}
}

@ -0,0 +1,8 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel styleName="invites-frame">
<g:HTML ui:field="header" styleName="invites-title"></g:HTML>
<g:SimplePanel ui:field="validationErrorsFormPanel" />
</g:HTMLPanel>
</ui:UiBinder>

@ -0,0 +1,178 @@
/**
*
*/
package org.gcube.portlets.widgets.inviteswidget.client.validation;
import java.util.HashSet;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Path;
import javax.validation.metadata.ConstraintDescriptor;
import org.gcube.portlets.widgets.inviteswidget.client.ui.FormViewImpl;
import org.gcube.portlets.widgets.inviteswidget.client.validation.FormView.UserDetails;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.editor.client.EditorDriver;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.validation.client.impl.PathImpl;
/**
*
* @author Massimiliano Assante, ISTI-CNR
*
*/
public class FormErrorsValidation extends AbstractActivity implements FormView.Delegate {
private FormView view;
/**
* @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
*/
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
view = new FormViewImpl(this);
panel.setWidget(view);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean onSendClick() {
EditorDriver<UserDetails> editorDriver = view.getEditorDriver();
UserDetails details = editorDriver.flush();
Set<ConstraintViolation<UserDetails>> violations = validateEmailTextBox(details);
//decorate widgets implementing HasEditorErrors with validation messages
return editorDriver.setConstraintViolations( (Set) violations);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean onEmailSendInviteClick() {
EditorDriver<UserDetails> editorDriver = view.getEditorDriver();
UserDetails details = editorDriver.flush();
Set<ConstraintViolation<UserDetails>> violations = validateName(details);
return !violations.isEmpty();
}
private Set<ConstraintViolation<UserDetails>> validateName(UserDetails user2InviteBean) {
Set<ConstraintViolation<UserDetails>> violations = new HashSet<ConstraintViolation<UserDetails>>();
if(user2InviteBean.getName() == null || "".equals(user2InviteBean.getName().trim())) {
violations.add(buildNotNullConstraintViolation(user2InviteBean, "name"));
}
return violations;
}
private Set<ConstraintViolation<UserDetails>> validateEmailTextBox(UserDetails user2InviteBean){
Set<ConstraintViolation<UserDetails>> violations = new HashSet<ConstraintViolation<UserDetails>>();
if(user2InviteBean.getEmail() == null || "".equals(user2InviteBean.getEmail().trim())) {
violations.add(buildNotNullConstraintViolation(user2InviteBean, "email"));
}
else if (!isValidEmailAddress(user2InviteBean.getEmail())) {
violations.add(buildInvalidEmailAddressConstraintViolation(user2InviteBean, "email"));
}
return violations;
}
private ConstraintViolation<UserDetails> buildNotNullConstraintViolation(final UserDetails bean, final String path) {
return new ConstraintViolation<UserDetails>() {
@Override
public String getMessage() {
return "must not be empty";
}
@Override
public String getMessageTemplate() {
return null;
}
@Override
public UserDetails getRootBean() {
return bean;
}
@Override
public Class<UserDetails> getRootBeanClass() {
return UserDetails.class;
}
@Override
public Object getLeafBean() {
return bean;
}
@Override
public Path getPropertyPath() {
return new PathImpl().append(path);
}
@Override
public Object getInvalidValue() {
return null;
}
@Override
public ConstraintDescriptor<?> getConstraintDescriptor() {
return null;
}
};
}
private ConstraintViolation<UserDetails> buildInvalidEmailAddressConstraintViolation(final UserDetails bean, final String path) {
return new ConstraintViolation<UserDetails>() {
@Override
public String getMessage() {
return "email address must be valid";
}
@Override
public String getMessageTemplate() {
return null;
}
@Override
public UserDetails getRootBean() {
return bean;
}
@Override
public Class<UserDetails> getRootBeanClass() {
return UserDetails.class;
}
@Override
public Object getLeafBean() {
return bean;
}
@Override
public Path getPropertyPath() {
return new PathImpl().append(path);
}
@Override
public Object getInvalidValue() {
return null;
}
@Override
public ConstraintDescriptor<?> getConstraintDescriptor() {
return null;
}
};
}
/**
*
* @param emailValue
* @return
*/
private boolean isValidEmailAddress(String emailValue) {
if(emailValue == null) return true;
String emailPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.(?:[a-zA-Z]{2,6})$";
boolean valid = false;
if(emailValue.getClass().toString().equals(String.class.toString())) {
valid = ((String)emailValue).matches(emailPattern);
} else {
valid = ((Object)emailValue).toString().matches(emailPattern);
}
return valid;
}
}

@ -0,0 +1,57 @@
/**
*
*/
package org.gcube.portlets.widgets.inviteswidget.client.validation;
import com.google.gwt.editor.client.EditorDriver;
import com.google.gwt.user.client.ui.IsWidget;
/**
*
* @author Massimiliano Assante, ISTI-CNR
*
*/
public interface FormView extends IsWidget {
public static class UserDetails {
String email;
String name;
String lastName;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "UserDetails [email=" + email + ", name=" + name
+ ", lastName=" + lastName + "]";
}
}
public interface Delegate {
boolean onSendClick();
boolean onEmailSendInviteClick();
}
EditorDriver<UserDetails> getEditorDriver();
}

@ -0,0 +1,68 @@
package org.gcube.portlets.widgets.inviteswidget.server;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.*;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.shared.InviteOperationResult;
import org.gcube.portal.invites.InvitesManager;
import org.gcube.portlets.widgets.inviteswidget.client.InviteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.util.PortalUtil;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class InviteServiceImpl extends RemoteServiceServlet implements InviteService {
private final static Logger _log = LoggerFactory.getLogger(InviteServiceImpl.class);
/**
* the current ASLSession
* @return the session
*/
private ASLSession getASLSession() {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("USER IS NULL setting test.user");
user = "test.user";
}
else {
_log.info("LIFERAY PORTAL DETECTED user=" + user);
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
*
*/
@Override
public InviteOperationResult sendInvite(String name, String lastName, String email) throws IllegalArgumentException {
ASLSession aslSession = getASLSession();
String portalUrl = null;
String vreDescription = null;
long organizationId = getASLSession().getGroupId();
try {
portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHost(), PortalUtil.getPortalPort(), true);
vreDescription = OrganizationLocalServiceUtil.getOrganization(organizationId).getComments();
} catch (Exception e1) {
e1.printStackTrace();
_log.warn("While trying to send email for invitation to " + email);
return null;
}
String portalSenderEmail = PortalContext.getConfiguration().getSenderEmail();
return InvitesManager.getInstance().sendInvite(aslSession, portalSenderEmail, portalUrl, name, lastName, email, vreDescription);
}
}

@ -0,0 +1,42 @@
package org.gcube.portlets.widgets.inviteswidget.shared;
/**
* <p>
* FieldVerifier validates that the name the user enters is valid.
* </p>
* <p>
* This class is in the <code>shared</code> packing because we use it in both
* the client code and on the server. On the client, we verify that the name is
* valid before sending an RPC request so the user doesn't have to wait for a
* network round trip to get feedback. On the server, we verify that the name is
* correct to ensure that the input is correct regardless of where the RPC
* originates.
* </p>
* <p>
* When creating a class that is used on both the client and the server, be sure
* that all code is translatable and does not use native JavaScript. Code that
* is note translatable (such as code that interacts with a database or the file
* system) cannot be compiled into client side JavaScript. Code that uses native
* JavaScript (such as Widgets) cannot be run on the server.
* </p>
*/
public class FieldVerifier {
/**
* Verifies that the specified name is valid for our service.
*
* In this example, we only require that the name is at least four
* characters. In your application, you can use more complex checks to ensure
* that usernames, passwords, email addresses, URLs, and other fields have the
* proper syntax.
*
* @param name the name to validate
* @return true if valid, false if invalid
*/
public static boolean isValidName(String name) {
if (name == null) {
return false;
}
return name.length() > 3;
}
}

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='InvitesWidget'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<inherits name='com.google.gwt.activity.Activity' />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Other module inherits -->
<inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- Specify the app entry point class. -->
<entry-point
class='org.gcube.portlets.widgets.inviteswidget.client.InvitesWidget' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>

@ -0,0 +1,34 @@
/** Add css rules here for your application. */
/** Example rules used by the template application (remove for your app) */
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.sendButton {
display: block;
font-size: 16pt;
}
/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
width: 400px;
}
.dialogVPanel {
margin: 5px;
}
.serverResponseLabelError {
color: red;
}
/** Set ids using widget.getElement().setId("idOfElement") */
#closeButton {
margin: 15px 6px 6px;
}

@ -0,0 +1,38 @@
<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout. -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="InvitesWidget.css">
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="InvitesWidget/InvitesWidget.nocache.js"></script>
</head>
<!-- -->
<!-- The body can have arbitrary html, or -->
<!-- you can leave the body empty if you want -->
<!-- to create a completely dynamic UI. -->
<!-- -->
<body>
<div id="invite-friends-DIV"></div>
</body>
</html>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.inviteswidget.server.InviteServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/InvitesWidget/greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>InvitesWidget.html</welcome-file>
</welcome-file-list>
</web-app>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to="InvitesWidget">
<!-- Inherit our applications main module. -->
<inherits name='org.gcube.portlets.widgets.inviteswidget.InvitesWidget' />
<!-- Specify the path to any remote services. -->
<servlet path="/InvitesWidget/greet" class="org.gcube.portlets.widgets.inviteswidget.server.GreetingServiceImpl" />
</module>
Loading…
Cancel
Save