I have been building a client to replace some content on the connections social website that we have. I have written a java client by following the sample code from the Github repo :https://github.com/OpenNTF/SocialSDK/tree/master/sdk/com.ibm.sbt.core.test/src/test/java/com/ibm/sbt/services/client/connections/files
And also using a this tutorial as a reference to create endpoints and then passing it to different service. http://bastide.org/2014/01/28/how-to-develop-a-simple-java-integration-with-the-ibm-social-business-toolkit-sdk/
To be clear , I am posting content on a community so I am using CommunityService to upload content and FileService to update community files.
This method works fine : fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, params) This creates multiple versions on the server which is not what I want.
However, I want to use this one - fileservice.updateFile(inputStream, file, params) If I use the above one in my code it causes the below error :
Error updating the file
com.ibm.sbt.services.client.connections.files.FileServiceException: Error updating the file
at com.ibm.sbt.services.client.connections.files.FileService.updateFile(FileService.java:2686)
at sbt.sample.standalone.java.StandaloneDemo.ReplacePhoto(StandaloneDemo.java:332)
at sbt.sample.standalone.java.StandaloneDemo.main(StandaloneDemo.java:239)
Caused by: java.lang.IllegalStateException: SBT context is not initialized for the request
at com.ibm.commons.runtime.Context.get(Context.java:57)
at com.ibm.sbt.services.endpoints.BasicEndpoint.authenticate(BasicEndpoint.java:151)
at com.ibm.sbt.services.client.ClientService.forceAuthentication(ClientService.java:296)
at com.ibm.sbt.services.client.ClientService.processResponse(ClientService.java:1154)
at com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1072)
at com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:1037)
at com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:1003)
at com.ibm.sbt.services.client.ClientService.put(ClientService.java:937)
at com.ibm.sbt.services.client.ClientService.put(ClientService.java:933)
at com.ibm.sbt.services.client.base.BaseService.updateData(BaseService.java:439)
at com.ibm.sbt.services.client.connections.files.FileService.updateFile(FileService.java:2683)
Note : The user that I am using in the program is the admin of the community to where content is posted. Moreover is there any way I can specify in the sbtsdk api to replace the file other without creating other versions?
I found this to be similar - Liferay Portal & IBM SBT SDK: SBT context is not initialized for the request But I don't understand if there was any resolution to it.
Thanks.
First of all its hard to understand why you are seeing "SBT context is not initialized for the request" because you can run one fileservice API and not the other.
Both fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, params)
and fileservice.updateFile(inputStream, file, params)
create new versions. They do not replace the latest version. There is a parameter with this API which controls whether to create new version or not.
This is what you need to do:
use parameter createVersion with value "false". like this:
Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("createVersion", "false");
Now use this paramsMap in updateCommunityFile API like this:
fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, paramsMap)