It's all about the answers!

Ask a question

Programmatically finding the process template used in a project


Praveen Kumar (371822) | asked May 02 '13, 1:28 a.m.
How do I programmaticlly find out the process template used in a project through Reportable Rest API.  If no methods are available in Reportable Rest API please suggest using RTC SDK. 

Comments
Geoffrey Clemm commented May 02 '13, 1:01 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

By "process template", do you mean the XML process configuration source for a specified project area?


Praveen Kumar commented May 03 '13, 2:34 a.m.

Yes.  I am talking about the "Process/Project Template" that is used while creating the project.   For example while creating a life cycle project we select "Scrum" as the "Project template".  I am looking for an API REST or SDK using which I can retrieve the "Project template" name.  In this case "Scrum"


Qiong Feng Huang commented May 03 '13, 8:30 a.m. | edited unknown
JAZZ DEVELOPER

 It's simple if you just want to get the name of the process template. Suppose you have got an instance of IProjectArea, you can use IProjectArea.getProcessDefinition() to get the handle of the process template, then you can use IRepositoryItemService.fetchItem() to get the instance of this process template. 


Qiong Feng Huang commented May 03 '13, 8:33 a.m.
JAZZ DEVELOPER

It's simple if you just want to get the name of the process template. Suppose you have got an instance of IProjectArea, you can use IProjectArea.getProcessDefinition() to get the handle of the process template, then you can use IRepositoryItemService.fetchItem() to get the instance of this process template. 


Praveen Kumar commented May 06 '13, 1:11 a.m.

If we use RTC SDK, the below suggestion from @sam detweiler works.  What if I want to use Rest API.  Can I find the "Process/Project Template" using reportable rest API


sam detweiler commented May 06 '13, 7:22 a.m.

far as I know this data is not available thru the REST api
(I had to use an internal class to get access to the parent if any)

showing 5 of 6 show 1 more comments

5 answers



permanent link
sam detweiler (12.5k6195201) | answered May 02 '13, 4:28 p.m.
edited May 02 '13, 4:31 p.m.
here is some code I used to find the process source, even if it was from a parent project
static String keyname = com.ibm.team.process.common.ProcessContentKeys.PROCESS_SPECIFICATION_KEY;
<code>
need to get access to the internal method to get the parent

import com.ibm.team.process.internal.common.impl.ProjectAreaImpl;

            if ((repo=login(url, userid, password, sPm)) != null )
            {
                // get the content Manager
                IContentManager icm = repo.contentManager();
               
                // get the list of projects
                // * means all
                // specific name means only that one.. case sensitive I think
                List<IProjectArea> projectList = getProjectArea(repo, sPm,
                        ProjectType);

                System.out.println(" there are " + projectList.size()
                        + " projects");

                // loop thru the list of projects, if any
                for (int i = 0; i < projectList.size(); i++)
                {
                    // get the project area
                    IProjectArea ip = projectList.get(i);
                    // if the project is not archived
                    if(!ip.isArchived())
                    {
                        System.out.println("\nproject name = " + ip.getName());               
                         
                        IItem ipi = ip.getWorkingCopy();
                        // call the internal only method to get the parent process
                        // provider.. if any
                        IProjectAreaHandle iparenthandle = ((ProjectAreaImpl) ipi)
                                .getProcessProvider();
                        // if there was a parent
                        if (iparenthandle != null)
                        {
                            // get it
                            IProjectArea parentProject = (IProjectArea) (repo
                                    .itemManager().fetchCompleteItem(iparenthandle,
                                    IItemManager.DEFAULT, sPm));
                            System.out.println("have parent project name = "
                                    + parentProject.getName());
                            // get the process data
                            @SuppressWarnings("unchecked")
                            Map<String, Object> pd = ip.getProcessData();
                            ////  here is the xml extract
                            // get the process config content object
                            IContent processSource = (IContent) pd.get(keyname);
                            if (processSource != null)
                            {
                                System.out.println("have xml source");
                                saveXMLSource(ip, processSource, icm, sPm);
                            }
</code>

saving the xml source
<code>
    private static void saveXMLSource(IProjectArea ip, IContent ic,
            IContentManager icm, SysoutProgressMonitor sPm)
    {
        // make an output stream for the content manager
        OutputStream os = new ByteArrayOutputStream();
        // get the content of the content object.
        try
        {
            icm.retrieveContent(ic, os, sPm);

            // write xml content to file
            // project name + data name
            FileOutputStream fo = new FileOutputStream(ip.getName() + "."
                    + keyname);
            // write
            fo.write(os.toString().getBytes(), 0, os.toString().length());
            // close
            fo.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
</code>

find the (or list of projects)
<code>
    public static List<IProjectArea> getProjectArea(ITeamRepository repo,
            IProgressMonitor monitor, String projectAreaName)
            throws TeamRepositoryException
    {
        List<IProjectArea> projectareaonly = new ArrayList<IProjectArea>();

        @SuppressWarnings("unchecked")
        // get all the projects in this repository
        List<IProjectArea> projectAreas = getProcessItemService(repo)
                .findAllProjectAreas(null, monitor);

        // if Not ALL projects
        if (!projectAreaName.equalsIgnoreCase("*"))
        {
            for (int i = 0; i < projectAreas.size(); i++)
            {
                // get next project from array
                IProjectArea projectArea = projectAreas.get(i);

                // if the names are equal, case sensitive
                if (projectArea.getName().equals(projectAreaName))
                {
                    // return this one project to the caller
                    System.out.println("Found " + projectAreaName);
                    projectareaonly.add(projectArea);
                    break;
                }
                else if (i + 1 == projectAreas.size())
                {
                    System.out.println("Failed to find requested project '"
                            + projectAreaName + "'");
                }
            }
            return projectareaonly;
        }
        else
            projectareaonly = projectAreas;
        return projectareaonly;
    }
</code>

permanent link
Harshal Bhavsar (111) | answered Mar 21 '14, 1:59 p.m.
I really want to find a way using REST API, how I can find "Process template" in particular project area?
Please let me know if somebody knows how to get handle to process templates using REST API's
Somebody in comment section said its not available.But still want to confirm

Thanks in advance!

permanent link
sam detweiler (12.5k6195201) | answered Mar 21 '14, 2:02 p.m.
 far as I know, this is not available via rest apis

permanent link
Qiong Feng Huang (76911610) | answered Mar 24 '14, 1:18 a.m.
JAZZ DEVELOPER
 We don't support it through REST API. 

For what we support in REST API, you could refer to: https://jazz.net/wiki/bin/view/Main/DraftTeamProcessRestApi

permanent link
Harshal Bhavsar (111) | answered Mar 24 '14, 1:29 a.m.
Al-right thanks for the answer Sam and Qiong!
I have another question since obvious option is RTC SDK now
If we use RTC SDK is there a way to create workitems in RTC using process templates programatically? similar to the way we do it in RTC UI manually?

I appreciate your help in this regard!

Thanks,
Harshal

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.