*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
// get the object for executing database queries
QueryRunner queryRunner = getDbObject(context, QueryRunner.class);
if (queryRunner == null)
return null;
// retrieve the WBS element name we are being asked to look up.
String wbsElementName = asString(getArg(arguments, 0));
if (wbsElementName == null)
return null;
if (wbsElementName.startsWith("/"))
wbsElementName = wbsElementName.substring(1);
if (wbsElementName.length() == 0)
return null;
wbsElementName = StringUtils.limitLength(wbsElementName, 255);
// retrieve the plan item ID of the item we are being asked to look up.
String planItemId = asString(getArg(arguments, 1));
// look up this WBS element in the database.
try {
int key;
List result = queryRunner.queryHql(NAME_QUERY, wbsElementName);
if ((result == null || result.isEmpty())
&& StringUtils.hasValue(planItemId))
result = queryRunner.queryHql(ID_QUERY, planItemId);
if (result != null && !result.isEmpty()) {
// extract the value from the result set
key = (Integer) result.get(0);
} else {
// not found? Use an impossible WBS key to result in no matches