Search in sources :

Example 6 with MalformedValueException

use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.

the class DataRepository method instantiateValue.

private SaveableData instantiateValue(String name, String dataPrefix, Object valueObj, boolean readOnly) {
    SaveableData o = null;
    if (valueObj instanceof SimpleData) {
        o = (SimpleData) valueObj;
        if (readOnly)
            o = o.getEditable(false);
    } else if (valueObj instanceof CompiledScript) {
        o = new CompiledFunction(name, (CompiledScript) valueObj, this, dataPrefix);
    } else if (valueObj instanceof SearchFactory) {
        o = ((SearchFactory) valueObj).buildFor(name, this, dataPrefix);
    } else if (valueObj instanceof String) {
        String value = (String) valueObj;
        if (value.startsWith("=")) {
            readOnly = true;
            value = value.substring(1);
        }
        try {
            o = ValueFactory.createQuickly(name, value, this, dataPrefix);
        } catch (MalformedValueException mfe) {
            // temporary fix to allow old PSP for Engineers add-on to work in 1.7
            if ("![(&&\tCompleted)]".equals(value)) {
                valueObj = Compiler.compile("[Completed]");
                o = new CompiledFunction(name, (CompiledScript) valueObj, this, dataPrefix);
            } else {
                o = new MalformedData(value);
            }
        }
        if (readOnly && o != null)
            o.setEditable(false);
    }
    return o;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) SimpleData(net.sourceforge.processdash.data.SimpleData) SaveableData(net.sourceforge.processdash.data.SaveableData) EscapeString(net.sourceforge.processdash.util.EscapeString) MalformedData(net.sourceforge.processdash.data.MalformedData)

Example 7 with MalformedValueException

use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.

the class ResultSet method get.

/** Perform a query and return a result set. */
public static ResultSet get(DataRepository data, String forParam, String[] conditions, String orderBy, String[] dataNames, String basePrefix) {
    // get the list of prefixes
    ListData prefixList = getFilteredList(data, forParam, conditions, orderBy, basePrefix);
    // Create a result set to return
    ResultSet result = new ResultSet(prefixList.size(), dataNames.length);
    // write the column headers into the result set.
    result.setColName(0, null);
    for (int i = 0; i < dataNames.length; i++) result.setColName(i + 1, dataNames[i]);
    // get the data and fill the result set.
    String prefix, dataName;
    if (basePrefix == null)
        basePrefix = "";
    int baseLen = basePrefix.length();
    // remove / as well
    if (baseLen > 0)
        baseLen++;
    for (int p = 0; p < prefixList.size(); p++) {
        // get the next prefix
        Object pfx = prefixList.get(p);
        if (pfx instanceof String)
            prefix = (String) pfx;
        else if (pfx instanceof SimpleData)
            prefix = ((SimpleData) pfx).format();
        else
            continue;
        // write the row headers into the result set.
        if (prefix.length() > baseLen && prefix.startsWith(basePrefix))
            result.setRowName(p + 1, prefix.substring(baseLen));
        else {
            result.setRowName(p + 1, prefix);
            if (!prefix.startsWith("/"))
                prefix = DataRepository.createDataName(basePrefix, prefix);
        }
        // look up the data for this row.
        for (int d = 0; d < dataNames.length; d++) if (dataNames[d].startsWith("\"")) {
            try {
                result.setData(p + 1, d + 1, new StringData(dataNames[d]));
            } catch (MalformedValueException mve) {
            }
        } else if (dataNames[d].indexOf('[') != -1) {
            try {
                result.setData(p + 1, d + 1, data.evaluate(dataNames[d], prefix));
            } catch (Exception e) {
            }
        } else {
            dataName = DataRepository.createDataName(prefix, dataNames[d]);
            result.setData(p + 1, d + 1, data.getSimpleValue(dataName));
        }
    }
    return result;
}
Also used : MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) SimpleData(net.sourceforge.processdash.data.SimpleData) LocalizedString(net.sourceforge.processdash.util.LocalizedString) StringData(net.sourceforge.processdash.data.StringData) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) ListData(net.sourceforge.processdash.data.ListData)

Example 8 with MalformedValueException

use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.

the class ResultSet method getList.

private static ListData getList(DataRepository data, String forParam, String[] conditions, String orderBy, String basePrefix) {
    // construct an applicable ResultSetSearchExpression.
    ResultSetSearchExpression rsse = new ResultSetSearchExpression(data, forParam, basePrefix, conditions, orderBy);
    // see if someone else has already generated a list name for
    // our ResultSetSearchExpression.  If not, generate one.
    String listName;
    synchronized (listNames) {
        listName = (String) listNames.get(rsse);
        if (listName == null) {
            int num = listNumber++;
            listName = DataRepository.createDataName(FAKE_DATA_NAME, "List" + num);
            listNames.put(rsse, listName);
        }
    }
    // fetch the value of the named list.
    ListData result = lookupList(data, listName);
    // save it in the repository.
    if (result == null)
        synchronized (listName) {
            result = lookupList(data, listName);
            if (result == null) {
                String expression = rsse.buildExpression();
                try {
                    data.putExpression(listName, "", expression);
                } catch (MalformedValueException mve) {
                    System.err.println("malformed value!");
                    data.putValue(listName, new ListData());
                }
                data.addDataListener(listName, NULL_LISTENER);
                result = lookupList(data, listName);
            }
        }
    return result;
}
Also used : MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) LocalizedString(net.sourceforge.processdash.util.LocalizedString) ListData(net.sourceforge.processdash.data.ListData)

Aggregations

MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)8 SimpleData (net.sourceforge.processdash.data.SimpleData)3 LocalizedString (net.sourceforge.processdash.util.LocalizedString)3 DoubleData (net.sourceforge.processdash.data.DoubleData)2 ListData (net.sourceforge.processdash.data.ListData)2 SaveableData (net.sourceforge.processdash.data.SaveableData)2 StringData (net.sourceforge.processdash.data.StringData)2 ParseException (java.text.ParseException)1 ImmutableDoubleData (net.sourceforge.processdash.data.ImmutableDoubleData)1 MalformedData (net.sourceforge.processdash.data.MalformedData)1 CompilationException (net.sourceforge.processdash.data.compiler.CompilationException)1 CompiledScript (net.sourceforge.processdash.data.compiler.CompiledScript)1 EscapeString (net.sourceforge.processdash.util.EscapeString)1