It's all about the answers!

Ask a question

How to set a stream as flow target using java RTC api?


Adrian Ronayne (2336) | asked Mar 20 '14, 4:49 a.m.
retagged Oct 16 '14, 5:35 a.m. by Morten Madsen (3053150)
 I use below code to create a workspace : 

    import org.eclipse.core.runtime.IProgressMonitor;
    import org.eclipse.core.runtime.NullProgressMonitor;
    import com.ibm.team.repository.client.ITeamRepository;
    import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
    import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
    import com.ibm.team.repository.client.TeamPlatform;
    import com.ibm.team.repository.common.TeamRepositoryException;
    import com.ibm.team.scm.client.IWorkspaceConnection;
    import com.ibm.team.scm.client.IWorkspaceManager;
    import com.ibm.team.scm.client.SCMPlatform;
    import com.ibm.team.scm.common.IFlowTable;
    
    public class RTCFirst {
   
    public static void main(String args[]) {
   
    String repositoryURI = "https://rtc.domain.com/jazz";
    String userId = "myid";
    String password = "****";
    
    IProgressMonitor monitor = new NullProgressMonitor();
    try {
    ITeamRepository repo = logIntoTeamRepository(repositoryURI,
    userId, password, monitor);
   
   
    IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
    IWorkspaceConnection workspace = wm.createWorkspace(repo.loggedInContributor(), "Example Workspace", "Description", monitor);
   
    IFlowTable ift = workspace.getFlowTable().getWorkingCopy();
    
    } catch (TeamRepositoryException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
   
    }
    
    private static ITeamRepository logIntoTeamRepository(String repositoryURI,
    String userId, String password, IProgressMonitor monitor)
    throws TeamRepositoryException {
    System.out.println("Trying to log into repository: " + repositoryURI);
    TeamPlatform.startup();
    ITeamRepository teamRepository = TeamPlatform
    .getTeamRepositoryService().getTeamRepository(repositoryURI);
    teamRepository.registerLoginHandler(new LoginHandler(userId, password));
    teamRepository.login(monitor);
    System.out.println("Login succeeded.");
    return teamRepository;
    }
   
    private static class LoginHandler implements ILoginHandler, ILoginInfo {
    
    private String fUserId;
    private String fPassword;
    
    private LoginHandler(String userId, String password) {
    fUserId = userId;
    fPassword = password;
    }
    
    public String getUserId() {
    return fUserId;
    }
    
    public String getPassword() {
    return fPassword;
    }
    
    public ILoginInfo challenge(ITeamRepository repository) {
    return this;
    }
    }
    
    }

I think I need to populate the IFlowTable with the stream I want to flow to ? If so how can this be achieved ? I can use below code to find the stream  :


    IWorkspaceHandle iwh = (IWorkspaceHandle) findConnectionByName(repo , "mystream" , 1 , monitor).get(0);
    
    
    private static List findConnectionByName(
    ITeamRepository teamRepository, String name, int kind,
    IProgressMonitor monitor) throws TeamRepositoryException {
    IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);
    IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY
    .newInstance().setKind(kind);
    if (name != null) {
    criteria.setExactName(name);
    }
    List<IWorkspaceHandle>workspaces= wm.findWorkspaces(criteria,
    Integer.MAX_VALUE, monitor);
    return workspaces;
    }

But once I've found the stream how do I add it as flow target ?

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Mar 20 '14, 6:45 a.m.
edited Mar 20 '14, 11:37 a.m.
here is code I use in my copy utility 
<code> 
IFlowTable flowtable = workspace.getFlowTable().getWorkingCopy();   
IFlowEntry[] targets = (IFlowEntry[]) flowtable.deliverTargets().toArray(new IFlowEntry[flowtable.deliverTargets().size()]);
for(IFlowEntry target:targets)
flowtable.addDeliverFlow(targetStream.getResolvedWorkspace(), repo.getId(), repo.getRepositoryURI(), null,
 targetStream.getDescription()); 
// get the node just added
IFlowEntry newnode = flowtable.getDeliverFlow(targetStream.getResolvedWorkspace());                                                                     
// record if this target flow node should be current or default
if(target.equals(flowtable.getCurrentDeliverFlow()))
{
    flowtable.setCurrent(newnode);
}
if(target.equals(flowtable.getDefaultDeliverFlow()))
{
   flowtable.setDefault(newnode); 
workspace.setFlowTable(flowtable, null); 
</code>
Adrian Ronayne selected this answer as the correct answer

Comments
Morten Madsen commented Oct 16 '14, 5:34 a.m.

Nice code example, I can get everything to work except for the setting of current and default.


One question: Why do you loop through all the existing flow targets of the workspace, and then for each, you add a new deliver flow for the same target stream.

Then after this, if the target is the current deliver flow, you set the new target stream as the new current. Why not just do this after the loop?

I'm just trying to understand the code :), and maybe it has something to do with mine not working.

Cheers,
/Morten.


sam detweiler commented Oct 16 '14, 7:26 a.m.

I have copied the workspace from some other system.
now I have to fix the flow table to point to streams on THIS system.

I loop thru the old flow table entries, and create a new entry that matches the stream from this system,
then I check to see if this old (only old entries processed in loop) matches the setting for default or current (as configured on the source system).

target.equals(flowtable.getDefaultDeliverFlow()

if it does than I set the newly created target node  as the new default/current

 flowtable.setDefault(newnode); or
 flowtable.setCurrent(newnode);


sam detweiler commented Oct 16 '14, 8:33 a.m.

I can't edit my comment, so

also, we had a few workspaces where there were multiple flow targets and some are neither current or default..  so the loop does
recreate all the flow table entries, pointing to the new workspaces/streams.
set the default/current for the new entry as appropriate


Morten Madsen commented Oct 23 '14, 2:39 p.m.

Thanks a lot for your answer :-).


I still cannot set the default and current flow target... It's on a stream though. The weird thing is this:
- I have Stream1 and Stream2
- Programmatically I add flow target Stream1 -> Stream2
- I then programmatically add this flow target as default and current
- When I look at Stream1, I can see Stream2 as flow target, but no (default) or (current) markings.
- I then try to set these manually using eclipse client, they appear as expected when I press the respective buttons but when I save Stream1 and refresh it these markings are gone again.
- If I then delete the flow target and manually add it through eclipse I can easily set default and current.... STRANGE!! 


sam detweiler commented Oct 23 '14, 3:31 p.m.

I don't know.. I never had problem with the settings not sticking..


you DID set the flowtable back into the workspace (stream), right?  else you didn't actually change it.
// after update, make sure to put the changes back into the workspace/stream
// no explicit write is required, the workspace manager will handle committing changes.
workspace.setFlowTable(flowtable, null);


Morten Madsen commented Oct 23 '14, 3:38 p.m.

Thanks again.


Yes, I did set the changes, and "Stream2" appears nicely in my flow targets for "Stream1"... but it's broken or incomplete somehow - I can't set the "default" or "current" on this entry... even manually in the user interface. When I run a debug and look at a manually added flow target (say, "Stream3", I cannot see any differences. I've even tried to add component scopes... no effect.

Have you ever tried adding a flow target to a stream programmatically? Maybe this only works for workspaces? I don't know .... :(. 


sam detweiler commented Oct 23 '14, 3:44 p.m.

my code is called for both streams and workspaces, cause I just copied a stream/workspace from a different system and the target doesn't have the same object ID on this system as it did on the old system.

I was copying from 3.0.1.3 to 4.0.3.. hm.. actually not true.. only  from/to like level systems..  3.01.3 to 3.01.3 then upgrade, then 4.0.3 to 4.0.3

what RTC version are u on


Morten Madsen commented Oct 23 '14, 3:51 p.m.

I'm on version 5.0.1... maybe there's an incompatibility between my API and the server... I'll have to check that out.


I've posted my entire code below as an answer so you can see it (working on it)....

showing 5 of 8 show 3 more comments

3 other answers



permanent link
Ralph Schoon (63.1k33646) | answered Mar 20 '14, 6:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Not sure this helps in your context, but I do a first deliver against a stream and that adds it as a flow target.
http://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/
Otherwise you will have to use the flow table. I have no code for that right now but I was able to find several posts around this topic using go***e 'flowtable site:jazz.net'. Limiting the search to the Jazz.net site is a great feature that helps me a lot finding the information I need.

permanent link
Morten Madsen (3053150) | answered Oct 23 '14, 3:54 p.m.
edited Oct 23 '14, 3:56 p.m.
 This is my code

********* WARNING, NOT AN ANSWER - NOT WORKING ********
public void doAddFlowTargetToStream(AddFlowTargetToStream addFlowTargetToStream) 
	
{
IProjectArea projectArea = jazzapi.findProjectArea(addFlowTargetToStream.getProjectarea());

IWorkspaceHandle sourceWorkspaceHandle = jazzapi.findWorkspace(projectArea, addFlowTargetToStream.getStream());

IWorkspaceHandle targetWorkspaceHandle = jazzapi.findStream(projectArea, addFlowTargetToStream.getFlowTarget());

IWorkspaceConnection sourceWorkspaceStreamConnection = jazzapi.getWorkspaceConnection(sourceWorkspaceHandle);
IFlowTable sourceFlowtable = sourceWorkspaceStreamConnection.getFlowTable().getWorkingCopy();

sourceFlowtable.addDeliverFlow(targetWorkspaceHandle, null, null, sourceWorkspaceStreamConnection.getComponents(), "Scoped");

// setting current + default
sourceFlowtable.setCurrent(sourceFlowtable.getDeliverFlow(targetWorkspaceHandle));
sourceFlowtable.setDefault(sourceFlowtable.getDeliverFlow(targetWorkspaceHandle));

// setting new flow table
sourceWorkspaceStreamConnection.setFlowTable(sourceFlowtable, jazzapi.monitor);
	    
}
	
	
	

permanent link
Morten Madsen (3053150) | answered Oct 23 '14, 4:30 p.m.
 DOH! found the solution:

summary: you have to use the "acceptflow" which actually is the deliver flow. the getDeliverFlow is only for component additions... or something...

https://jazz.net/forum/questions/64438/problem-with-quotsetcurrentquot-and-quotsetdefaultquo



Comments
sam detweiler commented Oct 23 '14, 5:17 p.m.

see what happens when you share the code? you start looking at it more...

congrats on finding it..


Morten Madsen commented Oct 24 '14, 8:43 a.m.

Thx, and actually,  they say that you should use acceptSources() and getAcceptFlow(). It's a confusing naming fo the API methods, but the acceptsources are actually your flowtargets. Shouldn't you use these instead?


I know, that when you set flow targets using the client, then both acceptSources and deliverTargets gets set, and that's why your code is working.. I guess.

But shouldn't you change to use acceptSources instead? That's how I read the post anyway.


sam detweiler commented Oct 24 '14, 8:50 a.m.

there is another whole loop for dealing with accept. My sample was intended to show the general process and api usage.. not every possible detail.

accept is incoming, deliver is outgoing..  they do not have to be symmetrical
I can accept from 1 (downstream) and deliver to a different one (upstream)

my purpose was to fixup the flow table because I had copied the workspace from system X to here, and the handles for the flow targets were no longer valid.

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.