12.11.1Cluster Manager Examples

 

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

12.11.2Example: Starter Server interceptor for all appSphere Pointcuts

 

The following example shows an interceptor that can be used as a starter appSphere interceptor, implementing a hook method for each available pointcut.

/*-
 * #%L
 * Smile CDR - CDR
 * %%
 * Copyright (C) 2016 - 2024 Smile CDR, Inc.
 * %%
 * All rights reserved.
 * #L%
 */

package com.smilecdr.demo.appgallery;

import ca.cdr.api.fhir.interceptor.CdrHook;
import ca.cdr.api.fhir.interceptor.CdrPointcut;
import ca.cdr.api.model.json.appgallery.console.AGConsoleJson;
import ca.uhn.fhir.interceptor.api.Interceptor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.annotation.Nonnull;

@SuppressWarnings({"unused"})
@Interceptor
public class AGApplicationStatusInterceptor {
    private static final Logger ourLogger = LoggerFactory.getLogger(AGApplicationStatusInterceptor.class);
    private final ObjectMapper myObjectMapper;

    public AGApplicationStatusInterceptor(@Nonnull ObjectMapper theObjectMapper) {
        myObjectMapper = theObjectMapper;
    }

    @CdrHook(CdrPointcut.AG_APPLICATION_STATUS_UPDATING)
    public void statusUpdating(@Nonnull AGConsoleJson theAGConsoleJson){
        logAGConsoleJsonAsString(theAGConsoleJson);
    }

    @CdrHook(CdrPointcut.AG_APPLICATION_STATUS_UPDATED)
    public void statusUpdated(@Nonnull AGConsoleJson theAGConsoleJson){
        logAGConsoleJsonAsString(theAGConsoleJson);
    }

    private void logAGConsoleJsonAsString(@Nonnull AGConsoleJson theAGConsoleJson) {
        try{
            final String serializedAGConsoleJson = myObjectMapper.writeValueAsString(theAGConsoleJson);
            ourLogger.info(serializedAGConsoleJson);
        } catch (JsonProcessingException theException){
            ourLogger.error("Could not serialize json");
        }
    }
}