{"id":11091,"date":"2013-11-29T17:54:49","date_gmt":"2013-11-29T12:24:49","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11091"},"modified":"2014-12-17T09:09:38","modified_gmt":"2014-12-17T03:39:38","slug":"aemcq5-6-bulk-editor-extension-part-1","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aemcq5-6-bulk-editor-extension-part-1\/","title":{"rendered":"AEM(CQ5.6) BULK EDITOR Extension Part 1"},"content":{"rendered":"<p>I am quite fond of the bulk editor feature of CQ and in the past I have used it quite often to quickly view and update content from within the Bulk editor console.<br \/>\nRecently I found the need to refer to this &#8220;old friend&#8221; to make some quick content updates from within the Bulk editor console when I noticed something was not right. (I had not used this feature for sometime).<\/p>\n<p>I found there were two issues:<\/p>\n<ul>\n<li>Bulk editor (BE) could not add multi-value properties.<\/li>\n<li>BE could not add properties other than type String.<\/li>\n<\/ul>\n<p>I did not test the aforementioned issues in old versions of CQ, so cannot say if these are new bugs or this has always been the case with bulk editor. Since I did not have much time to go through Adobe support, I fixed it for my own installation.<\/p>\n<p>In this post, I&#8217;ll tackle the first part i.e. Adding multi-value property (only String[] for now). In a later post I&#8217;ll take up the second part. I&#8217;m using the latest release of AEM 5.6.1.<\/p>\n<p><strong>ISSUE<\/strong><\/p>\n<p>I observed that the save operation relied on the Default Sling POST servlet while it should have used the default bulk editor post handler script (\/libs\/wcm\/core\/components\/bulkeditor\/save\/POST.jsp).<\/p>\n<p>Let&#8217;s try out by searching for a property for editing.<\/p>\n<p>Navigate to bulk editor console at http:\/\/&lt;host&gt;:&lt;port&gt;\/etc\/importers\/bulkeditor.html and configure the following properties &#8211;<br \/>\nrootpath = \/content\/geometrixx-media<br \/>\nQuery params = &lt;Keep it empty&gt;<br \/>\nContent mode = &lt;unchecked&gt;<br \/>\nProperties = Select sling:resourceType<br \/>\nCustom properties = cq:allowedTemplates<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2013\/11\/BE-initial1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-11095\" src=\"\/blog\/wp-ttn-blog\/uploads\/2013\/11\/BE-initial1.jpg\" alt=\"\" width=\"1247\" height=\"639\" \/><\/a><\/p>\n<p>Click on search and let the result load. In my local instance a total of 362 results were returned of which only one row contained non-empty &#8220;cq:allowedTemplates&#8221; property. You might have to click on search button 2 or 3 times for results to load properly.<\/p>\n<p>Now edit the multivalue &#8220;cq:allowedTemplates&#8221; property and click save. In CRXDELite, check the property and you&#8217;ll find that the whole comma separated string gets stored as the first element of the array.<br \/>\ne.g. cq:allowedTemplates=<strong>&#8220;<\/strong><em>\/apps\/geometrixx-media\/templates\/.*,\/apps\/geometrixx\/templates\/.*<\/em><strong>&#8220;<\/strong><\/p>\n<p>The expected behaviour was for the comma separated string to persist each value as individual array element\u00a0e.g.<br \/>\ncq:allowedTemplates=<strong>&#8220;<\/strong><em>\/apps\/geometrixx-media\/templates\/.*<\/em><strong>&#8220;<\/strong>,<strong>&#8220;<\/strong><em>\/apps\/geometrixx\/templates\/.*<\/em><strong>&#8220;<\/strong><\/p>\n<p><strong>CAUSE<\/strong><\/p>\n<p>If you edit any property and click on save, the resulting POST will be handled by the Sling Default POST servlet, even when there is a save POST handler available for this (\/libs\/wcm\/core\/components\/bulkeditor\/save\/POST.jsp). To invoke the bulk editor save POST handler, you would like the POST to be made to http:\/\/&lt;host&gt;:&lt;port&gt;\/etc\/importers\/bulkeditor\/save<\/p>\n<p><strong>SOLUTION<\/strong><\/p>\n<p><strong><\/strong>Gear up for making some code changes. There are two parts to this problem, Firstly the save action should be handled by the appropriate save POST script and secondly multivalue properties (only String[] for now) should be editable.<\/p>\n<p>Follow these steps : &#8211;<\/p>\n<ol>\n<li>Before making edits, overlay the bulk editor component under \/apps, such that we have \/apps\/wcm\/core\/components\/bulkeditor (We do not want to make any edits under \/libs).To test that the overlayed bulk editor component is being referred to by the bulk editor page, change the title in bulkeditor.jsp to something like:&lt;title&gt;CQ5 customized BulkEditor&lt;\/title&gt;<br \/>\nRefresh the bulk editor page http:\/\/&lt;host&gt;:&lt;port&gt;\/etc\/importers\/bulkeditor.html. You should see the updated page title.<\/li>\n<li>Under the overlayed bulk editor component, open all the Java files (json.java, POST.java, tsv.java) and update the package imports to start from &#8220;apps.wcm.core&#8230;..&#8221; instead of &#8220;libs.wcm.core&#8230;..&#8221;<\/li>\n<li>&#8220;save&#8221; operation should post to http:\/\/&lt;host&gt;:&lt;port&gt;\/etc\/importers\/bulkeditor\/save instead of Sling default POST servlet. To make this change follow instructions below:<br \/>\n&#8211; Open bulkeditor.jsp<br \/>\n&#8211; Add below lines (Refer attached screenshot):<br \/>\nString saveURL = &#8220;\/etc\/importers\/bulkeditor\/save&#8221;;<br \/>\nbulkEditorConfig.put(&#8220;saveURL&#8221;,saveURL);<a href=\"\/blog\/wp-ttn-blog\/uploads\/2013\/11\/Bulk-editor-jsp-updates1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-11097\" src=\"\/blog\/wp-ttn-blog\/uploads\/2013\/11\/Bulk-editor-jsp-updates1.jpg\" alt=\"\" width=\"696\" height=\"472\" \/><\/a><br \/>\nRemove browser cache (Shorthand &#8220;Ctrl + Shift + Delete&#8221; -&gt; Empty the cache) and refresh the bulk editor page. Search using same settings as described above. Edit a property and click save. Using firebug or browser supported debugging tool monitor the request being fired. You should see the &#8220;save&#8221; action POSTing to &#8220;http:\/\/&lt;host&gt;:&lt;port&gt;\/etc\/importers\/bulkeditor\/save&#8221;.<br \/>\nThis would result in the overlayed &#8220;\/apps\/wcm\/core\/components\/bulkeditor\/save\/POST.jsp&#8221; script being called. Put some loggers in this script to ensure this script is indeed being called.<\/li>\n<li>Allowing multivalue String properties editing through bulk editor interface<br \/>\nAs you might have noted, cq:allowedTemplates is a multivalue property (String []). If you tried editing any multivalue property via the OOTB implementation of bulk editor, you would notice that the whole comma separated value gets stored as the first element of the array, instead of each comma separated value being stored as the array element. In short, bulk editor save operation does not distinguish between String and String[].<br \/>\nOpen &#8220;\/apps\/wcm\/core\/components\/bulkeditor\/save\/POST.jsp&#8221; for editing and make following changes. Refer attached file[1]<\/li>\n<\/ol>\n<div>\n<p>There are other ways to achieve the same thing but I find this to be the easy and simple way. Also, please note that the above steps are not applicable for tsv file import utility.<\/p>\n<p>In the follow up to this post I&#8217;ll discuss the second part &#8220;Bulk Editor interface should support adding properties other than type String, e.g. Long,Boolean, Date&#8221;. In the meantime feel free to suggest alternate approaches you may like\/prefer.<\/p>\n<p><strong>REFERENCES\/LINKS<\/strong><\/p>\n<\/div>\n<div>[1]:\u00a0<a href=\"\/blog\/wp-ttn-blog\/uploads\/2013\/11\/POST.doc\">POST script for save action<\/a><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I am quite fond of the bulk editor feature of CQ and in the past I have used it quite often to quickly view and update content from within the Bulk editor console. Recently I found the need to refer to this &#8220;old friend&#8221; to make some quick content updates from within the Bulk editor [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":104},"categories":[1174],"tags":[4847,1244,1207],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11091"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11091"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11091\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}