Get Audit Data using java webscript

1. Create file at location: /config/alfresco/extension/templates/webscripts/org/alfresco/record.get.desc.xml
<webscript>
  <shortname>Audit Data Scripts</shortname>
  <description>Record Audit Information</description>
  <url>/api/test/extensions/record/{store_type}/{store_id}/{id}/{userName}/{action}/{site}</url>
  <authentication>user</authentication>
  <format default="">argument</format>
</webscript>

2. Create entry at location to call the webscript:
/source/web/components/test/demo.js
// Setup the URL to call for a GET web script that will record this action
var uri = YAHOO.lang.substitute(Alfresco.constants.PROXY_URI + "api/test/extensions/record/{store_type}/{store_id}/{id}/{userName}/{action}/{site}",
{
store_type: store,
store_id: store_type,
site: site,
id: nodeid,
userName: user,
action: actionName
});
   
//Send the request to record the action
Alfresco.util.Ajax.request(
{
method: Alfresco.util.Ajax.GET,
url: uri,
failureMessage: "Couldn't find this " + actionName + " transaction"
});

3. Register webscript at location:
/config/alfresco/extension/web-scripts-application-context.xml
<bean id="webscript.org.alfresco.record.get" 
      class="com.test.alfresco.SampleWebscript" 
      parent="webscript">
      <property name="auditComponent" ref="auditComponent"/>
      <property name="nodeService" ref="NodeService" />
      <property name="dictionaryService" ref="DictionaryService" />
      <property name="serviceRegistry" ref="ServiceRegistry" />
</bean>

4. Create webscript file at location:
/trunk/source/java/com/test/alfresco/SampleWebscript.java
public class SampleWebscript extends AbstractWebScript {
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException 
{
// locate the root path
Map<String, String> templateArgs = req.getServiceMatch().getTemplateVars();
String store_type = templateArgs.get("store_type");
String store_id = templateArgs.get("store_id");
String id = templateArgs.get("id");
String nodeRefStr = store_type + "://" + store_id + "/" + id;

String action = templateArgs.get("action");
String userName = templateArgs.get("userName");
String site = templateArgs.get("site");

NamespaceService nspr = serviceRegistry.getNamespaceService();
map.put(AuditApplication.buildPath("/action"), action); 
map.put(AuditApplication.buildPath("/container"), container);
map.put(AuditApplication.buildPath("/name"), docName);
map.put(AuditApplication.buildPath("/user"), userName);
map.put(AuditApplication.buildPath("/site"), site);
map.put(AuditApplication.buildPath("/type"), tdq.toPrefixString(nspr));
map.put("node", nodeRef);

auditComponent.recordAuditValues("/alfresco-access/transaction", auditMap);
}

}

Comments

Popular posts from this blog

Install Alfresco Content Service 6.0 on ubuntu 16 using distribution zip

Lucene and fts-search

Call javascript webscript from contoller