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

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

Introduction

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

Prototype

public static com.liferay.portal.kernel.model.User getUser(long userId)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the user with the primary key.

Usage

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

License:Open Source License

@Override
public List<Website> getUserWebsites(long userId) throws PortalException {

    _log.info("Getting websites for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    List<Website> websites = new ArrayList<>();

    if (user != null) {
        websites = user.getWebsites();/*from  w w  w .  j a va2 s . c  o  m*/
    }

    return websites;
}

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

License:Open Source License

@Override
public Contact getUserContact(long userId) throws PortalException {

    _log.info("Getting contact record for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    Contact contact = null;//w w  w .  ja  v a 2  s  .c o m

    if (user != null) {
        contact = user.fetchContact();
    }

    return contact;
}

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

License:Open Source License

@Override
public List<Organization> getUserOrganizations(long userId) throws PortalException {

    _log.info("Getting organizations for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    List<Organization> organizations = new ArrayList<>();

    if (user != null) {
        organizations = user.getOrganizations();
    }/*from  w w w .  j  a  va2  s . com*/

    return organizations;
}

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

License:Open Source License

@Override
public List<Group> getUserSites(long userId) throws PortalException {

    _log.info("Getting sites for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    List<Group> groups = new ArrayList<>();

    if (user != null) {
        groups = user.getMySiteGroups();
    }/*from w  w w .j av a 2s  .  c  om*/

    return groups;
}

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

License:Open Source License

@Override
public List<Group> getUserGroups(long userId) throws PortalException {

    _log.info("Getting groups for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    List<Group> groups = new ArrayList<>();

    if (user != null) {
        groups = user.getGroups();//  w ww.  jav a2 s  .  co m
    }

    return groups;
}

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

License:Open Source License

@Override
public List<Role> getUserRoles(long userId) throws PortalException {

    _log.info("Getting roles for user with id: " + String.valueOf(userId));

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

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

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    List<Role> userRoles = new ArrayList<>();

    if (user != null) {
        userRoles = user.getRoles();/*from  w ww  . java2  s. c o  m*/
    }

    return userRoles;
}

From source file:it.sysdata.base.service.impl.UserHelper_1_1ServiceImpl.java

License:Open Source License

@Override
@AccessControlled(guestAccessEnabled = false)
public String getUserProfilePage() throws PortalException, SystemException {

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    User realUser = UserLocalServiceUtil.getUser(getUserId());

    return TokenAutoLogin.getUserProfilePage(serviceContext.getRequest(), realUser.getUserId());
}

From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImpl.java

License:Open Source License

public Idea addMBMessage(Idea idea, ServiceContext serviceContext, long groupId, long userId, String comment,
        long ideaCommentClassPK) throws PortalException, SystemException {

    User user = UserLocalServiceUtil.getUser(userId);

    MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId, groupId,
            IdeaContent.class.getName(), ideaCommentClassPK, WorkflowConstants.STATUS_ANY);

    MBThread thread = messageDisplay.getThread();
    long threadId = thread.getThreadId();
    long rootThreadId = thread.getRootMessageId();

    String commentContentCleaned = comment;
    final int maxLenghtCommentSubject = 50;
    String commentSubject = comment;
    commentSubject = StringUtil.shorten(commentSubject, maxLenghtCommentSubject);
    commentSubject += "...";

    // TODO - validate comment and preserve line breaks
    MBMessageLocalServiceUtil.addDiscussionMessage(userId, user.getScreenName(), groupId,
            IdeaContent.class.getName(), ideaCommentClassPK, threadId, rootThreadId, commentSubject,
            commentContentCleaned, serviceContext);

    return idea;/*ww w. ja  v a2  s . c om*/
}

From source file:se.vgregion.service.innovationsslussen.idea.permission.IdeaPermissionCheckerServiceImpl.java

License:Open Source License

@Override
public IdeaPermissionChecker getIdeaPermissionChecker(long scopeGroupId, long userId, Idea idea) {

    IdeaPermissionChecker ideaPermissionChecker = new IdeaPermissionChecker();

    try {/*from w ww  .j av a2s .c o m*/
        String ideaId = idea.getId();

        if (ideaId == null) {
            ideaId = "0";
        }

        User user = UserLocalServiceUtil.getUser(userId);

        PermissionChecker permissionChecker = getPermissionChecker(user);

        // Get create permissions
        boolean hasPermissionCreateIdeaForOtherUser = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.CREATE_IDEA_FOR_OTHER_USER);

        // Get add permissions
        boolean hasPermissionAddCommentPublic = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.ADD_COMMENT_PUBLIC);
        boolean hasPermissionAddCommentPrivate = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.ADD_COMMENT_PRIVATE);

        boolean hasPermissionAddDocumentPublic = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.ADD_DOCUMENT_PUBLIC);

        boolean hasPermissionAddDocumentPrivate = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.ADD_DOCUMENT_PRIVATE);
        boolean hasPermissionAddFavorite = permissionChecker.hasPermission(scopeGroupId, Idea.class.getName(),
                ideaId, IdeaActionKeys.ADD_FAVORITE);
        boolean hasPermissionAddLike = permissionChecker.hasPermission(scopeGroupId, Idea.class.getName(),
                ideaId, IdeaActionKeys.ADD_LIKE);

        // Get delete permissions
        boolean hasPermissionDeleteCommentPublic = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.DELETE_COMMENT_PUBLIC);
        boolean hasPermissionDeleteCommentPrivate = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.DELETE_COMMENT_PRIVATE);

        boolean hasPermissionDeleteFavorite = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.DELETE_FAVORITE);
        boolean hasPermissionDeleteLike = permissionChecker.hasPermission(scopeGroupId, Idea.class.getName(),
                ideaId, IdeaActionKeys.DELETE_LIKE);

        // Get update permissions
        boolean hasPermissionUpdateFromBarium = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.UPDATE_FROM_BARIUM);

        // Get view permissions
        boolean hasPermissionViewCommentPublic = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.VIEW_COMMENT_PUBLIC);
        boolean hasPermissionViewCommentPrivate = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.VIEW_COMMENT_PRIVATE);
        boolean hasPermissionViewIdeaPublic = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.VIEW_IDEA_PUBLIC);
        boolean hasPermissionViewIdeaPrivate = permissionChecker.hasPermission(scopeGroupId,
                Idea.class.getName(), ideaId, IdeaActionKeys.VIEW_IDEA_PRIVATE);
        boolean hasPermissionViewInBarium = permissionChecker.hasPermission(scopeGroupId, Idea.class.getName(),
                ideaId, IdeaActionKeys.VIEW_IN_BARIUM);

        boolean userPrioCouncilMember = ideaService.isUserPrioCouncilMember(userId, scopeGroupId);
        boolean userInnovationsslussenEmployee = ideaService.isUserInnovationsslussenEmployee(userId,
                scopeGroupId);
        boolean userIdeaTransporter = ideaService.isUserIdeaTransporter(userId, scopeGroupId);

        // Get owner permissions
        boolean isIdeaOwner = (userId == idea.getUserId());

        // Set add permissions
        ideaPermissionChecker.setHasPermissionAddCommentPrivate(hasPermissionAddCommentPrivate);
        ideaPermissionChecker.setHasPermissionAddCommentPublic(hasPermissionAddCommentPublic);
        ideaPermissionChecker.setHasPermissionAddDocumentPrivate(hasPermissionAddDocumentPrivate);
        ideaPermissionChecker.setHasPermissionAddDocumentPublic(hasPermissionAddDocumentPublic);
        ideaPermissionChecker.setHasPermissionAddFavorite(hasPermissionAddFavorite);
        ideaPermissionChecker.setHasPermissionAddLike(hasPermissionAddLike);

        //Set create premissions
        ideaPermissionChecker.setHasPermissionCreateIdeaForOtherUser(hasPermissionCreateIdeaForOtherUser);

        // Set delete permissions
        ideaPermissionChecker.setHasPermissionDeleteCommentPrivate(hasPermissionDeleteCommentPrivate);
        ideaPermissionChecker.setHasPermissionDeleteCommentPublic(hasPermissionDeleteCommentPublic);
        ideaPermissionChecker.setHasPermissionDeleteFavorite(hasPermissionDeleteFavorite);
        ideaPermissionChecker.setHasPermissionDeleteLike(hasPermissionDeleteLike);

        // Set update permissions
        ideaPermissionChecker.setHasPermissionUpdateFromBarium(hasPermissionUpdateFromBarium);

        // Set view permissions
        ideaPermissionChecker.setHasPermissionViewCommentPublic(hasPermissionViewCommentPublic);
        ideaPermissionChecker.setHasPermissionViewCommentPrivate(hasPermissionViewCommentPrivate);
        ideaPermissionChecker.setHasPermissionViewIdeaPublic(hasPermissionViewIdeaPublic);
        ideaPermissionChecker.setHasPermissionViewIdeaPrivate(hasPermissionViewIdeaPrivate);
        ideaPermissionChecker.setHasPermissionViewInBarium(hasPermissionViewInBarium);

        // Set owner permissions
        ideaPermissionChecker.setIsIdeaOwner(isIdeaOwner);

        // Set info about roles.
        ideaPermissionChecker.setUserPrioCouncilMember(userPrioCouncilMember);
        ideaPermissionChecker.setUserInnovationsslussenEmployee(userInnovationsslussenEmployee);
        ideaPermissionChecker.setUserIdeaTransporter(userIdeaTransporter);

    } catch (PortalException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (SystemException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (PermissionCheckerException e) {
        LOGGER.error(e.getMessage(), e);
    }

    return ideaPermissionChecker;
}

From source file:tj.obwaja.informacija.service.impl.ObwajaInformacijaLocalServiceImpl.java

License:Open Source License

public ObwajaInformacija getObInfoByIzvewenieId(long IzvewenijaID, long userId) {

    ObwajaInformacija obwaja_informacija = new ObwajaInformacijaImpl();
    String phone = "";
    String email = "";
    String fullname = "";
    try {/*from  w  w w .ja v  a 2  s  .c o m*/
        obwaja_informacija = obwajaInformacijaPersistence.findByIzvewenieID(IzvewenijaID);
    } catch (NoSuchObwajaInformacijaException e) {
        List<Phone> phones = Collections.emptyList();

        try {
            User user = UserLocalServiceUtil.getUser(userId);
            phones = user.getPhones();

            if (!phones.isEmpty())
                phone = phones.get(0).getNumber();

            email = user.getEmailAddress();
            fullname = user.getFullName(false, true);

            obwaja_informacija.setJe_pochta(email);
            obwaja_informacija.setKontaktnyj_telefon(phone);
            obwaja_informacija.setKontaktnoe_lico(fullname);
        } catch (PortalException e1) {

        }

    }

    return obwaja_informacija;
}