Passing Parameter to ad hoc view from BuiltInUserParameterProvider

Hi,

I implemented ad hoc views & integrated in liferay using Iframe. Now i want to display data in the reports based on logged in user. So i implemented "CustomBuiltInUserParameterProvider.java". With hard coded "USER_ID" its working fine. Now i want to pass user data to "CustomBuiltInUserParameterProvider.java". But i dont have any idea, how to pass. Currently my data in liferay session.

Can u please guide me. Its urgent requirement for us.

Thanks & Regards,

VV Nagesh Bodapati.

 

 

 

nageshit2011's picture
Joined: Jul 22 2013 - 3:04am
Last seen: 8 years 1 month ago
Hi , can you please share CustomBuiltInUserParameterProvider.java , as i am doing somewhat same kind work ? . I need help .
snehal_hibare - 8 years 10 months ago

Hi,

Find the below code,

 

public class LiferayUserProfileBuiltInParameterProvider implements BuiltInParameterProvider
{
 
  private static final String LOGGED_IN_USER_PARAMETER_PREFIX = "LiferayUser";
  private static final String[] LOGGED_IN_USER_STANDARD_PARAMETERS = {LOGGED_IN_USER_PARAMETER_PREFIX};
  
  @SuppressWarnings("unchecked")
  public List<Object[]> getParameters(ExecutionContext context, List jrParameters, Map parameters)
  {
    List userProfileParameters = new ArrayList();
 
    for (String parameterName : LOGGED_IN_USER_STANDARD_PARAMETERS) 
{
 Object[] result = getParameter(context, jrParameters, parameters, parameterName);
 if (result != null) 
 {
userProfileParameters.add(result);
 }
    }
 
    return userProfileParameters;
  }
 
  @SuppressWarnings("unchecked")
  public Object[] getParameter(ExecutionContext context, List jrParameters, Map parameters, String name)
  {
      if ((name == null) || (!name.toLowerCase().startsWith("LiferayUser".toLowerCase()))) {
          return null;
        }
      try
      {
          Authentication auth = SecurityContextHolder.getContext().getAuthentication();
          if ((auth == null) || (!(auth.getPrincipal() instanceof MetadataUserDetails))) 
          {
            return null;
          }
          MetadataUserDetails userDetails = (MetadataUserDetails)auth.getPrincipal();
          String userName = userDetails.getUsername();
          return new Object[] { JRQueryExecuterAdapter.makeParameter(name, LiferayUser.class), liferayUser };
      }
      catch(Exception exception)
      {
          System.out.println("Exception Occured in LiferayUserProfileBuiltInParameterProvider - "+exception.getMessage());
      }
      return null;
  }
 
  public String getLiferayUserParameterPrefix() 
  {
    return LOGGED_IN_USER_PARAMETER_PREFIX;
  }
}

 

 

 

nageshit2011 - 8 years 10 months ago

0 Answers:

No answers yet
Feedback