Search in sources :

Example 1 with StudyGroupManager

use of net.sourceforge.processdash.tool.db.StudyGroupManager 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 2 with StudyGroupManager

use of net.sourceforge.processdash.tool.db.StudyGroupManager 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)

Aggregations

ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DoubleData (net.sourceforge.processdash.data.DoubleData)2 ListData (net.sourceforge.processdash.data.ListData)2 NumberData (net.sourceforge.processdash.data.NumberData)2 StudyGroupManager (net.sourceforge.processdash.tool.db.StudyGroupManager)2