Example usage for com.liferay.portal.kernel.service UserLocalServiceUtil addUserWithWorkflow

List of usage examples for com.liferay.portal.kernel.service UserLocalServiceUtil addUserWithWorkflow

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service UserLocalServiceUtil addUserWithWorkflow.

Prototype

public static com.liferay.portal.kernel.model.User addUserWithWorkflow(long creatorUserId, long companyId,
        boolean autoPassword, String password1, String password2, boolean autoScreenName, String screenName,
        String emailAddress, long facebookId, String openId, java.util.Locale locale, String firstName,
        String middleName, String lastName, long prefixId, long suffixId, boolean male, int birthdayMonth,
        int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds, long[] organizationIds,
        long[] roleIds, long[] userGroupIds, boolean sendEmail, ServiceContext serviceContext)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Adds a user with workflow.

Usage

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

@Override
public User addNewUser(String screenName, String emailAddress, long companyId, String locale, long[] groupIds,
        long[] organizationIds, long[] roleIds, long[] userGroupIds) throws PortalException {
    User newUser = null;//from   w  w  w.j a  v  a2 s . com
    long creatorId = 0;

    _log.info("Adding new user ...");

    _log.debug("    ... security check ...");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER);

    _log.debug("    .... processing ...");

    try {

        try {
            creatorId = this.getGuestOrUserId();
        } catch (PrincipalException pe) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to get current user ID", pe);
            }
        }

        boolean autoScreenName = false;

        if (StringUtils.isEmpty(screenName)) {
            _log.warn("No screen name given! Switching to auto screen name!");
            autoScreenName = true;
            screenName = "";
        }

        if (StringUtils.isEmpty(emailAddress)) {
            _log.warn("No email address given!");
            throw new PortalException("A email address is needed for new users!");
        }

        this.validateEmail(emailAddress, null);

        User existingUser = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, emailAddress);

        if (existingUser == null) {

            ServiceContext serviceContext = new ServiceContext();

            this.checkAddUserPermission(creatorId, companyId, emailAddress, groupIds, organizationIds, roleIds,
                    userGroupIds, serviceContext);

            // Null safe actions
            if (groupIds == null) {
                groupIds = new long[0];
            }

            if (organizationIds == null) {
                organizationIds = new long[0];
            }

            if (roleIds == null) {
                roleIds = new long[0];
            }

            if (userGroupIds == null) {
                userGroupIds = new long[0];
            }

            _log.info("Creating new user with email address: " + emailAddress);

            boolean autoPassword = true;
            String password1 = "";
            String password2 = "";
            long facebookId = 0;
            String openId = "";
            Locale loc = ServiceUtils.getLocaleFromString(locale);
            String firstName = INVISIBLE_PLACEHOLDER;
            String middleName = "";
            String lastName = INVISIBLE_PLACEHOLDER;
            int prefixId = 0;
            int suffixId = 0;
            boolean male = false;

            int birthdayMonth = 1;
            int birthdayDay = 1;
            int birthdayYear = 1970;
            String jobTitle = "";

            boolean sendEmail = true;

            boolean workflowEnabled = WorkflowThreadLocal.isEnabled();

            try {

                newUser = UserLocalServiceUtil.addUserWithWorkflow(creatorId, companyId, autoPassword,
                        password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, loc,
                        firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay,
                        birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
                        null);

                _log.debug("New user record: " + newUser.toString());

            } finally {
                WorkflowThreadLocal.setEnabled(workflowEnabled);
            }

        } else {
            _log.error(
                    "User cannot be created! Found already the following account: " + existingUser.toString());
            throw new PortalException("Fatal! User already exists");
        }
        // Send validation mail

    } catch (PortalException pe) {
        _log.error(pe);
        throw pe;
    }

    return newUser;
}