cancel
Showing results for 
Search instead for 
Did you mean: 

Getting tasks for all users in a role

david_palafox
Explorer
0 Kudos

Hi,

We need to get all users in a Role, and out of those, find out which one has the least tasks in their UWL using a WebService. Saw some example codes and here's my attempt at it. Doesn't quite work, I'm getting the Logged in users context or session doesn't exist Exception. Any help on this will be GREATLY appreciated.


public class LeastTasksBean implements LeastTasksLocal {

	public String getUserLeastTasks( String sRole )
	{
		try{
			Map<String, String> users = new HashMap<String, String>();
			Map<String, String> tasks = new HashMap<String, String>();

			final int sessionIdleTimeout = 60;

			String Users[] = UMFactory.getRoleFactory().getUsersOfRole( sRole, true );

			if( Users != null ){
				for( int i = 0; i < Users.length; i ++ ){

					UWLContext  uwlContext      = new UWLContext();
					IUWLService uwlService      = findService();
					uwlContext.setAllowBackEndConnections( true );
					
					IUser uwlContextUser        = UMFactory.getUserFactory().getUser( Users[0] );
					uwlContext.setUser            ( uwlContextUser );
					
					Locale loc                  = new Locale( "ES" );
					uwlContext.setLocale          ( loc );
					
					HttpServletRequest request  = getHttpRequest();
					uwlContext.setOriginRequest   ( request );
					
					IUWLSession session         = uwlService.beginSession( uwlContext, sessionIdleTimeout );
					uwlContext.setSession         ( session );

					IUWLItemManager itemManager = uwlService.getItemManager( uwlContext );
					QueryResult result          = itemManager.getItems( uwlContext, null, null );
					
					users.put( String.valueOf( i ), uwlContext.getUserName() );
					tasks.put( String.valueOf( i ), String.valueOf( result.getItems().size() ) );

					uwlService.endSession( uwlContext );
				}
				
				int userTasks = 0;
				int leastTasks = Integer.valueOf( tasks.get( 0 ) );
				int userKey = 0;

				for( int i = 0; i < Users.length; i ++ ){
					userTasks = Integer.valueOf( tasks.get( Integer.toString( i ) ) );
					if( userTasks < leastTasks ){
						leastTasks = userTasks;
						userKey = i;
					}
				}
				return users.get( Integer.toString( userKey ) );
			}
			else{
				return "No users exist for this role";
			}
		}
		
		//Exception Handling
	}
	
	private IUWLService findService() throws NamingException 
	{ 
		Properties properties = new Properties(); 
		properties.put( InitialContext.INITIAL_CONTEXT_FACTORY, "com.sapportals.portal.prt.registry.PortalRegistryFactory" );  

		InitialContext ctx = new InitialContext( propiedades );  
		
		IUWLService uwlService = ( IUWLService ) ctx.lookup( IUWLService.ALIAS_KEY );
		
		return uwlService; 
	}
	
	private HttpServletRequest getHttpRequest() throws Exception 
	{ 
		Properties properties = new Properties(); 
		properties.put( "domain", "true" ); 

		ApplicationWebServiceContext wsContext = 
			(ApplicationWebServiceContext) new InitialContext( propiedades ).lookup( "/wsContext/" + ApplicationWebServiceContext.APPLICATION_WSCONTEXT );
 
		HttpServletRequest request = wsContext.getHttpServletRequest();
		
		return request;  
	}
}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi David,

I have a similar requirement on our project. I need to get a count of pending workitems for all user but I'm getting similar message when I try to access UWL context of any other user.

Did you find any solution for this? Is it possible to get the workitems for all users using webservice or wendynpro?

I would appreciate if you can provide some inputs on this.

Thank you in advance.

Regards,

Seema Rane