Normally, when we want to create a live copy from a blueprint or a master site, we go to the Sites Console and use the “Create Live Copy” or “Create Site” button. But sometimes there might be a need to automate the creation of sites. For eg:, there might be a requirement to create multi-tenant sites using the blueprint or master site automatically or programmatically, based on some inputs or criteria. Currently there is no Java API which can be directly used to create the live copy.
Here is the solution: Call the WCMCommand Servlet using Sling Request Processor.
Create a custom OSGi Service
1. Create a custom OSGi Service which can be called from any other class.
2. Declare a method which accepts the arguments required to create a live copy -
-->a. Resource Resolver : required for the WCMCommand Servlet request
-->b. srcPath : the master path from which live copy has to be created
-->c. destPath : the path under which live copy has to be created
-->d. title : the livecopy root page title
-->e. label : the livecopy root page name
-->f. rolloutConfigs : an array of rollout configurations to be included