Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.collabnet.ce.webservices;
  
  import  com.collabnet.ce.soap50.webservices.ClientSoapStubFactory;
  
  import  com.collabnet.ce.soap50.webservices.cemain.ICollabNetSoap;
  import  com.collabnet.ce.soap50.webservices.cemain.GroupSoapList;
  import  com.collabnet.ce.soap50.webservices.cemain.GroupSoapRow;
  import  com.collabnet.ce.soap50.webservices.cemain.Group2SoapList;
  import  com.collabnet.ce.soap50.webservices.cemain.Group2SoapRow;
 import  com.collabnet.ce.soap50.webservices.cemain.ProjectMemberSoapList;
 import  com.collabnet.ce.soap50.webservices.cemain.ProjectMemberSoapRow;
 import  com.collabnet.ce.soap50.webservices.cemain.ProjectSoapList;
 import  com.collabnet.ce.soap50.webservices.cemain.ProjectSoapRow;
 import  com.collabnet.ce.soap50.webservices.cemain.UserSoapList;
 import  com.collabnet.ce.soap50.webservices.cemain.UserSoapRow;
 
 import java.util.Map;
 
This class represents the connection to the CollabNet webservice. Since it contains login/logout data, other webservices will require an instance of it. This is written based on the 5.0 version of the soap services.
 
 public class CollabNetApp {
     private static Logger logger = Logger.getLogger(CollabNetApp.class);
     public static String SOAP_SERVICE = "/ce-soap50/services/";
     private String sessionId;
     private String username;
     private String url;
     private ICollabNetSoap icns;

    
Creates a new session to the server at the given url.

Parameters:
url of the CollabNet server.
username to login as.
password to login with.
 
     public CollabNetApp(String urlString usernameString password
         throws RemoteException {
         this. = url;
         this. = username;
         this. = this.getICollabNetSoap();
         this. = this.login(password);
     }

    
Creates a new CollabNetApp without a session.

Parameters:
url of the CollabNet server.
username to login as.
 
     public CollabNetApp(String urlString username) {
         this. = url;
         this. = username;
         this. = this.getICollabNetSoap();
     }
    
    

Returns:
the session id.
 
     public String getSessionId() {
         return this.;
     }
    
    

Returns:
the url of the CollabNet server.
 
     public String getServerUrl() {
         return this.;
     }
    
    

Returns:
client soap stub for the main CollabNet.wsdl.
 
     private ICollabNetSoap getICollabNetSoap() {
         String soapURL = this. + . +
             "CollabNet?wsdl";
         return (ICollabNetSoap) ClientSoapStubFactory.
             getSoapStub(ICollabNetSoap.classsoapURL);
     } 

    

Returns:
client soap stub for an arbitrary url.
 
     private static ICollabNetSoap getICollabNetSoap(String url) {
         String soapURL = url + . +
             "CollabNet?wsdl";
         return (ICollabNetSoap) ClientSoapStubFactory.
             getSoapStub(ICollabNetSoap.classsoapURL);
     } 
    
    
Login is only done in the constructor. If you need to re-login, you should get a new CollabNetApp object.

Parameters:
password used to login with.
Returns:
a new sessionId.
Throws:
RemoteException
    private String login(String passwordthrows RemoteException {
         = .login(this.password);
        return ;
    }

    
Login with a token.

Parameters:
token one-time token
Returns:
sessionId
Throws:
RemoteException
    public void loginWithToken(String token
        throws RemoteException {
        this. = .loginWithToken(this.token);
    }
    
    
Logoff for this user and invalidate the sessionId.

Throws:
RemoteException
    public void logoff() throws RemoteException {
        this.checkValidSessionId();
        this..logoff(this.this.);
        this. = null;
    }

    

Parameters:
url of the CollabNet server.
Returns:
the API version number string. This string is in the format ${Release major}.${Release minor}.${service pack}.${hot fix}
Throws:
RemoteException
    public static String getApiVersion(String urlthrows RemoteException {
        return getICollabNetSoap(url).getApiVersion();
    }

    

Returns:
the version number string for SourceForge itself.
Throws:
RemoteException
    public String getVersion() throws RemoteException {
        this.checkValidSessionId();
        return this..getVersion(this.);
    }
    
    
Find the project that matches the given name, and return it's id.

Parameters:
projectName
Returns:
id for this project (if a match is found), null otherwise.
Throws:
RemoteException
    public String getProjectId(String projectNamethrows RemoteException {
        this.checkValidSessionId();
        ProjectSoapList pslist = this..getProjectList();
        ProjectSoapRow[] rows = pslist.getDataRows();
        for (int i = 0; i < rows.length; i++){
        	.debug(rows[i].getId() + " "rows[i].getTitle());
        	if (rows[i].getTitle().equals(projectName)){
        		return rows[i].getId();
        	}
        }
        return null;
    }

    
Return the list of project names.

Returns:
a Collection of project names.
Throws:
RemoteException
    public Collection<StringgetProjects() throws RemoteException {
        this.checkValidSessionId();
        ProjectSoapList pslist = this..getProjectList();
        Collection<Stringnames = new ArrayList<String>();
        for (ProjectSoapRow rowpslist.getDataRows()) {
            names.add(row.getTitle());
        }
        return names;
    }
    
    
Can the user can be found on the CollabNet server?

Parameters:
username to check.
Returns:
true, if the user is found, false otherwise.
Throws:
RemoteException
    public boolean isUsernameValid(String usernamethrows RemoteException {
        this.checkValidSessionId();
        UserSoapList usList = this..findUsers(this.username);
        for (UserSoapRow rowusList.getDataRows()) {
            if (row.getUserName().equals(username)) {
                return true;
            }
        }
        return false;
    }
    
    
Is the user a member of the project?

Parameters:
username to check.
projectId
Returns:
true, if the user is a member of the project, false otherwise.
Throws:
RemoteException
    public boolean isUserMemberOfProject(String usernameString projectId
        throws RemoteException {
        this.checkValidSessionId();
        ProjectMemberSoapList pmList = this..
            getProjectMemberList(this.projectId);
        for (ProjectMemberSoapRow rowpmList.getDataRows()) {
            if (row.getUserName().equals(username)) {
                return true;
            }
        }
        return false;
    }

    
Is the user a member of the group?

Parameters:
username to check.
group
Returns:
true, if the user is a member of the group, false otherwise.
Throws:
RemoteException
    public boolean isUserMemberOfGroup (String usernameString group
        throws RemoteException {
        this.checkValidSessionId();
        GroupSoapList gList = this..getUserGroupList(this.
                                                         username);
        for (GroupSoapRow rowgList.getDataRows()) {
            if (row.getFullName().equals(group)) {
                return true;
            }
        }
        return false;
    }

    
Get a list of the groups the user belongs to. This will only work if logged in as the user in question, or if the logged in user has superuser permissions.

Parameters:
username
Returns:
collection of group names.
Throws:
RemoteException
    public Collection<StringgetUserGroups(String username
        throws RemoteException {
        this.checkValidSessionId();
        Collection<Stringgroups = new ArrayList<String>();
        GroupSoapList gList = this..getUserGroupList(this.
                                                         username);
        for (GroupSoapRow rowgList.getDataRows()) {
            groups.add(row.getFullName());
        }
        return groups;
    }

    
Is the user a project admin?

Parameters:
username to check.
projectId
Returns:
true if the user is an admin of this project, false otherwise.
Throws:
RemoteException
    public boolean isUserProjectAdmin(String usernameString projectId
        throws RemoteException {
        this.checkValidSessionId();
        UserSoapList usList = this..listProjectAdmins(this.
                                                          projectId);
        for (UserSoapRow rowusList.getDataRows()) {
            if (row.getUserName().equals(username)) {
                return true;
            }
        }
        return false;
    }

    

Parameters:
username
Returns:
true if the user is a super user. False if not, or if the user is not found.
Throws:
RemoteException
    public boolean isUserSuper(String usernamethrows RemoteException {
        this.checkValidSessionId();
        UserSoapList usList = this..findUsers(this.username);
        for (UserSoapRow rowusList.getDataRows()) {
            if (row.getUserName().equals(username)) {
                return row.getSuperUser();
            }
        }
        return false;
    }

    
Get the usernames of all users.

Parameters:
String projectId
Returns:
collection of usernames
Throws:
RemoteException
    public Collection<StringgetUsers(String projectId
        throws RemoteException {
        this.checkValidSessionId();
        Collection<Stringusers = new ArrayList<String>();
        ProjectMemberSoapList pmList = this..
            getProjectMemberList(this.projectId);
        for (ProjectMemberSoapRow rowpmList.getDataRows()) {
            users.add(row.getUserName());
        }
        return users;
    }

    
Get the usernames of all project admins.

Parameters:
String projectId
Returns:
collection of admin usernames
Throws:
RemoteException
    public Collection<StringgetAdmins(String projectId
        throws RemoteException {
        this.checkValidSessionId();
        Collection<Stringadmins = new ArrayList<String>();
        UserSoapList usList = this..listProjectAdmins(this.
                                                          projectId);
        for (UserSoapRow rowusList.getDataRows()) {
            admins.add(row.getUserName());
        }
        return admins;
    }

    
Get the list of all Groups on the system. Can only be called by SuperUsers.

Returns:
a Map of all group name/ids.
Throws:
RemoteException
    public Map<StringStringgetGroups() throws RemoteException {
        this.checkValidSessionId();
        Map<StringStringnameId = new HashMap<StringString>();
        Group2SoapList gsList = this..getGroupList2(this.null);
        for (Group2SoapRow rowgsList.getDataRows()) {
            nameId.put(row.getFullName(), row.getId());
        }
        return nameId;
    } 

    
Given a list of group names, return a list of all unique users that are members of any of the groups. If the group name is not found, no error is thrown. Only works for SuperUsers.

Parameters:
groups collection of group names.
Returns:
a collection of user names.
Throws:
RemoteException
    public Collection<StringgetUsersInGroups(Collection<StringgroupNames
        throws RemoteException {
        this.checkValidSessionId();
        Map<StringStringgroupNameIds = this.getGroups();
        Collection<Stringusers = new HashSet<String>();
        for (String groupNamegroupNames) {
            String id = groupNameIds.get(groupName);
            if (id != null) {
                users.addAll(this.getGroupUsers(id));
            }
        }
        return users;
    }

    
Return a collection of users that are active members of the group.

Parameters:
groupId
Returns:
active users (collection of usernames).
Throws:
RemoteException
    public Collection<StringgetGroupUsers(String groupId
        throws RemoteException {
        this.checkValidSessionId();
        Collection<Stringusers = new ArrayList<String>();
        UserSoapList usList = this..getActiveGroupMembers(this.
                                                              groupId);
        for (UserSoapRow rowusList.getDataRows()) {
            users.add(row.getUserName());
        }
        return users;
    }
    
    
Throws a CollabNetAppException if there is no current sessionId.

Throws:
CollabNetAppException.
    public void checkValidSessionId() {
        if (this. == null) {
            throw new CollabNetApp.CollabNetAppException("Not currently in " +
                                                         "a valid session.");
        }
    }
    
    
Exception class to throw when something unexpected goes wrong.
    public static class CollabNetAppException extends RuntimeException{
        public CollabNetAppException(String msg) {
            super(msg);
        }
    }
New to GrepCode? Check out our FAQ X