faudit.caf-audit-maven-plugin.4.2.0-1223.source-code.AuditTransform.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of caf-audit-maven-plugin Show documentation
Show all versions of caf-audit-maven-plugin Show documentation
This project provides an XML to Java transformation plugin.
The newest version!
#*
* Copyright 2015-2024 Open Text.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*#
#set($namespace = $root.getRootElement().getNamespace())
#set($identifier = $root.getRootElement().getChild("ApplicationId",$namespace).getText())
#set($package = $packageName)
#set($space = " ")
#set($comma = ",")
#set($leftPar = "(")
#set($rightPar = ")")
#set($leftCurlyBracket = "{")
#set($rightCurlyBracket = "}")
#set($newline = "
")
#set($javadocParamsComment = " * @param")
#set($finalChannelArg = "final AuditChannel channel")
#set($finalTenantIdArg = "final String tenantId")
#set($finalUserIdArg = "final String userId")
#set($finalCorrelationIdArg = "final String correlationId")
#set($final = "final ")
#set($channelJavaDocsComment = " * @param channel Identifies the channel to be used for message queuing ")
#set($tenantIdJavaDocsComment = " * @param tenantId Identifies the tenant that the user belongs to ")
#set($userIdJavaDocsComment = " * @param userId Identifies the user who triggered the event ")
#set($correlationIdJavaDocsComment = " * @param correlationId Identifies the same user action ")
/*
* Copyright 2015-2024 Open Text.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package $package;
import com.hpe.caf.auditing.AuditChannel;
import com.hpe.caf.auditing.AuditEventBuilder;
import com.hpe.caf.auditing.exception.AuditingException;
import com.hpe.caf.auditing.AuditIndexingHint;
import java.io.IOException;
import java.util.Date;
/**
* Auto-generated class for writing $identifier events to the audit log
*/
public final class AuditLog
{
private static final String APPLICATION_IDENTIFIER = "$identifier";
private AuditLog() {
}
/**
* Checks that the AuditLog queue exists and creates it if it doesn't.
* This function should be called before any of the audit... functions are called.
*/
public static void declareApplication(final AuditChannel channel)
throws IOException
{
channel.declareApplication(APPLICATION_IDENTIFIER);
}
##
## For each audit event specified, generate code for auditing the actual event.
##
#foreach($auditevent in $root.getRootElement().getChild("AuditEvents",$namespace).getChildren("AuditEvent",$namespace))
##
#set($methodNamePrefix = "audit")
#set($categoryId = $auditevent.getChild("CategoryId",$namespace).getText())
#set($typeId = $auditevent.getChild("TypeId",$namespace).getText())
#set($upperCaseTypeId = "$typeId.substring(0, 1).toUpperCase()$typeId.substring(1)")
#set($argList = "")
#set($eventParamsList = "")
#set($javadocParamsList = "")
##
## For each parameter specified, build up argument, javadoc and eventParams list.
##
#foreach($param in $auditevent.getChild("Params",$namespace).getChildren("Param",$namespace))
##
#set($name="")
#set($type="")
#set($indexingHint="")
#set($minLength="")
#set($maxLength="")
#set($columnName="")
#set($desc="")
##
#set($name = $param.getChild("Name",$namespace).getText())
#set($type = $param.getChild("Type",$namespace).getText())
#set($indexingHint = $param.getChild("IndexingHint",$namespace).getText())
#set($minLength = $param.getChild("Constraints",$namespace).getChild("MinLength",$namespace).getText())
#set($maxLength = $param.getChild("Constraints",$namespace).getChild("MaxLength",$namespace).getText())
#set($columnName = $param.getChild("ColumnName",$namespace).getText())
## Do not change case for supported primitive types.
#if( $type == "short" || $type == "int" || $type == "long" || $type == "float" || $type == "double"|| $type == "boolean")
#set($upperCaseType = $type)
#else
#set($upperCaseType = "$type.substring(0, 1).toUpperCase()$type.substring(1)")
#end
#set($desc = $param.getChild("Description",$namespace).getText())
##
## Build up method argument list.
##
#if ( $argList != "" )
#set($argList = "$argList$comma
$final$upperCaseType$space$name")
#else
#set($argList = "$finalChannelArg$comma
$finalTenantIdArg$comma
$finalUserIdArg$comma
$finalCorrelationIdArg$comma
$final$upperCaseType$space$name")
#end
##
## Build up event params list.
##
#if ( "$!columnName" == "" )
#set($columnNameParam = "null")
#else
#set($columnNameParam = """$columnName""")
#end
#if ($type == "string")
## string type so check for optional indexing hint and constraints.
#if( "$!indexingHint" == "" )
## indexing hint not specified.
#set($indexingHintParam = "")
#else
## indexing hint specified.
#if ($indexingHint == "fulltext")
#set($indexingHintParam = "AuditIndexingHint.FULLTEXT")
#else
#set($indexingHintParam = "AuditIndexingHint.KEYWORD")
#end
#end
#if ($minLength != "" || $maxLength != "")
## minLength and/or maxLength constraints specified.
#if( "$!minLength" == "" )
## minLength not specified.
#if( "$!indexingHintParam" == "" )
## minLength and indexing hint not specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, -1, $maxLength);$newline")
#else
## maxLength and indexing hint specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $indexingHintParam, -1, $maxLength);$newline")
#end
#else
## minLength specified.
#if ("$!maxLength" == "")
## maxLength not specified.
#if( "$!indexingHintParam" == "" )
## maxLength and indexingHint not specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $minLength, -1);$newline")
#else
## minLength and indexing hint specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $indexingHintParam, $minLength, -1);$newline")
#end
#else
## minLength and maxLength specified.
#if( "$!indexingHintParam" == "" )
## indexingHint not specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $minLength, $maxLength);$newline")
#else
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $indexingHintParam, $minLength, $maxLength);$newline")
#end
#end
#end
#else
## minLength and maxLength constraints not specified.
#if( "$!indexingHintParam" == "" )
## indexing hint not specified.
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name);$newline")
#else
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name, $indexingHintParam);$newline")
#end
#end
#else
#set($eventParamsList = "$eventParamsList auditEventBuilder.addEventParameter(""$name"", $columnNameParam, $name);$newline")
#end
##
## Build up javadoc list.
##
#if ( $javadocParamsList != "" )
#set($javadocParamsList = "$javadocParamsList
$javadocParamsComment$space$name$space$desc$space")
#else
#set($javadocParamsList = "$javadocParamsList$channelJavaDocsComment
$tenantIdJavaDocsComment
$userIdJavaDocsComment
$correlationIdJavaDocsComment
$javadocParamsComment$space$name$space$desc$space")
#end
#end
##
#set($methodDeclaration = "$methodNamePrefix$upperCaseTypeId
$leftPar
$argList
$rightPar")
/**
* Audit the $typeId event
$javadocParamsList
*/
public static void $methodDeclaration
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("$categoryId", "$typeId");
$eventParamsList
auditEventBuilder.send();
}
#end
}