cosmos
cosmos

Reputation: 2424

Update document content in Alfresco using Apache Chemistry Asynchronously

I am using OpenCMIS 1.1.0 to execute CRUD operations on an Alfresco Content Repository. Using the examples provided here I am able to execute all CRUD operations on both folders and documents.

Now I want to execute these operations (esp. create and update) asynchronously. Using this excellent SO post I can create documents asynchronously. However, OpenCMIS AsyncSession class does not provide an updateContentStream method.

Is there some way I can use OpenCMIS API to update document content asynchronously.

Upvotes: 0

Views: 336

Answers (1)

Florian Müller
Florian Müller

Reputation: 3235

All operations that require a change token are not available in AsyncSession because the outcome would not be predicable if two operations on the same object would be scheduled. But you can add your own Callable. Cast your AsyncSession object to AbstractExecutorServiceAsyncSession and call submit with your own Callable object. Here you can do whatever you want.

Such a Callable class could look like this:

public class SetContentStreamCallable extends SessionCallable<ObjectId> {
    private Document doc;
    private ContentStream contentStream;
    private boolean overwrite;

    public SetContentStreamCallable(Session session, Document doc, ContentStream contentStream, boolean overwrite) {
        super(session);
        this.doc = doc;
        this.contentStream = contentStream;
        this.overwrite = overwrite;
    }

    @Override
    public ObjectId call() throws Exception {
        return doc.setContentStream(contentStream, overwrite, false);
    }
}

But keep in mind not to run two tasks on the same document!

Upvotes: 2

Related Questions