How to get Alfresco context and audit ScheduledJob in java?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 05:41 AM
Hi eveybody,
i need to audit my scheduled job, which is defined in xml beans and java class, but i m not able to get context from java class or call auditComponent.recordValues() method. Is there some guide for this in java or did i miss something
this is my scheduledjob definition xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="sk.jobs.ScheduledJobExecuter" class="sk.jobs.ScheduledJobExecuter">
<property name="serviceRegistry">
<ref bean="ServiceRegistry" />
</property>
</bean>
<bean id="sk.jobs.jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>sk.iway.makro.jobs.ScheduledJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="jobExecuter">
<ref bean="sk.iway.makro.jobs.ScheduledJobExecuter" />
</entry>
<entry key="jobLockService">
<ref bean="jobLockService" />
</entry>
</map>
</property>
</bean>
<bean id="sk.jobs.trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="sk.iway.makro.jobs.jobDetail" />
</property>
<property name="cronExpression">
<value>${dms3.scheduledjob_invoice.cronexpression}</value>
</property>
<property name="startDelay">
<value>${dms3.scheduledjob_invoice.cronstartdelay}</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton">
<property name="triggers">
<list>
<ref bean="sk.jobs.trigger"/>
</list>
</property>
</bean>
</beans>
this is my audit def/
<bean id="auditService" class="org.alfresco.repo.audit.AuditServiceImpl">
<property name="auditComponent">
<ref bean="auditComponent"/>
</property>
</bean>
<!-- Audit component -->
<bean id="auditComponent" class="org.alfresco.repo.audit.AuditComponentImpl">
<property name="transactionService" ref="transactionService"/>
<property name="auditDAO" ref="auditDAO"/>
<property name="auditModelRegistry" ref="Audit"/>
<property name="propertyValueDAO" ref="propertyValueDAO"/>
<property name="userAuditFilter" ref="userAuditFilter"/>
<property name="auditFilter">
<bean class="org.alfresco.repo.audit.PropertyAuditFilter">
<property name="properties" ref="global-properties" />
</bean>
</property>
</bean
Thank you for any help
sincerally
Jakub
- Labels:
-
Alfresco Content Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 04:39 PM
First of all I hope you are not (re-)defining the audit service and audit component beans in your context file. Those beans already exist and you should not be messed with it. You also do not need to define your own scheduler factory - you can just re-use the one already provided by Alfresco. That way your jobs would even show up in the scheduled jobs admin console tool (from either Enterprise Edition or OOTBee Support Tools).
As to your question, simply inject the audit component into your job via the job data map and you should be perfectly fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 07:47 AM
Hello Axel,
thank you for your help, it works now. But i get in the trouble in other way. I was testing code from AuditComponentTest.java class testAudit_basic method. Not this method but i tried to use this as a sample audit call. Everything works fine, no exceptions, but also no entries in database. Could you give me some advices what am i missing or what im doing wrong?
Thank you for your time
Jakub
Ps:
final RetryingTransactionCallback<Map<String,Serializable>> testCallback = new RetryingTransactionCallback<Map<String,Serializable>>() {
@Override
public Map<String, Serializable> execute() throws Throwable {
LOG.info("execute Start");
Map<String, Serializable> values = new HashMap<>(13);
values.put("/3.1/4.1", new Long(41));
values.put("/3.1/4.2", "42");
values.put("/3.1/4.3", new Date());
values.put("/3.1/4.4", "");
values.put("/3.1/4.5", null);
Map<String, Serializable> ret = new HashMap<>();
ret = auditComponent.recordAuditValues("/test/one.one/two.one", values);
int count = 0;
LOG.info("KeySetSize: " + ret.keySet().size());
for (String iterable_element : ret.keySet()) {
String key = iterable_element.toString();
String value = ret.get(iterable_element).toString();
LOG.info(count + ", Key: "+key + ", value: " + value );
count++;
}
LOG.info("execute END");
return ret;
// TODO Auto-generated method stub
//return null;
}
};
RunAsWork<Map<String, Serializable>> testRunsAs = new RunAsWork<Map<String,Serializable>>() {
@Override
public Map<String, Serializable> doWork() throws Exception {
// TODO Auto-generated method stub
LOG.info("DO WORK Start");
return transactionService.getRetryingTransactionHelper().doInTransaction(testCallback);
}
};
result of this is empty map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 04:27 PM
In order for any data to get written to the database you need to have an audit application configuration to actually map and record data. The audit component is only used to "offer" data for recording. Elements that use that record API are called "audit data producers" while an audit application would be an "audit data consumer".
