How to determine if IVersionable is a file or a directory?
Jazzers,
with a handle in IVersionable, what is a fast way to determine in java code whether this IVersionable is a directory or a file? Underlying reason: for a change set I want to determine whether it contains actual file changes or "just" added / removed directories. Best, Arne |
3 answers
I think you have to resolve it and then check the versionable for type of IFolder.
if its NOT an IFolder then it must be a file. Comments 1
It could also be a symbolic link in case it's required to detect files. It would be best to check specifically for the type that you want.
sam detweiler
commented Jul 23 '14, 11:03 a.m.
I didn't see an IFile (or symbolic link) type in the (5.0) javadoc.
|
Ralph Schoon (63.4k●3●36●46)
| answered Jul 23 '14, 11:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is what i used in https://rsjazz.wordpress.com/2013/10/15/extracting-an-archive-into-jazz-scm-using-the-plain-java-client-libraries/ another source to look at would be http://thescmlounge.blogspot.de/2013/08/getting-your-stuff-using-rtc-sdk-to-zip.html
/** * Find a folder in an existing parent folder. * * @param folderName * @param parentFolder * @return * @throws TeamRepositoryException */ private IFolder getFolder(String folderName, IFolderHandle parentFolder) throws TeamRepositoryException { IVersionable foundItem = getVersionable(folderName, parentFolder); if (null != foundItem) { if (foundItem instanceof IFolder) { return (IFolder) foundItem; } } return null; } /** * Tries to find a IFileItem node in a given IFolder. Returns the IFileItem * found or null if none was found. * * @param file * @param parentFolder * @return * @throws TeamRepositoryException */ private IFileItem getFile(File file, IFolderHandle parentFolder) throws TeamRepositoryException { IVersionable foundItem = getVersionable(file.getName(), parentFolder); if (null != foundItem) { if (foundItem instanceof IFileItem) { return (IFileItem) foundItem; } } return null; } Comments
sam detweiler
commented Jul 23 '14, 11:37 a.m.
IFileItem isn't in the javadoc was the only reason I didn't recommend it.
|
Thanks, everybody.
Actually I found IFolderHandle and now trying this: boolean result = ChangeSetFilter.IS_NOT_FILTERED; List <IChange> changeList = changeSet.changes(); for (IChange change : changeList) { if(! (change.item() instanceof IFolderHandle)) { result = ChangeSetFilter.IS_FILTERED; return result; } } (hopefully) sneakily getting around having to resolve all change set handles. Will update this if this is *not* working and post alternative. Comments
sam detweiler
commented Jul 23 '14, 12:32 p.m.
hey man.. you didn't say changeset!!
Well, I did ... sort of:
Sorry if I was misleading :-)
sam detweiler
commented Jul 23 '14, 12:40 p.m.
yeh yeh.. ask a question then qualify it with "if Ididn't ask it right, I meant this"!.. sneaky
|
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.