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