- * Delegates job execution and ensures locking
- * is enforced.
+ * Delegates job execution and ensures locking is enforced.
*
* @author Roy Wetherall
*/
@@ -55,11 +54,14 @@ public class RecordsManagementJob implements Job
{
private static Log logger = LogFactory.getLog(RecordsManagementJob.class);
+ /** which user should be used to log audit */
+ private String runAuditAs = AuthenticationUtil.getSystemUserName();
+
private static final long DEFAULT_TIME = 30000L;
private JobLockService jobLockService;
- private RecordsManagementJobExecuter jobExecuter;
+ private RecordsManagementJobExecuter jobExecuter = null;
private String jobName;
@@ -67,17 +69,17 @@ public class RecordsManagementJob implements Job
{
return QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, jobName);
}
-
+
private class LockCallback implements JobLockRefreshCallback
{
final AtomicBoolean running = new AtomicBoolean(true);
-
+
@Override
public boolean isActive()
{
return running.get();
}
-
+
@Override
public void lockReleased()
{
@@ -85,11 +87,10 @@ public class RecordsManagementJob implements Job
}
}
-
/**
- * Attempts to get the lock. If the lock couldn't be taken, then null is returned.
+ * Attempts to get the lock. If the lock couldn't be taken, then null is returned.
*
- * @return Returns the lock token or null
+ * @return Returns the lock token or null
*/
private String getLock()
{
@@ -103,31 +104,54 @@ public class RecordsManagementJob implements Job
}
}
- @Override
+ /**
+ * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
+ */
public void execute(JobExecutionContext context) throws JobExecutionException
{
+
// get the job lock service
- jobLockService = (JobLockService)context.getJobDetail().getJobDataMap().get("jobLockService");
- if (jobLockService == null)
- {
- throw new AlfrescoRuntimeException("Job lock service has not been specified.");
- }
+ jobLockService = (JobLockService) context.getJobDetail().getJobDataMap().get("jobLockService");
+ if (jobLockService == null) { throw new AlfrescoRuntimeException("Job lock service has not been specified."); }
// get the job executer
- jobExecuter = (RecordsManagementJobExecuter)context.getJobDetail().getJobDataMap().get("jobExecuter");
- if (jobExecuter == null)
- {
- throw new AlfrescoRuntimeException("Job executer has not been specified.");
- }
+ jobExecuter = (RecordsManagementJobExecuter) context.getJobDetail().getJobDataMap().get("jobExecuter");
+ if (jobExecuter == null) { throw new AlfrescoRuntimeException("Job executer has not been specified."); }
// get the job name
- jobName = (String)context.getJobDetail().getJobDataMap().get("jobName");
- if (jobName == null)
+ jobName = (String) context.getJobDetail().getJobDataMap().get("jobName");
+
+ if (jobName == null) { throw new AlfrescoRuntimeException("Job name has not been specified."); }
+
+ if (jobName.compareTo("dispositionLifecycle") == 0)
{
- throw new AlfrescoRuntimeException("Job name has not been specified.");
+ //RM-3293 - set user for audit
+ if (jobExecuter instanceof DispositionLifecycleJobExecuter)
+ {
+ String auditUser = (String) context.getJobDetail().getJobDataMap().get("runAuditAs");
+ if (((DispositionLifecycleJobExecuter) jobExecuter).getAuthenticationService()
+ .authenticationExists(auditUser))
+ {
+
+ setRunAuditAs(auditUser);
+ }
+ else
+ {
+ setRunAuditAs(AuthenticationUtil.getSystemUserName());
+ }
+
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("DispositionLifecycleJobExecuter() logged audit history with user: " + getRunAuditAs());
+
+ }
+
}
final LockCallback lockCallback = new LockCallback();
+
AuthenticationUtil.runAs(new RunAsWork