Puakma: Under the hood

I'm Brendon Upson, jack-of-all-trades, master of one or two. I'm talking about life running a small ISV tackling business issues and leaping technology hurdles in a single bound.

webWise Network Consultants is based in Sydney, Australia and develops the groundbreaking Tornado Server technology.

Running actions inside actions

Filed under: by Brendon Upson on 2005-10-06

Today we solved an annoying problem in a pretty simle way. A customer's app has a page which does some hideously complicated calculations to determine if a planned coal mining operation would actually make any money. Today they want the ability to group multiples of these plans together and provide (for example) a set of plans for a week. Trouble is now we have to repeat those hideous calculations inside another part of the application so we can sum the plans for a week and determine if we'll make any money that week.I absolutely hate duplicating code, and I also hate rewriting perfectly good code to do something slightly different.

So we used the cruel and cunning plan of calling the original action programmatically for each plan in the group, summing the results as we go and outputting the totals on to the page. This enabled us to reuse 100% of the exiting code and write a small wrapper to get each plan's totals. Here's a snippet:

while(looping_through_plans)
{
int iLongPlanID = RS.getInt("LongPlanID"); //unique id of the plan
HTMLDocument docTemp = new HTMLDocument(pSystem, pSession);
docTemp.rPath = new RequestPath(getDBURL() + "/LRPlan?OpenPage&ID=" + iLongPlanID);
docTemp.setParameters("&ID=" + iLongPlanID);
//now run the action for the other page on our temporary document
pSession.runActionOnDocument(docTemp, "OpenEditLRPlan");
if(docTemp.hasItem("grpPlantCost"))
{
//get the values off the temp document and sum them
m_dPlantCost += docTemp.getItemNumericValue("grpPlantCost");
m_dLabourCost += docTemp.getItemNumericValue("grpLabourCost");
}
}//while