Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-2423

BugzillaImport. Please add import of attachments.

    XMLWordPrintable

Details

    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

    Description

      Hi guys. Please add posibility to import attachments or you may use my code
      private void createAttachments(PreparedStatement attachPrepStatement, int bug_id, GenericValue issue) throws Exception
      {
      ResultSet resultSet = null;
      try
      {
      attachPrepStatement.clearParameters();
      attachPrepStatement.setInt(1, bug_id);
      resultSet = attachPrepStatement.executeQuery();
      while (resultSet.next())
      {
      String fileName = resultSet.getString("filename");
      if (fileName.lastIndexOf('
      ') > -1)

      { fileName = fileName.substring(fileName.lastIndexOf('\\') + 1); }

      if (fileName.lastIndexOf('/') > -1)

      { fileName = fileName.substring(fileName.lastIndexOf('/') + 1); }

      final Blob fileData = resultSet.getBlob("thedata");

      Map fields = new HashMap();
      fields.put("issue", issue.getLong("id"));
      fields.put("author", getUser(resultSet.getInt("submitter_id")).getName());
      fields.put("mimetype", resultSet.getString("mimetype"));
      fields.put("filename", fileName);
      fields.put("filesize", new Long(fileData.length()));
      fields.put("created", resultSet.getTimestamp("creation_ts"));

      GenericValue attachment = EntityUtils.createValue("FileAttachment", fields);
      issue.set("updated", UtilDateTime.nowTimestamp());
      CoreFactory.getGenericDelegator().storeAll(UtilMisc.toList(issue));
      ManagerFactory.getCacheManager().flush(CacheManager.ISSUE_CACHE, issue);

      File realAttachFile = new File(AttachmentUtils.getAttachmentDirectory(issue), attachment.getLong("id") + "_" + fileName);
      BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(realAttachFile));
      FileUtils.copy(new BufferedInputStream(fileData.getBinaryStream()), out);
      }
      }
      catch (SQLException e)

      { log("Error on importing attachments for bug " + bug_id + ". Error:" + e.getMessage()); }

      finally

      { closeResultSet(resultSet); }

      }

      And in method createIssues() add:
      1. attachPrepStatement = connection.prepareStatement("SELECT * FROM attachments WHERE bug_id = ? ORDER BY attach_id ASC");

      2. createAttachments(attachPrepStatement, resultSet.getInt("bug_id"), issue);

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              da168f590483 Alex Falca
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: