Example usage for com.liferay.portal.kernel.util PortalUtil getUserName

List of usage examples for com.liferay.portal.kernel.util PortalUtil getUserName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getUserName.

Prototype

public static String getUserName(long userId, String defaultUserName) 

Source Link

Usage

From source file:com.liferay.filesystemaccess.audit.AuditMessageBuilder.java

License:Open Source License

public static AuditMessage buildAuditMessage(String eventType, String className, long classPK,
        List<Attribute> attributes) {

    long companyId = CompanyThreadLocal.getCompanyId();

    long userId = 0;

    if (PrincipalThreadLocal.getName() != null) {
        userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
    }/*from  w  w  w.  j  a va2 s  .c o  m*/

    AuditRequestThreadLocal auditRequestThreadLocal = AuditRequestThreadLocal.getAuditThreadLocal();

    long realUserId = auditRequestThreadLocal.getRealUserId();

    String realUserName = PortalUtil.getUserName(realUserId, StringPool.BLANK);

    JSONObject additionalInfo = JSONFactoryUtil.createJSONObject();

    if ((realUserId > 0) && (userId != realUserId)) {
        additionalInfo.put("doAsUserId", String.valueOf(userId));
        additionalInfo.put("doAsUserName", PortalUtil.getUserName(userId, StringPool.BLANK));
    }

    if (attributes != null) {
        additionalInfo.put("attributes", _getAttributesJSON(attributes));
    }

    return new AuditMessage(eventType, companyId, realUserId, realUserName, className, String.valueOf(classPK),
            null, additionalInfo);
}

From source file:com.liferay.microblogs.web.internal.util.MicroblogsWebUtil.java

License:Open Source License

protected static String replaceUserTags(String content, ServiceContext serviceContext) throws PortalException {

    Matcher matcher = _userTagPattern.matcher(content);

    while (matcher.find()) {
        String result = matcher.group();

        try {//from ww  w. j  a v a 2s  . co  m
            StringBuilder sb = new StringBuilder(5);

            sb.append("<a href=\"");

            String assetTagScreenName = result.replace("[@", StringPool.BLANK);

            assetTagScreenName = assetTagScreenName.replace("]", StringPool.BLANK);

            ThemeDisplay themeDisplay = serviceContext.getThemeDisplay();

            User assetTagUser = UserLocalServiceUtil.getUserByScreenName(themeDisplay.getCompanyId(),
                    assetTagScreenName);

            sb.append(assetTagUser.getDisplayURL(themeDisplay));

            sb.append("\">");

            String assetTagUserName = PortalUtil.getUserName(assetTagUser.getUserId(), assetTagScreenName);

            sb.append(assetTagUserName);

            sb.append("</a>");

            String userLink = sb.toString();

            content = StringUtil.replace(content, result, userLink);
        } catch (NoSuchUserException nsue) {
            if (_log.isDebugEnabled()) {
                _log.debug(nsue, nsue);
            }
        }
    }

    return content;
}

From source file:tj.izvewenija.service.impl.IzvewenijaLocalServiceImpl.java

License:Open Source License

public Izvewenija insertIzvewenija(long sostojanie_id, long status_id, long tip_izvewenija_id,
        long organizacija_id, String naimenovanie, long layoutPrototypeId, ServiceContext serviceContext) {
    final String ECONOMIC_OPERATOR = "ECONOMIC_OPERATOR";
    final String actionId[] = { "VIEW" };

    long izvewenija_id = CounterLocalServiceUtil.increment(Izvewenija.class.toString());
    Izvewenija izvewenija = IzvewenijaLocalServiceUtil.createIzvewenija(izvewenija_id);

    String description = description = "This group for member commission bid number "
            + String.valueOf(izvewenija.getIzvewenija_id());
    ;/*from   ww  w.ja va 2s.c om*/
    String groupName = "bid number " + String.valueOf(izvewenija.getIzvewenija_id());

    UserGroup userGroup = null;
    Group userGroupGroup = null;
    try {
        userGroup = UserGroupLocalServiceUtil.addUserGroup(serviceContext.getUserId(),
                serviceContext.getCompanyId(), groupName, description, serviceContext);

        userGroupGroup = userGroup.getGroup();

    } catch (PortalException e1) {

    }

    izvewenija.setSostojanie_id(sostojanie_id);
    izvewenija.setStatus_id(status_id);
    izvewenija.setTip_izvewenija_id(tip_izvewenija_id);
    izvewenija.setOrganizacija_id(organizacija_id);
    izvewenija.setNaimenovanie(naimenovanie);

    izvewenija.setCreateDate(new Date());
    izvewenija.setModifiedDate(new Date());

    izvewenija.setSozdal(serviceContext.getUserId());
    izvewenija.setIzmenil(serviceContext.getUserId());

    izvewenija.setCompanyId(serviceContext.getCompanyId());
    izvewenija.setGroupId(serviceContext.getScopeGroupId());
    izvewenija.setUserId(serviceContext.getUserId());
    izvewenija.setUserName(PortalUtil.getUserName(serviceContext.getUserId(), "--"));

    izvewenija.setUserGroupId(userGroup.getUserGroupId());

    izvewenija = IzvewenijaLocalServiceUtil.addIzvewenija(izvewenija);

    try {
        resourceLocalService.addModelResources(izvewenija, serviceContext);

    } catch (PortalException e) {
        e.printStackTrace();
    } catch (SystemException e) {
        e.printStackTrace();
    }

    if (Validator.isNotNull(userGroup) && Validator.isNotNull(userGroupGroup)) {
        description = "This group for member commission bid number "
                + String.valueOf(izvewenija.getIzvewenija_id());
        groupName = "bid number " + String.valueOf(izvewenija.getIzvewenija_id());

        userGroup.setDescription(description);
        userGroup.setName(groupName);

        UserGroupLocalServiceUtil.updateUserGroup(userGroup);

        LayoutPrototype pageTemplate = null;
        try {
            pageTemplate = LayoutPrototypeLocalServiceUtil.getLayoutPrototype(layoutPrototypeId);

        } catch (PortalException e) {

        }
        String templateUuid = pageTemplate.getUuid();
        ServiceContext tserviceContext = new ServiceContext();
        tserviceContext.setAttribute("layoutPrototypeUuid", templateUuid);
        tserviceContext.setAttribute("layoutPrototypeLinkedEnabled", true);

        try {
            Layout layout = LayoutLocalServiceUtil.addLayout(serviceContext.getUserId(),
                    userGroupGroup.getGroupId(), false, 0,
                    "BID NUMBER " + String.valueOf(izvewenija.getIzvewenija_id()),
                    "BID NUMBER " + String.valueOf(izvewenija.getIzvewenija_id()),
                    "BID NUMBER " + String.valueOf(izvewenija.getIzvewenija_id()),

                    "portlet", false, "/group-" + String.valueOf(userGroup.getUserGroupId()), tserviceContext);

        } catch (PortalException e) {
            System.out.println("layout don't created");
        }

    }
    SystemConfig config = null;

    try {
        config = SystemConfigLocalServiceUtil.getSystemConfig(ECONOMIC_OPERATOR);
    } catch (NoSuchSystemConfigException e) {

        e.printStackTrace();
    }

    //ResourcePermissionLocalServiceUtil.addResourcePermission(serviceContext.getCompanyId(), Izvewenija.class.toString(), 4 ,String.valueOf(izvewenija.getIzvewenija_id()) , Long.valueOf(config.getValue()), actionId);
    try {
        ResourcePermissionLocalServiceUtil.setResourcePermissions(serviceContext.getCompanyId(),
                "tj.izvewenija.model.Izvewenija", 4, String.valueOf(izvewenija.getIzvewenija_id()),
                Long.valueOf(config.getValue()), actionId);
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return izvewenija;
}