View Javadoc

1   /*
2    * Copyright (C) 2012 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.input;
18  
19  import com.atlassian.jira.rest.client.api.domain.BasicUser;
20  import com.atlassian.jira.rest.client.api.domain.Visibility;
21  import com.google.common.base.Objects;
22  import org.joda.time.DateTime;
23  
24  import javax.annotation.Nullable;
25  import java.net.URI;
26  
27  /**
28   * Represents worklog item in JIRA. Is used to create new worklog or update existing one.
29   * Contains also estimate adjustment options which are used only to adjust change of remaining
30   * estimate (adjustEstimate and adjustEstimateValue).<br/>
31   * Possible values for adjustEstimate and adjustEstimateValue are:<br/>
32   * <li>When adjustEstimate is set to {@link AdjustEstimate#AUTO} or {@link AdjustEstimate#LEAVE} adjustEstimateValue
33   * is not used</li>
34   * <li>When adjustEstimate is set to {@link AdjustEstimate#NEW} then remaining estimate is set to adjustEstimateValue</li>
35   * <li>When adjustEstimate is set to {@link AdjustEstimate#MANUAL} then remaining estimate is reduced by adjustEstimateValue</li>
36   */
37  public class WorklogInput {
38  	@Nullable
39  	private final URI self;
40  	private final URI issueUri;
41  	@Nullable
42  	private final BasicUser author;
43  	@Nullable
44  	private final BasicUser updateAuthor;
45  	@Nullable
46  	private final String comment;
47  	private final DateTime startDate;
48  	private final int minutesSpent;
49  	@Nullable
50  	private final Visibility visibility;
51  
52  	@Nullable
53  	private final String adjustEstimateValue;
54  	private final AdjustEstimate adjustEstimate;
55  
56  	/**
57  	 * Creates new WorklogInput with given values
58  	 *
59  	 * @param self                URI to this worklog, pass null if this is new worklog item.
60  	 * @param issueUri            URI to destination issue
61  	 * @param author              author of this worklog
62  	 * @param updateAuthor        author of worklog actualization
63  	 * @param comment             comment attached to worklog
64  	 * @param startDate           date of work start
65  	 * @param minutesSpent        time spend in minutes
66  	 * @param visibility          visibility settings for this worklog
67  	 * @param adjustEstimate      adjust estimate option
68  	 * @param adjustEstimateValue value for estimate adjustment. Only used when adjustEstimate is set
69  	 *                            to {@link AdjustEstimate#NEW} or {@link AdjustEstimate#MANUAL}
70  	 */
71  	public WorklogInput(@Nullable URI self, URI issueUri, @Nullable BasicUser author, @Nullable BasicUser updateAuthor,
72  			@Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility,
73  			AdjustEstimate adjustEstimate, @Nullable String adjustEstimateValue) {
74  		this.visibility = visibility;
75  		this.minutesSpent = minutesSpent;
76  		this.startDate = startDate;
77  		this.comment = comment;
78  		this.updateAuthor = updateAuthor;
79  		this.author = author;
80  		this.issueUri = issueUri;
81  		this.self = self;
82  		this.adjustEstimate = adjustEstimate;
83  		this.adjustEstimateValue = adjustEstimateValue;
84  	}
85  
86  	/**
87  	 * Creates new WorklogInput with given values. Sets adjust estimate option to default value - {@link AdjustEstimate#AUTO}.
88  	 *
89  	 * @param self         URI to this worklog, pass null if this is new worklog item.
90  	 * @param issueUri     URI to destination issue
91  	 * @param author       author of this worklog
92  	 * @param updateAuthor author of worklog actualization
93  	 * @param comment      comment attached to worklog
94  	 * @param startDate    date of work start
95  	 * @param minutesSpent time spend in minutes
96  	 * @param visibility   visibility settings for this worklog
97  	 */
98  	public WorklogInput(@Nullable URI self, URI issueUri, @Nullable BasicUser author, @Nullable BasicUser updateAuthor,
99  			@Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility) {
100 		this(self, issueUri, author, updateAuthor, comment, startDate, minutesSpent, visibility, AdjustEstimate.AUTO, null);
101 	}
102 
103 	public static WorklogInput create(URI issueUri, @Nullable String comment, DateTime startDate, int minutesSpent) {
104 		return new WorklogInputBuilder(issueUri).setComment(comment).setStartDate(startDate).setMinutesSpent(minutesSpent)
105 				.build();
106 	}
107 
108 	public static WorklogInput create(URI issueUri, @Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility) {
109 		return new WorklogInputBuilder(issueUri).setComment(comment).setStartDate(startDate).setMinutesSpent(minutesSpent)
110 				.setVisibility(visibility).build();
111 	}
112 
113 	@Nullable
114 	public URI getSelf() {
115 		return self;
116 	}
117 
118 	public URI getIssueUri() {
119 		return issueUri;
120 	}
121 
122 	@Nullable
123 	public BasicUser getAuthor() {
124 		return author;
125 	}
126 
127 	@Nullable
128 	public BasicUser getUpdateAuthor() {
129 		return updateAuthor;
130 	}
131 
132 	@Nullable
133 	public String getComment() {
134 		return comment;
135 	}
136 
137 	public DateTime getStartDate() {
138 		return startDate;
139 	}
140 
141 	public int getMinutesSpent() {
142 		return minutesSpent;
143 	}
144 
145 	@Nullable
146 	public Visibility getVisibility() {
147 		return visibility;
148 	}
149 
150 	public AdjustEstimate getAdjustEstimate() {
151 		return adjustEstimate;
152 	}
153 
154 	@Nullable
155 	public String getAdjustEstimateValue() {
156 		return adjustEstimateValue;
157 	}
158 
159 	@Override
160 	public String toString() {
161 		return Objects.toStringHelper(this)
162 				.add("self", self)
163 				.add("issueUri", issueUri)
164 				.add("author", author)
165 				.add("updateAuthor", updateAuthor)
166 				.add("comment", comment)
167 				.add("startDate", startDate)
168 				.add("minutesSpent", minutesSpent)
169 				.add("visibility", visibility)
170 				.add("adjustEstimate", adjustEstimate)
171 				.add("adjustEstimateValue", adjustEstimateValue)
172 				.toString();
173 	}
174 
175 	@Override
176 	public boolean equals(Object obj) {
177 		if (obj instanceof WorklogInput) {
178 			final WorklogInput that = (WorklogInput) obj;
179 
180 			return Objects.equal(this.self, that.self)
181 					&& Objects.equal(this.issueUri, that.issueUri)
182 					&& Objects.equal(this.author, that.author)
183 					&& Objects.equal(this.updateAuthor, that.updateAuthor)
184 					&& Objects.equal(this.comment, that.comment)
185 					&& Objects.equal(this.startDate, that.startDate)
186 					&& Objects.equal(this.minutesSpent, that.minutesSpent)
187 					&& Objects.equal(this.visibility, that.visibility)
188 					&& Objects.equal(this.adjustEstimate, that.adjustEstimate)
189 					&& Objects.equal(this.adjustEstimateValue, that.adjustEstimateValue);
190 		}
191 		return false;
192 	}
193 
194 	@Override
195 	public int hashCode() {
196 		return Objects.hashCode(self, issueUri, author, updateAuthor, comment, startDate, minutesSpent, visibility,
197 				adjustEstimate, adjustEstimateValue);
198 	}
199 
200 	public static enum AdjustEstimate {
201 		/**
202 		 * Set remaining estimate to given value.
203 		 */
204 		NEW,
205 		/**
206 		 * Leave estimate as is.
207 		 */
208 		LEAVE,
209 		/**
210 		 * Decrease estimate manually by given value.
211 		 */
212 		MANUAL,
213 		/**
214 		 * Automatically decrease estimate based on given time spent. This is the default value.
215 		 */
216 		AUTO;
217 
218 		public final String restValue;
219 
220 		private AdjustEstimate() {
221 			restValue = this.name().toLowerCase();
222 		}
223 	}
224 }
225