How to create mixed media sets programmatically in aem? | Community
Skip to main content
Adobe Employee
July 28, 2023
Solved

How to create mixed media sets programmatically in aem?

  • July 28, 2023
  • 3 replies
  • 3016 views

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?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PriyankaKu

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
and then updateSet api to add members to it as well as generate thumbnails these are all the set types we can pass in it

            S7damConstants.S7_IMAGE_SET,
            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

3 replies

ayushmishra07
Adobe Employee
Adobe Employee
July 28, 2023

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?lang=en 

Adobe Employee
July 28, 2023

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.

 

 

November 11, 2024

Hi,

 

Facing similar issue while connecting from external java application? do we have solution for this?

Nishant-Singh
Adobe Employee
Adobe Employee
July 28, 2023

@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);

 

Adobe Employee
July 31, 2023

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.

 

Nishant-Singh
Adobe Employee
Adobe Employee
July 31, 2023

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);

PriyankaKuAdobe EmployeeAccepted solution
Adobe Employee
April 23, 2024

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
and then updateSet api to add members to it as well as generate thumbnails these are all the set types we can pass in it

            S7damConstants.S7_IMAGE_SET,
            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