001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2025 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.camel; 011 012import ca.cdr.api.model.enm.TransactionLogBodyTypeEnum; 013import ca.cdr.api.model.enm.TransactionLogOutcomeEnum; 014import ca.cdr.api.model.enm.TransactionLogStepTypeEnum; 015import ca.cdr.api.model.json.TransactionLogStepJson; 016import ca.cdr.api.transactionlog.ITransactionLogCommonSettings; 017import org.apache.camel.Exchange; 018import org.apache.commons.lang3.tuple.Pair; 019 020import java.util.List; 021 022public interface ICamelProcessorTxLogHelper { 023 024 /** 025 * Requests to include message body in the transaction log step 026 * Default value is true 027 */ 028 String TX_LOG_PARAM_SHOW_BODY = "showMsgBody"; 029 030 /** 031 * If transaction logging was initiated (smile:txLogStart procedure, present before current procedure in 032 * route), adds a log step to the transaction log 033 * @param theExchange the camel exchange 034 * @param theProcedureName the log-producing procedure name 035 */ 036 void addStepIfTxLogActive(Exchange theExchange, String theProcedureName); 037 038 /** 039 * If transaction logging was initiated (smile:txLogStart procedure, present before current procedure in 040 * route), adds step from provider to the transaction log 041 * @param theExchange the camel exchange 042 * @param theStepsProvider the provider of the corresponding transaction log steps 043 */ 044 void addStepIfTxLogActive(Exchange theExchange, ITxLogStepsProvider theStepsProvider); 045 046 /** 047 * If transaction logging was initiated (smile:txLogStart procedure, present before current procedure in 048 * route), adds step from provider to the transaction log, adds the list of steps to the transaction log 049 * @param theExchange the camel exchange 050 * @param theLogSteps the log steps to be added to the transaction log 051 */ 052 void addStepIfTxLogActive(Exchange theExchange, List<TransactionLogStepJson> theLogSteps); 053 054 /** 055 * Builds a new transaction log step from provided exchange properties and parameters. 056 * If theExchange.isFailed(), the step outcome is set to FAIL, otherwise SUCCESS. 057 * @param theExchange the camel exchange 058 * @param theLogStepType the transaction log step type 059 * @param theBodyAndType A Pair containing the body and the body type or null 060 * @return the built transaction log step 061 */ 062 TransactionLogStepJson buildTxLogStep( 063 Exchange theExchange, 064 TransactionLogStepTypeEnum theLogStepType, 065 Pair<String, TransactionLogBodyTypeEnum> theBodyAndType); 066 067 /** 068 * @deprecated use {@link ICamelProcessorTxLogHelper#buildTxLogStep(Exchange, TransactionLogStepTypeEnum, Pair)} 069 * Builds a new transaction log step considering received exchange properties and parameters. 070 * @param theExchange the camel exchange 071 * @param theLogStepType the transaction log step type 072 * @param theBodyAndType A Pair containing the body and the body type or null 073 * @param theOutcome Ignored. 074 * @return the built transaction log step 075 */ 076 @Deprecated 077 default TransactionLogStepJson buildTxLogStep( 078 Exchange theExchange, 079 TransactionLogStepTypeEnum theLogStepType, 080 Pair<String, TransactionLogBodyTypeEnum> theBodyAndType, 081 @SuppressWarnings("unused") TransactionLogOutcomeEnum theOutcome) { 082 return buildTxLogStep(theExchange, theLogStepType, theBodyAndType); 083 } 084 085 /** 086 * Builds a string containing the received procedure name, including the module id if present in the exchange 087 * @param theExchange the camel exchange 088 * @param theProcedureName the log-producing procedure name 089 * @return a string with the built executing procedure URI 090 */ 091 String getRequestUrl(Exchange theExchange, String theProcedureName); 092 093 /** 094 * Informs if 'showMsgBody' parameter is present 095 * @param theExchange the camel exchange 096 * @return boolean indicating if 'showMsgBody' parameter is present 097 */ 098 boolean isTxLogShowBody(Exchange theExchange); 099 100 /** 101 * informs if a transaction log is active for the route 102 * @param theExchange the camel exchange 103 * @return boolean indicating if transaction log is active for the route 104 */ 105 boolean isTxLogStarted(Exchange theExchange); 106 107 /** 108 * Requests transaction log initiation for the route 109 * @param theExchange the camel exchange 110 */ 111 void startTxLog(Exchange theExchange); 112 113 /** 114 * Commits the transaction log to configured writers 115 * @param theExchange the camel exchange 116 */ 117 void commitTxLog(Exchange theExchange); 118 119 /** 120 * Discards current transaction logging and marks logging not initiated for the route 121 * @param theExchange the camel exchange 122 */ 123 void clearTxLog(Exchange theExchange); 124 125 /** 126 * Returns the settings associated with this writer. Event sources can use this to optimize whether to 127 * include specific elements in their log entries. 128 */ 129 ITransactionLogCommonSettings getSettings(); 130}