/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2015 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.auth;

import javax.inject.Inject;

import com.axelor.auth.db.User;
import com.axelor.auth.db.repo.UserRepository;
import com.google.common.base.Preconditions;

/**
 * This class can be used to run batch jobs that requires to keep track of audit
 * logs.
 *
 */
public class AuditableRunner {

	static ThreadLocal<User> batchUser = new ThreadLocal<>();

	private static final String DEFAULT_BATCH_USER = "admin";

	private UserRepository users;

	@Inject
	public AuditableRunner(UserRepository users) {
		this.users = users;
	}

	/**
	 * Run a batch job.
	 *
	 * @param job
	 *            the job to run
	 */
	public void run(Runnable job) {

		Preconditions.checkNotNull(job);
		Preconditions.checkNotNull(users);

		User user = AuthUtils.getUser();
		if (user == null) {
			user = users.findByCode(DEFAULT_BATCH_USER);
		}

		batchUser.set(user);
		try {
			job.run();
		} finally {
			batchUser.remove();
		}
	}
}

@@ -724,16 +724,55 @@
 .auth;%0A%0A
+import java.util.concurrent.Callable;%0A%0A
 import j
@@ -915,16 +915,58 @@
 ditions;
+%0Aimport com.google.common.base.Throwables;
 %0A%0A/**%0A *
@@ -1424,16 +1424,22 @@
 oid run(
+final 
 Runnable
@@ -1446,16 +1446,440 @@
  job) %7B%0A
+%09%09try %7B%0A%09%09%09run(new Callable%3CBoolean%3E() %7B%0A%09%09%09%09@Override%0A%09%09%09%09public Boolean call() throws Exception %7B%0A%09%09%09%09%09job.run();%0A%09%09%09%09%09return true;%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// propagate the exception%0A%09%09%09throw Throwables.propagate(e);%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * Run a batch job.%0A%09 * %0A%09 * @param job%0A%09 *            the job to run%0A%09 * @return job result%0A%09 * @throws Exception%0A%09 */%0A%09public %3CT%3E T run(Callable%3CT%3E job) throws Exception %7B
 %0A%09%09Preco
@@ -2088,23 +2088,31 @@
 ry %7B%0A%09%09%09
-job.run
+return job.call
 ();%0A%09%09%7D 

Allow to run auditable runner with callbale