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:com.liferay.exportimport.trash.test.util.ExportImportConfigurationTestUtil.java

License:Open Source License

public static Map<String, Serializable> getDefaultSettingsMap(long userId, long groupId) throws Exception {

    User user = UserLocalServiceUtil.getUser(userId);

    return ExportImportConfigurationSettingsMapFactory.buildPublishLayoutLocalSettingsMap(user, groupId,
            groupId, false, null, null);
}

From source file:com.liferay.journal.service.test.JournalArticleExpirationTest.java

License:Open Source License

protected Calendar getExpirationCalendar(long timeUnit, int timeValue) throws PortalException {

    Calendar calendar = new GregorianCalendar();

    calendar.setTime(new Date(System.currentTimeMillis() + timeUnit * timeValue));

    User user = UserLocalServiceUtil.getUser(TestPropsValues.getUserId());

    calendar.setTimeZone(user.getTimeZone());

    return calendar;
}

From source file:com.liferay.layout.internal.model.adapter.StagedLayoutSetImpl.java

License:Open Source License

public StagedLayoutSetImpl(LayoutSet layoutSet) {
    Objects.requireNonNull(layoutSet, "Unable to create a new staged layout set for a null layout set");

    _layoutSet = layoutSet;/*from  w ww. ja v  a 2 s.co  m*/

    // Last publish date

    UnicodeProperties settingsProperties = _layoutSet.getSettingsProperties();

    String lastPublishDateString = settingsProperties.getProperty("last-publish-date");

    Instant instant = Instant.ofEpochMilli(GetterUtil.getLong(lastPublishDateString));

    _lastPublishDate = Date.from(instant);

    // Layout set prototype

    if (Validator.isNotNull(_layoutSet.getLayoutSetPrototypeUuid())) {
        LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil
                .fetchLayoutSetPrototypeByUuidAndCompanyId(_layoutSet.getLayoutSetPrototypeUuid(),
                        _layoutSet.getCompanyId());

        if (layoutSetPrototype != null) {
            _layoutSetPrototypeName = layoutSetPrototype.getName(LocaleUtil.getDefault());
        }
    }

    try {
        Group layoutSetGroup = _layoutSet.getGroup();

        _userId = layoutSetGroup.getCreatorUserId();

        User user = UserLocalServiceUtil.getUser(_userId);

        _userName = user.getFullName();
        _userUuid = user.getUuid();
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }
    }
}

From source file:com.liferay.micro.maintainance.candidate.service.impl.CandidateEntryLocalServiceImpl.java

License:Open Source License

/**
 * Upon flagging a wiki page for a certain maintenance task this method
 * creates a candidate entry, belonging to the page, in the database.
 * It also creates an AnalysisEntry element, in which the current status of
 * the voting is stored, and a CandidateMaintenance element, which binds the
 * task and the candidate together./*from ww w  .  ja v a  2 s .  co  m*/
 *
 * @param userId: the id of the user who flagged the page
 * @param groupId: the id of the group to which the wiki page belongs
 * @param wikiPageId: the id of the flagged wiki page
 * @param taskId: the id of the maintenance task for which the page is
 * flagged
 * @return the CandidateEntry that was added
 * @throws PortalException
 */
@Override
public CandidateEntry addCandidateEntry(long userId, long groupId, long wikiPageId, long taskId)
        throws PortalException {

    CandidateEntry candidateEntry = getCandidateByWikiPageId(wikiPageId);

    if (candidateEntry == null) {
        User user = UserLocalServiceUtil.getUser(userId);
        long candidateEntryId = counterLocalService.increment();
        Date now = new Date();

        candidateEntry = candidateEntryPersistence.create(candidateEntryId);

        candidateEntry.setGroupId(groupId);

        candidateEntry.setCompanyId(user.getCompanyId());
        candidateEntry.setUserId(userId);
        candidateEntry.setUserName(user.getFullName());
        candidateEntry.setCreateDate(now);
        candidateEntry.setModifiedDate(now);

        candidateEntry.setWikiPageId(wikiPageId);

        candidateEntryPersistence.update(candidateEntry);
    }

    CandidateMaintenance existingCandidateMaintenance = CandidateMaintenanceLocalServiceUtil
            .getCandidateMaintenaceTask(candidateEntry.getCandidateEntryId(), taskId);

    if (existingCandidateMaintenance == null) {
        CandidateMaintenance candidateMaintenance = CandidateMaintenanceLocalServiceUtil
                .addCandidateMaintenance(candidateEntry.getCandidateEntryId(), taskId);

        AnalysisEntry analysisEntry = AnalysisEntryLocalServiceUtil.addAnalysisEntry(userId,
                candidateMaintenance.getCandidateMaintenanceId());
    }

    return candidateEntry;
}

From source file:com.liferay.product.navigation.site.administration.internal.display.context.SiteAdministrationPanelCategoryDisplayContext.java

License:Open Source License

public String getGroupName() throws PortalException {
    if (_groupName != null) {
        return _groupName;
    }//from w w w  .j av a  2 s.  c  om

    Group group = getGroup();

    if (group == null) {
        _groupName = StringPool.BLANK;
    } else {
        if (group.isUser()) {
            if (group.getClassPK() == _themeDisplay.getUserId()) {
                _groupName = LanguageUtil.get(_themeDisplay.getRequest(), "my-site");
            } else {
                User user = UserLocalServiceUtil.getUser(group.getClassPK());

                _groupName = LanguageUtil.format(getResourceBundle(), "x-site", user.getFullName());
            }
        } else {
            _groupName = group.getDescriptiveName(_themeDisplay.getLocale());
        }
    }

    return _groupName;
}

From source file:com.liferay.site.memberships.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static List<User> getUsers(ResourceRequest request) throws Exception {

    long[] userIds = ParamUtil.getLongValues(request, "rowIds");

    List<User> users = new ArrayList<>();

    for (long userId : userIds) {
        User user = UserLocalServiceUtil.getUser(userId);

        users.add(user);/*from  w w  w  .ja v  a2s  . c o  m*/
    }

    return users;
}

From source file:com.liferay.social.activity.service.test.SocialActivityServiceTest.java

License:Open Source License

@Test
public void testPagingFilterActivities() throws Exception {
    for (int i = 0; i < 4; i++) {
        addFileEntry(RandomTestUtil.randomString() + ".txt", String.valueOf(i));

        FileEntry fileEntry = addFileEntry(RandomTestUtil.randomString() + ".txt",
                RandomTestUtil.randomString());

        deleteGuestPermission(fileEntry);
    }//from w ww . ja  va 2 s.com

    long userId = PrincipalThreadLocal.getUserId();

    ServiceTestUtil.setUser(_user);

    try {
        Assert.assertEquals(8, SocialActivityServiceUtil.getGroupActivitiesCount(_group.getGroupId()));

        List<SocialActivity> activities = SocialActivityServiceUtil.getGroupActivities(_group.getGroupId(), 0,
                2);

        Assert.assertEquals(activities.toString(), 2, activities.size());

        int index = 3;

        for (SocialActivity activity : activities) {
            String title = String.valueOf(index);

            Assert.assertEquals(title, activity.getExtraDataValue("title"));

            index--;
        }

        activities = SocialActivityServiceUtil.getGroupActivities(_group.getGroupId(), 2, 4);

        Assert.assertEquals(activities.toString(), 2, activities.size());

        for (SocialActivity activity : activities) {
            String title = String.valueOf(index);

            Assert.assertEquals(title, activity.getExtraDataValue("title"));

            index--;
        }
    } finally {
        User user = UserLocalServiceUtil.getUser(userId);

        ServiceTestUtil.setUser(user);
    }
}

From source file:com.rivetlogic.skype.model.impl.SkypeGroupImpl.java

License:Open Source License

private JSONArray getContactsArray() {
    JSONArray array = JSONFactoryUtil.createJSONArray();
    Long userId = null;/*from  ww  w  . j a  va2  s .  com*/
    boolean isSkype = false;
    User user = null;
    JSONObject item = null;
    JSONObject value = null;
    JSONArray contacts = null;
    try {
        contacts = JSONFactoryUtil.createJSONArray(getSkypeContacts());
        if (contacts != null) {
            for (int i = 0; contacts.length() > i; i++) {
                item = contacts.getJSONObject(i);
                userId = item.getLong(USER_ID);
                isSkype = item.getBoolean(IS_SKYPE);
                try {
                    user = UserLocalServiceUtil.getUser(userId);
                } catch (PortalException e) {
                    LOG.error(e);
                }
                if (user != null) {
                    value = JSONFactoryUtil.createJSONObject();
                    value.put(FIRST_NAME, user.getFirstName());
                    value.put(LAST_NAME, user.getLastName());
                    value.put(USER_ID, user.getUserId());
                    if (isSkype) {
                        value.put(SKYPE_SCREEN_NAME, getSkypeScreenName(user));
                        value.put(PRIMARY_PHONE, StringPool.BLANK);
                    } else {
                        value.put(PRIMARY_PHONE, getPrimaryPhone(user));
                        value.put(SKYPE_SCREEN_NAME, StringPool.BLANK);
                    }

                    value.put(IS_SKYPE, isSkype);
                    array.put(value);
                }
            }
        }

    } catch (JSONException e) {
        LOG.error(e);
    }

    return array;
}

From source file:com.rivetlogic.skype.service.impl.SkypeGroupLocalServiceImpl.java

License:Open Source License

public SkypeGroup createSkypeGroup(SkypeGroup skypeGroup) throws SystemException, PortalException {
    skypeGroup.setSkypeGroupId(counterLocalService.increment(SkypeGroup.class.getName()));
    User user = UserLocalServiceUtil.getUser(skypeGroup.getUserId());
    Date now = getTodayDate();//from  ww  w. ja  v a 2 s.  c  o  m

    skypeGroup.setUserName(user.getScreenName());
    skypeGroup.setCreateDate(now);
    skypeGroup.setModifiedDate(now);

    skypeGroupPersistence.update(skypeGroup);
    LOG.debug("New skypeGroup: " + skypeGroup.toJSON());
    return skypeGroup;
}

From source file:com.rivetlogic.skype.util.SkypeUtil.java

License:Open Source License

public static UserBean getUserBean(Long userId) {
    UserBean userBean = null;//  w w w . j a  v  a 2 s  .c  o  m
    User user = null;
    try {
        user = UserLocalServiceUtil.getUser(userId);
        userBean = parseUser(user);
    } catch (Exception e) {
        LOG.error(e);
    }
    return userBean;
}