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