Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to move assets from one path to another path in damadmin with updated references where the image used in pages

Avatar

Not applicable

Hi 

I want to move images from one path to path with updated references , can someone explain the best possible solution for that.

i want to make sure that it should not effect the pages where the old path images are used as because i want to do this PROD server.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

When you goto /damadmin and select an asset to move, it shows all the references of that asset in the dialog and ask if it has to be adjusted for the new link and it would take care by itself

So, you can use the 'move' option in damadmin

View solution in original post

3 Replies

Avatar

Administrator

Hi

Please have a look at these reference links, it is not completely covering what you are asking but covers most of it:

Link:- https://helpx.adobe.com/experience-manager/using/graniteAPI.html

//Moving DAM Assets using the Adobe Experience Manager Granite AssetManager API

 

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

//Move/Copy Multiple DAM assets in different folders.

 

Link:- https://www.linkedin.com/pulse/20140922122516-67953490-asset-migration-in-aem-cq5-6

// ASSET MIGRATION IN AEM

 

Link:- https://forums.adobe.com/thread/1164099?tstart=0

//How to move assets in different directory using java service

 

I hope this will help you.

Thanks and REgards

Kautuk Sahni

Avatar

Correct answer by
Community Advisor

When you goto /damadmin and select an asset to move, it shows all the references of that asset in the dialog and ask if it has to be adjusted for the new link and it would take care by itself

So, you can use the 'move' option in damadmin

Avatar

Level 1

Hi,

If the assets and referenced pages are more, then you can create one groovy script or servlet which will read the asset files from specific folder and move it to destination folder. Continuing to same script create one query which will read the nodes from provided path for reading the property value and if any property matches with old asset path then set the same property with new asset path where the asset is moved. Please find below Servlet example for one the we-retail asset movement and reference update.

 

import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.servlet.Servlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi. framework.Constants;
import org.osgi. service.component.annotations. Component ;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.granite.asset.api.AssetManager;
import com.day.cq.search.PredicateGroup;
import com.day.cq.search.Query;
import com.day.cq. search.QueryBuilder;
import com.day.cq.search.result.Hit;
import com.day.cq.search.result.SearchResult;


@component(service =Servlet.class,
property = {
Constants.SERVICE_DESCRIPTION + "= Asset Migration Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.paths=" + "/bin/assetmigration/update"
})
public class AssetMigrationServlet extends SlingSafeMethodsServlet{

private static final long serialVersionUID = 7524136240611031420L;
private static final Logger LOGGER = LoggerFactory.getLogger(AssetMigrationServlet.class);

@reference
private QueryBuilder builder;

private static final String CONTENT_PATH = "/content/dam/we-retail/en/products/apparel/scarfs/";

@Override
protected void doGet (SlingHttpServletRequest request, SlingHttpServletResponse response) {
LOGGER.info("Asset Migration Servlet Called successfully!! ");

try {
ResourceResolver resourceResolver = request.getResourceResolver();
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);

Session session = resourceResolver.adaptTo(Session.class);
if(session.nodeExists(CONTENT_PATH)) {

Node parentNode = session.getNode(CONTENT_PATH);

if(parentNode.hasNodes()) {
NodeIterator childNode = parentNode.getNodes();

while(childNode.hasNext()) {
Node assetNode = childNode.nextNode();
String assetName = assetNode.getName();

String assetPath = CONTENT_PATH + assetName;
String movePath = "/content/dam/we-retail/en/" + assetName;

if(assetName.equalsIgnoreCase("jcr:content")) {
LOGGER.info("JCR:CONTENT Node found, hence skipped movement...");
}else {
assetManager.moveAsset(assetPath, movePath);
Map<String, String> predicate = new HashMap<>();

predicate.put("path", "/content/we-retail");
predicate.put("fulltext", assetPath);

Query query = builder.createQuery(PredicateGroup.create(predicate), session);

query.setStart(0);
query.setHitsPerPage(20);

SearchResult searchResult = query.getResult();

for(Hit hit : searchResult.getHits()) {

String path = hit.getPath();

Node node = session.getNode(path);

PropertyIterator pitors = node.getProperties();
while(pitors.hasNext()) {

Property ps = pitors.nextProperty();
if(ps.isMultiple()) {
Value vr[] = ps.getValues();
for (int i = 0; i < vr.length; i++) {
response.getWriter().println("*****************************Property Value:::::::::::::" + vr[i]);
}
}else {
String value = ps.getValue().toString();
if(ps.getValue().toString().equalsIgnoreCase(assetPath)) {
String propertyValue = ps.getValue().toString();
response.getWriter().println("***********************OLD Property Value***************:" + propertyValue);
String temp = propertyValue;
String newValue = temp.replace(assetPath, movePath);
propertyValue = newValue;
node.setProperty(ps.getName().toString(), newValue);
response.getWriter().println("*************************Updated Property :" + node.getProperty(ps.getName() + " With Value:::::::::::::::::" + movePath));
}
}
}
response.getWriter().println("**************************************Updated Value for the node****************************:" + path);
}
response.getWriter().println("***********************************Asset With Name: " + assetPath + " is Moved to: " + movePath);

}
}
}
}
session.save();
session.logout();
}catch(Exception e) {
e.printStackTrace();
}

}

}