diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..9ace2b1 --- /dev/null +++ b/.classpath @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gwt/.gwt-log b/.gwt/.gwt-log new file mode 100644 index 0000000..e69de29 diff --git a/.project b/.project new file mode 100644 index 0000000..190a7fc --- /dev/null +++ b/.project @@ -0,0 +1,53 @@ + + + create-users + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + com.google.gdt.eclipse.core.webAppProjectValidator + + + + + com.google.gwt.eclipse.core.gwtProjectValidator + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + com.google.gwt.eclipse.core.gwtNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..b72a6a4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/com.google.appengine.eclipse.core.prefs b/.settings/com.google.appengine.eclipse.core.prefs new file mode 100644 index 0000000..82c36af --- /dev/null +++ b/.settings/com.google.appengine.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +filesCopiedToWebInfLib= diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs new file mode 100644 index 0000000..d83ef36 --- /dev/null +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +lastWarOutDir=/home/costantino/workspace/create-users/target/create-users-1.0.0-SNAPSHOT +warSrcDir=src/main/webapp +warSrcDirIsOutput=false diff --git a/.settings/com.google.gwt.eclipse.core.prefs b/.settings/com.google.gwt.eclipse.core.prefs new file mode 100644 index 0000000..f23a752 --- /dev/null +++ b/.settings/com.google.gwt.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +entryPointModules= diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -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/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..443e085 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..6e43947 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..dcd7752 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..7bca8c8 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,2 @@ +${gcube.license} + diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..65b75d6 --- /dev/null +++ b/distro/README @@ -0,0 +1,63 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Costantino Perciante at ISTI-CNR(Pisa), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +----------- + +* Costantino Perciante at ISTI-CNR(Pisa), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + ${gcube.wikiRoot} + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..08f83d2 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + + First Release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..4efc827 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,48 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + target/apidocs + /${artifactId}/doc/api + true + 755 + + + + + ${distroDirectory}/profile.xml + ./ + true + + + target/${build.finalName}.war + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..51c3b6b --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Service + + ${description} + PortletUser + ${artifactId} + ${version} + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + target/${build.finalName}.war + + + + + diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cd241d5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,222 @@ + + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.portlets.admin + create-users + war + 1.0.0-SNAPSHOT + Create users portlet + + Create users portlet allows a VRE-Manager to enter user's personal data and automatically register he/she in the portal. + The portlet also sends a temporary password to the just registered user. + + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/${project.artifactId} + + + + + 2.7.0 + 6.2.5 + + 1.7 + 1.7 + + ${project.build.directory}/${project.build.finalName} + UTF-8 + UTF-8 + + + + + + com.google.gwt + gwt + ${gwtVersion} + pom + import + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + + com.google.gwt + gwt-servlet + provided + ${gwtVersion} + + + com.google.gwt + gwt-user + provided + ${gwtVersion} + + + com.google.gwt + gwt-dev + provided + ${gwtVersion} + + + org.gcube.portal + custom-portal-handler + + + com.github.gwtbootstrap + gwt-bootstrap + 2.3.2.0 + + + org.gcube.dvos + usermanagement-core + + provided + + + com.liferay.portal + portal-service + ${liferayVersion} + provided + + + org.gcube.applicationsupportlayer + aslcore + + + commons-codec + commons-codec + compile + + + org.gcube.core + common-scope-maps + compile + + + javax.portlet + portlet-api + provided + + + org.gcube.portal + social-networking-library + provided + + + org.gcube.common + home-library-model + provided + + + org.ow2.asm + asm-all + [5.0.0-SNAPSHOT, 6.0.0-SNAPSHOT) + + + org.gcube.common + home-library + provided + + + asm-all + asm + + + + + org.gcube.common + home-library-jcr + provided + + + junit + junit + 4.11 + test + + + + + + ${webappDirectory}/WEB-INF/classes + + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwtVersion} + + + + compile + + + + + + + + Statistics.html + ${webappDirectory} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + + compile + + exploded + + + + + ${webappDirectory} + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + + + diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsers.java b/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsers.java new file mode 100644 index 0000000..9c2c658 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsers.java @@ -0,0 +1,19 @@ +package org.gcube.portlets.admin.createusers.client; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.user.client.ui.RootPanel; + + +/** + * The main module that contains the entry point of the portlet. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class CreateUsers implements EntryPoint { + + @Override + public void onModuleLoad() { + + RootPanel.get("create-users-container").add(new CreateUsersPanel()); + + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsersPanel.java b/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsersPanel.java new file mode 100644 index 0000000..a8a1781 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/CreateUsersPanel.java @@ -0,0 +1,124 @@ +package org.gcube.portlets.admin.createusers.client; +import java.util.List; + +import org.gcube.portlets.admin.createusers.client.ui.AddUserForm; +import org.gcube.portlets.admin.createusers.client.ui.LoadingText; +import org.gcube.portlets.admin.createusers.client.ui.RegisteredUsersTable; +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +import com.github.gwtbootstrap.client.ui.AlertBlock; +import com.github.gwtbootstrap.client.ui.TabPane; +import com.github.gwtbootstrap.client.ui.TabPanel; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.VerticalPanel; + +/** + * The panel that contains the list of users already registered and the form to add new ones. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class CreateUsersPanel extends Composite { + + // main vertical panel + private VerticalPanel mainPanel = new VerticalPanel(); + + // Tab panel + private TabPanel navTabs = new TabPanel(); + + // add user subpanel + private TabPane addUserSubPanel = new TabPane("Create New User"); + + // registered users subpanel + private TabPane registeredUsersSubPanel = new TabPane("Already Created Users") ; + + // Create a remote service proxy to talk to the server-side user manager service. + private final HandleUsersServiceAsync userServices = GWT.create(HandleUsersService.class); + + // table of registered users + private RegisteredUsersTable registeredUsersTable; + + // event bus + private final HandlerManager eventBus = new HandlerManager(null); + + public CreateUsersPanel(){ + + super(); + initWidget(mainPanel); + + // form panel + AddUserForm addUserForm = new AddUserForm(userServices, eventBus, this); + addUserSubPanel.add(addUserForm); + + // add temporary loader for registered users table + LoadingText loader = new LoadingText(); + loader.setVisible(true); + registeredUsersSubPanel.add(loader); + + // add stuff to the main panel + navTabs.add(addUserSubPanel); + navTabs.add(registeredUsersSubPanel); + mainPanel.add(navTabs); + + // select add user form tab + navTabs.selectTab(0); + + // enlarge navTabs + mainPanel.setWidth("100%"); + + // squeeze the form panel + addUserSubPanel.setWidth("50%"); + + // require already registered users + userServices.getAlreadyRegisterdUsers(new AsyncCallback>() { + + @Override + public void onSuccess(List result) { + + if(result == null){ + showProblemsRetrievingList(); + return; + } + + GWT.log("List of registered users received!"); + registeredUsersTable = new RegisteredUsersTable(result, eventBus); + registeredUsersSubPanel.clear(); + registeredUsersSubPanel.add(registeredUsersTable); + } + + @Override + public void onFailure(Throwable caught) { + + GWT.log("Unable to retrieve list of registered users!" + caught.toString()); + showProblemsRetrievingList(); + + } + }); + } + + /** + * Show error block if retrieving registered data fails. + */ + private void showProblemsRetrievingList() { + + registeredUsersSubPanel.clear(); + AlertBlock error = new AlertBlock(AlertType.ERROR); + error.setText("It is not possible to retrieve the requested data at the moment. Retry later..."); + error.setAnimation(true); + error.setClose(false); + registeredUsersSubPanel.add(error); + + } + + /** + * Determine if a user with this email has been already registered + * @param actualEmail + * @return + */ + public boolean isUserPresent(String actualEmail) { + return registeredUsersTable.isUserPresent(actualEmail); + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersService.java b/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersService.java new file mode 100644 index 0000000..4db4baf --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersService.java @@ -0,0 +1,33 @@ +package org.gcube.portlets.admin.createusers.client; + +import java.util.List; + +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +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("usersservice") +public interface HandleUsersService extends RemoteService { + + /** + * Register this user to the current vre. + * @param name + * @param surname + * @param company + * @param email + * @param sendEmail + * @param isMale + * @return the registered user information or null if the registration failed + */ + VreUserBean register(String name, String surname, String company, String email, boolean sendEmail, boolean isMale); + + /** + * Retrieve the list of already registered users. + * @return a list of already registered users or null in case of error + */ + List getAlreadyRegisterdUsers(); + +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersServiceAsync.java b/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersServiceAsync.java new file mode 100644 index 0000000..4cc6c02 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/HandleUsersServiceAsync.java @@ -0,0 +1,19 @@ +package org.gcube.portlets.admin.createusers.client; + +import java.util.List; + +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * Async version of the service for the client. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public interface HandleUsersServiceAsync { + + void getAlreadyRegisterdUsers(AsyncCallback> callback); + + void register(String name, String surname, String company, String email, + boolean sendEmail, boolean isMale, AsyncCallback callback); +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEvent.java b/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEvent.java new file mode 100644 index 0000000..d6a0fa2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEvent.java @@ -0,0 +1,29 @@ +package org.gcube.portlets.admin.createusers.client.event; +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +import com.google.gwt.event.shared.GwtEvent; + + +public class AddUserEvent extends GwtEvent { + public static Type TYPE = new Type(); + + private VreUserBean addedUserBean; + + public AddUserEvent(VreUserBean addedUserBean) { + this.addedUserBean = addedUserBean; + } + + public VreUserBean getAddedUserBean() { + return addedUserBean; + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(AddUserEventHandler handler) { + handler.onAddUser(this); + } +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEventHandler.java b/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEventHandler.java new file mode 100644 index 0000000..1062950 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/event/AddUserEventHandler.java @@ -0,0 +1,7 @@ +package org.gcube.portlets.admin.createusers.client.event; + +import com.google.gwt.event.shared.EventHandler; + +public interface AddUserEventHandler extends EventHandler { + void onAddUser(AddUserEvent event); +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.java b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.java new file mode 100644 index 0000000..6ce8396 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.java @@ -0,0 +1,236 @@ +package org.gcube.portlets.admin.createusers.client.ui; + +import org.gcube.portlets.admin.createusers.client.HandleUsersServiceAsync; +import org.gcube.portlets.admin.createusers.client.CreateUsersPanel; +import org.gcube.portlets.admin.createusers.client.event.AddUserEvent; +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +import com.github.gwtbootstrap.client.ui.AlertBlock; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.Form; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.KeyUpEvent; +import com.google.gwt.event.shared.HandlerManager; +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; + +/** + * Form to add new user to the vre. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class AddUserForm extends Composite{ + + private static AddUserFormUiBinder uiBinder = GWT + .create(AddUserFormUiBinder.class); + + interface AddUserFormUiBinder extends UiBinder { + } + + @UiField + Form form; + + @UiField + Button submit; + + @UiField + CheckBox sendMailCheckbox; + + // @UiField + // RadioButton maleCheckbox; + + @UiField + TextBox emailTextbox; + + @UiField + TextBox nameTextbox; + + @UiField + TextBox surnameTextbox; + + @UiField + TextBox companyTextbox; + + @UiField + AlertBlock errorBlock; + + @UiField + AlertBlock successBlock; + + private static final String NAME_SURNAME_PATTERN = "^[a-zA-Z\\s]*$"; + + private static final String EMAIL_PATTERN = + "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + + private static final int HIDE_AFTER_MILLISECONDS = 6000; + + private final HandleUsersServiceAsync registrationService; + + private final HandlerManager eventBus; + + private final CreateUsersPanel parent; + + public AddUserForm(HandleUsersServiceAsync userServices, HandlerManager eventBus, CreateUsersPanel parent) { + initWidget(uiBinder.createAndBindUi(this)); + this.registrationService = userServices; + this.eventBus = eventBus; + this.parent = parent; + } + + @UiHandler("submit") + void onClick(ClickEvent e) { + + // input validation + String actualName = nameTextbox.getText(); + String actualSurname = surnameTextbox.getText(); + String actualEmail = emailTextbox.getText(); + String actualCompany = companyTextbox.getText(); + + if(actualEmail.isEmpty() || !actualEmail.matches(EMAIL_PATTERN)){ + + showError("Wrong or empty Email field"); + return; + + } + + if(actualName.isEmpty() || !actualName.matches(NAME_SURNAME_PATTERN)){ + + showError("Wrong or empty Name field"); + return; + + } + + if(actualSurname.isEmpty() || !actualSurname.matches(NAME_SURNAME_PATTERN)){ + + showError("Wrong or empty Surname field"); + return; + + } + + // check if this user is already present among the people added with this portlet + boolean presentTable = parent.isUserPresent(actualEmail); + + if(presentTable){ + + showAlertBlockThenHide( + errorBlock, + "Please note that a user with this email already exists", + HIDE_AFTER_MILLISECONDS + ); + + }else{ + + // remote service invocation + registrationService.register( + actualName, + actualSurname, + actualCompany, + actualEmail, + sendMailCheckbox.getValue(), + // maleCheckbox.getValue(), + true, + new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + + GWT.log("There was an error while adding the new user.", caught); + showAlertBlockThenHide( + errorBlock, + "It is not possible to add this user at the moment, retry later.", + HIDE_AFTER_MILLISECONDS); + } + + @Override + public void onSuccess(VreUserBean result) { + + if(result == null){ + + GWT.log("There was an error while adding the new user." + + " Are you sure he/she is not already present?"); + + showAlertBlockThenHide( + errorBlock, + "It is not possible to add this user at the moment, retry later." + + " Also check that he/she was not already registered in the portal.", + HIDE_AFTER_MILLISECONDS); + + }else{ + + showAlertBlockThenHide( + successBlock, + "User correctly added to this VRE", + HIDE_AFTER_MILLISECONDS); + + // append to the list of registered users + eventBus.fireEvent(new AddUserEvent(result)); + + } + + } + }); + } + + // reset form + form.reset(); + } + + private void showAlertBlockThenHide(final AlertBlock alert, String msg, int hideAfterMs){ + + // set text + alert.setText(msg); + alert.setVisible(true); + + // hide after a while + Timer t = new Timer() { + @Override + public void run() { + alert.setVisible(false); + } + }; + t.schedule(hideAfterMs); + + } + + private void showError(String msg) { + + errorBlock.setText(msg); + errorBlock.setVisible(true); + + } + + private void hideAlertBlocks(){ + + errorBlock.setVisible(false); + successBlock.setVisible(false); + } + + @UiHandler("emailTextbox") + void onChangeEmailTextbox(KeyUpEvent event){ + hideAlertBlocks(); + } + + @UiHandler("nameTextbox") + void onChangeNameTextbox(KeyUpEvent event){ + hideAlertBlocks(); + } + + @UiHandler("surnameTextbox") + void onChangeSurnameTextbox(KeyUpEvent event){ + hideAlertBlocks(); + } + + @UiHandler("companyTextbox") + void onChangeCompanyTextbox(KeyUpEvent event){ + hideAlertBlocks(); + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.ui.xml b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.ui.xml new file mode 100644 index 0000000..6d60305 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/AddUserForm.ui.xml @@ -0,0 +1,118 @@ + + + + .form-main-style { + margin-left: 10px; + } + + .fieldset-border-style { + border: 1px groove #444; + -webkit-box-shadow: 0px 0px 0px 0px #000; + box-shadow: 0px 0px 0px 0px #000; + padding: 10px; + } + + .legend-style { + width: auto; + padding: 10px; + margin-bottom: 0px; + } + + @external .form-horizontal .control-label; + .form-horizontal .control-label { + margin-bottom: 15px; + text-align: left; + } + + @external .form-horizontal .input-large; + .form-horizontal .input-large { + width: 95%; + margin-bottom: 15px; + } + + .block-alert-style { + margin-top: 10px; + padding: 10px; + } + + + + + + + Insert User Information + * is required + + + + + + * + E-mail: + + + + + + + * + Name: + + + + + + + * + Surname: + + + + + + Company: + + + + + Send mail: + + + + + + + + + + + + +

+ + + Add + + +

+ + + + + +
+
+
+
+
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.java b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.java new file mode 100644 index 0000000..a543721 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.java @@ -0,0 +1,19 @@ +package org.gcube.portlets.admin.createusers.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class LoadingText extends Composite { + + private static LoadingTextUiBinder uiBinder = GWT + .create(LoadingTextUiBinder.class); + + interface LoadingTextUiBinder extends UiBinder { + } + + public LoadingText() { + initWidget(uiBinder.createAndBindUi(this)); + } +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.ui.xml b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.ui.xml new file mode 100644 index 0000000..2055b1b --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/LoadingText.ui.xml @@ -0,0 +1,13 @@ + + + + + + Please wait + + Contacting database... + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/RegisteredUsersTable.java b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/RegisteredUsersTable.java new file mode 100644 index 0000000..f3cbbc5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/RegisteredUsersTable.java @@ -0,0 +1,286 @@ +package org.gcube.portlets.admin.createusers.client.ui; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import org.gcube.portlets.admin.createusers.client.event.AddUserEvent; +import org.gcube.portlets.admin.createusers.client.event.AddUserEventHandler; +import org.gcube.portlets.admin.createusers.shared.VreUserBean; + +import com.github.gwtbootstrap.client.ui.CellTable; +import com.google.gwt.cell.client.Cell; +import com.google.gwt.cell.client.TextCell; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.cellview.client.Column; +import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.view.client.ListDataProvider; +import com.google.gwt.view.client.Range; + +/** + * Show already registered users list. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class RegisteredUsersTable extends Composite { + + //CellTable custom UI resource + private CellTable.Resources tableRes = GWT.create(TableResources.class); + protected ListDataProvider dataProvider = new ListDataProvider(); + private CellTable table = new CellTable(1, tableRes); + private final HandlerManager eventBus; + + public RegisteredUsersTable(List registeredUsers, HandlerManager eventBus) { + + super(); + initWidget(table); + + // bind event + this.eventBus = eventBus; + bind(); + + dataProvider.setList(registeredUsers); + dataProvider.addDataDisplay(table); + table.setStriped(true); + table.setWidth("95%", false); + table.addStyleName("table-style"); + table.setVisibleRange(new Range(0, registeredUsers.size())); + table.setBordered(true); + table.setRowCount(registeredUsers.size(), true); + + // column for mail and sorting handler + Column emailCol = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return user.getEmail(); + } + }); + + ListHandler emailColHandler = new ListHandler(dataProvider.getList()); + emailColHandler.setComparator(emailCol, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + + return o1.getEmail().compareTo(o2.getEmail()); + + } + }); + emailCol.setSortable(true); + emailCol.setDefaultSortAscending(false); + table.addColumnSortHandler(emailColHandler); + + // name column plus handler for sorting + Column nameCol = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return user.getName(); + } + }); + + ListHandler nameColHandler = new ListHandler(dataProvider.getList()); + nameColHandler.setComparator(nameCol, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + + return o1.getName().compareTo(o2.getName()); + + } + }); + nameCol.setSortable(true); + nameCol.setDefaultSortAscending(false); + table.addColumnSortHandler(nameColHandler); + + // surname column plus handler for sorting + Column surnameCol = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return user.getSurname(); + } + }); + + ListHandler surnameColHandler = new ListHandler(dataProvider.getList()); + nameColHandler.setComparator(surnameCol, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + + return o1.getSurname().compareTo(o2.getSurname()); + + } + }); + surnameCol.setSortable(true); + surnameCol.setDefaultSortAscending(false); + table.addColumnSortHandler(surnameColHandler); + + // company and handler for sorting + Column companyCol = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return user.getCompany(); + } + }); + + ListHandler companyColHandler = new ListHandler(dataProvider.getList()); + companyColHandler.setComparator(companyCol, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + + return o1.getCompany().compareTo(o2.getCompany()); + + } + }); + companyCol.setSortable(true); + companyCol.setDefaultSortAscending(false); + table.addColumnSortHandler(companyColHandler); + + // password and handler for sorting + Column passwordChanged = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return (user.isPasswordChanged() ? "True" : "False"); + } + }); + + ListHandler passwordChangedColHandler = new ListHandler(dataProvider.getList()); + passwordChangedColHandler.setComparator(passwordChanged, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + + String o1PasswordChangedString = o1.isPasswordChanged() ? "True" : "False"; + String o2PasswordChangedString = o2.isPasswordChanged() ? "True" : "False"; + return o1PasswordChangedString.compareTo(o2PasswordChangedString); + + } + }); + passwordChanged.setSortable(true); + passwordChanged.setDefaultSortAscending(false); + table.addColumnSortHandler(passwordChangedColHandler); + + // registration column plus handler for sorting + Column registrationDate = getColumn(new TextCell(), new GetValue() { + @Override + public String getValue(VreUserBean user) { + return DateTimeFormat.getShortDateFormat().format(new Date(user.getRegisrationDate())); + } + }); + + ListHandler registrationDateColHandler = new ListHandler(dataProvider.getList()); + registrationDateColHandler.setComparator(registrationDate, new Comparator() { + @Override + public int compare(VreUserBean o1, VreUserBean o2) { + return new Long(o1.getRegisrationDate()).compareTo(new Long(o2.getRegisrationDate())); + + } + }); + registrationDate.setDefaultSortAscending(false); + registrationDate.setSortable(true); + table.addColumnSortHandler(registrationDateColHandler); + table.getColumnSortList().push(registrationDate); + + // add columns + SafeHtmlBuilder builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Email"); + builder.appendHtmlConstant(""); + table.addColumn(emailCol, builder.toSafeHtml()); + builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Name"); + builder.appendHtmlConstant(""); + table.addColumn(nameCol, builder.toSafeHtml()); + builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Surname"); + builder.appendHtmlConstant(""); + table.addColumn(surnameCol, builder.toSafeHtml()); + builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Company"); + builder.appendHtmlConstant(""); + table.addColumn(companyCol, builder.toSafeHtml()); + builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Password Changed"); + builder.appendHtmlConstant(""); + table.addColumn(passwordChanged, builder.toSafeHtml()); + builder = new SafeHtmlBuilder(); + builder.appendHtmlConstant(""); + builder.appendEscaped("Registration date"); + builder.appendHtmlConstant(""); + table.addColumn(registrationDate, builder.toSafeHtml()); + + } + + /** + * events binder + */ + private void bind() { + eventBus.addHandler(AddUserEvent.TYPE, new AddUserEventHandler() { + + @Override + public void onAddUser(AddUserEvent user) { + + addUserToTable(user); + + } + }); + } + + /** + * Update the list of registered users + * @param event + */ + private void addUserToTable(AddUserEvent event) { + + VreUserBean userToAdd = event.getAddedUserBean(); + GWT.log("Adding " + userToAdd); + dataProvider.getList().add(userToAdd); + table.setVisibleRange(new Range(0, dataProvider.getList().size())); + table.setRowCount(dataProvider.getList().size(), true); + dataProvider.refresh(); + + } + + /** + * Check if a user whit this email already exists + * @param actualEmail + * @return + */ + public boolean isUserPresent(String actualEmail) { + List users = dataProvider.getList(); + + for (VreUserBean vreUserBean : users) { + if(vreUserBean.getEmail().equals(actualEmail)) + return true; + } + + return false; + } + + /** + * Interface for getting a cell value + * @param + */ + private static interface GetValue { + C getValue(VreUserBean user); + } + + + /** + * get a column + * + * @param the cell type + * @param cell the cell used to render the column + * @param getter the value getter for the cell + */ + private Column getColumn(Cell cell, final GetValue getter) { + Column column = new Column(cell) { + @Override + public C getValue(VreUserBean object) { + return getter.getValue(object); + } + }; + return column; + } +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/Table.css b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/Table.css new file mode 100644 index 0000000..2f4eb08 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/Table.css @@ -0,0 +1,65 @@ +.cellTableHeader { +/* padding: 0px; */ +/* color: #545454; */ +/* text-align: center !important; */ +/* font-size: 13px; */ +/* background-image: none; */ +/* background-color: #cfcfcf; */ +/* height: 25px; */ + vertical-align: bottom!important; + font-weight: bold; +/* text-shadow: 0 1px 1px rgba(255, 255, 255, .7); */ +/* border: 2px solid #999999; */ +} + +.cellTableFirstColumnHeader { +} + +.cellTableLastColumnHeader { + +} + +.cellTableCell { + padding: 4px; +/* text-align: center !important; */ + vertical-align: middle !important; + overflow: hidden; + font-size: 12px; +/* border: 1px dotted #999999; */ +} + +.cellTableEvenRow { + +} + +.cellTableOddRow { + +} + +.cellTableSelectedRow { + background: #628cd5; +} + +.cellTableSelectedRowCell { + +} + +.cellTableHoveredRow { + +} + +.cellTableHoveredRowCell { + +} + +.cellTableKeyboardSelectedRow { + background: #c9c9c1; +} + +.cellTableKeyboardSelectedRowCell { + border: none; +} + +.cellTableKeyboardSelectedCell { + border: none; +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/admin/createusers/client/ui/TableResources.java b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/TableResources.java new file mode 100644 index 0000000..b8d0feb --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/client/ui/TableResources.java @@ -0,0 +1,11 @@ +package org.gcube.portlets.admin.createusers.client.ui; + +import com.github.gwtbootstrap.client.ui.CellTable; + +public interface TableResources extends CellTable.Resources{ + + @Source({CellTable.Style.DEFAULT_CSS, "org/gcube/portlets/admin/createusers/client/ui/Table.css"}) + TableStyle cellTableStyle(); + + interface TableStyle extends CellTable.Style {} +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/server/CreateUsersImpl.java b/src/main/java/org/gcube/portlets/admin/createusers/server/CreateUsersImpl.java new file mode 100644 index 0000000..aa30834 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/server/CreateUsersImpl.java @@ -0,0 +1,430 @@ +package org.gcube.portlets.admin.createusers.server; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portlets.admin.createusers.client.HandleUsersService; +import org.gcube.portlets.admin.createusers.shared.VreUserBean; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.kernel.dao.jdbc.DataAccess; +import com.liferay.portal.service.UserLocalServiceUtil; + +/** + * The server side implementation of the RPC service. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsersService{ + + private final static Logger logger = LoggerFactory.getLogger(CreateUsersImpl.class); + private static final long serialVersionUID = -3124676000683430170L; + private static final String REGISTERED_USERS_TABLE = "registered_users"; + + //dev user + public static final String userid = "test.user"; + + //dev vre + private static final String vreID = "/gcube/devsec/devVRE"; + + // SQL TABLE FIELDS + private static final String FIELD_EMAIL = "email"; + private static final String FIELD_NAME = "name"; + private static final String FIELD_SURNAME = "surname"; + private static final String FIELD_COMPANY = "company"; + private static final String FIELD_REGISTRATION_DATE = "registration_date"; + private static final String FIELD_VRE = "vre"; + + @Override + public void init(){ + + logger.debug("Trying to get connect to liferay's DB from API"); + try { + + Connection con = DataAccess.getConnection(); + logger.debug("Connected!"); + + // check if the table already exists + boolean exists = tableExists(con); + + if(exists){ + logger.debug("Table " + REGISTERED_USERS_TABLE + " already exists."); + } + else{ + initializeTable(con); + } + } catch (Exception e) { + logger.error("Failed to connect to liferay's DB"); + return; + } + } + + /** + * check if tables exist in the database + * @param conn . + * @throws SQLException + */ + private boolean tableExists(Connection con) throws SQLException { + logger.debug("Looking for " + REGISTERED_USERS_TABLE + " table"); + Statement s = con.createStatement(); + ResultSet rs = s.executeQuery("SELECT * FROM pg_tables where schemaname='public' and tablename = '" + REGISTERED_USERS_TABLE +"' "); + boolean toReturn = rs.next(); + if (toReturn) + logger.debug("Auxiliary Table Found! Returning ... "); + return toReturn; + } + + /** + * create the table REGISTERED_USERS_TABLE + * @throws SQLException + */ + private void initializeTable(Connection con) { + try { + + logger.debug("Creating table " + REGISTERED_USERS_TABLE); + Statement s = con.createStatement(); + + s.execute("CREATE TABLE " + REGISTERED_USERS_TABLE + + " (id serial primary key, " // like autoincrement + + "email varchar(255) NOT NULL, " + + "name" + " varchar(255) NOT NULL, " + + "surname" + " varchar(255) NOT NULL, " + + "company" + " varchar(255) DEFAULT NULL, " + + "vre" + " varchar(255) NOT NULL, " + + "registration_date" + " TIMESTAMP NOT NULL)"); + + logger.debug(REGISTERED_USERS_TABLE + " created"); + + } catch (SQLException e) { + logger.error("Error while creating table", e); + } + try { + con.close(); + } catch (SQLException e1) { + logger.error("Error while closing connection", e1); + } + } + + + /** + * 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) { + + logger.warn("USER IS NULL setting " + userid + " and Running OUTSIDE PORTAL"); + user = getDevelopmentUser(); + SessionManager.getInstance().getASLSession(sessionID, user).setScope(vreID); + + } + + return SessionManager.getInstance().getASLSession(sessionID, user); + } + + /** + * Online or in development mode? + * @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) { + logger.trace("Development Mode ON"); + return false; + } + } + + /** + * when packaging test will fail if the user is not set to test.user + * @return . + */ + public String getDevelopmentUser() { + String user = userid; + // user = "costantino.perciante"; + return user; + } + + + @Override + public VreUserBean register(String name, String surname, String company, + String email, boolean sendEmail, boolean isMale) { + + // if in dev mode return ok + if (!isWithinPortal()) { + + logger.debug("In dev mode."); + return new VreUserBean(name, surname, company, email, false, System.currentTimeMillis(), isMale); + + }else{ + + ASLSession session = getASLSession(); + String userName = session.getUsername(); + + //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info) + //this check just return nothing if that happens + if (userName.compareTo("test.user") == 0) { + logger.debug("Found " + userName + " returning nothing"); + return null; + } + + String vre = session.getScopeName(); + long timestamp = System.currentTimeMillis(); + + //checking if the user has been already registered or is already in the portal + LiferayUserManager userManager = new LiferayUserManager(); + boolean exists = userManager.userExistsByEmail(email); + + if(exists){ + + logger.debug("User with this email already present in the portal."); + return null; + + } + else{ + + logger.debug("Trying to add user: " + name + ", " + surname + ", " + email + ", " + company); + Connection con = null; + try{ + + con = DataAccess.getConnection(); + String insert = "INSERT into " + REGISTERED_USERS_TABLE + + "("+ FIELD_EMAIL + "," + + FIELD_NAME +"," + + FIELD_SURNAME + "," + + FIELD_COMPANY + "," + + FIELD_REGISTRATION_DATE + "," + + FIELD_VRE + + ") values(?, ?, ?, ?, ?, ?)"; + + PreparedStatement statement = con.prepareStatement(insert); + + statement.setString(1, email); + statement.setString(2, name); + statement.setString(3, surname); + statement.setString(4, company); + statement.setTimestamp(5, new Timestamp(timestamp)); + statement.setString(6, vre); + int res = statement.executeUpdate(); + + if(res != 0){ + + logger.debug("User added in " + REGISTERED_USERS_TABLE); + + // add in liferay too + try{ + GCubeUser user = userManager.createUser( + true, + "", + email, + name, + "", + surname, + company, + "", + isMale, + null, + null, + sendEmail, // determine if we need to send him/her an email + true); // force the password reset + + // adding to the current VRE + userManager.assignUserToGroup(getCurrentGroupID(), userManager.getUserId(user.getUsername())); + + //adding to the HL + addUserToHLGroup(user.getUsername(), session.getScope()); + + }catch(Exception e){ + + // unable to create.. we need to delete it from the list of users + logger.error("Unable to create the user " + email + " in liferay. Removing he/she from the table " + + REGISTERED_USERS_TABLE, e); + + deleteUserFromTable(email, con); + return null; + } + } + else{ + + logger.debug("User NOT added in " + REGISTERED_USERS_TABLE); + return null; + } + }catch(Exception e){ + logger.error("Unable to add user, sorry..", e); + return null; + }finally{ + try { + if(con != null) + con.close(); + } catch (SQLException e) { + logger.error("Unable to close connection to the DB"); + } + } + + return new VreUserBean(name, surname, company, email, false, timestamp, isMale); + } + } + } + + @Override + public List getAlreadyRegisterdUsers() { + + List toReturn = new ArrayList(); + + // if in dev mode return some samples + if (!isWithinPortal()) { + + logger.debug("In dev mode."); + toReturn.add(new VreUserBean("Dylan", "Dog", "ISTI-CNR", "dylan.dog@gmail.com", false, System.currentTimeMillis(), true)); + toReturn.add(new VreUserBean("Costantino", "Perciante", "ISTI-CNR", "costantino8@gmail.com", false, System.currentTimeMillis(), true)); + return toReturn; + + }else{ + + LiferayUserManager userManager = new LiferayUserManager(); + ASLSession session = getASLSession(); + String userName = session.getUsername(); + + //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info) + //this check just return nothing if that happens + if (userName.compareTo("test.user") == 0) { + logger.debug("Found " + userName + " returning nothing"); + return null; + } + + // evaluate current vre + String vre = session.getScopeName(); + + Connection con = null; + try{ + + con = DataAccess.getConnection(); + Statement stmt = con.createStatement(); + + String sql = "SELECT * FROM " + REGISTERED_USERS_TABLE + " WHERE " + FIELD_VRE + "='" + vre + "';"; + ResultSet rs = stmt.executeQuery(sql); + + while(rs.next()){ + + String name = rs.getString(FIELD_NAME); + String surname = rs.getString(FIELD_SURNAME); + String company = rs.getString(FIELD_COMPANY); + String email = rs.getString(FIELD_EMAIL); + long registrationDate = rs.getTimestamp(FIELD_REGISTRATION_DATE).getTime(); + + // check if the password has been changed or not wrt the default one + boolean passwordChanged = userManager.isPasswordChanged(email); + + // the gender information is useless (set to false) + toReturn.add(new VreUserBean(name, surname, company, email, passwordChanged, registrationDate, false)); + + } + + // now, make sure these users are still on portal + Iterator iterator = toReturn.iterator(); + while (iterator.hasNext()) { + VreUserBean user = (VreUserBean) iterator.next(); + + if(!userManager.userExistsByEmail(user.getEmail())){ + + // remove from the table + deleteUserFromTable(user.getEmail(), con); + + // remove from this collection + iterator.remove(); + + } + } + + }catch(Exception e){ + logger.error("Unable to retrieve users list, sorry...", e); + return null; + }finally{ + try { + if(con != null) + con.close(); + } catch (SQLException e) { + logger.error("Unable to close connection to the DB"); + } + } + + return toReturn; + } + } + + /** + * Remove a row from the table of the registered users + * @param email + * @param con + */ + private void deleteUserFromTable(String email, Connection con) { + + try{ + + logger.debug("Going to delete user with email " + email); + + String remove = "DELETE FROM " + REGISTERED_USERS_TABLE + " WHERE " + FIELD_EMAIL + "= ?"; + PreparedStatement statementDelete = con.prepareStatement(remove); + statementDelete.setString(1, email); + statementDelete.executeUpdate(); + + }catch(Exception e){ + + logger.error("Error while deleting user=" + email + "from the table"); + } + } + + /** + * Add user to Home Library Group + * @param username + * @param group + */ + private void addUserToHLGroup(String username, String group) { + try { + org.gcube.common.homelibrary.home.workspace.usermanager.UserManager um = HomeLibrary.getHomeManagerFactory().getUserManager(); + um.associateUserToGroup(group, username); + } catch (Exception e) { + logger.error("Failed to get the usermanager from HL. Could not add user to the HL group"); + } + } + + /** + * Get the current group ID + * + * @return the current group ID or null if an exception is thrown + * @throws Exception + */ + private String getCurrentGroupID() { + ASLSession session = getASLSession(); + logger.debug("The current group NAME is --> " + session.getGroupName()); + String toReturn = null; + try { + toReturn = new LiferayGroupManager().getGroupId(session.getGroupName()); + } catch (UserManagementSystemException | GroupRetrievalFault e) { + logger.error("Unable to retrieve id for group " + session.getGroupName()); + } + return toReturn; + } +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/server/portlet/CreateUsersPortlet.java b/src/main/java/org/gcube/portlets/admin/createusers/server/portlet/CreateUsersPortlet.java new file mode 100644 index 0000000..88b296a --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/server/portlet/CreateUsersPortlet.java @@ -0,0 +1,28 @@ + +package org.gcube.portlets.admin.createusers.server.portlet; + +import javax.portlet.GenericPortlet; +import javax.portlet.ActionRequest; +import javax.portlet.RenderRequest; +import javax.portlet.ActionResponse; +import javax.portlet.RenderResponse; +import javax.portlet.PortletException; +import java.io.IOException; +import javax.portlet.PortletRequestDispatcher; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; + +/** + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ + public class CreateUsersPortlet extends GenericPortlet { + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); + ScopeHelper.setContext(request); + PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/CreateUsers_view.jsp"); + dispatcher.include(request, response); + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException { + } +} diff --git a/src/main/java/org/gcube/portlets/admin/createusers/shared/VreUserBean.java b/src/main/java/org/gcube/portlets/admin/createusers/shared/VreUserBean.java new file mode 100644 index 0000000..1db9da5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/createusers/shared/VreUserBean.java @@ -0,0 +1,117 @@ +package org.gcube.portlets.admin.createusers.shared; + +import java.io.Serializable; + +/** + * Information of an already registered user to the VRE. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class VreUserBean implements Serializable{ + + private static final long serialVersionUID = -8674087530839002999L; + + + private String name; + private String surname; + private String company; + private String email; + private boolean passwordChanged; + private long regisrationDate; + private boolean isMale; + + /** + * Build a default user bean object. + */ + public VreUserBean(){ + super(); + } + + /** + * Build a user bean object. + * @param name + * @param surname + * @param company + * @param email + * @param passwordChanged + * @param registrationDate + * @param isMale + */ + public VreUserBean(String name, String surname, String company, + String email, boolean passwordChanged, long registrationDate, boolean isMale) { + super(); + this.name = name; + this.surname = surname; + this.company = company; + this.email = email; + this.passwordChanged = passwordChanged; + this.regisrationDate = registrationDate; + this.isMale = isMale; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public boolean isPasswordChanged() { + return passwordChanged; + } + + public void setPasswordChanged(boolean passwordChanged) { + this.passwordChanged = passwordChanged; + } + + + public long getRegisrationDate() { + return regisrationDate; + } + + public void setRegisrationDate(long regisrationDate) { + this.regisrationDate = regisrationDate; + } + + + public boolean isMale() { + return isMale; + } + + public void setMale(boolean isMale) { + this.isMale = isMale; + } + + @Override + public String toString() { + return "VreUserBean [name=" + name + ", surname=" + surname + + ", company=" + company + ", email=" + email + + ", passwordChanged=" + passwordChanged + ", regisrationDate=" + + regisrationDate + ", isMale=" + isMale + "]"; + } + +} diff --git a/src/main/resources/clientlog4j.properties b/src/main/resources/clientlog4j.properties new file mode 100644 index 0000000..4a2e1cd --- /dev/null +++ b/src/main/resources/clientlog4j.properties @@ -0,0 +1,12 @@ +log4j.rootLogger=DEBUG, A1 +log4j.appender.A1=org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout=org.apache.log4j.PatternLayout + +# Print the date in ISO 8601 format +log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +# Print only messages of level TRACE or above in the package org.gcube +log4j.logger.org.gcube=TRACE +log4j.logger.org.gcube.application.framework.core.session=INFO +log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR +log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR \ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/admin/createusers/CreateUsers.gwt.xml b/src/main/resources/org/gcube/portlets/admin/createusers/CreateUsers.gwt.xml new file mode 100644 index 0000000..e2598b2 --- /dev/null +++ b/src/main/resources/org/gcube/portlets/admin/createusers/CreateUsers.gwt.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/CreateUsers.css b/src/main/webapp/CreateUsers.css new file mode 100644 index 0000000..4f112f8 --- /dev/null +++ b/src/main/webapp/CreateUsers.css @@ -0,0 +1,12 @@ +/** Add css rules here for your application. */ +.portlet-title-style { + display: block; + font-size: 16px; + color: #555; + font-weight: bolder; + margin-bottom: 10px; +} + +.table-style { + margin-left: 10px; +} \ No newline at end of file diff --git a/src/main/webapp/CreateUsers.html b/src/main/webapp/CreateUsers.html new file mode 100644 index 0000000..fbb7962 --- /dev/null +++ b/src/main/webapp/CreateUsers.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + +Create users portlet + + + + + + + + + + + + + + + + + + +
+ + diff --git a/src/main/webapp/WEB-INF/js/jquery.autosize.js b/src/main/webapp/WEB-INF/js/jquery.autosize.js new file mode 100644 index 0000000..370279e --- /dev/null +++ b/src/main/webapp/WEB-INF/js/jquery.autosize.js @@ -0,0 +1,187 @@ +/*! + jQuery Autosize v1.16.12 + (c) 2013 Jack Moore - jacklmoore.com + updated: 2013-05-31 + license: http://www.opensource.org/licenses/mit-license.php +*/ + +(function ($) { + var + defaults = { + className: 'autosizejs', + append: '', + callback: false + }, + hidden = 'hidden', + borderBox = 'border-box', + lineHeight = 'lineHeight', + + // border:0 is unnecessary, but avoids a bug in FireFox on OSX + copy = '