Example usage for com.liferay.portal.kernel.exception NoSuchUserException NoSuchUserException

List of usage examples for com.liferay.portal.kernel.exception NoSuchUserException NoSuchUserException

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.exception NoSuchUserException NoSuchUserException.

Prototype

public NoSuchUserException(Throwable cause) 

Source Link

Usage

From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCActionCommand.java

License:Open Source License

protected User getUser(ActionRequest actionRequest) throws Exception {
    PortletSession portletSession = actionRequest.getPortletSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String sessionEmailAddress = (String) portletSession
            .getAttribute(WebKeys.FORGOT_PASSWORD_REMINDER_USER_EMAIL_ADDRESS);

    User user = null;//from  www  .j a  v  a 2s.c  o  m

    if (Validator.isNotNull(sessionEmailAddress)) {
        user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), sessionEmailAddress);
    } else {
        long userId = ParamUtil.getLong(actionRequest, "userId");
        String screenName = ParamUtil.getString(actionRequest, "screenName");
        String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

        if (Validator.isNotNull(emailAddress)) {
            user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
        } else if (Validator.isNotNull(screenName)) {
            user = _userLocalService.getUserByScreenName(themeDisplay.getCompanyId(), screenName);
        } else if (userId > 0) {
            user = _userLocalService.getUserById(userId);
        } else {
            throw new NoSuchUserException("User does not exist");
        }
    }

    if (!user.isActive()) {
        throw new UserActiveException("Inactive user " + user.getUuid());
    }

    _userLocalService.checkLockout(user);

    return user;
}

From source file:com.mimacom.service.service.impl.TaskLocalServiceImpl.java

License:Open Source License

public Task updateTask(long taskId, long userId, String taskDescription, boolean completed, Date initDate,
        Date endDate, ServiceContext serviceContext) throws NoSuchUserException {

    //Check if user exist in the portal
    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    Task task = TaskLocalServiceUtil.fetchTask(taskId);

    //Only update if userId == task.userId
    if (task.getUserId() == userId) {
        task.setModifiedDate(serviceContext.getModifiedDate(now));
        task.setTask(taskDescription);/*  w  w w.ja va 2s  .c  o  m*/
        task.setCompleted(completed);
        task.setInitDate(initDate);
        task.setEndDate(endDate);

        super.updateTask(task);
    } else {
        throw new NoSuchUserException("USER ID NOT EQUALS WITH TASK USER ID!");
    }

    return task;
}