Coverage Report - com.jcabi.github.RtIssue
 
Classes in this File Line Coverage Branch Coverage Complexity
RtIssue
70%
24/34
0%
0/24
1
RtIssue$1
20%
1/5
N/A
1
RtIssue$AjcClosure1
100%
1/1
N/A
1
RtIssue$AjcClosure11
0%
0/1
N/A
1
RtIssue$AjcClosure13
100%
1/1
N/A
1
RtIssue$AjcClosure15
100%
1/1
N/A
1
RtIssue$AjcClosure17
100%
1/1
N/A
1
RtIssue$AjcClosure3
100%
1/1
N/A
1
RtIssue$AjcClosure5
100%
1/1
N/A
1
RtIssue$AjcClosure7
100%
1/1
N/A
1
RtIssue$AjcClosure9
100%
1/1
N/A
1
 
 1  14
 /**
 2  
  * Copyright (c) 2013-2017, 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 com.jcabi.http.Request;
 35  
 import com.jcabi.http.response.RestResponse;
 36  
 import java.io.IOException;
 37  
 import java.net.HttpURLConnection;
 38  
 import javax.json.JsonObject;
 39  
 import lombok.EqualsAndHashCode;
 40  
 import org.hamcrest.Matchers;
 41  
 
 42  
 /**
 43  
  * Github issue.
 44  
  *
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id: 970169e497412f2a46e534aa27b5438b21a7813c $
 47  
  * @since 0.1
 48  
  * @checkstyle MultipleStringLiterals (500 lines)
 49  
  */
 50  0
 @Immutable
 51  
 @Loggable(Loggable.DEBUG)
 52  0
 @EqualsAndHashCode(of = { "request", "owner", "num" })
 53  
 @SuppressWarnings("PMD.TooManyMethods")
 54  0
 final class RtIssue implements Issue {
 55  
 
 56  
     /**
 57  
      * API entry point.
 58  
      */
 59  
     private final transient Request entry;
 60  
 
 61  
     /**
 62  
      * RESTful request.
 63  
      */
 64  
     private final transient Request request;
 65  
 
 66  
     /**
 67  
      * Repository we're in.
 68  
      */
 69  
     private final transient Repo owner;
 70  
 
 71  
     /**
 72  
      * Issue number.
 73  
      */
 74  
     private final transient int num;
 75  
 
 76  
     /**
 77  
      * Public ctor.
 78  
      * @param req Request
 79  
      * @param repo Repository
 80  
      * @param number Number of the get
 81  
      */
 82  15
     RtIssue(final Request req, final Repo repo, final int number) {
 83  15
         this.entry = req;
 84  15
         final Coordinates coords = repo.coordinates();
 85  15
         this.request = this.entry.uri()
 86  15
             .path("/repos")
 87  15
             .path(coords.user())
 88  15
             .path(coords.repo())
 89  15
             .path("/issues")
 90  15
             .path(Integer.toString(number))
 91  15
             .back();
 92  15
         this.owner = repo;
 93  15
         this.num = number;
 94  15
     }
 95  
 
 96  
     @Override
 97  
     public String toString() {
 98  0
         return this.request.uri().get().toString();
 99  
     }
 100  
 
 101  
     @Override
 102  
     public Repo repo() {
 103  6
         return this.owner;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public int number() {
 108  14
         return this.num;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public Comments comments() {
 113  2
         return new RtComments(this.entry, this);
 114  
     }
 115  
 
 116  
     @Override
 117  
     public IssueLabels labels() {
 118  2
         return new RtIssueLabels(this.entry, this);
 119  
     }
 120  
 
 121  
     @Override
 122  
     public Iterable<Event> events() {
 123  3
         return new RtPagination<Event>(
 124  1
             this.request.uri().path("/events").back(),
 125  1
             new RtValuePagination.Mapping<Event, JsonObject>() {
 126  
                 @Override
 127  
                 public Event map(final JsonObject object) {
 128  0
                     return new RtEvent(
 129  0
                         RtIssue.this.entry,
 130  0
                         RtIssue.this.owner,
 131  0
                         object.getInt("id")
 132  
                     );
 133  
                 }
 134  
             }
 135  
         );
 136  
     }
 137  
 
 138  
     @Override
 139  
     public boolean exists() throws IOException {
 140  0
         return this.request.fetch().as(RestResponse.class)
 141  0
             .assertStatus(
 142  0
                 Matchers.isOneOf(
 143  0
                     HttpURLConnection.HTTP_OK,
 144  0
                     HttpURLConnection.HTTP_NOT_FOUND
 145  
             )
 146  0
         ).status() == HttpURLConnection.HTTP_OK;
 147  
     }
 148  
 
 149  
     @Override
 150  
     public JsonObject json() throws IOException {
 151  8
         return new RtJson(this.request).fetch();
 152  
     }
 153  
 
 154  
     @Override
 155  
     public void patch(final JsonObject json) throws IOException {
 156  2
         new RtJson(this.request).patch(json);
 157  1
     }
 158  
 
 159  
     @Override
 160  
     public int compareTo(
 161  
         final Issue issue
 162  
     ) {
 163  4
         return this.number() - issue.number();
 164  
     }
 165  
 
 166  
 }