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

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

Introduction

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

Prototype

public static AuditRequestThreadLocal getAuditThreadLocal() 

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());
    }/*ww  w.  j  a  va 2 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.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());
    }/*w  w  w  .j a v  a  2  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);
}