Search in sources :

Example 31 with ListData

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

the class Dblabelfiltergroup method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Arguments: Project key list, filtered task IDs
     */
public Object call(List arguments, ExpressionContext context) {
    // get the name of the data element we are calculating for
    String listenerName = asStringVal(context.get(SubscribingExpressionContext.LISTENERVAR_NAME));
    // get the database keys of the projects in question
    ListData projectKeyList = asList(getArg(arguments, 0));
    if (projectKeyList == null)
        return null;
    List<Integer> projectKeys = new ArrayList();
    for (int i = 0; i < projectKeyList.size(); i++) {
        Object oneKeyVal = projectKeyList.get(i);
        if (oneKeyVal instanceof NumberData) {
            int oneKey = ((NumberData) oneKeyVal).getInteger();
            projectKeys.add(oneKey);
        }
    }
    if (projectKeys.isEmpty())
        return null;
    // get the list of task IDs we are searching for, and convert them to
    // plain String objects
    Set<String> taskIds = new HashSet();
    for (Object oneTaskIdVal : collapseLists(arguments, 1)) {
        String oneTaskId = asStringVal(oneTaskIdVal);
        if (oneTaskId != null)
            taskIds.add(oneTaskId);
    }
    // study group.
    if (taskIds.isEmpty())
        return new DoubleData(-1, false);
    // retrieve the study group manager
    StudyGroupManager mgr = getDbObject(context, StudyGroupManager.class);
    if (mgr == null)
        return null;
    // create a study group for this list of items, and return its key
    try {
        int result = mgr.getPlanItemGroup(projectKeys, taskIds, true, listenerName);
        return new DoubleData(result, false);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected error while calculating", e);
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) DoubleData(net.sourceforge.processdash.data.DoubleData) ListData(net.sourceforge.processdash.data.ListData) StudyGroupManager(net.sourceforge.processdash.tool.db.StudyGroupManager) NumberData(net.sourceforge.processdash.data.NumberData) HashSet(java.util.HashSet)

Example 32 with ListData

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

the class Dbuserfiltergroup method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Arguments: Project key list, dataset ID list
     */
public Object call(List arguments, ExpressionContext context) {
    // get the name of the data element we are calculating for
    String listenerName = asStringVal(context.get(SubscribingExpressionContext.LISTENERVAR_NAME));
    // get the database keys of the projects in question
    ListData projectKeyList = asList(getArg(arguments, 0));
    if (projectKeyList == null)
        return null;
    List<Integer> projectKeys = new ArrayList();
    for (int i = 0; i < projectKeyList.size(); i++) {
        Object oneKeyVal = projectKeyList.get(i);
        if (oneKeyVal instanceof NumberData) {
            int oneKey = ((NumberData) oneKeyVal).getInteger();
            projectKeys.add(oneKey);
        }
    }
    if (projectKeys.isEmpty())
        return null;
    // get the list of dataset IDs we are searching for, and convert them
    // to plain String objects
    Set<String> datasetIds = new HashSet();
    for (Object oneDatasetIdVal : collapseLists(arguments, 1)) {
        String oneDatasetId = asStringVal(oneDatasetIdVal);
        if (oneDatasetId != null)
            datasetIds.add(oneDatasetId);
    }
    // either way, return null to indicate "no filtering"
    if (datasetIds.isEmpty())
        return null;
    // error code signifying an empty group
    if (datasetIds.contains(UserGroupManagerDash.EMPTY_GROUP_TOKEN))
        return new DoubleData(-1, false);
    // retrieve the study group manager
    StudyGroupManager mgr = getDbObject(context, StudyGroupManager.class);
    if (mgr == null)
        return null;
    try {
        int result = mgr.getDataBlockGroup(projectKeys, datasetIds, listenerName);
        return new DoubleData(result, false);
    } catch (Throwable t) {
        // disable user group filtering.
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) DoubleData(net.sourceforge.processdash.data.DoubleData) ListData(net.sourceforge.processdash.data.ListData) StudyGroupManager(net.sourceforge.processdash.tool.db.StudyGroupManager) NumberData(net.sourceforge.processdash.data.NumberData) HashSet(java.util.HashSet)

Example 33 with ListData

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

the class Filter method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    CompiledScript script = null;
    try {
        script = (CompiledScript) arguments.get(0);
    } catch (ClassCastException cce) {
    }
    if (script == null)
        return null;
    ListData result = new ListData();
    LocalExpressionContext lContext = new LocalExpressionContext(context);
    ListStack stack = new ListStack();
    Iterator i = collapseLists(arguments, 1).iterator();
    Object item;
    while (i.hasNext()) try {
        lContext.setLocalValue(item = i.next());
        stack.clear();
        script.run(stack, lContext);
        handleItem(result, item, stack.pop());
    } catch (Exception e) {
    }
    return result;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) LocalExpressionContext(net.sourceforge.processdash.data.compiler.LocalExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) Iterator(java.util.Iterator) ListData(net.sourceforge.processdash.data.ListData)

Example 34 with ListData

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

the class DbAbstractFunction method getDbObject.

/**
     * Return an object from the database plugin's registry.
     */
protected <T> T getDbObject(ExpressionContext context, Class<T> clazz) {
    ListData dbItem = (ListData) context.get(DatabasePlugin.DATA_REPOSITORY_NAME);
    if (dbItem == null)
        return null;
    DatabasePlugin plugin = (DatabasePlugin) dbItem.get(0);
    T result = plugin.getObject(clazz);
    return result;
}
Also used : DatabasePlugin(net.sourceforge.processdash.tool.db.DatabasePlugin) ListData(net.sourceforge.processdash.data.ListData)

Example 35 with ListData

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

the class Hierleaves method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    String prefix;
    if (!arguments.isEmpty())
        prefix = asStringVal(getArg(arguments, 0));
    else
        prefix = context.get(ExpressionContext.PREFIXVAR_NAME).format();
    if (prefix == null)
        return null;
    try {
        ListData hierItem = (ListData) context.get(DashHierarchy.DATA_REPOSITORY_NAME);
        DashHierarchy hier = (DashHierarchy) hierItem.get(0);
        PropertyKey key = hier.findExistingKey(prefix);
        if (key == null)
            return null;
        ListData result = new ListData();
        collect(result, hier, key);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) PropertyKey(net.sourceforge.processdash.hier.PropertyKey) ListData(net.sourceforge.processdash.data.ListData)

Aggregations

ListData (net.sourceforge.processdash.data.ListData)129 SimpleData (net.sourceforge.processdash.data.SimpleData)20 ArrayList (java.util.ArrayList)18 List (java.util.List)16 Iterator (java.util.Iterator)15 StringData (net.sourceforge.processdash.data.StringData)15 EVTaskListData (net.sourceforge.processdash.ev.EVTaskListData)9 Map (java.util.Map)8 HashSet (java.util.HashSet)7 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 DoubleData (net.sourceforge.processdash.data.DoubleData)5 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)5 LocalizedString (net.sourceforge.processdash.util.LocalizedString)5 NodeList (org.w3c.dom.NodeList)5 Date (java.util.Date)4 EVTaskList (net.sourceforge.processdash.ev.EVTaskList)4 Element (org.w3c.dom.Element)4