It's all about the answers!

Ask a question

Update a file on a serverside extension

Marco Gianfico (2049) | asked Sep 15 '14, 4:45 a.m.
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);
                bytes.length, null, inStream);
VersionedContent vc = ScmFactory.eINSTANCE.createVersionedContent();

ICommitParameter parm = ICommitParameter.FACTORY.create(singleChangeSet);
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

Marco Gianfico commented Sep 15 '14, 6:48 a.m. | edited Sep 15 '14, 6:49 a.m.

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
Remy Suen (426124) | answered Sep 15 '14, 2:03 p.m.
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

Marco Gianfico commented Sep 16 '14, 3:44 a.m.

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

Marco Gianfico commented Sep 16 '14, 6:02 a.m.

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
Marco Gianfico (2049) | answered Sep 16 '14, 6:00 a.m.
edited Sep 16 '14, 6:01 a.m.
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.setSize(b.length);//oppure fileContent.getSize()
                                 FileContentProperties context = new FileContentProperties(fileContent);
IFileItem modifiedFile = (IFileItem) file.getWorkingCopy();
                                        modifiedFile.setContent((IFileContent) c);

permanent link
Arne Bister (2.6k12832) | answered Sep 15 '14, 5:10 a.m.

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

Marco Gianfico commented Sep 15 '14, 5:42 a.m.

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