As in the subject, I have an already configured File Transfer Replication Job, which I am able to run manually.
Now, I would like to start it at the end of a Script (not a Web Script or Java). However I cannot find documentation or example on how to achieve this. I have spot a Transfer object in the official documentation, but I have not been able to found any more API details.
My Alfresco version is 4.2.
It took me a while to figure it out, but eventually I found two solutions.
First solution
At the official documentation regarding the Root Objects part there is a
replicationService
which maps toorg.alfresco.repo.replication.script.ScriptReplicationService
but it really doesn't say much.If you are familiar with Alfresco, you can track down to the impl class by going into Alfresco folder and open
WEB-INF/classes/alfresco/replication-services-context.xml
. I have guessed the file name, but you can do a search of all xml files with replicationService as key. Here is the relevant part:If you open the source code or the API you can spot the relevant methods:
loadReplicationDefinitions(String target)
where target is the name of the target configured in the Replication Job andreplicate(ReplicationDefinition replicationDefinition)
which can be invoked from a Script.In the end this is the fragment that invoke your replication job.
That's it, your content is transferred.
Second solution
One other not so easy option is to invoke the
transfer
root object, which is the object the replication service rely on, it works too but then you have to manually build your array of ScriptNodes to be transferred.If you go further you can also invoke asynchronously and have your callback, but I didn't experiment on it yet.
Note - I don't use the FTR, so I haven't actually tested it, but I know how similar bits of Alfresco work!
Starting from a script, you need to take advantage of FTR being available as an Action. If you look at the source code for FileTransferActionExecutor then you'll see that the action name is
ftr-action
. (Also confirmed from the spring context file)Next, you need to follow the slightly poorly documented Script Action docs to create an action for this, configure it and run it
You'll need to do something like:
That will create a FTR action, configure it with the FTR to run, then run it until it completes.
executeAsynchronously
is also available if you want to run it in the background