17.11.1Cluster Manager Examples

 

This page contains example interceptors that can be registered with Cluster Manager

17.11.2Example: Starter Server interceptor for Auditing and Open ID Connect Client Pointcuts

 

The following example shows an interceptor that can be used as a starter interceptor, implementing a hook method for pointcuts available on the Cluster Manager.

/*-
 * #%L
 * Smile CDR - CDR
 * %%
 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
 * %%
 * All rights reserved.
 * #L%
 */
package com.smilecdr.demo.clustermgr;

import ca.cdr.api.fhir.interceptor.CdrHook;
import ca.cdr.api.fhir.interceptor.CdrPointcut;
import ca.cdr.api.i18n.ILocalizer;
import ca.cdr.api.model.json.AuditEventJson;
import ca.cdr.api.model.json.AuditEventPrePersistJson;
import ca.cdr.api.model.json.IOAuth2ClientDetails;
import ca.cdr.api.model.json.OAuth2ClientDetailsJson;
import ca.cdr.api.model.json.UserSessionDetailsJson;
import ca.cdr.api.transactionlog.ITransactionLogFetchingSvc;
import ca.cdr.api.transactionlog.ITransactionLogStoringSvc;
import ca.uhn.fhir.interceptor.api.Interceptor;
import jakarta.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Sample Cluster Manager Interceptor implementing all pointcuts available in the Cluster Manager.
 * Note that the autowired beans are unused in the template, and are just here to show what is available to implementers.
 */
@SuppressWarnings({"unused", "EmptyTryBlock"})
@Interceptor
public class ClusterManagerTemplate {

	@Autowired
	private ITransactionLogFetchingSvc myTransactionLogFetchingSvc;

	@Autowired
	private ITransactionLogStoringSvc myTransactionLogStoringSvc;

	@Autowired
	private ILocalizer myLocalizer;

	private static final Logger ourLog = LoggerFactory.getLogger(ClusterManagerTemplate.class);

	@CdrHook(CdrPointcut.SMART_OIDC_CLIENT_SAVING)
	public void oidcClientSaving(IOAuth2ClientDetails theClientDetails) {
		// Insert custom code here.
	}

	@CdrHook(CdrPointcut.SMART_OIDC_CLIENT_SAVED)
	public void oidcClientSaved(IOAuth2ClientDetails theClientDetails) {
		// Insert custom code here.
	}

	@CdrHook(CdrPointcut.AUDIT_EVENT_PRE_PERSIST)
	public void auditEventPrePersist(
			AuditEventJson theAuditEventJson,
			@Nullable UserSessionDetailsJson theUserSessionDetails,
			@Nullable OAuth2ClientDetailsJson theClientDetailsJson,
			AuditEventPrePersistJson theAuditEventPrePersistJson) {
		// Insert custom code here.
	}
}