[[BackLinksMenu]]

[[TicketQuery(summary=BUG_REPORT_FORM_R0, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|)]]

= Analysis =
== Overview ==
Bug report form should actually send the bug reports somewhere
== Task requirements ==
 * For report form
  * Add a "Send Report" button to the bug report form
  * Rename the "Save as File" to "Save Report As"
  * Add "Attach a file" for attaching books, etc.
 * For the server that will handle the information
  * Create a database to handle the error reports
   * The database should support fields (see implementation idea)
  * Create a limit for the size of the reports
   * Think of way to block spam 
  * [Optional] Create a UI for the database so developers can access the information
   * create different sort and group ways for the information - for example by OS, by Java version, by user e-mail

== Task result ==
Code

== Implementation idea ==
 * On clicking the 'Send' button, a HTTP POST request to sophie2.org/bugreports should be sent.
 * Since it may contain an attached file, its format should be as if posted by a form using ENCTYPE="multipart/form-data"
 * The database may contain the following fields:
   * Date & Time
   * Log
   * Exception
   * User e-mail address
   * User notes
 * The attached files may not be saved in the database, but in a special folder on the server.
   * However, they should be renamed, so that there are no files with the same name and it is possible to understand to which bug report they were attached. For example: ReportNo<N>Attachment.<extension>, where <N> is the number of the report and <extension> is the original extension of the file.
 * Write a php script that fills the information in the database and uploads the files.
 
== Related ==
APP_BUG_REPORT_FORM_R0

== How to demo ==
 * Open the bug report from from the Help menu
 * Send a bug report with an attached file
 * Using the UI for the database or a console, if it is not yet ready, make sure that the bug report was stored on sophie2.org

= Design =
 * Restore the 'Attach File' control from an older version of trunk:
   * In {{{ BugReportDialog }}} there should be:
     * a nested class {{{ AttachmentField }}} extending BoundTextField;
     * public Prop<AttachmentField> attachmentField() - text field for the absolute name of the attached file;
     * ATTACH_FILE in EventIds enum.
   * The operation ON_ATTACH_FILE in {{{ BugReportLogic }}} should handle changing the attached file in the bug report form.

 * 'Send Report' button:
   * add SEND_REPORT BugReportDialog.EventIds enum
   * in BugReportDialog.swingComponent...create() create a new {{{ LogicR3Button }}} that fires a SEND_REPORT event when clicked and add it to the bottom panel

 * 'Send Report' logic:
   * A new operation ON_SEND_REPORT in {{{ BugReportLogic }}} should handle a user request to send a bug report.
   * Using the util class ConnectionUtil (see below) it will open a new HTTP connection to "sophie2.org/bugreports", send the bug report data (which may include an attached file) as a multi-part HTTP request and read the response from the server
   * If no exceptions occurred during the communication with the server, an informative {{{ MessageDialogInput }}} will be shown.
     * The response of the server will be a string which will be shown in this dialog.
   * If an exception occured during the communication with the server, an error dialog will appear to inform the user that ther bug report was not processed.
     * (?) However, no new bug report form will appear.

 * Move some of the logic for sending multi-part requests from {{{ FacadeInvocationHandler }}} to a new class {{{ ConnectionUtil }}} in {{{ org.sophie2.base.commons.util }}} package.
   * The new class will contain the following methods:
     * {{{ public static HttpURLConnection createConnection(String urlAddress) throws IOException }}} - creates an HttpURLConnection to the HTTP server referred to by the given URL.
     * {{{ public static void writeData(HttpURLConnection connection, String[] names, Object[] dataValues) throws IOException }}} - sends a multi-part POST request using the specified connection (as if from a form using ENCTYPE="multipart/form-data").
       * The {{{ names }}} argument contains the names of the fields to send.
       * The {{{ values }}} argument contains the values to send. They should be either Strings or Files.
       * Files are Base64 encoded.
     * {{{ public static String readResponse(HttpURLConnection connection) throws IOException }}} - reads the response sent through the specified connection.

 * Database:
   * Create a new database on sophie2.org with a single table {{{ reports }}}.
   * The table should contain the following columns:
     * id - INTEGER AUTO_INCREMENT PRIMARY KEY
     * date - DATETIME - the time when the report was submitted
     * stacktrace - TEXT - stacktrace of the exception that caused the bug report form to appear and the user to submit the report
     * log - TEXT - the contents of Sophie's Log file around the time when the exception occurred
     * systemProperties - TEXT - all Java system properties at the moment of the bug report submission, serialized as string.
     * email - VARCHAR(50) - user e-mail
     * userExplanation - TEXT - user notes

 * Php script to process the bug reports:
   * reads the data in $_POST and using a simple sql query, writes it in the database;
   * renames the attached files in the way specified in the implementation idea and uploads them in a special folder on the server

 * Source code: [8007]
   
= Implementation =
 * The suggestion to replace the util class {{{ ConnectionsUtil }}} by a {{{ MultipartRequest }}} from the design review was implemented.

 * A new {{{ ConfigKey<String> BUG_REPORT_ADDRESS }}} was added in {{{ BugReportLogic }}} to keep the address where bug reports should be sent.
   * Its default value is currently "" and should be changed.

 * A new {{{ ConfigKey<Long> MAX_ATTACHMENT_SIZE }}} was added in {{{ BugReportDialog }}} to keep the maximum allowed attachment size.
   * Its default value is 11mb.
   * It is used both for validation of BugReportDialog.AttachmentField and in the ON_ATTACH_FILE operation in BugReportLogic.
   * If a user clicks on the 'Browse' button and selects from the dialog input a file that is too large, the dialog will be closed and an error message will appear. The bug report form will remain open.

 * The server's response will be a simple string that starts with a number:
   * 0 means success
   * 1 means that the bug report was submitted but the attached file could not be opened
   * anything else means that the bug report was not submitted

 * Source code:
   * [8007], [8010] and [8034]
   * see the attachments
     * the username and password to connect to the database must be changed (line 13)
     * the folder where the uploaded files are saved should also be changed (currently it is the folder where process_bug_report.php is/uploads)
   
 * Commited to trunk in [8110]
 * PHP deployed to http://sophie2.org/bug-report

= Testing =
^(Place the testing results here.)^

= Comments =
^(Write comments for this or later revisions here.)