use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.
the class Dbgetresultvalue method call.
/**
* Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*
* Expected arguments: (ResultSet, String... keys, String targetColumn)
*
* Each "key" should be of the form "ColumnName=Value", identifying the name
* of a column in the result set, and the value we are searching for.
*
* The targetColumn should be the name of the column we want to select when
* we find the matching row. The targetColumn can optionally be surrounded
* by "sum()", which will instruct this method to find all of the matching
* rows and add their values together.
*/
public Object call(List arguments, ExpressionContext context) {
SimpleData arg0 = getArg(arguments, 0);
if (!(arg0 instanceof ResultSetData))
return null;
ResultSetData rs = (ResultSetData) arg0;
if (!rs.test())
return null;
List toFind = collapseLists(arguments, 1);
if (toFind.isEmpty())
return null;
boolean sum = false;
String targetColName = asStringVal(toFind.remove(toFind.size() - 1));
if (targetColName.toLowerCase().startsWith("sum(") && targetColName.endsWith(")")) {
sum = true;
targetColName = targetColName.substring(4, targetColName.length() - 1);
}
int targetCol = rs.getColumnPos(targetColName);
if (targetCol == -1)
return null;
int[] findColumns = new int[toFind.size()];
String[] findValues = new String[toFind.size()];
for (int i = 0; i < findColumns.length; i++) {
String findItem = asString(toFind.get(i));
int eqPos = findItem.indexOf('=');
if (eqPos == -1)
return null;
String findColumnName = findItem.substring(0, eqPos);
findColumns[i] = rs.getColumnPos(findColumnName);
if (findColumns[i] == -1)
return null;
findValues[i] = findItem.substring(eqPos + 1);
}
double sumResult = 0;
List<Object[]> rawResultData = rs.getData();
for (Object[] oneRow : rawResultData) {
if (matches(oneRow, findColumns, findValues)) {
if (targetCol >= oneRow.length) {
return null;
} else if (sum) {
Object oneVal = oneRow[targetCol];
if (oneVal instanceof Number) {
sumResult += ((Number) oneVal).doubleValue();
} else if (oneVal != null) {
return ImmutableDoubleData.BAD_VALUE;
}
} else {
return toSimpleData(oneRow[targetCol]);
}
}
}
if (sum)
return new DoubleData(sumResult, false);
else
return null;
}
use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.
the class Constrain method call.
/** Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
SimpleData lowerBound = getArg(arguments, 0);
SimpleData upperBound = getArg(arguments, 1);
SimpleData data = getArg(arguments, 2);
if (data == null) {
return null;
} else if (data instanceof DoubleData) {
double d = ((DoubleData) data).getDouble();
if (Double.isNaN(d) || Double.isInfinite(d))
return data;
}
if (data.lessThan(lowerBound)) {
return lowerBound;
} else if (data.greaterThan(upperBound)) {
return upperBound;
} else {
return data;
}
}
use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.
the class Iff method call.
/** Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
if (arguments.size() < 2)
return null;
SimpleData test = getArg(arguments, 0);
Object result = null;
if (test != null && test.test())
result = arguments.get(1);
else if (arguments.size() > 2)
result = arguments.get(2);
if (result instanceof CompiledScript) {
try {
CompiledScript script = (CompiledScript) result;
ListStack stack = new ListStack();
script.run(stack, context);
result = stack.pop();
} catch (Exception e) {
}
}
return result;
}
use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.
the class Indexof method call.
/**
* Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
SimpleData item = getArg(arguments, 0);
List args = collapseLists(arguments, 1);
for (int i = 0; i < args.size(); i++) {
if (eq(item, asSimpleData(args.get(i))))
return new ImmutableDoubleData(i, false, true);
}
return NOT_FOUND;
}
use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.
the class DefectImportForm method getDefaultValueForSetting.
protected String getDefaultValueForSetting(String settingName) {
String dataName = "/Defect_Import/" + formId + "/Default " + settingName;
SimpleData sd = dashboardContext.getData().getSimpleValue(dataName);
return (sd != null ? sd.format() : null);
}
Aggregations