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.domain.input;
18  
19  import com.atlassian.jira.rest.client.domain.BasicUser;
20  import com.atlassian.jira.rest.client.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  	 * @param self URI to this worklog, pass null if this is new worklog item.
59  	 * @param issueUri URI to destination issue
60  	 * @param author author of this worklog
61  	 * @param updateAuthor author of worklog actualization
62  	 * @param comment comment attached to worklog
63  	 * @param startDate date of work start
64  	 * @param minutesSpent time spend in minutes
65  	 * @param visibility visibility settings for this worklog
66  	 * @param adjustEstimate adjust estimate option
67  	 * @param adjustEstimateValue value for estimate adjustment. Only used when adjustEstimate is set
68  	 *                               to {@link AdjustEstimate#NEW} or {@link AdjustEstimate#MANUAL}
69  	 */
70  	public WorklogInput(@Nullable URI self, URI issueUri, @Nullable BasicUser author, @Nullable BasicUser updateAuthor,
71  			@Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility,
72  			AdjustEstimate adjustEstimate, @Nullable String adjustEstimateValue) {
73  		this.visibility = visibility;
74  		this.minutesSpent = minutesSpent;
75  		this.startDate = startDate;
76  		this.comment = comment;
77  		this.updateAuthor = updateAuthor;
78  		this.author = author;
79  		this.issueUri = issueUri;
80  		this.self = self;
81  		this.adjustEstimate = adjustEstimate;
82  		this.adjustEstimateValue = adjustEstimateValue;
83  	}
84  
85  	/**
86  	 * Creates new WorklogInput with given values. Sets adjust estimate option to default value - {@link AdjustEstimate#AUTO}.
87  	 * @param self URI to this worklog, pass null if this is new worklog item.
88  	 * @param issueUri URI to destination issue
89  	 * @param author author of this worklog
90  	 * @param updateAuthor author of worklog actualization
91  	 * @param comment comment attached to worklog
92  	 * @param startDate date of work start
93  	 * @param minutesSpent time spend in minutes
94  	 * @param visibility visibility settings for this worklog
95  	 */
96  	public WorklogInput(@Nullable URI self, URI issueUri, @Nullable BasicUser author, @Nullable BasicUser updateAuthor,
97  			@Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility) {
98  		this(self, issueUri, author, updateAuthor, comment, startDate, minutesSpent, visibility, AdjustEstimate.AUTO, null);
99  	}
100 
101 	public static WorklogInput create(URI issueUri, @Nullable String comment, DateTime startDate, int minutesSpent) {
102 		return new WorklogInputBuilder(issueUri).setComment(comment).setStartDate(startDate).setMinutesSpent(minutesSpent).build();
103 	}
104 
105 	public static WorklogInput create(URI issueUri, @Nullable String comment, DateTime startDate, int minutesSpent, @Nullable Visibility visibility) {
106 		return new WorklogInputBuilder(issueUri).setComment(comment).setStartDate(startDate).setMinutesSpent(minutesSpent)
107 				.setVisibility(visibility).build();
108 	}
109 
110 	@Nullable
111 	public URI getSelf() {
112 		return self;
113 	}
114 
115 	public URI getIssueUri() {
116 		return issueUri;
117 	}
118 
119 	@Nullable
120 	public BasicUser getAuthor() {
121 		return author;
122 	}
123 
124 	@Nullable
125 	public BasicUser getUpdateAuthor() {
126 		return updateAuthor;
127 	}
128 
129 	@Nullable
130 	public String getComment() {
131 		return comment;
132 	}
133 
134 	public DateTime getStartDate() {
135 		return startDate;
136 	}
137 
138 	public int getMinutesSpent() {
139 		return minutesSpent;
140 	}
141 
142 	@Nullable
143 	public Visibility getVisibility() {
144 		return visibility;
145 	}
146 
147 	public AdjustEstimate getAdjustEstimate() {
148 		return adjustEstimate;
149 	}
150 
151 	@Nullable
152 	public String getAdjustEstimateValue() {
153 		return adjustEstimateValue;
154 	}
155 
156 	@Override
157 	public String toString() {
158 		return Objects.toStringHelper(this)
159 				.add("self", self)
160 				.add("issueUri", issueUri)
161 				.add("author", author)
162 				.add("updateAuthor", updateAuthor)
163 				.add("comment", comment)
164 				.add("startDate", startDate)
165 				.add("minutesSpent", minutesSpent)
166 				.add("visibility", visibility)
167 				.add("adjustEstimate", adjustEstimate)
168 				.add("adjustEstimateValue", adjustEstimateValue)
169 				.toString();
170 	}
171 
172 	@Override
173 	public boolean equals(Object obj) {
174 		if (obj instanceof WorklogInput) {
175 			final WorklogInput that = (WorklogInput) obj;
176 
177 			return Objects.equal(this.self, that.self)
178 					&& Objects.equal(this.issueUri, that.issueUri)
179 					&& Objects.equal(this.author, that.author)
180 					&& Objects.equal(this.updateAuthor, that.updateAuthor)
181 					&& Objects.equal(this.comment, that.comment)
182 					&& Objects.equal(this.startDate, that.startDate)
183 					&& Objects.equal(this.minutesSpent, that.minutesSpent)
184 					&& Objects.equal(this.visibility, that.visibility)
185 					&& Objects.equal(this.adjustEstimate, that.adjustEstimate)
186 					&& Objects.equal(this.adjustEstimateValue, that.adjustEstimateValue);
187 		}
188 		return false;
189 	}
190 
191 	@Override
192 	public int hashCode() {
193 		return Objects.hashCode(self, issueUri, author, updateAuthor, comment, startDate, minutesSpent, visibility,
194 				adjustEstimate, adjustEstimateValue);
195 	}
196 
197 	public static enum AdjustEstimate {
198 		/**
199 		 * Set remaining estimate to given value.
200 		 */
201 		NEW,
202 		/**
203 		 * Leave estimate as is.
204 		 */
205 		LEAVE,
206 		/**
207 		 * Decrease estimate manually by given value.
208 		 */
209 		MANUAL,
210 		/**
211 		 * Automatically decrease estimate based on given time spent. This is the default value.
212 		 */
213 		AUTO;
214 
215 		public final String restValue;
216 
217 		private AdjustEstimate() {
218 			restValue = this.name().toLowerCase();
219 		}
220 	}
221 }
222