async removal of the user after the respons

This commit is contained in:
Massimiliano Assante 2020-01-30 15:12:59 +01:00
parent 5ff98c894d
commit 6e368e570c
3 changed files with 51 additions and 9 deletions

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <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/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="remove-account-library-1.2.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/remove-account-library/remove-account-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="tou-optout-hook"/> <property name="context-root" value="tou-optout-hook"/>
<property name="java-output-path" value="/tou-optout-hook/target/classes"/> <property name="java-output-path" value="/tou-optout-hook/target/classes"/>
</wb-module> </wb-module>

View File

@ -3,7 +3,7 @@ package com.liferay.samplestrutsaction.hook.action;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.gcube.portal.removeaccount.D4ScienceRemoveAccountManager; import org.gcube.portal.tou.removeaccount.thread.RemovedUserAccountThread;
import com.liferay.portal.kernel.struts.BaseStrutsAction; import com.liferay.portal.kernel.struts.BaseStrutsAction;
import com.liferay.portal.kernel.struts.StrutsAction; import com.liferay.portal.kernel.struts.StrutsAction;
@ -17,14 +17,21 @@ public class UpdateTermsOfUseAction extends BaseStrutsAction {
public String execute(StrutsAction originalStrutsAction, HttpServletRequest request, HttpServletResponse response) throws Exception { public String execute(StrutsAction originalStrutsAction, HttpServletRequest request, HttpServletResponse response) throws Exception {
String agreement = request.getParameter("agreement"); String agreement = request.getParameter("agreement");
if (agreement.compareTo("i-disagree")==0) { //the user did not agree if (agreement.compareTo("i-disagree")==0) { //the user did not agree
User user = PortalUtil.getUser(request); String username2Delete = null;
try { try {
D4ScienceRemoveAccountManager removeAccountManager = new D4ScienceRemoveAccountManager(user.getScreenName()); User user = PortalUtil.getUser(request);
removeAccountManager.doAsyncRemoveAccount(); username2Delete = user.getScreenName();
System.out.println("*** UpdateTermsOfUseAction user DID NOT AGREE, removeUser account for username=" + user.getScreenName() + " done with success, notified also the managers ... ");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("*** UpdateTermsOfUseAction user DID NOT AGREE, removeUser account for username=" + username2Delete + " ongoing ... ");
if (username2Delete != null) {
Thread dropUserAccountThread = new Thread(new RemovedUserAccountThread(username2Delete));
dropUserAccountThread.start();
} else {
System.out.println("Account not removed");
}
return "/../c/portal/logout"; return "/../c/portal/logout";
} }
else //the user agreed else //the user agreed

View File

@ -0,0 +1,38 @@
package org.gcube.portal.tou.removeaccount.thread;
import org.gcube.portal.removeaccount.D4ScienceRemoveAccountManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Massimiliano Assante ISTI-CNR
*
*/
public class RemovedUserAccountThread implements Runnable {
private static final Logger _log = LoggerFactory.getLogger(RemovedUserAccountThread.class);
private String userNameToDelete;
public RemovedUserAccountThread(String userNameToDelete) {
super();
this.userNameToDelete = userNameToDelete;
}
@Override
public void run() {
try {
D4ScienceRemoveAccountManager removeAccountManager = new D4ScienceRemoveAccountManager(userNameToDelete);
boolean result = removeAccountManager.doAsyncRemoveAccount();
_log.info("The user "+userNameToDelete+ " removed her/his account with success?"+ result);
} catch (Exception e) {
_log.error("An error occurred during user workspace removal: ", e);
}
}
}