public static void writeIssue(Issue issue, final JSONWriter writer) throws JSONException { JsonOutput.addIfNotNull(writer, "id", issue.getId()); JsonOutput.addIfNotNull(writer, "subject", issue.getSubject()); JsonOutput.addIfNotNull(writer, "parent_issue_id", issue.getParentId()); JsonOutput.addIfNotNull(writer, "estimated_hours", issue.getEstimatedHours()); JsonOutput.addIfNotNull(writer, "spent_hours", issue.getSpentHours()); if (issue.getAssignee() != null) JsonOutput.addIfNotNull(writer, "assigned_to_id", issue.getAssignee().getId()); JsonOutput.addIfNotNull(writer, "priority_id", issue.getPriorityId()); JsonOutput.addIfNotNull(writer, "done_ratio", issue.getDoneRatio()); if (issue.getProject() != null) JsonOutput.addIfNotNull(writer, "project_id", issue.getProject().getIdentifier()); if (issue.getAuthor() != null) JsonOutput.addIfNotNull(writer, "author_id", issue.getAuthor().getId()); addShort2(writer, "start_date", issue.getStartDate()); addIfNotNullShort2(writer, "due_date", issue.getDueDate()); if (issue.getTracker() != null) JsonOutput.addIfNotNull(writer, "tracker_id", issue.getTracker().getId()); JsonOutput.addIfNotNull(writer, "description", issue.getDescription()); addIfNotNullFull(writer, "created_on", issue.getCreatedOn()); addIfNotNullFull(writer, "updated_on", issue.getUpdatedOn()); JsonOutput.addIfNotNull(writer, "status_id", issue.getStatusId()); if (issue.getTargetVersion() != null) JsonOutput.addIfNotNull(writer, "fixed_version_id", issue.getTargetVersion().getId()); if (issue.getCategory() != null) JsonOutput.addIfNotNull(writer, "category_id", issue.getCategory().getId()); JsonOutput.addIfNotNull(writer, "notes", issue.getNotes()); writeCustomFields(writer, issue.getCustomFields()); if (issue.getAttachments() != null && issue.getAttachments().size() > 0) { final List<Attachment> uploads = new ArrayList<Attachment>(); for (Attachment attach : issue.getAttachments()) if (attach.getToken() != null) uploads.add(attach); JsonOutput.addArrayIfNotEmpty(writer, "uploads", uploads, UPLOAD_WRITER); } /* * Journals and Relations cannot be set for an issue during creation or * updates. */ }
@SuppressWarnings("unused") private static void tryUpload( RedmineManager mgr, IssueManager issueManager, AttachmentManager attachmentManager) throws RedmineException, IOException { final byte[] content = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; final Attachment attach1 = attachmentManager.uploadAttachment("test.bin", "application/ternary", content); final Issue testIssue = new Issue(); testIssue.setSubject("This is upload ticket!"); testIssue.addAttachment(attach1); final Project tmpProject = ProjectFactory.create("Upload project", "uploadtmpproject"); final Project project = mgr.getProjectManager().createProject(tmpProject); try { final Issue createdIssue = issueManager.createIssue(project.getIdentifier(), testIssue); try { System.out.println(createdIssue.getAttachments()); } finally { issueManager.deleteIssue(createdIssue.getId()); } } finally { mgr.getProjectManager().deleteProject(project.getIdentifier()); } }