Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.collabnet.util;
  
  import  com.collabnet.ce.soap50.webservices.tracker.ArtifactSoapDO;
  
 
Class for methods that are useful across Hudson plugins.
 
 public class CNHudsonUtil {
     private static Logger log = Logger.getLogger("CNHudsonUtil");

    
As a utility class, CNHudsonUtil should never be instantiated.
 
     private CNHudsonUtil() {}

    

Parameters:
url
username
password
Returns:
collabnet app, if one can be created; null otherwise.
 
     public static CollabNetApp getCollabNetApp(String url
                                                String username
                                                String password) {
         try {
             return new CollabNetApp(urlusernamepassword);
         } catch (RemoteException re) {
             CommonUtil.logRE("getCollabNetApp"re);
             // more logging
             .log(...."getCollabNetApp failed"
                     re);
             return null;
         }
     }

    
Get a CollabNetApp, given a StaplerRequest with url, username, and password set. If login fails, null will be returned.
 
     public static CollabNetApp getCollabNetApp(StaplerRequest request) {
         String url = request.getParameter("url");
         String username = request.getParameter("username");
         String password = request.getParameter("password");
         
         if (CommonUtil.unset(url) || CommonUtil.unset(username
             || CommonUtil.unset(password)) {
             return null;
         }
         return getCollabNetApp(urlusernamepassword);
     }

    
Logs off the CollabNetApp, if possible.

Parameters:
cna CollabNetApp
 
     public static void logoff(CollabNetApp cna) {
         if (cna != null) {
             try {
                 cna.logoff();
             } catch (RemoteException re) {
                 CommonUtil.logRE("logoff"re);
             }
         }
     }

    
Get the packageId for the package name.

Parameters:
fa for accessing the FileReleaseSystem webservices.
rpackage name of the package.
projectId the project id.
Returns:
the package id if found, null otherwise.
 
     public static String getPackageId(CollabNetApp cnaString rpackage
                                 String projectId) {
         String packageId = null;
         if (cna != null && projectId != null) {
             FrsApp fa = new FrsApp(cna);
             try {
                 packageId = fa.findPackageId(rpackageprojectId);
             } catch (RemoteException re) {
                 CommonUtil.logRE("getPackageId"re);
                 return null;
             }
         }
         return packageId;
     }

    
Get the projectId for the project name.

Parameters:
cna for accessing the webservice methods.
project name.
Returns:
the id for the project or null, if no such project exist.
    public static String getProjectId(CollabNetApp cnaString project) {
        String projectId = null;
        if (cna != null) {
            try {
                projectId = cna.getProjectId(project);
            } catch (RemoteException re) {
                CommonUtil.logRE("getProjectId"re);
            }
        }
        return projectId;
    }

    
Get the release id.

Parameters:
cna for accessing the webservice methods.
packageId the id of the package which contains this release.
release the name of the release
Returns:
the release id, or null if none is found.
    public static String getReleaseId(CollabNetApp cnaString packageId
                               String release) {
        if (cna == null || packageId == null) {
            return null;
        }
        String releaseId = null;
        FrsApp fa = new FrsApp(cna);
        try {
            releaseId = fa.findReleaseIdByPackage(releasepackageId);
        } catch (RemoteException re) {
            CommonUtil.logRE("getReleaseId"re);
        }
        return releaseId;
    }

    
Get the file id.

Parameters:
cna for accessing the webservice methods.
releaseId the id of the release.
file name
Returns:
the file id, or null if none is found.
    public static String getFileId(CollabNetApp cnaString releaseId
                                   String file) {
        if (cna == null || releaseId == null) {
            return null;
        }
        String fileId = null;
        FrsApp fa = new FrsApp(cna);
        try {
            fileId = fa.findFrsFile(filereleaseId);
        } catch (RemoteException re) {
            CommonUtil.logRE("getFileId"re);
        }
        return fileId;
    }

    
Get a releaseId, given a projectId and a release title.

Parameters:
cna for accessing the webservice methods.
projectId
release
Returns:
the releaseId in this project which matches the release name or null if none is found.
    public static String getProjectReleaseId (CollabNetApp cna
                                              String projectId,
                                              String release) {
        if (cna == null || projectId == null) {
            return null;
        }
        FrsApp fa = new FrsApp(cna);
        String releaseId = null;
        try {
            releaseId = fa.findReleaseId(releaseprojectId);
        } catch (RemoteException re) {
            CommonUtil.logRE("getProjectReleaseId"re);
        }
        return releaseId;
    }

    
Given a tracker title and a projectId, find the matching tracker id.

Parameters:
cna for accessing the webservice methods.
projectId
trackerName
Returns:
the tracker id for the tracker that matches this name, or null if no matching tracker is found.
    public static String getTrackerId(CollabNetApp cnaString projectId
                                      String trackerName) {
        if (cna == null || projectId == null) {
            return null;
        }
        TrackerApp ta = new TrackerApp(cna);
        String trackerId = null;
        try {
            trackerId = ta.getTrackerId(projectIdtrackerName);
        } catch (RemoteException re) {
            CommonUtil.logRE("getTrackerId"re);
            return null;
        }
        return trackerId;
    }

    
Given a project and issue title, find the most recent matching issue object, or null if none matches.
    public static ArtifactSoapDO getTrackerArtifact(CollabNetApp cna
                                                    String project
                                                    String tracker
                                                    String issueTitle) {
        ArtifactSoapDO artifact = null;
        if (cna != null) {
            String projectId = CNHudsonUtil.getProjectId(cnaproject);
            if (projectId != null) {
                String trackerId = CNHudsonUtil.getTrackerId(cnaprojectId
                                                             tracker);
                if (trackerId != null) {
                    TrackerApp ta = new TrackerApp(cna);
                    try {
                        artifact = ta.findLastTrackerArtifact(trackerId
                                                              issueTitle);
                    } catch (RemoteException re) {}
                }
            }
        }
        return artifact;
    }
    
    
Given project, package, release, and file name, find the fileId for a file in the system, or null if none is found.

Parameters:
cna for accessing webservice methods
project name
rpackage name
release name
file name
    public static String getFileId(CollabNetApp cnaString project
                                   String rpackageString release
                                   String file) {
        String fileId = null;
        String projectId = CNHudsonUtil.getProjectId(cnaproject);
        if (projectId != null) {
            String packageId = CNHudsonUtil.getPackageId(cnarpackage
                                                         projectId);
            if (packageId != null) {
                String releaseId = CNHudsonUtil.getReleaseId(cnapackageId
                                                             release);
                if (releaseId != null) {
                    fileId = CNHudsonUtil.getFileId(cnareleaseIdfile);
                }
            }
        }
        return fileId;
    }

    

Parameters:
cna for accessing the webservice methods.
username
Returns:
true if the user can be found.
    public static boolean isUserValid(CollabNetApp cnaString username) {
        boolean valid = false;
        try {
            valid = cna.isUsernameValid(username);
        } catch (RemoteException re) {
            CommonUtil.logRE("userExists"re);
        }
        return valid;
    }
    
    

Parameters:
cna for accessing the webservice methods.
username
projectId
Returns:
true if the user is a member of the project.
    public static boolean isUserMember(CollabNetApp cna,
                                       String username,
                                       String projectId) {
        boolean member = false;
        try {
            member = cna.isUserMemberOfProject(usernameprojectId);
        } catch (RemoteException re) {
            CommonUtil.logRE("userMember"re);
        }
        return member;
    }
New to GrepCode? Check out our FAQ X