Added new event and its sender to accomplish task by event publish to the orchestrator. Related to tasks #19811 and #19812

This commit is contained in:
Mauro Mugnaini 2020-09-21 17:39:22 +02:00
parent b9d9d41569
commit e78b60ebd6
2 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,90 @@
package org.gcube.portlets.admin.createusers.orchestrator;
import org.gcube.portal.event.publisher.lr62.PortalEvent;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.security.auth.CompanyThreadLocal;
import com.liferay.portal.security.auth.DefaultScreenNameGenerator;
import com.liferay.portal.service.UserLocalServiceUtil;
public class CreateUserAddToVre extends PortalEvent {
private static final long serialVersionUID = 1499288552188273747L;
public static final String NAME = "create-user-add-to-vre";
public static final String FIRST_NAME_ENTRY = "first-name";
public static final String LAST_NAME_ENTRY = "last-name";
public static final String EMAIL_ENTRY = "email";
public static final String PASSWORD_ENTRY = "password";
private static DefaultScreenNameGenerator defaultScreenNameGenerator = new DefaultScreenNameGenerator();
private CreateUserAddToVre(String firstname, String lastname, String email, String password, Group group)
throws PortalException, SystemException {
super(NAME);
setUser(computeUsername(email));
setFirstname(firstname);
setLastname(lastname);
setEmail(email);
setPassword(password);
setGroup(group);
}
public static CreateUserAddToVre newEvent(String firstname, String lastname, String email, String password,
Group group) {
try {
return new CreateUserAddToVre(firstname, lastname, email, password, group);
} catch (PortalException | SystemException e) {
log.error("Cannot create event from group model object", e);
return null;
}
}
protected String computeUsername(String email) {
try {
Long companyId = CompanyThreadLocal.getCompanyId();
Long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
return defaultScreenNameGenerator.generate(companyId, defaultUserId, email);
} catch (Exception e) {
log.error("Cannot generate username via screen name generator", e);
return "";
}
}
public void setFirstname(String firstname) {
set(FIRST_NAME_ENTRY, firstname);
}
public String getFirstname() {
return (String) get(FIRST_NAME_ENTRY);
}
public void setLastname(String lastname) {
set(LAST_NAME_ENTRY, lastname);
}
public String getLastname() {
return (String) get(LAST_NAME_ENTRY);
}
public void setEmail(String email) {
set(EMAIL_ENTRY, email);
}
public String getEmail() {
return (String) get(EMAIL_ENTRY);
}
public void setPassword(String password) {
set(PASSWORD_ENTRY, password);
}
public String getPassword() {
return (String) get(PASSWORD_ENTRY);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.portlets.admin.createusers.orchestrator;
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
public class CreateUserAddToVrePublisher extends AbstractLR62EventPublisher {
public CreateUserAddToVrePublisher() {
super();
}
}