92 lines
3.0 KiB
Java
92 lines
3.0 KiB
Java
package org.gcube.portlets.admin.createusers.orchestrator;
|
|
|
|
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
|
import org.gcube.portlets.admin.createusers.server.CreateUsersImpl;
|
|
|
|
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 = CreateUsersImpl.getCompany().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);
|
|
}
|
|
|
|
}
|