Goal
Activations initiated by clicking Activate button on DAM Admin UI show the user name in Published column of grid, but activations via workflow show Administrator as the publisher. This post is on showing initiating user as well in the grid (assuming the workflow Request for Activation is used for activation)
A better and simple solution is to use ACS Commons "Replicated by workflow process" step
The solution here uses CQ querybuilder, and can be improved to send a single query with each page load; also create oak indexes to avoid the traversing cursor
29.02.2016 11:48:22.174 *WARN* [0:0:0:0:0:0:0:1 [1456768102069] GET /bin/querybuilder.json HTTP/1.1] org.apache.jackrabbit.oak.spi.query.Cursors$TraversingCursor Traversed 12000 nodes with filter Filter(query=select [jcr:path], [jcr:score], * from [nt:base] as a where [modelId] = '/etc/workflow/models/request_for_activation/jcr:content/model' and [data/payload/path] = '/content/dam/geometrixx/portraits/alison_parker.jpg' and isdescendantnode(a, '/etc/workflow/instances') order by [endTime] desc /* xpath: /jcr:root/etc/workflow/instances//*[@modelId = '/etc/workflow/models/request_for_activation/jcr:content/model' and data/payload/@path = '/content/dam/geometrixx/portraits/alison_parker.jpg'] order by @endTime descending */, path=/etc/workflow/instances//*, property=[modelId=[/etc/workflow/models/request_for_activation/jcr:content/model], data/payload/path=[/content/dam/geometrixx/portraits/alison_parker.jpg]]); consider creating an index or changing the query
Demo | Package Install
Solution
1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/classicui-show-publish-workflow-initiator
2) Create node /apps/classicui-show-publish-workflow-initiator/clientlib of type cq:ClientLibraryFolder and add a String property categories with value cq.widgets and dependencies - underscore
3) Create file (nt:file) /apps/classicui-show-publish-workflow-initiator/clientlib/js.txt and add
show-workflow-initiator.js
4) Create file (nt:file) /apps/classicui-show-publish-workflow-initiator/clientlib/show-workflow-initiator.js and add the following code
(function(){ if(window.location.pathname !== "/damadmin"){ return; } //id defined in /libs/wcm/core/content/damadmin var SA_GRID = "cq-damadmin-grid", PUBLISHED_ID = "published", PUBLISHING_WORKFLOW = '/etc/workflow/models/request_for_activation/jcr:content/model', ALLOWED_CUSHION = 5000, QUERY_PREFIX = "/bin/querybuilder.json?path=/etc/workflow/instances" + "&1_property=modelId&1_property.value=" + PUBLISHING_WORKFLOW + "&orderby=@endTime&orderby.sort=desc&p.limit=1&p.nodedepth=1&p.hits=full" + "&2_property=@data/payload/path&2_property.value="; var modifyPublished = function(grid){ var pColumn = grid.getColumnModel().getColumnById(PUBLISHED_ID); if(!pColumn){ return; } var renderer = pColumn.renderer; pColumn.renderer = function(v, params, record) { var html = renderer.call(this, v, params, record); var replication = record.data.replication; if ( !replication || (replication.action != "ACTIVATE")) { return html; } var query = QUERY_PREFIX + record.id; //WARNING - for demonstration only - individual queries are not very efficient //may take its toll on your damadmin performance $.ajax({ url : query, async : false }).done(findInitiator); function findInitiator(data){ if(_.isEmpty(data) || _.isEmpty(data.hits)){ return; } var hit = data.hits[0]; if( (replication.published - new Date(hit.endTime).getTime()) < ALLOWED_CUSHION ){ html = $(html).append(", Requested by - <span style='color:red'>" + hit.initiator + "</span>")[0].outerHTML; } } return html; }; grid.store.load(); }; var SA_INTERVAL = setInterval(function(){ var grid = CQ.Ext.getCmp(SA_GRID); if(!grid || ( grid.rendered != true)){ return; } var cm = grid.getColumnModel(); if(!cm || !cm.columns){ return; } clearInterval(SA_INTERVAL); try{ modifyPublished(grid); }catch(err){ console.log("Error executing modify published column extension"); } }, 250); })();
No comments:
Post a Comment