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 to org.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:
<bean id="replicationService" class="org.alfresco.repo.replication.ReplicationServiceImpl" >
<property name="actionService" ref="ActionService"/>
<property name="scheduledPersistedActionService" ref="scheduledPersistedActionService" />
<property name="replicationDefinitionPersister" ref="replicationDefinitionPersister" />
</bean>
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 and replicate(ReplicationDefinition replicationDefinition)
which can be invoked from a Script.
In the end this is the fragment that invoke your replication job.
var jobs = replicationService.loadReplicationDefinitions('MyTargetName');
var job = jobs[0]; // I only have one target with that name, it safe to get 0
replicationService.replicate(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.
var nodes = // your array of ScriptNodes
transfer.transfer('MyTargetName', nodes);
If you go further you can also invoke asynchronously and have your callback, but I didn't experiment on it yet.