Hi,
We have a requirement in our project to create the mixed media set programmatically for the files having similar file names of 13 digits. There' already imagesets create automatically. Similar way we need to try for mixed media set if there's images and videos having same 13 digits add it to the mixed media set. Is it possible to create mixedmedia sets programmatically?
Solved! Go to Solution.
Views
Replies
Total Likes
We have found alternate API which is more suitable for automating mixed media set and it's working as expected. Below are the details: SetHelper class has createSet api to create the set resource S7damConstants.S7_SPIN_SET, S7damConstants.S7_SWATCH_SET, S7damConstants.S7_MIXED_MEDIA_SET, S7damConstants.S7_VIDEO_SET, S7damConstants.S7_CAROUSEL_SET it supports thumbnail generation as well Implementing using this method is creating the mixedmediaset automatically and adding the members from imageset, spinset and video.
Thanks, Priyanka |
Hi @Keerthana_H_N ,
You can try using the Java Content Repository (JCR) API for creating mixed media sets programmatically. JCR API allows you to perform CRUD operations programmatically so using that you can create the nodes corresponding to the mixed media sets programmatically.
Please refer to the below code as a sample :
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.jackrabbit.commons.JcrUtils;
public class MixedMediaSetCreator {
public static void main(String[] args) {
String aemInstanceUrl = "http://localhost:4502"; // Replace with your AEM instance URL
String username = "admin"; // Replace with a valid AEM username
String password = "admin"; // Replace with the password for the AEM user
createMixedMediaSet(aemInstanceUrl, username, password);
}
public static void createMixedMediaSet(String aemInstanceUrl, String username, String password) {
Session session = null;
try {
// Establish a connection to the AEM repository
Repository repository = JcrUtils.getRepository(aemInstanceUrl);
session = repository.login(new SimpleCredentials(username, password.toCharArray()));
// Specify the path where you want to create the mixed media set
String mixedMediaSetPath = "/content/mixed-media-sets/my-mixed-media-set";
// Create the node for the mixed media set
Node mixedMediaSetNode = session.getNode(mixedMediaSetPath);
// Set properties for the mixed media set
mixedMediaSetNode.setProperty("jcr:title", "My Mixed Media Set");
mixedMediaSetNode.setProperty("jcr:description", "This is a sample mixed media set.");
mixedMediaSetNode.setProperty("tags", new String[] {"tag1", "tag2"});
// Add references to assets in the mixed media set
mixedMediaSetNode.setProperty("assets", new String[] {
"/content/dam/assets/image1.jpg",
"/content/dam/assets/image2.jpg",
"/content/dam/assets/video1.mp4"
});
// Save the changes
session.save();
System.out.println("Mixed media set created successfully!");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.logout();
}
}
}
}
For getting complete details about the JCR API and its capabilities you can refer to the following link : https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/access-jcr.html?la...
Hi @ayushmishra07 , thank you for sharing the details. We have tried using the above implementation in our logic and facing issue while calling getRepository method.
Repository repository = JcrUtils.getRepository(aemInstanceUrl);
will it work for any AEM version ? Currently we are using AEMaaCS jar file in our local.
I haven't tried it on AEMaaCS, but it is not present in the list of deprecated APIs, so I believe it should be accessible.
Can you please confirm weather you added jackrabbit-standalone-2.4.0.jar file to your Java application’s class path or not. Also, can you please share the error which you received.
@Keerthana_H_N yes its possible.
you can use com.day.cq.dam.commons.util.S7SetHelper class.
and then you can use as below
set = S7SetHelper.createS7MixedMediaSet(res, name, props);
Hi @Nishant-Singh , I am observing after creating mixed media set programmatically using S7SetHelper class - S7SetHelper.createS7MixedMediaSet(newResource, imageSetData, props);
Sets are having processing label all the time. Not completing the processing. Also in the props how can we add properties similar to how it will add while using OOTB. For example in ootb we have s7Set node under related node and sling:members with all the list of assets, also few properties have to be added to metadata node as well.
Thanks.
you need to adapt image as Asset
Asset asset1 = resourceAsset1.adaptTo(Asset.class);
Asset asset2 = resourceAsset2.adaptTo(Asset.class);
then you need to add those to Mixed media set.
MediaSet mixedMediaSet = S7SetHelper.createS7MixedMediaSet(newResource, imageSetData, props);
mixedMediaSet.add(asset1);
mixedMediaSet.add(asset1);
Got it @Nishant-Singh .Thanks a lot. Also we are creating mixed media sets programmatically for video file and image set. When we are adding assets to mixed media sets we need to add references from image set. All sling:members under image set need to be added to mixed media set. Any suggestion in extracting the image set references and add it to newly created mixed media set. Thanks
@Nishant-Singh We are able to create mixed media set programmatically and node hierarchy is also same as out of box functionality but rendition folder is by default empty.
Do you have any idea how can we generate renditions for mixed media set which will create thumbnail.
Programmatically created node using S7SetHelper.createS7MixedMediaSet
Out of box created nodes:
Thanks,
try using below 2 properties and then check.
props.put("dam:imageServerAsset", true);
props.put("dam:assetState", "processing");
@Nishant-Singh It's not working, still it keeps processing
We have found alternate API which is more suitable for automating mixed media set and it's working as expected. Below are the details: SetHelper class has createSet api to create the set resource S7damConstants.S7_SPIN_SET, S7damConstants.S7_SWATCH_SET, S7damConstants.S7_MIXED_MEDIA_SET, S7damConstants.S7_VIDEO_SET, S7damConstants.S7_CAROUSEL_SET it supports thumbnail generation as well Implementing using this method is creating the mixedmediaset automatically and adding the members from imageset, spinset and video.
Thanks, Priyanka |