Coverage Report - com.jcabi.github.Milestone
 
Classes in this File Line Coverage Branch Coverage Complexity
Milestone
N/A
N/A
1.25
Milestone$Smart
22%
9/40
0%
0/16
1.25
Milestone$Smart$AjcClosure1
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure11
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure13
100%
1/1
N/A
1.25
Milestone$Smart$AjcClosure15
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure17
100%
1/1
N/A
1.25
Milestone$Smart$AjcClosure19
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure21
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure23
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure25
100%
1/1
N/A
1.25
Milestone$Smart$AjcClosure27
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure29
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure3
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure31
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure33
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure35
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure37
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure39
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure41
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure5
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure7
0%
0/1
N/A
1.25
Milestone$Smart$AjcClosure9
100%
1/1
N/A
1.25
 
 1  0
 /**
 2  
  * Copyright (c) 2013-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import java.io.IOException;
 35  
 import java.net.URL;
 36  
 import java.text.ParseException;
 37  
 import java.util.Date;
 38  
 import javax.json.Json;
 39  
 import javax.json.JsonObject;
 40  
 import javax.validation.constraints.NotNull;
 41  
 import lombok.EqualsAndHashCode;
 42  
 import lombok.ToString;
 43  
 
 44  
 /**
 45  
  * Github Milestone.
 46  
  *
 47  
  * <p>Use a supplementary "smart" decorator to get other properties
 48  
  * from an milestone, for example:
 49  
  *
 50  
  * <pre> Milestone.Smart milestone = new Milestone.Smart(origin);
 51  
  * if (milestone.isOpen()) {
 52  
  *   milestone.close();
 53  
  * }
 54  
  * </pre>
 55  
  *
 56  
  * @author Paul Polishchuk (ppol@ua.fm)
 57  
  * @version $Id$
 58  
  * @see <a href="http://developer.github.com/v3/issues/milestones/">Milestones API</a>
 59  
  * @since 0.7
 60  
  */
 61  
 @Immutable
 62  
 @SuppressWarnings("PMD.TooManyMethods")
 63  
 public interface Milestone extends Comparable<Milestone>,
 64  
     JsonReadable, JsonPatchable {
 65  
 
 66  
     /**
 67  
      * Milestone state.
 68  
      */
 69  
     String OPEN_STATE = "open";
 70  
 
 71  
     /**
 72  
      * Milestone state.
 73  
      */
 74  
     String CLOSED_STATE = "closed";
 75  
 
 76  
     /**
 77  
      * Repository we're in.
 78  
      * @return Repo
 79  
      */
 80  
     @NotNull(message = "repository is never NULL")
 81  
     Repo repo();
 82  
 
 83  
     /**
 84  
      * Get its number.
 85  
      * @return Milestone number
 86  
      */
 87  
     int number();
 88  
 
 89  
     /**
 90  
      * Smart Milestone with extra features.
 91  
      */
 92  0
     @Immutable
 93  0
     @ToString
 94  
     @Loggable(Loggable.DEBUG)
 95  0
     @EqualsAndHashCode(of = { "milestone", "jsn" })
 96  
     final class Smart implements Milestone {
 97  
 
 98  
         /**
 99  
          * Name of mailestone state attribute.
 100  
          */
 101  
         private static final String STATE = "state";
 102  
 
 103  
         /**
 104  
          * Name of mailestone description attribute.
 105  
          */
 106  
         private static final String DESCRIPTION = "description";
 107  
 
 108  
         /**
 109  
          * Name of mailestone title attribute.
 110  
          */
 111  
         private static final String TITLE = "title";
 112  
 
 113  
         /**
 114  
          * Name of mailestone due_on attribute.
 115  
          */
 116  
         private static final String DUE_ON = "due_on";
 117  
 
 118  
         /**
 119  
          * Encapsulated milestone.
 120  
          */
 121  
         private final transient Milestone milestone;
 122  
 
 123  
         /**
 124  
          * SmartJson object for convenient JSON parsing.
 125  
          */
 126  
         private final transient SmartJson jsn;
 127  
 
 128  
         /**
 129  
          * Public ctor.
 130  
          * @param mls Issue
 131  
          */
 132  
         public Smart(
 133  
             @NotNull(message = "mls can't be NULL") final Milestone mls
 134  4
         ) {
 135  4
             this.milestone = mls;
 136  4
             this.jsn = new SmartJson(mls);
 137  4
         }
 138  
 
 139  
         /**
 140  
          * Get its creator.
 141  
          * @return Creator of milestone (who submitted it)
 142  
          * @throws java.io.IOException If there is any I/O problem
 143  
          */
 144  
         @NotNull(message = "user is never NULL")
 145  
         public User creator() throws IOException {
 146  0
             return this.milestone.repo().github().users().get(
 147  
                 this.jsn.value(
 148  
                     "creator", JsonObject.class
 149  
                 ).getString("login")
 150  
             );
 151  
         }
 152  
 
 153  
         /**
 154  
          * Is it open?
 155  
          * @return TRUE if it's open
 156  
          * @throws IOException If there is any I/O problem
 157  
          */
 158  
         public boolean isOpen() throws IOException {
 159  0
             return Milestone.OPEN_STATE.equals(this.state());
 160  
         }
 161  
 
 162  
         /**
 163  
          * Open it (make sure it's open).
 164  
          * @throws IOException If there is any I/O problem
 165  
          */
 166  
         public void open() throws IOException {
 167  0
             this.state(Milestone.OPEN_STATE);
 168  0
         }
 169  
 
 170  
         /**
 171  
          * Close it (make sure it's closed).
 172  
          * @throws IOException If there is any I/O problem
 173  
          */
 174  
         public void close() throws IOException {
 175  0
             this.state(Milestone.CLOSED_STATE);
 176  0
         }
 177  
 
 178  
         /**
 179  
          * Get its state.
 180  
          * @return State of milestone
 181  
          * @throws IOException If there is any I/O problem
 182  
          */
 183  
         @NotNull(message = "state is never NULL")
 184  
         public String state() throws IOException {
 185  2
             return this.jsn.text(STATE);
 186  
         }
 187  
 
 188  
         /**
 189  
          * Change its state.
 190  
          * @param state State of milestone
 191  
          * @throws IOException If there is any I/O problem
 192  
          */
 193  
         public void state(
 194  
             @NotNull(message = "state can't be NULL") final String state
 195  
         ) throws IOException {
 196  0
             this.milestone.patch(
 197  
                 Json.createObjectBuilder().add(STATE, state).build()
 198  
             );
 199  0
         }
 200  
 
 201  
         /**
 202  
          * Get its title.
 203  
          * @return Title of milestone
 204  
          * @throws IOException If there is any I/O problem
 205  
          */
 206  
         @NotNull(message = "title is never NULL")
 207  
         public String title() throws IOException {
 208  2
             return this.jsn.text(TITLE);
 209  
         }
 210  
 
 211  
         /**
 212  
          * Change its title.
 213  
          * @param title Title of milestone
 214  
          * @throws IOException If there is any I/O problem
 215  
          */
 216  
         public void title(
 217  
             @NotNull(message = "title can't be NULL") final String title
 218  
         ) throws IOException {
 219  0
             this.milestone.patch(
 220  
                 Json.createObjectBuilder().add(TITLE, title).build()
 221  
             );
 222  0
         }
 223  
 
 224  
         /**
 225  
          * Get its description.
 226  
          * @return Title of milestone
 227  
          * @throws IOException If there is any I/O problem
 228  
          */
 229  
         @NotNull(message = "description is never NULL")
 230  
         public String description() throws IOException {
 231  2
             return this.jsn.text(DESCRIPTION);
 232  
         }
 233  
 
 234  
         /**
 235  
          * Change its description.
 236  
          * @param description Description of milestone
 237  
          * @throws IOException If there is any I/O problem
 238  
          */
 239  
         public void description(
 240  
             @NotNull(message = "description can't be NULL")
 241  
             final String description
 242  
         ) throws IOException {
 243  0
             this.milestone.patch(
 244  
                 Json.createObjectBuilder()
 245  
                     .add(DESCRIPTION, description).build()
 246  
             );
 247  0
         }
 248  
 
 249  
         /**
 250  
          * Get its URL.
 251  
          * @return URL of milestone
 252  
          * @throws IOException If there is any I/O problem
 253  
          */
 254  
         @NotNull(message = "URL is never NULL")
 255  
         public URL url() throws IOException {
 256  0
             return new URL(this.jsn.text("url"));
 257  
         }
 258  
 
 259  
         /**
 260  
          * When this milestone was created.
 261  
          * @return Date of creation
 262  
          * @throws IOException If there is any I/O problem
 263  
          */
 264  
         @NotNull(message = "Date is never NULL")
 265  
         public Date createdAt() throws IOException {
 266  
             try {
 267  0
                 return new Github.Time(
 268  
                     this.jsn.text("created_at")
 269  
                 ).date();
 270  0
             } catch (final ParseException ex) {
 271  0
                 throw new IllegalStateException(ex);
 272  
             }
 273  
         }
 274  
 
 275  
         /**
 276  
          * The milestone due date.
 277  
          * @return The milestone due date
 278  
          * @throws IOException If there is any I/O problem
 279  
          */
 280  
         @NotNull(message = "date is never NULL")
 281  
         public Date dueOn() throws IOException {
 282  
             try {
 283  2
                 return new Github.Time(
 284  
                     this.jsn.text(DUE_ON)
 285  
                 ).date();
 286  0
             } catch (final ParseException ex) {
 287  0
                 throw new IllegalStateException(ex);
 288  
             }
 289  
         }
 290  
 
 291  
         /**
 292  
          * Change milestone due date.
 293  
          * @param dueon New milestone due date
 294  
          * @throws IOException If there is any I/O problem
 295  
          */
 296  
         public void dueOn(
 297  
             @NotNull(message = "dueon can't be NULL") final Date dueon
 298  
         ) throws IOException {
 299  0
             this.milestone.patch(
 300  
                 Json.createObjectBuilder()
 301  
                     .add(DUE_ON, new Github.Time(dueon).toString()).build()
 302  
             );
 303  0
         }
 304  
 
 305  
         /**
 306  
          * Get number of open issues.
 307  
          * @return Number of open issues
 308  
          * @throws IOException If there is any I/O problem
 309  
          */
 310  
         public int openIssues() throws IOException {
 311  0
             return this.jsn.number("open_issues");
 312  
         }
 313  
 
 314  
         /**
 315  
          * Get number of closed issues.
 316  
          * @return Number of closed issues
 317  
          * @throws IOException If there is any I/O problem
 318  
          */
 319  
         public int closedIssues() throws IOException {
 320  0
             return this.jsn.number("closed_issues");
 321  
         }
 322  
 
 323  
         @Override
 324  
         @NotNull(message = "Repo is never NULL")
 325  
         public Repo repo() {
 326  0
             return this.milestone.repo();
 327  
         }
 328  
 
 329  
         @Override
 330  
         public int number() {
 331  0
             return this.milestone.number();
 332  
         }
 333  
 
 334  
         @Override
 335  
         @NotNull(message = "JSON is never NULL")
 336  
         public JsonObject json() throws IOException {
 337  0
             return this.milestone.json();
 338  
         }
 339  
 
 340  
         @Override
 341  
         public void patch(
 342  
             @NotNull(message = "json can't be NULL") final JsonObject json
 343  
         ) throws IOException {
 344  0
             this.milestone.patch(json);
 345  0
         }
 346  
 
 347  
         @Override
 348  
         public int compareTo(
 349  
             @NotNull(message = "obj can't be NULL") final Milestone obj
 350  
         ) {
 351  0
             return this.milestone.compareTo(obj);
 352  
         }
 353  
 
 354  
     }
 355  
 }