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

Update a file on a serverside extension

Hi all!
I'm trying to update the content of a file using server api. I've read the thread link to the discussion
I found that they use IFIleContentManager and FileSystemCore to store the content in the file. But these classes are from client api. It is possibile to use them on the serverside? Or, are there any server version of these classes?

In my code I've tried to do this but it doesn't work

serverVersionedContentService.fetchContent(file, hash, out);
                        byte[] bytes = out.toByteArray();
//some modifics occurs on bytes
IFileItem modifiedFile = (IFileItem) file.getWorkingCopy();

contentHashCode = ContentHash.valueOf(new ByteArrayInputStream(bytes));
ByteArrayInputStream inStream = new ByteArrayInputStream(bytes);
serverVersionedContentService.storeContentNoProperties(contentHashCode,
                bytes.length, null, inStream);
VersionedContent vc = ScmFactory.eINSTANCE.createVersionedContent();
vc.setHash(contentHashCode);
vc.setPredecessorHint((ContentHash)null);
vc.setSize(bytes.length);
modifiedFile.setContent(vc);

ICommitParameter parm = ICommitParameter.FACTORY.create(singleChangeSet);
parm.addItemToSave(file);
this.getScmService().batchCommit(workspaceHandle, new ICommitParameter[]{parm}, null, null, null);

this give me the errore that a fileItem cannot get the content from a VersionedContent but just from a FileContent

what can I do? Any suggestion?
Thanks in advance

0 votes

Comments

the real problem is to set the content of the file on the serverside.
with the help of the class IServerSideVersionedContentService we are able to get a VersionedContent or also an IVersionedContent (the superclass) but we aren't able to put this IVersionedContent in a IFileContent (it's a sublcass of IVersionedContent), and the poor IFileItem can just take a IFileContent through the method setContent


Accepted answer

Permanent link
If the server won't take a VersionedContent and wants a FileContent, couldn't you just create one?
FileContent content = FilesystemFactory.eINSTANCE.createFileContent();
Marco Gianfico selected this answer as the correct answer

0 votes

Comments

That's right, but how can I fill it if I cannot use IFileContentManager on the server side?

Thanks Remy,
in the last answer of this thread I posted a snippet of code that can be useful for who can face the same problem


2 other answers

Permanent link
For whom is interested in on server api does not provide the method setContent for a FileContent that on the client side is provided by FileContentManager.setContent().

So you have manually to set hash, predecessorhint, size, characterencoding, ld count and ldsetting through FileContent set methods.
A snippet of code that can be useful:

VersionedContent newContent = ..//createcontent through ServerVersionedContentService.storeContent(...)
FileContent c = FilesystemFactory.eINSTANCE.createFileContent();
                                 c.setHash(newContent.getHash());
                                 c.setPredecessorHint(newContent.getPredecessorHint());
                                 c.setSize(b.length);//oppure fileContent.getSize()
                                 c.setCharacterEncoding(fileContent.getCharacterEncoding());
                                 FileContentProperties context = new FileContentProperties(fileContent);
                                 c.setLineDelimiterCount(context.getLineDelimiterCount());
                                 c.setLineDelimiterSetting(ld.dbValue())
IFileItem modifiedFile = (IFileItem) file.getWorkingCopy();
                                        modifiedFile.setContent((IFileContent) c);

1 vote


Permanent link
Marco,

my colleague Kevin Eifinger describes a very elegant solution to modifying files directly on a stream with server side code. You can find the links in Ralph Schoons Blog. Is this what you are looking for?

Then please mark the answer as accepted.

- Arne

0 votes

Comments

The fact is the he uses IFileContentManager, FileSystemCore and ScmPlatform that are from the client api. In my little experience in rtc development i never figured out how to import client classes in a server side environment.
Is it possible to import client classes in a server side extension?

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
× 11,055

Question asked: Sep 15 '14, 4:45 a.m.

Question was seen: 5,255 times

Last updated: Sep 16 '14, 6:02 a.m.

Confirmation Cancel Confirm