long time = System.currentTimeMillis();
WorkflowAPI wfapi = new WorkflowAPI();
String uname = data.getUser().getName();
SWAMPTurbineUser user = (SWAMPTurbineUser) data.getUser();
ParameterParser pp = data.getParameters();
// get an Array of Workflow Templates (for filters)
ArrayList templateIdList = wfapi.getAllWorkflowTemplateNames(uname);
context.put("wftmpls", templateIdList);
MapToFilterlist urlToFilter = new MapToFilterlist();
ArrayList filters = urlToFilter.getFilters(
Workflows.parameterParserToHashMap(pp));
StringBuffer filterText = urlToFilter.getFilterText();
context.put("filters", filters);
context.put("filtercount", String.valueOf(filters.size()));
context.put("systemFilterText", filterText);
// do we have a multiple workflow type view?
boolean multipleview = false;
if (urlToFilter.getTemplateName() == null){
multipleview = true;
} else {
WorkflowTemplate wfTemp = wfapi.getWorkflowTemplate(urlToFilter.getTemplateName(), uname);
// automatically add filter for workflow user if needed
if (wfTemp.getWorkflowRole(WorkflowRole.USER).isRestricted()) {
RoleFilter filter = new RoleFilter(uname, WorkflowRole.USER, urlToFilter.getTemplateName());
filters.add(filter);
}
context.put("mastertemplatename", urlToFilter.getTemplateName());
SwampUIManager uitool = (SwampUIManager) TurbinePull.getTool(context, "ui");
SwampUIManager.setInterface(data.getUser(), wfTemp.getMasterParentTemplate().getName());
uitool.init(data.getUser());
}
context.put("multipleview", new Boolean(multipleview));
// configure task display:
if (urlToFilter.getTaskOwner() != null){
context.put("taskOwner", urlToFilter.getTaskOwner());
}
// restrict the displayed tasks:
if (pp.containsKey("systemfilter_displayedtasks")){
SWAMPHashSet displayedTasks = new SWAMPHashSet();
displayedTasks.add(pp.get("systemfilter_displayedtasks"), ",");
context.put("displaytasks", displayedTasks);
}
// FIXME:
// more than one workflowtype on one page not possible, because of
// sorting criteria
// sorting: get the order criteria from users permstorage -> wf-defaults -> default
// need a template-type to load the default sorting criteria!
// else automatically sorted by wf-id
DatabaseFilter order = this.getOrderFilter(pp.
getString("systemfilter_wftemplate"), data, context);
List workflowIDList = wfapi.getWorkflowIds(filters, order, uname);
int numberOfWorkflows = workflowIDList.size();
// setting displaysubwfs user option
HashMap displaysubwfsSet = new HashMap();
// name: templatename, value: LinkedList with workflows
HashMap wflists = new HashMap();
// list of templates where the subworkflow-display config dropdown is shown
List displaySubworkflowsDropdown = new ArrayList();
for (Iterator it = templateIdList.iterator(); it.hasNext(); ){
String templateName = (String) it.next();
String displaysubwfs = "systemfilter_displaysubwfs_" + templateName;
String value;
// manual user-change:
if (pp.containsKey("subwfsuserchange_" + templateName)){
value = pp.get(displaysubwfs);
user.setPerm(displaysubwfs, pp.get(displaysubwfs));
// systemfilter parameter setting
} else if (pp.containsKey(displaysubwfs)){
value = pp.get(displaysubwfs);
// fetch from usersession (only for masterworkflow or for all in multi-view)
} else if (templateName.equals(urlToFilter.getTemplateName())
&& user.getPerm(displaysubwfs) != null) {
value = (String) user.getPerm(displaysubwfs);
// default to none in multipleview
} else if (multipleview) {
value = "none";
} else {
value = "all";
}
// Logger.DEBUG("Set " + displaysubwfs + " - " + value);
displaysubwfsSet.put(displaysubwfs, value);
wflists.put(templateName, new LinkedList());
// check if we need to show the subworkflow dropdown
if (WorkflowManager.getInstance().getWorkflowTemplate(templateName).getSubworkflowTemplates().isEmpty()) {
displaySubworkflowsDropdown.add(templateName);
}
}
context.put("displaysubwfsSet", displaysubwfsSet);
int wfsPerPage = 30, wfOffset = 0;
HashMap wfsPerPageMap = new HashMap();
for (Iterator it = templateIdList.iterator(); it.hasNext(); ){
String template = (String) it.next();
String wfsPerPageParam = "systemfilter_wfsPerPage_" + template;
String wfsPerPageUser = "wfsPerPage_" + template;
if (pp.containsKey(wfsPerPageUser) &&
pp.getInt(wfsPerPageUser) > 0 ){
wfsPerPage = pp.getInt(wfsPerPageUser);
user.setPerm(wfsPerPageParam, String.valueOf(wfsPerPage));
} else if (pp.containsKey(wfsPerPageParam) &&
pp.getInt(wfsPerPageParam) > 0 ){
wfsPerPage = pp.getInt(wfsPerPageParam);
} else if (data.getUser().getPerm(wfsPerPageParam) != null) {
try {
wfsPerPage = new Integer((String) user.getPerm(wfsPerPageParam)).intValue();
} catch (NumberFormatException e) {
Logger.ERROR("Invalid wfsPerPage value:" + user.getPerm(wfsPerPageParam) + " in "
+ user.getName() + "s permdata!");
wfsPerPage = 30;
}
}
wfsPerPageMap.put(wfsPerPageParam, new Integer(wfsPerPage));
}
context.put("wfsPerPageMap", wfsPerPageMap);
if (urlToFilter.getTemplateName() != null){
wfsPerPage = ((Integer) wfsPerPageMap.get("systemfilter_wfsPerPage_" +
urlToFilter.getTemplateName())).intValue();
}
if (!multipleview){
if (pp.containsKey("wfOffset") &&
pp.getInt("wfOffset") > 0 &&
pp.getInt("wfOffset") < workflowIDList.size()){
wfOffset = pp.getInt("wfOffset");
} else {
wfOffset = 0;
}
context.put("wfOffset", new Integer(wfOffset));
ArrayList pages = new ArrayList();
for (int i=1, total=numberOfWorkflows/wfsPerPage; i<=total; i++)
pages.add(new Integer(i));
if ((numberOfWorkflows % wfsPerPage) > 0)
pages.add(new Integer(numberOfWorkflows/wfsPerPage + 1));
context.put("currentPage", new Integer(wfOffset / wfsPerPage +1));
context.put("pages", pages);
if ((wfOffset + wfsPerPage) > workflowIDList.size())
workflowIDList = workflowIDList.subList(wfOffset, workflowIDList.size());
else
workflowIDList = workflowIDList.subList(wfOffset, wfOffset + wfsPerPage);
}
// iterate over all found workflows, sort them into a list of their template, check permissions.
int wfcount = 0;
for (Iterator it = workflowIDList.iterator(); it.hasNext();) {
int wfid = ((Integer) it.next()).intValue();
// only add those that he is allowed to see
try {
Workflow wf = wfapi.getWorkflow(wfid, uname);
wfcount++;
((LinkedList) wflists.get(wf.getTemplateName())).add(wf);
} catch (SecurityException e) {
Logger.DEBUG("Removed wf-" + wfid + " (no permission for " + uname + ")");
}
}
context.put("displayedWorkflows", new Integer(wfcount));
context.put("numberOfWorkflows", new Integer(numberOfWorkflows));
context.put("displaySubworkflowsDropdown", displaySubworkflowsDropdown);
// Check each List for its Order Criteria and displayed Columns
// we also need to add all possible subtypes
if (urlToFilter.getTemplateName() != null) {
List templates = wfapi.getSubworkflowTemplateNames(urlToFilter.getTemplateName(), uname);
templates.add(urlToFilter.getTemplateName());
populateColumns(context, data, templates);
} else {
populateColumns(context, data, wfapi.getWorkflowTemplateNames(uname));
}
// Set var for changing displayed columns
if (pp.containsKey("editcolumns")) {
String editcolumntemplate = pp.get("editcolumns");
context.put("editcolumns", editcolumntemplate);
// list of possible databit columns:
WorkflowTemplate wfTemp = wfapi.getWorkflowTemplate(editcolumntemplate, uname);
List pathList = wfTemp.getAllDatabitPaths();