Custom Mapping Methods

<< Click to Display Table of Contents >>

Navigation:  EDP > Customizability >

Custom Mapping Methods

One of the advantages of using a custom handler is to implement custom business rules that will be applied while mapping the EDD to the EQuIS database during the import process (i.e., the "Create" step in EDP). These methods may be used for any type of business rule, but one typical example is combining separate date and time fields from the EDD into a single DateTime field in EQuIS.


The first step in using a custom mapping method is to define the mapping in the EQuIS Format Definition (EFD) file as shown:


<edd:table mode="parent" target="dt_sample">




 <edd:field source="Sys_Sample_Code" target="Sys_Sample_Code" />




 <!-- call the custom handler's GetSampleDate() function to combine sample_date and sample_time -->




 <edd:field method="GetSampleDate" target="sample_date"  />






The method attribute indicates that the value for the target field should come from a function call (to the custom handler object) instead of coming directly from a source field in the EDD. After defining the mapping using the method attribute, the next step is to define the function in the custom handler. The function must be a Public function and return any valid Object type (the return type must match the type of the target field in the database).


An example GetSampleDate function is shown here:


Public Function GetSampleDate(ByVal eddRow As System.Data.DataRow) As Date




 ' combine sample date and sample time




 Return Date.Parse(String.Format("{0} {1}", CType(eddRow.Item("sample_date"), Date).ToString("yyyy-MM-dd"), eddRow.Item("sample_time")))




End Function


When rows are being mapped, EDP will call this function and pass in the current row from the EDD. The function takes the values from the sample_date and sample_time columns, converts those values into a single Date value (that includes the time) and returns that Date value. That Date value is then inserted (according to the mapping) into the SAMPLE_DATE_COLUMN of the new DT_SAMPLE row.


In some cases, the function may need to know specific information about the target row. In that case, the function could be defined as follows:


Public Function SomeFunction(ByVal eddRow As System.Data.DataRow, ByVal targetRow As System.Data.DataRow) As <some type>




 ' do something ...




Return <some object>




End Function


If the function is defined with the second DataRow argument, then EDP will automatically pass that row as well. This is the DataRow object that represents the current target row that is being mapped.