Example usage for java.util Hashtable toString

List of usage examples for java.util Hashtable toString

Introduction

In this page you can find the example usage for java.util Hashtable toString.

Prototype

public synchronized String toString() 

Source Link

Document

Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).

Usage

From source file:com.sfs.dao.bugreport.JiraBugReportHandler.java

/**
 * Submit the bug report./*from   www  . jav a2  s .  c o  m*/
 *
 * @param bugReport the bug report to submit
 *
 * @throws SFSDaoException the sfs dao exception
 */
public final void submitReport(final BugReportBean bugReport) throws SFSDaoException {
    if (bugReport == null) {
        throw new SFSDaoException("BugReportBean cannot be null");
    }
    if (jiraBaseUrl == null) {
        throw new SFSDaoException("The Jira base url cannot be null");
    }
    if (jiraUsername == null) {
        throw new SFSDaoException("The Jira username cannot be null");
    }
    if (jiraPassword == null) {
        throw new SFSDaoException("The Jira password cannot be null");
    }
    if (bugReport.getUser() == null) {
        throw new SFSDaoException("Submission of a bug report requires a valid user object");
    }
    if (bugReport.getReportClass() == null) {
        throw new SFSDaoException("The bug report class cannot be null");
    }

    final String jiraReportUrl = buildUrl(XMLRPC_ENDPOINT);

    Hashtable<String, String> issue = new Hashtable<String, String>();

    /** Set the bug report type url parameters **/
    String bugTypeParameters = "";
    try {
        ObjectTypeBean objectType = this.objectTypeDAO.load("Bug Report Type", bugReport.getReportType(),
                bugReport.getReportClass());
        bugTypeParameters = StringUtils.replace(objectType.getAbbreviation(), "&amp;", "&");
    } catch (SFSDaoException sde) {
        throw new SFSDaoException("Error submitting Jira report: " + sde.getMessage());
    }
    // Convert this string of bug report parameters to the array
    if (StringUtils.isNotBlank(bugTypeParameters)) {
        StringTokenizer st = new StringTokenizer(bugTypeParameters, "&");

        while (st.hasMoreElements()) {
            final String option = st.nextToken();
            final String parameter = option.substring(0, option.indexOf("="));
            final String value = option.substring(option.indexOf("=") + 1, option.length());

            logger.debug("Parameter: " + parameter + ", value: " + value);
            issue.put(parameter, value);
        }
    }

    /** Set the bug priority url parameters **/
    String priority = "";
    try {
        ObjectTypeBean objectType = this.objectTypeDAO.load("Bug Report Priority", "", bugReport.getPriority());
        priority = StringUtils.replace(objectType.getAbbreviation(), "&amp;", "&");
    } catch (SFSDaoException sde) {
        throw new SFSDaoException("Error submitting Jira report: " + sde.getMessage());
    }
    issue.put("priority", priority);

    /** Set the summary **/
    if (StringUtils.isBlank(bugReport.getTitle())) {
        bugReport.setTitle("Untitled issue");
    }
    issue.put("summary", bugReport.getTitle());

    /** Set the description **/
    issue.put("description", bugReport.getDescription());

    /** The username of the reporter **/
    issue.put("reporter", bugReport.getUser().getUserName().toLowerCase());

    /** Set the assignee - if none default set to automatic **/
    if (StringUtils.isNotBlank(this.jiraAssignee)) {
        issue.put("assignee", this.jiraAssignee);
    } else {
        // Set to automatic (-1 in Jira)
        issue.put("assignee", "-1");
    }

    if (!debugMode) {
        /** Post the bug report to Jira **/
        try {
            logger.info("Jira Report - submitting");
            logger.info("Jira URL: " + jiraReportUrl.toString());
            logger.info("Jira Parameters: " + issue.toString());

            final String response = this.performRestRequest(jiraReportUrl.toString(), issue);

            logger.info("Jira response: " + response);

        } catch (XmlRpcException xre) {
            throw new SFSDaoException("Error submitting Jira report via XMLRPC: " + xre.getMessage());
        } catch (MalformedURLException mue) {
            throw new SFSDaoException("Error with the Jira XMLRPC URL: " + mue.getMessage());
        }
    } else {
        logger.debug("Jira Report - debug mode");
        logger.debug("Jira URL: " + jiraReportUrl.toString());
        logger.debug("Jira Parameters: " + issue.toString());
    }
}