Search in sources :

Example 11 with ProcessUtil

use of net.sourceforge.processdash.process.ProcessUtil in project processdash by dtuma.

the class DefectUtil method guessRemovalPhase.

/** Make an educated guess about which removal phase might correspond to
     * a particular dashboard task
     */
private static String guessRemovalPhase(String defectPath, String taskPath, DashboardContext context) {
    // first, check to see if this task has registered an effective phase
    ProcessUtil pu = new ProcessUtil(context.getData());
    String effectivePhase = pu.getEffectivePhase(taskPath, false);
    if (effectivePhase != null)
        return effectivePhase;
    // if no effective phase was registered, infer it from the path.  We
    // don't use the path inference provided by ProcessUtil because we
    // need to preserve more than just the final path segment. For example,
    // in the case of a PSP3 project, we need to keep both the cycle name
    // and the phase name.
    int prefixLength = defectPath.length() + 1;
    if (taskPath.length() > prefixLength && Filter.pathMatches(taskPath, defectPath))
        return taskPath.substring(prefixLength);
    // no luck so far.  Look at the task in question, and see if it only
    // includes a single phase child (typical for old-style team projects
    // with phase stubs).
    DashHierarchy hier = context.getHierarchy();
    PropertyKey defectPathKey = hier.findExistingKey(defectPath);
    if (defectPathKey != null) {
        Enumeration leafNames = hier.getLeafNames(defectPathKey);
        List possibleMatches = new ArrayList();
        while (leafNames.hasMoreElements()) {
            String oneLeaf = (String) leafNames.nextElement();
            if (oneLeaf.length() > prefixLength) {
                String leafTail = oneLeaf.substring(prefixLength);
                if (leafTail.indexOf('/') == -1)
                    possibleMatches.add(leafTail);
            }
        }
        if (possibleMatches.size() == 1)
            return (String) possibleMatches.get(0);
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProcessUtil(net.sourceforge.processdash.process.ProcessUtil) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 12 with ProcessUtil

use of net.sourceforge.processdash.process.ProcessUtil in project processdash by dtuma.

the class TableOfPhaseMetrics method writeContents.

protected void writeContents() throws IOException {
    DataContext dataContext = getDataContext();
    // retrieve the heading and label the user wants displayed
    String heading = getParameter(HEADING_PARAM);
    String label = getParameter(LABEL_PARAM);
    // retrieve the list of columns the user wants to display
    List columns = new ArrayList();
    for (int i = 0; i < COLUMNS.length; i++) {
        if (COLUMNS[i].isShowing(parameters))
            columns.add(COLUMNS[i]);
    }
    if (dataContext.getSimpleValue("Rollup Tag") != null) {
        columns.remove(MetricsTableColumn.TO_DATE);
        columns.remove(MetricsTableColumn.TO_DATE_PCT);
    }
    if (columns.isEmpty()) {
        out.write("<!-- no columns selected;  no table to display -->\n\n");
        return;
    }
    ProcessUtil procUtil = new ProcessUtil(getDataContext());
    // retrieve the list of phases the user wants to display
    String phaseList = getSelectedPhaseList();
    List phases = null;
    for (int i = 0; i < PHASES.length; i++) {
        if (PHASES[i][0].equals(phaseList)) {
            phases = procUtil.getProcessListPlain(PHASES[i][1]);
            break;
        }
    }
    if (phases == null)
        // default to all phases
        phases = procUtil.getProcessListPlain(PHASES[0][1]);
    // filter the list of phases, if applicable
    phases = procUtil.filterPhaseList(phases);
    applyExplicitPhaseFilter(phases);
    if (phases.isEmpty()) {
        out.write("<!-- no phases selected;  no table to display -->\n\n");
        return;
    }
    // retrieve the list of metrics the user wants to display
    Map[] metrics = SnippetDataEnumerator.getEnumeratedValues(parameters, ITEM_TYPE);
    if (metrics == null) {
        out.write("<!-- no metrics selected;  no table to display -->\n\n");
        return;
    }
    // write out heading if requested
    if (StringUtils.hasValue(heading)) {
        out.write("<h2>");
        out.write(HTMLUtils.escapeEntities(heading));
        out.write("</h2>\n\n");
    }
    String mergeTables = getParameter(MERGE_PARAM);
    if (mergeTables != null) {
        out.write(AbstractViewPageAssembler.MERGE_TABLES_DIRECTIVE);
        out.write(mergeTables);
        out.write(" -->");
    }
    // write the header row of the table
    out.write("<p><table><tr><th align=\"left\">");
    if (label != null)
        out.write(esc(label));
    out.write("</th>\n");
    if (metrics.length > 1) {
        for (int i = 0; i < metrics.length; i++) {
            out.write("<th");
            out.write(MetricsTableColumn.PADDING_LEFT);
            out.write(" colspan=\"");
            out.write(Integer.toString(columns.size()));
            out.write("\">");
            String metricName = (String) metrics[i].get(DISPLAY_NAME_ATTR);
            if (metricName == null || metricName.trim().length() == 0) {
                String dataName = (String) metrics[i].get(DATA_NAME_ATTR);
                metricName = TranslatingAutocompleter.translateDataName(dataName);
            }
            out.write(esc(metricName));
            out.write("</th>\n");
        }
        out.write("</tr>\n");
    }
    if (columns.size() > 1) {
        out.write("<tr><th></th>");
        for (int j = 0; j < metrics.length; j++) {
            boolean pad = true;
            for (Iterator i = columns.iterator(); i.hasNext(); ) {
                MetricsTableColumn col = (MetricsTableColumn) i.next();
                col.writeHeader(out, resources, pad);
                pad = false;
            }
        }
        out.write("</tr>\n");
    }
    if (mergeTables != null)
        out.write(AbstractViewPageAssembler.MERGE_TABLES_CUT_MARK);
    // write a table row for each process phase
    for (Iterator i = phases.iterator(); i.hasNext(); ) {
        String phase = (String) i.next();
        writeTableRow(phase, metrics, columns, dataContext, procUtil);
    }
    if (parameters.containsKey("ShowTotalRow") && ALL_PHASES.equals(phaseList))
        writeTableRow(null, metrics, columns, dataContext, procUtil);
    out.write("</table></p>\n\n");
}
Also used : DataContext(net.sourceforge.processdash.data.DataContext) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ProcessUtil(net.sourceforge.processdash.process.ProcessUtil) Map(java.util.Map)

Aggregations

ProcessUtil (net.sourceforge.processdash.process.ProcessUtil)12 ArrayList (java.util.ArrayList)8 List (java.util.List)5 Iterator (java.util.Iterator)3 SimpleData (net.sourceforge.processdash.data.SimpleData)3 DataContext (net.sourceforge.processdash.data.DataContext)2 TimeLogEntry (net.sourceforge.processdash.log.time.TimeLogEntry)2 Color (java.awt.Color)1 Paint (java.awt.Paint)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 PDashQuery (net.sourceforge.processdash.api.PDashQuery)1 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)1 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)1 AddTaskTypeOption (net.sourceforge.processdash.hier.ui.AddTaskTypeOption)1 SizePerItemTable (net.sourceforge.processdash.tool.probe.SizePerItemTable)1