I have a model which has a generic model link field, which contains an Id field which needs to hold the surrogate id of the model it's linking to. How do I specify this in my inbound interface?
You have to add custom fields to the inbound interface for the NKs of the target model, and then use a transformer to convert these to the surrogate id.
Here's an example for the NeoPrescription model, which has an Owner field that we want to point to a WBProblem model.
We add custom fields to the inbound interface to represent the natural keys of the WBProblem model:
OwnerProblemId
OwnerProblemTypeName
Then, we add the derived fields that our transformer will calculate, and specify a Java class to handle the transformation:
Here are the contents for this example's transformer, which fetches the WBProblem model with the natural keys and sets the OwnerId
and OwnerModelLevel
derived fields on the CsvRow
:
public class NeoPrescriptionInboundInterfaceTransformer extends InboundCsvTransformer {
public void transform(CsvRow row, CsvTransformContext context) throws CsvTransformException {
String problemId = row.get("OwnerProblemId");
String problemTypeName = row.get("OwnerProblemTypeName");
SqlParams params = new SqlParams();
params.setStringValue("PROBLEM_ID", problemId);
params.setStringValue("PROBLEM_TYPE_NAME", problemTypeName);
SqlService ss = Services.get(SqlService.class);
SqlResult result = ss.executeQuery(
"SELECT P.SYS_WBPROBLEM_ID FROM WBPROBLEM P" +
" INNER JOIN WBPROBLEM_TYPE T ON P.SYS_PROBLEM_TYPE_ID = T.SYS_WBPROBLEM_TYPE_ID" +
" WHERE P.PROBLEM_ID = $PROBLEM_ID$ AND T.NAME = $PROBLEM_TYPE_NAME$", params);
if (result.getRows().isEmpty()) {
throw new RuntimeException("WBProblem not found for ProblemId = " + problemId + " and WBProblemType.Name = " + problemTypeName);
}
Long problemSysId = result.getRows().get(0).getLongValue("SYS_WBPROBLEM_ID");
row.set("OwnerId", problemSysId.toString());
row.set("OwnerModelLevel", "WBProblem");
}
}
If the IB data file contains thousands of records then querying per row will result in high I/O and less throughput (since chunk size is 1 in PROD). Hence to avoid this either you can use cache manager if cache is enabled for the Model or if chunk size is not 1 then transformer class can implement com.transcendsys.platform.integ.batch.relational.CustomGroupTransformer and read all the ids in one query for that chunk.