Search in sources :

Example 11 with SimpleData

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;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) ResultSetData(net.sourceforge.processdash.data.ResultSetData) DoubleData(net.sourceforge.processdash.data.DoubleData) ImmutableDoubleData(net.sourceforge.processdash.data.ImmutableDoubleData) List(java.util.List)

Example 12 with SimpleData

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;
    }
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 13 with SimpleData

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;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) ListStack(net.sourceforge.processdash.data.compiler.ListStack) SimpleData(net.sourceforge.processdash.data.SimpleData)

Example 14 with SimpleData

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;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) List(java.util.List) ImmutableDoubleData(net.sourceforge.processdash.data.ImmutableDoubleData)

Example 15 with SimpleData

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);
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData)

Aggregations

SimpleData (net.sourceforge.processdash.data.SimpleData)164 ListData (net.sourceforge.processdash.data.ListData)20 DoubleData (net.sourceforge.processdash.data.DoubleData)15 SaveableData (net.sourceforge.processdash.data.SaveableData)14 StringData (net.sourceforge.processdash.data.StringData)13 IOException (java.io.IOException)11 DataRepository (net.sourceforge.processdash.data.repository.DataRepository)11 DateData (net.sourceforge.processdash.data.DateData)10 Iterator (java.util.Iterator)9 List (java.util.List)7 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ImmutableDoubleData (net.sourceforge.processdash.data.ImmutableDoubleData)6 NumberData (net.sourceforge.processdash.data.NumberData)6 Element (org.w3c.dom.Element)6 Map (java.util.Map)5 DataContext (net.sourceforge.processdash.data.DataContext)5 EscapeString (net.sourceforge.processdash.util.EscapeString)5 File (java.io.File)4