Adding a Custom Validation for CSV Files
You can add custom validations that apply to either a single comma-separated value (CSV) file or all CSV files in PTC Arbortext Content Delivery.
Follow these steps to add a custom validation for CSV files:
1. Add both the validation entry in the CSVFileValidationScanner component and the validation details in the customizedContext_YY.conf.xml file. The file customizedContext_YY.conf.xml is a copy of its default version and YY in the file name corresponds to a numeric value lesser than the numeric value of the default file. For more information, see Configuring Custom Validations for CSV Files.
2. Create a Java class file that extends the default validation. The file must call the validate(String inputData) API for the column and file type validations and the validate() API for the row type validation.
3. Add the Java class file to the SCECSVLoad.jar file located at <HOME>/SW/SW/System/WildFly/modules/system/layers/base/com/ptc/e3c/main.
4. Restart the coreServer, coreCMIserver, and JBoss services.
All validations are executed in the given sequence when you run the Validate CSV Data task from the Task Manager. The Validation_Results_(<task_id>) file is generated each time your run the Validate CSV Data task and the task identifier <task_id> is appended to the validation results file name. The Validation_Results_(<task_id>) file is located in the directory <HOME>/Data/Work/Applications/TaskManager/Work/TaskReport/CSVValidationReports. If a validation is of type error and it fails or is of type warning, the Validation_Results_(<task_id>) file displays the code, description, and resolution for the validation.
In this example, a custom validation is added for the order column in the producthierarchy.csv file.
Follow these steps to add the custom validation:
1. Add the following validation details in the customizedContext_YY.conf.xml file:
<Component Name="OrderValidator">
<Creation Type="JavaObject">
<Class>com.ptc.csvtoinservice. validation.
OrderValidator</Class>
</Creation>
<Config>
<Validation code="2001" description="CSV
Order column values missing"
resolution="CSV order column value should be added." />
</Config>
</Component>
2. Add the following validation entry in the CSVFileValidationScanner component of the customizedContext_YY.conf.xml file:
<Component Name="CSVFileValidationScanner">
<Creation Type="JavaObject">
<Class>com.ptc.csvtoinservice. main.
CSVFileValidationScanner</Class>
</Creation>
<Config>
<validator appliesTo="DataScripts/producthierarchy.csv">
<rule type="column" columnName="Order" validationCriteria=
"OrderValidator" required="true"/>
</validator>
3. Create a Java class file that extends the default validation and add the file to the SCECSVLoad.jar file. The following Java class file shows an example format to extend the default validation:
public class OrderValidator extends DefaultValidator {

/**
This method can be used to implement custom validation
logic for column OR file type validator.
It receives a string value of specified column for each row
of specified CSV file. To include multiple valdation messages, you can call the following method:
logger. writeLog(ValidationMessage validationRecord, String taskCode, Object ... params);

Return false if validation fails; otherwise, return true.
*/
<Override
public boolean validate (String inputData) {
/* validation logic need to write here */

/*to generate output log messages in case of failure.
Here 2000 is validation code as specified in customizedContext__3.conf.xml
logger.writeLog(validationMessage,”2000”);*/
}

/**
This method can be used to implement custom validation logic
for row type validator.
Return false if validation needs to fail, otherwise return true.
*/
<Override
public boolean validate () {
}

}
4. Restart the coreServer, coreCMIserver, and JBoss services.