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;
}
}
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;
}
}
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;
}
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;
}
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;
}
}
Aggregations