Closed JeanBeaurepaire closed 8 years ago
+1, the same problem. If I assign a sequence number to the id property, it will upload all attachments.
Do you have some code that correct this issue @jenghung ?
I found multiple issues. I will try to share a solution we coded. The issues were that if you upload the attachment, token is set. However as stated above the equals method works on id alone. Second if you upload a file with the same name as an existing defect, by default the system will update the file.
We use this code to send up the attachments, and then add them to the issue attachments array. Then we save the issue with either issueManager.createIssue(issue); or issueManager.update(issue); if an update.
String attachmentUniqueName = UUID.randomUUID().toString();
Attachment attachment = attachmentManager.uploadAttachment(attachmentUniqueName, mimeType, contents);
attachment.setFileName(file.getName());
attachment.setAuthor(author);
attachment.setCreatedOn(createdOn);
issue.addAttachment(attachment);
Then update com.taskadapter.redmineapi.bean.Attachment as follows
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Attachment that = (Attachment) o;
if (id != null ? !id.equals(that.id) : that.id != null) {
return false;
}
if (token != null ? !token.equals(that.token) : that.token != null) {
return false;
}
return true;
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : (token == null ? 0 : token.hashCode());
}
1+
+1
is anyone ready to submit a PR for this?
Let's see if these can be fixed. Any failing test already avaliable ( I mean TDD)?
all existing tests pass. our dev Jenkins is currently down due to the OS upgrade which revealed this Jenkins bug: https://issues.jenkins-ci.org/browse/JENKINS-25333 . looks like this Jenkins issue is affecting multiple jenkins installs world-wide.
fixed.
I need to add some Attachments with the function addAttachments :
But juste the first attachment created is uploaded. Because all of this attachment created have an id equals to 0, i'm asking me if the problem is because we look on the hashCode in the file Attachment.java :
It seems to be that the hashcode depends of the id and the id is alltime equals to 0 when u create an Attachment.