It's all about the answers!

Ask a question

How to determine if IVersionable is a file or a directory?


Arne Bister (2.6k12832) | asked Jul 23 '14, 10:12 a.m.
JAZZ DEVELOPER
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



permanent link
sam detweiler (12.5k6194201) | answered Jul 23 '14, 10:22 a.m.
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
Tim Mok commented Jul 23 '14, 10:47 a.m.
JAZZ DEVELOPER

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. 


permanent link
Ralph Schoon (62.7k33643) | 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.


permanent link
Arne Bister (2.6k12832) | answered Jul 23 '14, 12:29 p.m.
JAZZ DEVELOPER
Thanks, everybody.
Actually I found IFolderHandle and now trying this:
                 
            boolean result = ChangeSetFilter.IS_NOT_FILTERED;
            List <IChange> changeList = changeSet.changes();
if (changeList.isEmpty()) {
result = ChangeSetFilter.IS_FILTERED;
return result;
}
            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!!


Arne Bister commented Jul 23 '14, 12:38 p.m.
JAZZ DEVELOPER

Well, I did ... sort of:
"[...] Underlying reason: for a change set I want to ..."


Arne Bister commented Jul 23 '14, 12:38 p.m.
JAZZ DEVELOPER

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


Register or to post your answer.