// Map the data from the job into the Rules Engine
// First create a data map.
Mapping mapping = session.getMapping();
DataMap datamap = session.getDataMap(mapping,null);
datamap.opentag(job,"job");
datamap.readDO(job, "job");
Case c = job.getCase();
datamap.opentag(c,"case");
datamap.readDO(c,"case");
for(Client client : c.getClients()){
datamap.opentag(client,"client");
datamap.readDO(client,"client");
for(Income income : client.getIncomes()){
datamap.readDO(income,"income");
}
datamap.closetag();
}
for(Relationship r : c.getRelationships()){
datamap.opentag("relationship");
datamap.printdata("type", r.getType());
datamap.readDO(r.getSource(), "source");
datamap.readDO(r.getTarget(), "target");
datamap.closetag();
}
datamap.closetag();
datamap.closetag();
int id = job.getId();
if(app.save >0 && id % app.save == 0){
String cnt = ""+id;
for(;id<100000;id*=10)cnt = "0"+cnt;
try {
datamap.print(new FileOutputStream(app.getOutputDirectory()+"job_"+cnt+".xml"));
} catch (Exception e) {
System.out.println("Couldn't write to '"+app.getOutputDirectory()+"job_"+cnt+".xml'");
}
}