Hi All,
We are using custom workflow to Activate page / path using Replicator API. Below is the code
java.jcr.Session session = WorkflowSession.getSession();
ReplicationOptions option = new ReplicationOptions(); option.setSynchronous(true); replicator.replicate(session, ReplicationActionType.ACTIVATE, path, option);
Question : 1- When we use AEM Activate option on selected page (right click on page and Activate) , it shows list of Assets like images, pdfs which are Outdated, Not published in the selected page in Pop-up screen, These assets also gets activated on checkbox selection, where as using the Above code, it does not include those assets and publish.
How do we handle this programmatically ? Please advice.
2- When we use Activate option, it shows who activated the page in Published column, where as when we use the custom workflow using above code, Its shows published by Administrator.
How do we ensure who Activated the page.
We have used below code to get Resource Resolver
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(Collection<String, Object> singletonMap(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);
Please let me how to get the logged user name and same should show on Published column.
Appreciate your help ! Thanks.
Solved! Go to Solution.
Hi,
To 1) You can use the AssetReferenceSearch class to find all referenced assets; you need to activate them explicitly then.
Regarding 2) the easiest way is to use a session which belongs to the user which has initiated the activation. Just use open an admin session to then impersonate into a session which belongs to this user. In your implementation of the the WorkflowProcess you can use something like this
void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { Workflow wf = item.getWorkflow(); String initiator = wf.getInitiator(); ResourceResolver rr = null; userSession = null; try { rr = resourceResolverFactor.getAdministrativeResourceResolver(null); Session admiinSession = rr.adaptTo(Session.class); userSession = adminSession.impersonate (new SimpleCredentials(initiator,"")); replicator.replicate (userSession, ReplicationActionType.ACTIVATE, path, option); } finally { if (userSession != null && userSession.isLive() { userSession.close(); } if (rr != null && rr.isLive()) { rr.close(); } } }
I haven't tried to get rid of the administrative login here yet, so this is still my preferred pattern :-)
UPDATE: I changed to the code to close the ResourceResolver as well.
Views
Replies
Total Likes
ka786 wrote...
On which Aem you are trying this piece of code?? I mean AEM 5.6.1/6.1
AEM 6.1
Views
Replies
Total Likes
Sorry, version is 6.0.0.1 (6.0.0.x)
Views
Replies
Total Likes
Hi,
To 1) You can use the AssetReferenceSearch class to find all referenced assets; you need to activate them explicitly then.
Regarding 2) the easiest way is to use a session which belongs to the user which has initiated the activation. Just use open an admin session to then impersonate into a session which belongs to this user. In your implementation of the the WorkflowProcess you can use something like this
void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { Workflow wf = item.getWorkflow(); String initiator = wf.getInitiator(); ResourceResolver rr = null; userSession = null; try { rr = resourceResolverFactor.getAdministrativeResourceResolver(null); Session admiinSession = rr.adaptTo(Session.class); userSession = adminSession.impersonate (new SimpleCredentials(initiator,"")); replicator.replicate (userSession, ReplicationActionType.ACTIVATE, path, option); } finally { if (userSession != null && userSession.isLive() { userSession.close(); } if (rr != null && rr.isLive()) { rr.close(); } } }
I haven't tried to get rid of the administrative login here yet, so this is still my preferred pattern :-)
UPDATE: I changed to the code to close the ResourceResolver as well.
hey anand,
Here is the code which will find all the asset that are referring to current page thus you can add replication of these assets as well.
Code link: http://adobeaemclub.com/how-to-get-all-dam-assets-referred-in-a-page/
I'm able to replicate with above code based on user initiator. Thanks.
Views
Replies
Total Likes
With this code I'm able to search the Map of related assets. This solves my requirement.
On more thing I am trying , as this code gives related assets which are part of page and need activation, I want to get list of tags which are not published for this page.
Activate pop-up list both Assets and Node, which if not available/ outdated in publisher.
Thanks for you help.
Views
Replies
Total Likes
Now I get the list of reference Assets and Tags of the related Page used for activation using workflow with provided help,
One question : How do we check whether the page is published, outdated , Not available ?
One way suggested is :
String path = "content/...." resource = resourceResolver.getResource(path + "/" +JcrConstant.JCR_CONTENT); Page page = resouce.adaptTo(Page.class); ReplicationStatus status = page.adaptTo(ReplicationStatus.class); status.isActivated(); ---
Is there easy way to check using the content path - String path
- Get the lastModifieddate and publishedDate
if lastModifiedDate > publishedDate
then , publish/activate that path.
Thanks,
Views
Replies
Total Likes
Hi,
The replication API does not check, if a replication is needed at all; if you want to implement the same behaviour as the UI does (replicate only if there's some modification), you should implement the logic as you outlined yourself.
Jörg
Views
Likes
Replies