3

I am searching for a .txt file that is located at change set. Then I need to create locally over my pc the full path directory of this file.

For example if there a file called"test.txt" that it's located at: Project1-->Folder1-->Folder2-->test.txt

Till now I have managed to search for this file. Now I need to fetch the full directory and create similar one over my pc: Result at my pc: Folder1-->Folder2-->test.txt

That's what I did to search for the file within a changeset and retrieve it:

public IFileItem getTextFileFile(IChangeSet changeSet, ITeamRepository repository) throws TeamRepositoryException{
    IVersionableManager vm = SCMPlatform.getWorkspaceManager(repository).versionableManager();
    List changes = changeSet.changes();
    IFileItem toReturn = null;
    for(int i=0;i<changes.size();i++) {="" <br="">             Change change = (Change) changes.get(i);
        IVersionableHandle after = change.afterState();
        if( after != null && after instanceof IFileItemHandle) {
            IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null);
            if(fileItem.getName().contains(".txt")) {
                   toReturn = fileItem;
                   break;
            } else {
               continue;
            }
        }
    }
    if(toReturn == null){
        throw new TeamRepositoryException("Could not find the file");
    }
    return toReturn;
}

I use RTC:4 Win:XP

Thanks in advance.

Echo
  • 2,959
  • 15
  • 52
  • 65
  • So... as Tim Mok asked you at https://jazz.net/forum/questions/103355/java-get-the-full-path-of-a-file-at-change-set, you are still not willing to "provide here what went wrong with your attempts given those answers"? No error message? No nothing? (not to mention the version of RTC, of Java, of the OS, ... the basics: that can help us help you too) – VonC Feb 20 '13 at 21:57
  • it's RTC 4 with win.xp – Echo Feb 20 '13 at 22:27
  • Sorry for that as I have been searching here and there for any thing that can help a newbie like me into RTC.I've updated my question over there – Echo Feb 20 '13 at 22:29
  • Is there any clue I can use ! – Echo Feb 21 '13 at 06:57

1 Answers1

2

I have the following IConfiguration that I fetched by the following:

IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository); 

IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance(); 


wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS); 


wsSearchCriteria.setPartialOwnerNameIgnoreCase(projectAreaName); 


List <iworkspacehandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, Application.getMonitor());  

IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0),Application.getMonitor()); 

IComponentHandle component = changeSet.getComponent(); 


IConfiguration configuration = workspaceConnection.configuration(component); 

List lst = new ArrayList<string>(); 

lst=configuration.locateAncestors(lst,Application.getMonitor()); 

=========================================

Now to get the full path of the file item ,I made the following method I got from :

https://jazz.net/forum/questions/94927/how-do-i-find-moved-from-location-for-a-movedreparented-item-using-rtc-4-java-api

=========================================

private String getFullPath(List ancestor, ITeamRepository repository) 

throws TeamRepositoryException { 

String directoryPath = ""; 


for (Object ancestorObj : ancestor) { 


IAncestorReport ancestorImpl = (IAncestorReport) ancestorObj; 


for (Object nameItemPairObj : ancestorImpl.getNameItemPairs()) { 


NameItemPairImpl nameItemPair = (NameItemPairImpl) nameItemPairObj; 


Object item = SCMPlatform.getWorkspaceManager(repository) 

.versionableManager() 

.fetchCompleteState(nameItemPair.getItem(), null); 


String pathName = ""; 


if (item instanceof IFolder) { 

pathName = ((IFolder) item).getName(); 

} 


else if (item instanceof IFileItem) { 

pathName = ((IFileItem) item).getName(); 

} 


if (!pathName.equals("")) 

directoryPath = directoryPath + "\\" + pathName; 

} 

} 

return directoryPath; 

} 

=========================================

Echo
  • 2,959
  • 15
  • 52
  • 65
  • 1
    Thanks VonC for your assistance.Please if you have any materials that can help me through RTC-SDK,please share. – Echo Feb 23 '13 at 07:55