package ext;

import java.util.*;

import wt.auth.*;
import wt.fc.*;
import wt.query.*;
import wt.util.*;

import wt.team.Team;
import wt.project.Role;
import wt.inf.team.ContainerTeam;
import wt.project.Role;

import wt.org.*;
import wt.org.WTOrganization;
import wt.org.WTGroup;
import wt.org.WTPrincipal;
import wt.org.WTPrincipalReference;

import wt.inf.team.*;
import wt.inf.container.*;
import wt.inf.container.WTContainer;

import wt.projmgmt.admin.*;

import wt.method.RemoteMethodServer;
import wt.httpgw.GatewayAuthenticator;

public class TeamRoleUser{

	public static void main(String[] args) throws Exception{

		RemoteMethodServer rms = RemoteMethodServer.getDefault();
		GatewayAuthenticator auth = new GatewayAuthenticator();
		auth.setRemoteUser("wcadmin");
		rms.setAuthenticator(auth);

		QueryResult resCTT=PersistenceHelper.manager.find(new QuerySpec(ContainerTeam.class));
		while(resCTT.hasMoreElements()) {
			ContainerTeam contTeam = (ContainerTeam)resCTT.nextElement();
			System.out.println( "\nContainerTeam: " + contTeam.getName()+"\n" );

			Vector vector = contTeam.getRoles();
			int i = vector.size();
		label0:
			for(int j = 0; j < i; j++)
			{
				Role role = (Role)vector.get(j);

				System.out.println("\tRole: "+role.getDisplay());
				ArrayList arraylist = contTeam.getAllPrincipalsForTarget(role);

				int k = 0;
				do
				{
					if(k >= arraylist.size()) {
						continue label0;
					}
					WTPrincipalReference wtprincipalreference1 = (WTPrincipalReference)(WTPrincipalReference)arraylist.get(k);
					WTPrincipal wtprincipal = (WTPrincipal)wtprincipalreference1.getObject();
					if(wtprincipal instanceof WTUser) {

						WTUser wtuser = (WTUser)wtprincipal;
						System.out.println( "\t\tUser/Principal: "+wtuser.getName());
					}
					k++;
				} while(true);
			}
		}
		System.out.println("\nNumber of ContainerTeams: "+resCTT.size() + "\n");
	}
}
