Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Question about programmatic asset activation

Avatar

Level 3

I've got a servlet that does bulk image upload, creates asset pages for the images, then calls Replicator.replicate to activate the new images and pages on the publish. The logs indicate that the activate is successful (both on author and publish) but the images are not actually being published correctly.

Here's the code where the image asset itself is created:

log.info("---->INFO Creating high-res asset for image: " + metadata.getCatalogNumber() + " in " + assetPath); Asset asset = assetManager.createAsset(assetPath + "/" + metadata.getCatalogNumber(), fis, mimeType, true); Resource metadataRes = asset.adaptTo( Resource.class ).getChild( "jcr:content/metadata" ); addMetadataToAsset( metadataRes, metadata ); replicator.replicate(session, ReplicationActionType.ACTIVATE, asset.getPath());

And this is the code that creates the asset page:

imagePage = pageManager.create( parentPage.getPath(), imageName, imageTemplate, imageTitle ); // At this point the page is created, but does not have the image associated with it; the next // method will add the media info to the jcr:content of the page String imagePath = LOW_RES_PATH + getAssetContainerName( metadata, null ) + "/" + imageTitle; addMediaInfoToImagePage( imagePage, imagePath ); // session.save is called in the addMediaInfoToImagePage method replicator.replicate( session, ReplicationActionType.ACTIVATE, imagePage.getPath() );

 

The asset pages are published correctly but the images are not - they do not show as activated when I look at the DAM assets on the publisher and the thumbnail images are not created. If I go back to the author and use the 'activate tree', then they are published as expected. 

Does anyone have any suggestions as to what I'm doing wrong? I'm beginning to wonder if I should be doing the activation right after the creation - is the author creation completed when the activate is called.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi Randy,

if you activate pages on the UI, the UI displays all referenced assets and ask you if you want to activate them (and does the activation). The page activation workflow doesn't have this implemented, and you need to add your own workflow step to achieve the same behaviour. You can use the AssetReferenceSearch[0] to search for all referenced assets, see [2] for an example. If you have know the assets, you can activate them also.

kind regards,
Jörg

[1] http://docs.adobe.com/docs/br/aem/6-0/develop/ref/javadoc/com/day/cq/dam/commons/util/AssetReference...
[2] http://wemcode.wemblog.com/get_asset_reference_in_page

View solution in original post

3 Replies

Avatar

Level 10

One area you can explore is using Workflows to manage assets. Then you can programmatically invoke the workflow. See this topic for more information:

http://docs.adobe.com/docs/en/aem/6-0/develop/extending/assets/media-handlers.html

Avatar

Correct answer by
Employee Advisor

Hi Randy,

if you activate pages on the UI, the UI displays all referenced assets and ask you if you want to activate them (and does the activation). The page activation workflow doesn't have this implemented, and you need to add your own workflow step to achieve the same behaviour. You can use the AssetReferenceSearch[0] to search for all referenced assets, see [2] for an example. If you have know the assets, you can activate them also.

kind regards,
Jörg

[1] http://docs.adobe.com/docs/br/aem/6-0/develop/ref/javadoc/com/day/cq/dam/commons/util/AssetReference...
[2] http://wemcode.wemblog.com/get_asset_reference_in_page

Avatar

Level 3

I appreciate the input. I suppose it makes sense, but do you activate the assets contained by the page before or after the page itself is activated? Or does the order of activation matter?