Example usage for com.liferay.portal.kernel.audit AuditRequestThreadLocal getRealUserId

List of usage examples for com.liferay.portal.kernel.audit AuditRequestThreadLocal getRealUserId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.audit AuditRequestThreadLocal getRealUserId.

Prototype

public long getRealUserId() 

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  ww  .j  a v  a2s  .  c om*/

    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.portlet.documentlibrary.util.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  va 2s.com*/

    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);
}