It's all about the answers!

Ask a question

How to write/upload any file(zip) inside any specific folder of RTC source control (component) in java?


Vivek Mishra (1314) | asked Oct 11 '17, 8:59 a.m.
 I have found following code from 1 of the articles but I am not sure how to pass parameters to that method. Basically it requies 'IFileItem' object. I dont know how to create or get that object containing details of the folder of RTC source control where I want to upload my file.

 //method to uploadContentToFile
public static IFileItem uploadContentToFile(IFileItem fileItem,
ITeamRepository repo, String newContent) throws TeamRepositoryException {

IProgressMonitor monitor = new NullProgressMonitor();
IFileItem fileWorkingCopy = (IFileItem) fileItem.getWorkingCopy();

IFileContentManager contentManager = FileSystemCore
.getContentManager(repo);

VersionedContentManagerByteArrayInputStreamPovider inputStream = new VersionedContentManagerByteArrayInputStreamPovider(
newContent.getBytes());

IFileContent uploadedcontent = null;
uploadedcontent = contentManager.storeContent(
IFileContent.ENCODING_UTF_8,
FileLineDelimiter.LINE_DELIMITER_PLATFORM, inputStream, null,
monitor);

fileWorkingCopy.setContent(uploadedcontent);
System.out.println("Loaded new content into file.");
return fileWorkingCopy;
}

//method to applyLock
public static void applyLock(ITeamRepository repo,
IWorkspaceConnection streamConnection,
IComponentHandle componentHandle, IFileItem fileItem,
IProgressMonitor monitor) throws TeamRepositoryException {

IWorkspaceManager wsManager = (IWorkspaceManager) repo
.getClientLibrary(IWorkspaceManager.class);
IVersionableLockOperationFactory lockFactory = wsManager
.lockOperationFactory();
ArrayList<IVersionableLockOperation> lockOperations = new ArrayList<IVersionableLockOperation>();
lockOperations.add(lockFactory.acquire(fileItem, streamConnection,
componentHandle));
wsManager.applyLockOperations(lockOperations, monitor);
}

//method to removeLock
public static void removeLock(ITeamRepository repo,
IWorkspaceConnection streamConnection,
IComponentHandle componentHandle, IFileItem fileItem,
IProgressMonitor monitor) throws TeamRepositoryException {

IWorkspaceManager wsManager = (IWorkspaceManager) repo
.getClientLibrary(IWorkspaceManager.class);
IVersionableLockOperationFactory lockFactory = wsManager
.lockOperationFactory();
ArrayList<IVersionableLockOperation> lockOperations = new ArrayList<IVersionableLockOperation>();
lockOperations.add(lockFactory.release(fileItem, streamConnection,
componentHandle, true));
wsManager.applyLockOperations(lockOperations, monitor);
}

Accepted answer


permanent link
Shashikant Padur (4.2k27) | answered Oct 12 '17, 6:35 a.m.
JAZZ DEVELOPER

 Take a look at the following link: http://thescmlounge.blogspot.in/ and search for Uploading new content. Follow through with committing the change to a change set.

Vivek Mishra selected this answer as the correct answer

Comments
Ralph Schoon commented Oct 12 '17, 6:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Also see https://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/ and make sure to understand which file types, line ending etc. to use for zip  - e.g. look at the values it has in RTC Eclipse. ZIP is not mergeable binary (which is why it normally should not be in SCM).

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.