<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is there any endpoint in alfresco that allows applying the aspects in bulk in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110083#M30840</link>
    <description>&lt;P&gt;Hello community&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the title says, i was searching in the community content about any available endpoints to apply aspects in bulk on several nodes in one or more sites. I have 4-5 aspects which i have added to my content model which i want to apply to old nodes&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Is there anything available already or do i need to create a custom WebScript or something?&lt;/P&gt;&lt;P&gt;Appreciate any hint/guidance&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jun 2020 17:18:32 GMT</pubDate>
    <dc:creator>bip1989</dc:creator>
    <dc:date>2020-06-30T17:18:32Z</dc:date>
    <item>
      <title>Is there any endpoint in alfresco that allows applying the aspects in bulk</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110083#M30840</link>
      <description>&lt;P&gt;Hello community&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the title says, i was searching in the community content about any available endpoints to apply aspects in bulk on several nodes in one or more sites. I have 4-5 aspects which i have added to my content model which i want to apply to old nodes&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Is there anything available already or do i need to create a custom WebScript or something?&lt;/P&gt;&lt;P&gt;Appreciate any hint/guidance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:18:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110083#M30840</guid>
      <dc:creator>bip1989</dc:creator>
      <dc:date>2020-06-30T17:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any endpoint in alfresco that allows applying the aspects in bulk</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110084#M30841</link>
      <description>&lt;P&gt;As far as i know, there are no ootb rest api which can be used for your use case. However, there is a way to add/remove aspects to one node.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;You can see details here:&lt;/U&gt;&lt;BR /&gt;&lt;A href="https://javaworld-abhinav.blogspot.com/2017/06/addremove-aspects-on-node-in-alfresco.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://javaworld-abhinav.blogspot.com/2017/06/addremove-aspects-on-node-in-alfresco.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;For applying aspects to multiple nodes to a specific site or on all the available sites, you can do following:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1- Create a java backed or repo (js) webscript which will search for the nodes in site for missing aspect.&lt;BR /&gt;2- You can target one site at a time or you can list all sites and iterate on iterate&lt;BR /&gt;3- Search query would be something like:&lt;/P&gt;

&lt;PRE&gt;PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary//*" AND (TYPE:"cm:content" AND NOT ASPECT:"xyz:aspectName" AND NOT ASPECT:"cm:lockable") [Here, cm:test-site is the site short name.]&lt;/PRE&gt;

&lt;P&gt;You can limit the search to a specific folder and custom content types as well.&lt;/P&gt;
&lt;P&gt;4- Iterate on resulted nodes and apply the aspect using NodeService (when using java backed webscript) or call addAspect on node (node.addAspect("xyz:aspectName")).&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Here is a sample repo (js) webscript, you can take reference from it and tweak it as per your need, It allows applying aspect to all the sites based on search query:&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;apply-aspect.get.js
&lt;/STRONG&gt;
main();

function main(){
	var aspectName = args["aspectName"];
	var contentType = args["contentType"];
    var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"]; //defaults to 0, if argument is not passed.
	var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?100000:args["maxCount"]; //defaults to 100000, if argument is not passed.
	
	var successfullNodes = [];
	var erroredNodes = [];
	
	var query = 'PATH:"/app:company_home/st:sites//*" AND TYPE:"'+contentType+'" AND NOT ASPECT:"'+aspectName+'" AND NOT ASPECT:"cm:lockable"';
	
	var page = {
			skipCount : parseInt(skipCount),
			maxItems : parseInt(maxCount)
	};

	var searchQuery = {
			query : query,
			language : "lucene",
			page : page
	};
	
 	logger.log("Query for search: "+query)
 	var nodes = search.query(searchQuery);
 	logger.log("Resulted Nodes: "+nodes.length)

	for each(node in nodes) {
		try {
			if(!node.hasAspect(aspectName)){
				node.addAspect(aspectName);
				successfullNodes[node.nodeRef] = "Aspect '"+aspectName+"' applied successfully to: " +node.name;
			}
		} catch(excp) {
			logger.log("Failed to apply aspect due to: "+excp.message);
			erroredNodes[node.nodeRef] = "Aspect '"+aspectName+"' could not be applied to: " +node.name+", due to: "+excp.message;			
		}
	}
	//Put the result in model so that we can display it in a template&lt;BR /&gt;        model.successfullNodes = successfullNodes;
	model.erroredNodes = erroredNodes;
}&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;You can also refer this documentation on creating/deploying the webscripts: &lt;BR /&gt;&lt;A href="https://docs.alfresco.com/5.2/references/dev-extension-points-webscripts.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/5.2/references/dev-extension-points-webscripts.html&lt;/A&gt;&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 00:39:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110084#M30841</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-07-01T00:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any endpoint in alfresco that allows applying the aspects in bulk</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110085#M30842</link>
      <description>&lt;P&gt;Thanks a lot, it worked.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 16:07:09 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/is-there-any-endpoint-in-alfresco-that-allows-applying-the/m-p/110085#M30842</guid>
      <dc:creator>bip1989</dc:creator>
      <dc:date>2020-07-07T16:07:09Z</dc:date>
    </item>
  </channel>
</rss>

