View Javadoc

1   /*
2    * Copyright (C) 2010 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.api.domain;
18  
19  import com.atlassian.jira.rest.client.api.AddressableEntity;
20  import com.google.common.base.Objects;
21  import org.joda.time.DateTime;
22  
23  import javax.annotation.Nullable;
24  import java.net.URI;
25  
26  /**
27   * A file attachment attached to an issue
28   *
29   * @since v0.1
30   */
31  public class Attachment implements AddressableEntity {
32  	private final URI self;
33  	private final String filename;
34  	private final BasicUser author;
35  	private final DateTime creationDate;
36  	private final int size;
37  	private final String mimeType;
38  	private final URI contentUri;
39  
40  	@Nullable
41  	private final URI thumbnailUri;
42  
43  	public Attachment(URI self, String filename, BasicUser author, DateTime creationDate, int size, String mimeType, URI contentUri, URI thumbnailUri) {
44  		this.self = self;
45  		this.filename = filename;
46  		this.author = author;
47  		this.creationDate = creationDate;
48  		this.size = size;
49  		this.mimeType = mimeType;
50  		this.contentUri = contentUri;
51  		this.thumbnailUri = thumbnailUri;
52  	}
53  
54  	public boolean hasThumbnail() {
55  		return thumbnailUri != null;
56  	}
57  
58  	@Override
59  	public URI getSelf() {
60  		return self;
61  	}
62  
63  	public String getFilename() {
64  		return filename;
65  	}
66  
67  	public BasicUser getAuthor() {
68  		return author;
69  	}
70  
71  	public DateTime getCreationDate() {
72  		return creationDate;
73  	}
74  
75  	public int getSize() {
76  		return size;
77  	}
78  
79  	public String getMimeType() {
80  		return mimeType;
81  	}
82  
83  	public URI getContentUri() {
84  		return contentUri;
85  	}
86  
87  	@Nullable
88  	public URI getThumbnailUri() {
89  		return thumbnailUri;
90  	}
91  
92  	@Override
93  	public String toString() {
94  		return Objects.toStringHelper(this).
95  				add("self", self).
96  				add("filename", filename).
97  				add("author", author).
98  				add("creationDate", creationDate).
99  				add("size", size).
100 				add("mimeType", mimeType).
101 				add("contentUri", contentUri).
102 				add("thumbnailUri", thumbnailUri).
103 				toString();
104 	}
105 
106 	@Override
107 	public boolean equals(Object obj) {
108 		if (obj instanceof Attachment) {
109 			Attachment that = (Attachment) obj;
110 			return Objects.equal(this.self, that.self)
111 					&& Objects.equal(this.filename, that.filename)
112 					&& Objects.equal(this.author, that.author)
113 					&& this.creationDate.isEqual(that.creationDate)
114 					&& Objects.equal(this.size, that.size)
115 					&& Objects.equal(this.mimeType, that.mimeType)
116 					&& Objects.equal(this.contentUri, that.contentUri)
117 					&& Objects.equal(this.thumbnailUri, that.thumbnailUri);
118 		}
119 		return false;
120 	}
121 
122 	@Override
123 	public int hashCode() {
124 		return Objects.hashCode(self, filename, author, creationDate, size, mimeType, contentUri, thumbnailUri);
125 	}
126 }