Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.collabnet.util;
  
  
 
 
These classes are used to update the list of items for a combo box.
 
 public abstract class ComboBoxUpdater {
     protected static Logger log = Logger.getLogger("ComboBoxUpdater");
 
     protected final StaplerRequest request;
     protected final StaplerResponse response;
 
     protected ComboBoxUpdater(StaplerRequest reqStaplerResponse rsp) {
         this. = req;
         this. = rsp;
     }
 
     protected abstract Collection<StringgetList();
 
     public void update() throws IOException {
         Collection<Stringlist = this.getList();
         this..setContentType("text/plain;charset=UTF-8");
         JSONObject jsonObj = new JSONObject();
         jsonObj.element("items"list);
         this..getWriter().print(jsonObj.toString());
     }

    
Class to update a list of projects. Requires the login info (url, username, password) be set.
 
     public static class ProjectsUpdater extends ComboBoxUpdater {
         
         public ProjectsUpdater(StaplerRequest reqStaplerResponse rsp) {
             super(reqrsp);
         }
 
         protected Collection<StringgetList() {
             CollabNetApp cna = CNHudsonUtil.getCollabNetApp(this.);
             Collection<Stringlist = getProjectList(cna);
             CNHudsonUtil.logoff(cna);
             return list;
         }

        

Returns:
a list of projects which has been sanitized.
 
         public static Collection<StringgetProjectList(CollabNetApp cna) {
             Collection<Stringprojects = Collections.emptyList();
             if (cna != null) {
                 try {
                     projects = cna.getProjects();
                 } catch (RemoteException re) {
                     CommonUtil.logRE("getProjectList"re);
                 }
             }
             return CommonUtil.sanitizeForJS(projects);
         }
     }

    
Class to update a list of packages. Requires that the login info (url, username, password) be set, as well as the project.
 
     public static class PackagesUpdater extends ComboBoxUpdater {
         
         public PackagesUpdater(StaplerRequest reqStaplerResponse rsp) {
             super(reqrsp);
         }
 
         protected Collection<StringgetList() {
             CollabNetApp cna = CNHudsonUtil.getCollabNetApp(this.);
             String project = .getParameter("project");
             String projectId = CNHudsonUtil.getProjectId(cnaproject);
             Collection<Stringlist = getPackageList(cnaprojectId);
             CNHudsonUtil.logoff(cna);
             return list;
         }

        

Returns:
a list of packages which has been sanitized.
 
         public static Collection<StringgetPackageList(CollabNetApp cna
                                                         String projectId) {
            Collection<Stringpackages = Collections.emptyList();
            if (cna != null && projectId != null) {
                FrsApp fa = new FrsApp(cna);
                try {
                    packages = fa.getPackages(projectId);
                } catch (RemoteException re) {
                    CommonUtil.logRE("getPackageList"re);
                }
            }
            return CommonUtil.sanitizeForJS(packages);
        }
    }

    
Class to update the list of releases. Requires a StaplerRequest with login info (url, username, password), project, and (optionally) package.
    public static class ReleasesUpdater extends ComboBoxUpdater {
        
        public ReleasesUpdater(StaplerRequest reqStaplerResponse rsp) {
            super(reqrsp);
        }
        protected Collection<StringgetList() {
            CollabNetApp cna = CNHudsonUtil.getCollabNetApp(this.);
            String project = .getParameter("project");
            String projectId = CNHudsonUtil.getProjectId(cnaproject);
            String rpackage = .getParameter("package");
            Collection<Stringlist = Collections.emptyList();
            if (CommonUtil.unset(rpackage)) {
                list = getProjectReleaseList(cnaprojectId);
            } else {
                String packageId = CNHudsonUtil.getPackageId(cnarpackage
                                                             projectId);
                list = getReleaseList(cnapackageId);
            }
            CNHudsonUtil.logoff(cna);
            return list;
        }

        

Returns:
a list of releases in the package which has been sanitized.
        public static Collection<StringgetReleaseList(CollabNetApp cna
                                                        String packageId) {
            Collection<Stringreleases = Collections.emptyList();
            if (cna != null && packageId != null) {
                FrsApp fa = new FrsApp(cna);
                try {
                    releases = fa.getReleases(packageId);
                } catch (RemoteException re) {
                    CommonUtil.logRE("getReleaseList"re);
                }
            }
            return CommonUtil.sanitizeForJS(releases);
        }

        

Returns:
a list of all releases in the project which has been sanitized.
        public static Collection<StringgetProjectReleaseList
            (CollabNetApp cnaString projectId) {
            Collection<Stringreleases = Collections.emptyList();
            if (cna != null && projectId != null) {
                FrsApp fa = new FrsApp(cna);
                try {
                    releases = fa.getProjectReleases(projectId);
                } catch (RemoteException re) {
                    CommonUtil.logRE("getProjectReleaseList"re);
                }
            }
            return CommonUtil.sanitizeForJS(releases);
        }
    }

    
Class to update a list of trackers. Requires that the login info (url, username, password) be set, as well as the project.
    public static class TrackersUpdater extends ComboBoxUpdater {
        
        public TrackersUpdater(StaplerRequest reqStaplerResponse rsp) {
            super(reqrsp);
        }
        protected Collection<StringgetList() {
            CollabNetApp cna = CNHudsonUtil.getCollabNetApp(this.);
            String project = .getParameter("project");
            String projectId = CNHudsonUtil.getProjectId(cnaproject);
            Collection<Stringlist = getTrackerList(cnaprojectId);
            CNHudsonUtil.logoff(cna);
            return list;
        }

        

Returns:
a list of trackers which has been sanitized.
        public static Collection<StringgetTrackerList(CollabNetApp cna
                                                        String projectId) {
            Collection<Stringtrackers = Collections.emptyList();
            if (cna != null && projectId != null) {
                TrackerApp ta = new TrackerApp(cna);
                try {
                    trackers = ta.getTrackers(projectId);
                } catch (RemoteException re) {
                    CommonUtil.logRE("getTrackerList"re);
                }
            }
            return CommonUtil.sanitizeForJS(trackers);
        }
    }
    
    
Class to update a list of project users. Requires that the login info (url, username, password) be set, as well as the project.
    public static class UsersUpdater extends ComboBoxUpdater {
        
        public UsersUpdater(StaplerRequest reqStaplerResponse rsp) {
            super(reqrsp);
        }
        protected Collection<StringgetList() {
            CollabNetApp cna = CNHudsonUtil.getCollabNetApp(this.);
            String project = .getParameter("project");
            String projectId = CNHudsonUtil.getProjectId(cnaproject);
            Collection<Stringlist = getUserList(cnaprojectId);
            CNHudsonUtil.logoff(cna);
            return list;
        }

        

Returns:
a list of usernames which has been sanitized.
        public static Collection<StringgetUserList(CollabNetApp cna
                                                     String projectId) {
            Collection<Stringusers = Collections.emptyList();
            if (cna != null && projectId != null) {
                try {
                    users = cna.getUsers(projectId);
                } catch (RemoteException re) {
                    CommonUtil.logRE("getUserList"re);
                }
            }
            return CommonUtil.sanitizeForJS(users);
        }
    }
New to GrepCode? Check out our FAQ X