Buttons to delete and re-send the welcome email added and working
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/create-users@125883 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b7d038c670
commit
e342908ac2
2
pom.xml
2
pom.xml
|
@ -29,7 +29,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Convenience property to set the GWT version -->
|
<!-- Convenience property to set the GWT version -->
|
||||||
<gwtVersion>2.7.0</gwtVersion>
|
<gwtVersion>2.7.0</gwtVersion>
|
||||||
<liferayVersion>6.2.5</liferayVersion>
|
<liferayVersion>6.0.6</liferayVersion>
|
||||||
<!-- GWT needs at least java 1.6 -->
|
<!-- GWT needs at least java 1.6 -->
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
|
|
@ -11,11 +11,8 @@ import com.github.gwtbootstrap.client.ui.TabPane;
|
||||||
import com.github.gwtbootstrap.client.ui.TabPanel;
|
import com.github.gwtbootstrap.client.ui.TabPanel;
|
||||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
|
||||||
import com.google.gwt.event.dom.client.ClickHandler;
|
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwt.user.client.ui.Button;
|
|
||||||
import com.google.gwt.user.client.ui.Composite;
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
|
@ -36,9 +33,6 @@ public class CreateUsersPanel extends Composite {
|
||||||
|
|
||||||
// registered users subpanel
|
// registered users subpanel
|
||||||
private TabPane registeredUsersSubPanel = new TabPane("Already Created Users") ;
|
private TabPane registeredUsersSubPanel = new TabPane("Already Created Users") ;
|
||||||
|
|
||||||
// TODO remove
|
|
||||||
private TabPane sendMailTabPane = new TabPane("Send Mail");
|
|
||||||
|
|
||||||
// Create a remote service proxy to talk to the server-side user manager service.
|
// Create a remote service proxy to talk to the server-side user manager service.
|
||||||
private final HandleUsersServiceAsync userServices = GWT.create(HandleUsersService.class);
|
private final HandleUsersServiceAsync userServices = GWT.create(HandleUsersService.class);
|
||||||
|
@ -62,32 +56,6 @@ public class CreateUsersPanel extends Composite {
|
||||||
LoadingText loader = new LoadingText();
|
LoadingText loader = new LoadingText();
|
||||||
loader.setVisible(true);
|
loader.setVisible(true);
|
||||||
registeredUsersSubPanel.add(loader);
|
registeredUsersSubPanel.add(loader);
|
||||||
|
|
||||||
// TODO remove
|
|
||||||
Button sendMail = new Button("Test send email");
|
|
||||||
sendMail.addClickHandler(new ClickHandler() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(ClickEvent event) {
|
|
||||||
GWT.log("send email requested");
|
|
||||||
userServices.sendEmailToUser("costantino.perciante@isti.cnr.it", new AsyncCallback<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Void result) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
GWT.log("ok");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(Throwable caught) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
GWT.log("not ok");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sendMailTabPane.add(sendMail);
|
|
||||||
navTabs.add(sendMailTabPane);
|
|
||||||
|
|
||||||
// add stuff to the main panel
|
// add stuff to the main panel
|
||||||
navTabs.add(addUserSubPanel);
|
navTabs.add(addUserSubPanel);
|
||||||
|
@ -115,7 +83,7 @@ public class CreateUsersPanel extends Composite {
|
||||||
}
|
}
|
||||||
|
|
||||||
GWT.log("List of registered users received!");
|
GWT.log("List of registered users received!");
|
||||||
registeredUsersTable = new RegisteredUsersTable(result, eventBus);
|
registeredUsersTable = new RegisteredUsersTable(result, eventBus, userServices);
|
||||||
registeredUsersSubPanel.clear();
|
registeredUsersSubPanel.clear();
|
||||||
registeredUsersSubPanel.add(registeredUsersTable);
|
registeredUsersSubPanel.add(registeredUsersTable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.github.gwtbootstrap.client.ui.AlertBlock;
|
||||||
import com.github.gwtbootstrap.client.ui.Button;
|
import com.github.gwtbootstrap.client.ui.Button;
|
||||||
import com.github.gwtbootstrap.client.ui.CheckBox;
|
import com.github.gwtbootstrap.client.ui.CheckBox;
|
||||||
import com.github.gwtbootstrap.client.ui.Form;
|
import com.github.gwtbootstrap.client.ui.Form;
|
||||||
|
import com.github.gwtbootstrap.client.ui.Image;
|
||||||
import com.github.gwtbootstrap.client.ui.TextBox;
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.core.client.Scheduler;
|
import com.google.gwt.core.client.Scheduler;
|
||||||
|
@ -32,6 +33,11 @@ public class AddUserForm extends Composite{
|
||||||
private static AddUserFormUiBinder uiBinder = GWT
|
private static AddUserFormUiBinder uiBinder = GWT
|
||||||
.create(AddUserFormUiBinder.class);
|
.create(AddUserFormUiBinder.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path of the image to be shown during loading
|
||||||
|
*/
|
||||||
|
public static final String imagePath = GWT.getModuleBaseURL() + "../images/loader.gif";
|
||||||
|
|
||||||
interface AddUserFormUiBinder extends UiBinder<Widget, AddUserForm> {
|
interface AddUserFormUiBinder extends UiBinder<Widget, AddUserForm> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +50,8 @@ public class AddUserForm extends Composite{
|
||||||
@UiField
|
@UiField
|
||||||
CheckBox sendMailCheckbox;
|
CheckBox sendMailCheckbox;
|
||||||
|
|
||||||
// @UiField
|
@UiField
|
||||||
// RadioButton maleCheckbox;
|
Image performingRequest;
|
||||||
|
|
||||||
@UiField
|
@UiField
|
||||||
TextBox emailTextbox;
|
TextBox emailTextbox;
|
||||||
|
@ -84,9 +90,12 @@ public class AddUserForm extends Composite{
|
||||||
this.registrationService = userServices;
|
this.registrationService = userServices;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
|
// set loader url
|
||||||
|
performingRequest.setUrl(imagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttach() {
|
protected void onAttach() {
|
||||||
super.onAttach();
|
super.onAttach();
|
||||||
|
@ -141,6 +150,12 @@ public class AddUserForm extends Composite{
|
||||||
);
|
);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
|
// show loading image
|
||||||
|
performingRequest.setVisible(true);
|
||||||
|
|
||||||
|
// disable add button
|
||||||
|
submit.setEnabled(false);
|
||||||
|
|
||||||
// remote service invocation
|
// remote service invocation
|
||||||
registrationService.register(
|
registrationService.register(
|
||||||
|
@ -198,6 +213,12 @@ public class AddUserForm extends Composite{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAlertBlockThenHide(final AlertBlock alert, String msg, int hideAfterMs){
|
private void showAlertBlockThenHide(final AlertBlock alert, String msg, int hideAfterMs){
|
||||||
|
|
||||||
|
// hide loading image
|
||||||
|
performingRequest.setVisible(false);
|
||||||
|
|
||||||
|
// enable button again
|
||||||
|
submit.setEnabled(true);
|
||||||
|
|
||||||
// set text
|
// set text
|
||||||
alert.setText(msg);
|
alert.setText(msg);
|
||||||
|
|
|
@ -75,10 +75,10 @@
|
||||||
b:id="surname" title="User's surname" ui:field="surnameTextbox" />
|
b:id="surname" title="User's surname" ui:field="surnameTextbox" />
|
||||||
</b:Controls>
|
</b:Controls>
|
||||||
|
|
||||||
<b:ControlLabel for="company" title="User's company">Company:</b:ControlLabel>
|
<b:ControlLabel for="company" title="User's company">Institution/Organization:</b:ControlLabel>
|
||||||
<b:Controls>
|
<b:Controls>
|
||||||
<b:TextBox alternateSize="LARGE" placeholder="Company"
|
<b:TextBox alternateSize="LARGE" placeholder="Institution/Organization"
|
||||||
b:id="company" title="User's company" ui:field="companyTextbox" />
|
b:id="company" title="User's Institution/Organization" ui:field="companyTextbox" />
|
||||||
</b:Controls>
|
</b:Controls>
|
||||||
|
|
||||||
<b:ControlLabel for="sendmail"
|
<b:ControlLabel for="sendmail"
|
||||||
|
@ -105,6 +105,8 @@
|
||||||
|
|
||||||
<br></br>
|
<br></br>
|
||||||
|
|
||||||
|
<b:Image ui:field="performingRequest" visible="false"></b:Image>
|
||||||
|
|
||||||
<b:AlertBlock type="ERROR" close="false" animation="true"
|
<b:AlertBlock type="ERROR" close="false" animation="true"
|
||||||
visible="false" ui:field="errorBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
|
visible="false" ui:field="errorBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
|
||||||
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package org.gcube.portlets.admin.createusers.client.ui;
|
|
||||||
|
|
||||||
import com.google.gwt.user.client.ui.PopupPanel;
|
|
||||||
|
|
||||||
public class PopupPanelExtended extends PopupPanel {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,24 +3,27 @@ import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.createusers.client.HandleUsersServiceAsync;
|
||||||
import org.gcube.portlets.admin.createusers.client.event.AddUserEvent;
|
import org.gcube.portlets.admin.createusers.client.event.AddUserEvent;
|
||||||
import org.gcube.portlets.admin.createusers.client.event.AddUserEventHandler;
|
import org.gcube.portlets.admin.createusers.client.event.AddUserEventHandler;
|
||||||
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
||||||
|
|
||||||
import com.github.gwtbootstrap.client.ui.Button;
|
|
||||||
import com.github.gwtbootstrap.client.ui.CellTable;
|
import com.github.gwtbootstrap.client.ui.CellTable;
|
||||||
|
import com.google.gwt.cell.client.ButtonCell;
|
||||||
import com.google.gwt.cell.client.Cell;
|
import com.google.gwt.cell.client.Cell;
|
||||||
import com.google.gwt.cell.client.TextCell;
|
import com.google.gwt.cell.client.TextCell;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.dom.client.Element;
|
||||||
|
import com.google.gwt.dom.client.EventTarget;
|
||||||
|
import com.google.gwt.dom.client.NativeEvent;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||||
import com.google.gwt.user.cellview.client.Column;
|
import com.google.gwt.user.cellview.client.Column;
|
||||||
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
|
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
|
||||||
|
import com.google.gwt.user.client.Window;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwt.user.client.ui.Composite;
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
import com.google.gwt.user.client.ui.PopupPanel;
|
|
||||||
import com.google.gwt.view.client.CellPreviewEvent;
|
|
||||||
import com.google.gwt.view.client.CellPreviewEvent.Handler;
|
|
||||||
import com.google.gwt.view.client.ListDataProvider;
|
import com.google.gwt.view.client.ListDataProvider;
|
||||||
import com.google.gwt.view.client.Range;
|
import com.google.gwt.view.client.Range;
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ public class RegisteredUsersTable extends Composite {
|
||||||
private CellTable<VreUserBean> table = new CellTable<VreUserBean>(1, tableRes);
|
private CellTable<VreUserBean> table = new CellTable<VreUserBean>(1, tableRes);
|
||||||
private final HandlerManager eventBus;
|
private final HandlerManager eventBus;
|
||||||
|
|
||||||
public RegisteredUsersTable(List<VreUserBean> registeredUsers, HandlerManager eventBus) {
|
public RegisteredUsersTable(List<VreUserBean> registeredUsers, HandlerManager eventBus, final HandleUsersServiceAsync userServices) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
initWidget(table);
|
initWidget(table);
|
||||||
|
@ -182,41 +185,136 @@ public class RegisteredUsersTable extends Composite {
|
||||||
table.addColumnSortHandler(registrationDateColHandler);
|
table.addColumnSortHandler(registrationDateColHandler);
|
||||||
table.getColumnSortList().push(registrationDate);
|
table.getColumnSortList().push(registrationDate);
|
||||||
|
|
||||||
// add row click handler
|
// delete option
|
||||||
table.addCellPreviewHandler(new Handler<VreUserBean>() {
|
Column<VreUserBean, String> deleteUser = new Column<VreUserBean, String>(new ButtonCell()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCellPreview(CellPreviewEvent<VreUserBean> event) {
|
public String getValue(VreUserBean object) {
|
||||||
boolean isClick = "click".equals(event.getNativeEvent().getType());
|
return object.isPasswordChanged() ? "True" : "False"; // useless
|
||||||
if(isClick){
|
}
|
||||||
|
|
||||||
int rowIndex = event.getIndex();
|
@Override
|
||||||
PopupPanel drop = new PopupPanel();
|
public void render(Cell.Context context, VreUserBean value, SafeHtmlBuilder sb){
|
||||||
drop.setGlassEnabled(true);
|
|
||||||
|
if(value == null)
|
||||||
// add buttons and events
|
return;
|
||||||
VreUserBean rowBean = dataProvider.getList().get(rowIndex);
|
|
||||||
|
if(!value.isPasswordChanged())
|
||||||
Button deleteUserButton = new Button("Delete User");
|
sb.appendHtmlConstant("<Button>Delete User</Button>");
|
||||||
Button sendWelcomeButton = new Button("Send Email");
|
else
|
||||||
|
sb.appendHtmlConstant("<Button disabled>Delete User</Button>");
|
||||||
|
|
||||||
if(!rowBean.isPasswordChanged())
|
}
|
||||||
deleteUserButton.setEnabled(false);
|
|
||||||
|
@Override
|
||||||
// add to drop
|
public void onBrowserEvent(Cell.Context context, final Element parent, final VreUserBean user, NativeEvent event) {
|
||||||
drop.add(deleteUserButton);
|
event.preventDefault();
|
||||||
drop.add(sendWelcomeButton);
|
|
||||||
|
if(!"click".equals(event.getType()))
|
||||||
// position and show
|
return;
|
||||||
int left = table.getRowElement(rowIndex).getAbsoluteLeft();
|
|
||||||
int top = table.getRowElement(rowIndex).getAbsoluteTop();
|
EventTarget eventTarget = event.getEventTarget();
|
||||||
drop.setPopupPosition(left, top);
|
|
||||||
drop.show();
|
if(parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))){
|
||||||
|
|
||||||
|
// get the button and disable it
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", true);
|
||||||
|
|
||||||
|
userServices.deleteInvitedUser(user.getEmail(), new AsyncCallback<Boolean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Boolean result) {
|
||||||
|
|
||||||
|
// delete this row too
|
||||||
|
if(result){
|
||||||
|
|
||||||
|
dataProvider.getList().remove(user);
|
||||||
|
table.setVisibleRange(new Range(0, dataProvider.getList().size()));
|
||||||
|
table.setRowCount(dataProvider.getList().size(), true);
|
||||||
|
dataProvider.refresh();
|
||||||
|
|
||||||
|
Window.alert("Deleted user with email " + user.getEmail());
|
||||||
|
|
||||||
|
}else
|
||||||
|
Window.alert("Unable to delete this user, sorry!");
|
||||||
|
|
||||||
|
// enable the button again
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
|
||||||
|
Window.alert("Unable to delete this user, sorry!");
|
||||||
|
|
||||||
|
// enable the button again
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// send email option
|
||||||
|
Column<VreUserBean, String> sendWelcomeMessage = new Column<VreUserBean, String>(new ButtonCell()) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue(VreUserBean object) {
|
||||||
|
return "Send Welcome"; // useless
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Cell.Context context, VreUserBean value, SafeHtmlBuilder sb){
|
||||||
|
|
||||||
|
if(value == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sb.appendHtmlConstant("<Button>Send Welcome</Button>");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBrowserEvent(Cell.Context context, final Element parent, final VreUserBean user, NativeEvent event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if(!"click".equals(event.getType()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
EventTarget eventTarget = event.getEventTarget();
|
||||||
|
|
||||||
|
if(parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))){
|
||||||
|
|
||||||
|
// get the button and disable it
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", true);
|
||||||
|
|
||||||
|
userServices.sendEmailToUser(user.getEmail(), new AsyncCallback<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void result) {
|
||||||
|
|
||||||
|
Window.alert("Welcome message sent to " + user.getEmail());
|
||||||
|
|
||||||
|
// get the button and enable it
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
|
||||||
|
Window.alert("Unable to send the welcome message to " + user.getEmail());
|
||||||
|
|
||||||
|
// get the button and enable it
|
||||||
|
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
// add columns
|
// add columns
|
||||||
SafeHtmlBuilder builder = new SafeHtmlBuilder();
|
SafeHtmlBuilder builder = new SafeHtmlBuilder();
|
||||||
|
@ -249,7 +347,16 @@ public class RegisteredUsersTable extends Composite {
|
||||||
builder.appendEscaped("Registration date");
|
builder.appendEscaped("Registration date");
|
||||||
builder.appendHtmlConstant("</span>");
|
builder.appendHtmlConstant("</span>");
|
||||||
table.addColumn(registrationDate, builder.toSafeHtml());
|
table.addColumn(registrationDate, builder.toSafeHtml());
|
||||||
|
builder = new SafeHtmlBuilder();
|
||||||
|
builder.appendHtmlConstant("<span title=\"" + "Delete User"+ "\">");
|
||||||
|
builder.appendEscaped("Delete");
|
||||||
|
builder.appendHtmlConstant("</span>");
|
||||||
|
table.addColumn(deleteUser, builder.toSafeHtml());
|
||||||
|
builder = new SafeHtmlBuilder();
|
||||||
|
builder.appendHtmlConstant("<span title=\"" + "Send Welcome Message" + "\">");
|
||||||
|
builder.appendEscaped("Send Welcome");
|
||||||
|
builder.appendHtmlConstant("</span>");
|
||||||
|
table.addColumn(sendWelcomeMessage, builder.toSafeHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -306,7 +413,6 @@ public class RegisteredUsersTable extends Composite {
|
||||||
C getValue(VreUserBean user);
|
C getValue(VreUserBean user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a column
|
* get a column
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,7 +15,6 @@ import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
import org.gcube.portlets.admin.createusers.client.HandleUsersService;
|
import org.gcube.portlets.admin.createusers.client.HandleUsersService;
|
||||||
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
||||||
|
@ -34,6 +33,10 @@ import com.liferay.portal.kernel.dao.jdbc.DataAccess;
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
import com.liferay.portal.kernel.exception.PortalException;
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
import com.liferay.portal.kernel.mail.MailMessage;
|
import com.liferay.portal.kernel.mail.MailMessage;
|
||||||
|
import com.liferay.portal.kernel.util.GetterUtil;
|
||||||
|
import com.liferay.portal.kernel.util.PropsUtil;
|
||||||
|
import com.liferay.portal.model.Company;
|
||||||
|
import com.liferay.portal.service.CompanyLocalServiceUtil;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
import com.liferay.portal.util.PortalUtil;
|
import com.liferay.portal.util.PortalUtil;
|
||||||
|
|
||||||
|
@ -60,6 +63,8 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
private static final String FIELD_INSTITUTION = "institution_organization";
|
private static final String FIELD_INSTITUTION = "institution_organization";
|
||||||
private static final String FIELD_REGISTRATION_DATE = "registration_date";
|
private static final String FIELD_REGISTRATION_DATE = "registration_date";
|
||||||
private static final String FIELD_VRE = "vre";
|
private static final String FIELD_VRE = "vre";
|
||||||
|
|
||||||
|
public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
|
@ -180,18 +185,27 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteInvitedUser(String email) {
|
public boolean deleteInvitedUser(String email) {
|
||||||
|
|
||||||
try{
|
// if in dev mode return some samples
|
||||||
|
if (!isWithinPortal()) {
|
||||||
|
|
||||||
Connection con = DataAccess.getConnection();
|
logger.debug("In dev mode.");
|
||||||
boolean deletedLiferay = deleteUserFromLiferay(email);
|
return false;
|
||||||
boolean deletedTable = deleteUserFromTable(email, con);
|
|
||||||
return deletedLiferay && deletedTable;
|
|
||||||
|
|
||||||
}catch(SQLException e){
|
}else{
|
||||||
logger.debug("Error while trying to delete user with email = " + email, e);
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
Connection con = DataAccess.getConnection();
|
||||||
|
boolean deletedLiferay = deleteUserFromLiferay(email);
|
||||||
|
boolean deletedTable = deleteUserFromTable(email, con);
|
||||||
|
return deletedLiferay && deletedTable;
|
||||||
|
|
||||||
|
}catch(SQLException e){
|
||||||
|
logger.debug("Error while trying to delete user with email = " + email, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -208,7 +222,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
InternetAddress from = new InternetAddress(emailSender);
|
InternetAddress from = new InternetAddress(emailSender);
|
||||||
|
|
||||||
LiferayUserManager userManager = new LiferayUserManager();
|
LiferayUserManager userManager = new LiferayUserManager();
|
||||||
String portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHostname(), 443, true);
|
String portalUrl = PortalUtil.getPortalURL(getCompany().getVirtualHost(), 443, true);
|
||||||
String username = userManager.getFullNameFromEmail(email);
|
String username = userManager.getFullNameFromEmail(email);
|
||||||
|
|
||||||
MailMessage mailMessage = new MailMessage();
|
MailMessage mailMessage = new MailMessage();
|
||||||
|
@ -216,14 +230,11 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
mailMessage.setTo(to);
|
mailMessage.setTo(to);
|
||||||
|
|
||||||
String body = "<p>Dear " + username + ",<br />" + "<br />" +
|
String body = "<p>Dear " + username + ",<br />" + "<br />" +
|
||||||
"Welcome! You recently created an account at http:// " + portalUrl + ". Your password is not sent by email for security purposes.<br />" +
|
"Welcome! You recently created an account at " + portalUrl + ". Your password is not sent by email for security purposes.<br />" +
|
||||||
"<br />" + "Sincerely,<br />" +
|
"<br />" + "Sincerely,<br />" +
|
||||||
gatewayName + "<br />" +
|
gatewayName + "<br />" +
|
||||||
emailSender + "<br />" + portalUrl;
|
emailSender + "<br />" + portalUrl;
|
||||||
String subject = "http://" + portalUrl + ": Your New Account was created successfully!";
|
String subject = portalUrl + ": Your New Account was created successfully!";
|
||||||
|
|
||||||
logger.debug("Body is " + body);
|
|
||||||
logger.debug("Subject is " + subject);
|
|
||||||
|
|
||||||
mailMessage.setBody(body);
|
mailMessage.setBody(body);
|
||||||
mailMessage.setSubject(subject);
|
mailMessage.setSubject(subject);
|
||||||
|
@ -365,7 +376,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
if (!isWithinPortal()) {
|
if (!isWithinPortal()) {
|
||||||
|
|
||||||
logger.debug("In dev mode.");
|
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("Dylan", "Dog", "ISTI-CNR", "dylan.dog@gmail.com", true, System.currentTimeMillis(), true));
|
||||||
toReturn.add(new VreUserBean("Costantino", "Perciante", "ISTI-CNR", "costantino8@gmail.com", false, System.currentTimeMillis(), true));
|
toReturn.add(new VreUserBean("Costantino", "Perciante", "ISTI-CNR", "costantino8@gmail.com", false, System.currentTimeMillis(), true));
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
||||||
|
@ -451,7 +462,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
logger.debug("Going to delete user with email " + email);
|
logger.debug("Going to delete user with email " + email + " from the table of registered users");
|
||||||
|
|
||||||
String remove = "DELETE FROM " + REGISTERED_USERS_TABLE + " WHERE " + FIELD_EMAIL + "= ?";
|
String remove = "DELETE FROM " + REGISTERED_USERS_TABLE + " WHERE " + FIELD_EMAIL + "= ?";
|
||||||
PreparedStatement statementDelete = con.prepareStatement(remove);
|
PreparedStatement statementDelete = con.prepareStatement(remove);
|
||||||
|
@ -518,4 +529,23 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Company getCompany() throws PortalException, SystemException {
|
||||||
|
return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the default company web-id (e.g. iMarine.eu)
|
||||||
|
*/
|
||||||
|
public static String getDefaultCompanyWebId() {
|
||||||
|
String defaultWebId = "";
|
||||||
|
try {
|
||||||
|
defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
|
||||||
|
}
|
||||||
|
catch (NullPointerException e) {
|
||||||
|
logger.error("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
|
||||||
|
return DEFAULT_COMPANY_WEB_ID;
|
||||||
|
}
|
||||||
|
return defaultWebId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
Loading…
Reference in New Issue