Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes



3 answers

Permanent link
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.

2 votes

Comments

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.

1 vote

I didn't see an IFile (or symbolic link) type in the (5.0) javadoc. 


Permanent link
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;
	}

1 vote

Comments

IFileItem isn't in the javadoc was the only reason I didn't recommend it.


Permanent link
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.

0 votes

Comments

hey man.. you didn't say changeset!!

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

Sorry if I was misleading :-)

yeh yeh..   ask a question then qualify it with "if Ididn't ask it right, I meant this"!.. sneaky

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Jul 23 '14, 10:12 a.m.

Question was seen: 4,199 times

Last updated: Jul 23 '14, 12:40 p.m.

Confirmation Cancel Confirm