List of usage examples for com.liferay.portal.kernel.service ServiceContext setAttributes
public void setAttributes(Map<String, Serializable> attributes)
From source file:com.liferay.exportimport.messaging.BasePublisherMessageListener.java
License:Open Source License
protected void initThreadLocals(long userId, Map<String, String[]> parameterMap) throws PortalException { User user = UserLocalServiceUtil.getUserById(userId); CompanyThreadLocal.setCompanyId(user.getCompanyId()); PrincipalThreadLocal.setName(userId); PermissionChecker permissionChecker = null; try {/*w w w . ja v a 2s . co m*/ permissionChecker = PermissionCheckerFactoryUtil.create(user); } catch (Exception e) { throw new SystemException("Unable to initialize thread locals because an error occured " + "when creating a permission checker for user " + userId, e); } PermissionThreadLocal.setPermissionChecker(permissionChecker); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(user.getCompanyId()); serviceContext.setPathMain(PortalUtil.getPathMain()); serviceContext.setSignedIn(!user.isDefaultUser()); serviceContext.setUserId(user.getUserId()); Map<String, Serializable> attributes = new HashMap<>(); for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) { String param = entry.getKey(); String[] values = entry.getValue(); if (ArrayUtil.isNotEmpty(values)) { if (values.length == 1) { attributes.put(param, values[0]); } else { attributes.put(param, values); } } } serviceContext.setAttributes(attributes); ServiceContextThreadLocal.pushServiceContext(serviceContext); }