Expand my Community achievements bar.

Custom audit log type breaking timeline

Avatar

Level 2

We have functionality that inserts a custom audit log type whenever a certain property is updated -

 

auditLogger.add(new AuditLogEntry(
  "com/day/cq/wcm/core/page",
  new Date(),
  newEvent.getUserID(),
  pageNodePath,
  "PageRestricted",
  entryProperties
));

 

This was added back in classic and has been working fine, but we just noticed that in touch it causes the timeline to display "An error has occurred." The log shows that this is because it can't handle that "PageRestricted" type -

 

2022-05-05T19:25:39.848Z *ERROR* 127.0.0.1 [1651778739703] GET /mnt/overlay/wcm/core/content/sites/jcr%3acontent/rails/timeline/items/timeline/items/events.provider.html HTTP/1.1 org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException 
java.lang.IllegalArgumentException: Unknown modification type: PageRestricted
        at com.day.cq.wcm.api.PageModification$ModificationType.fromName(PageModification.java:114)
        at com.day.cq.wcm.core.impl.AuditLogTimelineEventProvider.getEvents(AuditLogTimelineEventProvider.java:122)
        at com.adobe.granite.timeline.internal.TimelineAggregatorImpl.createTimeline(TimelineAggregatorImpl.java:82)

 

Is there any way to register that custom entry type so that timeline can consume it? Or does anyone have any suggestions on how we'd get around the error?

 

Thanks!

2 Replies

Avatar

Employee Advisor

Sorry to say that I don't know your complete requirement. But I tried something here.

This is my sample EventHandler associated with Page related event -

 

package com.aem.demo.core.listeners;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.osgi.service.event.EventConstants;

import com.day.cq.audit.AuditLog;
import com.day.cq.audit.AuditLogEntry;
import com.day.cq.wcm.api.PageEvent;
import com.day.cq.wcm.api.PageModification;

@Component(service = EventHandler.class,immediate = true ,property = {EventConstants.EVENT_TOPIC + "=" + PageEvent.EVENT_TOPIC})
public class PagePropertyUpdateListener implements EventHandler {
	
	private static final Logger LOG = LoggerFactory.getLogger(PagePropertyUpdateListener.class);
	
	@Reference
	private AuditLog auditLog;

	@Override
	public void handleEvent(Event event) {
		List<AuditLogEntry> entries = new ArrayList<AuditLogEntry>();
		Iterator<PageModification> pagemodifications = PageEvent.fromEvent(event).getModifications();
		
		while (pagemodifications.hasNext()) {
			PageModification pageModification = pagemodifications.next();
			String auditType = pageModification.getType().toString();
			LOG.info("\n Type :  {},  Page : {}",pageModification.getType(),pageModification.getPath());
            pageModification.getEventProperties().forEach((k,v)->LOG.info("\n key : {}, Value : {} " , k , v));
			
            AuditLogEntry auditLogEntry = new AuditLogEntry(PageEvent.EVENT_TOPIC, pageModification.getModificationDate(), pageModification.getUserId(), pageModification.getPath(), "PageRestricted", pageModification.getEventProperties());
			entries.add(auditLogEntry);
		}
		LOG.info("******* AUDIT LOG SIZE ********** {}", entries.size());
		auditLog.add(entries);
		
		
	}

	
}

Here you could see I have used PageRestricted as type and performed different activities like page creation , page property update , content authoring in touch but I didn't get the above mentioned error -

 

Added log for your review -

07.05.2022 19:47:22.149 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 Type :  PageCreated,  Page : /content/we-retail/language-masters/en/men/debal-aem-india-test
07.05.2022 19:47:22.185 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : path, Value : /content/we-retail/language-masters/en/men/debal-aem-india-test 
07.05.2022 19:47:22.185 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : modifiedDate, Value : Sat May 07 19:47:22 IST 2022 
07.05.2022 19:47:22.185 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : type, Value : PageCreated 
07.05.2022 19:47:22.185 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : userId, Value : admin 
07.05.2022 19:47:22.186 *INFO* [EventAdminAsyncThread #10] com.aem.demo.core.listeners.PagePropertyUpdateListener ******* AUDIT LOG SIZE ********** 1
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 Type :  PageModified,  Page : /content/we-retail/language-masters/en/men/debal-aem-india-test
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : path, Value : /content/we-retail/language-masters/en/men/debal-aem-india-test 
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : modifiedDate, Value : Sat May 07 19:47:35 IST 2022 
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : changes, Value : [jcr:content/root/responsivegrid/text/jcr:lastModifiedBy, jcr:content/root/responsivegrid/text/jcr:primaryType, jcr:content/root/responsivegrid/text/jcr:created, jcr:content/cq:lastModified, jcr:content/root/responsivegrid/text/jcr:createdBy, jcr:content/root/responsivegrid/text/sling:resourceType, jcr:content/root/responsivegrid/text/jcr:lastModified, jcr:content/root/responsivegrid/text] 
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : type, Value : PageModified 
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : userId, Value : admin 
07.05.2022 19:47:35.196 *INFO* [EventAdminThread #18] com.aem.demo.core.listeners.PagePropertyUpdateListener ******* AUDIT LOG SIZE ********** 1
07.05.2022 19:47:51.305 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 Type :  PageModified,  Page : /content/we-retail/language-masters/en/men/debal-aem-india-test
07.05.2022 19:47:51.305 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : path, Value : /content/we-retail/language-masters/en/men/debal-aem-india-test 
07.05.2022 19:47:51.305 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : modifiedDate, Value : Sat May 07 19:47:51 IST 2022 
07.05.2022 19:47:51.308 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : changes, Value : [jcr:content/cq:lastModified, jcr:content/root/responsivegrid/text/text, jcr:content/root/responsivegrid/text/jcr:lastModified, jcr:content/root/responsivegrid/text/textIsRich] 
07.05.2022 19:47:51.309 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : type, Value : PageModified 
07.05.2022 19:47:51.309 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : userId, Value : admin 
07.05.2022 19:47:51.309 *INFO* [EventAdminThread #4] com.aem.demo.core.listeners.PagePropertyUpdateListener ******* AUDIT LOG SIZE ********** 1
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 Type :  PageModified,  Page : /content/we-retail/language-masters/en/men/debal-aem-india-test
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : path, Value : /content/we-retail/language-masters/en/men/debal-aem-india-test 
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : modifiedDate, Value : Sat May 07 19:48:07 IST 2022 
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : changes, Value : [jcr:content/cq:contextHubPath, jcr:content/cq:tags, jcr:content/cq:contextHubSegmentsPath, jcr:content/cq:lastModified, jcr:content/cq:target-ambits] 
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : type, Value : PageModified 
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener 
 key : userId, Value : admin 
07.05.2022 19:48:07.615 *INFO* [EventAdminThread #11] com.aem.demo.core.listeners.PagePropertyUpdateListener ******* AUDIT LOG SIZE ********** 1

 

 

 

 

 

 

 

 

 

 

 

 

 

Avatar

Level 2

Thanks for that, sorry if i was not clear. The issue we're experiencing is with the Timeline functionality within sites.html. It is unable to load the timeline because some internal logic is trying to parse the events and expects one of the pre-defined event types.