How to start an FTR Replication Job from Alfresco

2019-09-05 16:19发布

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.

2条回答
做个烂人
2楼-- · 2019-09-05 16:47

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.

查看更多
Deceive 欺骗
3楼-- · 2019-09-05 16:58

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:

var ftr = actions.create("ftr-action");
ftr.parameters["ftr"] = "name of the ftr to run";
ftr.execute(nodeRef);

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

查看更多
登录 后发表回答