Coverage Report - com.jcabi.github.Release
 
Classes in this File Line Coverage Branch Coverage Complexity
Release
N/A
N/A
1.212
Release$Smart
42%
21/50
5%
1/18
1.212
Release$Smart$AjcClosure1
100%
1/1
N/A
1.212
Release$Smart$AjcClosure11
100%
1/1
N/A
1.212
Release$Smart$AjcClosure13
100%
1/1
N/A
1.212
Release$Smart$AjcClosure15
100%
1/1
N/A
1.212
Release$Smart$AjcClosure17
100%
1/1
N/A
1.212
Release$Smart$AjcClosure19
100%
1/1
N/A
1.212
Release$Smart$AjcClosure21
0%
0/1
N/A
1.212
Release$Smart$AjcClosure23
0%
0/1
N/A
1.212
Release$Smart$AjcClosure25
100%
1/1
N/A
1.212
Release$Smart$AjcClosure27
0%
0/1
N/A
1.212
Release$Smart$AjcClosure29
100%
1/1
N/A
1.212
Release$Smart$AjcClosure3
0%
0/1
N/A
1.212
Release$Smart$AjcClosure31
100%
1/1
N/A
1.212
Release$Smart$AjcClosure33
0%
0/1
N/A
1.212
Release$Smart$AjcClosure35
100%
1/1
N/A
1.212
Release$Smart$AjcClosure37
100%
1/1
N/A
1.212
Release$Smart$AjcClosure39
0%
0/1
N/A
1.212
Release$Smart$AjcClosure41
100%
1/1
N/A
1.212
Release$Smart$AjcClosure43
100%
1/1
N/A
1.212
Release$Smart$AjcClosure45
0%
0/1
N/A
1.212
Release$Smart$AjcClosure47
0%
0/1
N/A
1.212
Release$Smart$AjcClosure49
0%
0/1
N/A
1.212
Release$Smart$AjcClosure5
0%
0/1
N/A
1.212
Release$Smart$AjcClosure51
0%
0/1
N/A
1.212
Release$Smart$AjcClosure53
0%
0/1
N/A
1.212
Release$Smart$AjcClosure7
100%
1/1
N/A
1.212
Release$Smart$AjcClosure9
0%
0/1
N/A
1.212
 
 1  4
 /**
 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.json.JsonValue;
 41  
 import javax.validation.constraints.NotNull;
 42  
 import lombok.EqualsAndHashCode;
 43  
 import lombok.ToString;
 44  
 
 45  
 /**
 46  
  * Github release.
 47  
  *
 48  
  * @author Paul Polishchuk (ppol@ua.fm)
 49  
  * @version $Id$
 50  
  * @since 0.8
 51  
  * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a>
 52  
  * @checkstyle MultipleStringLiterals (500 lines)
 53  
  */
 54  
 @Immutable
 55  
 @SuppressWarnings("PMD.TooManyMethods")
 56  
 public interface Release extends JsonReadable, JsonPatchable {
 57  
 
 58  
     /**
 59  
      * Owner of them.
 60  
      * @return Repo
 61  
      */
 62  
     @NotNull(message = "repository is never NULL")
 63  
     Repo repo();
 64  
 
 65  
     /**
 66  
      * Release id.
 67  
      * @return Id
 68  
      */
 69  
     int number();
 70  
 
 71  
     /**
 72  
      * Deletes a release.
 73  
      * @throws IOException If any I/O problems occur.
 74  
      */
 75  
     void delete() throws IOException;
 76  
 
 77  
     /**
 78  
      * Get all release assets of this release.
 79  
      * @return Release assets.
 80  
      * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a>
 81  
      */
 82  
     @NotNull(message = "assets are never NULL")
 83  
     ReleaseAssets assets();
 84  
 
 85  
     /**
 86  
      * Smart release.
 87  
      */
 88  
     @Immutable
 89  0
     @ToString
 90  
     @Loggable(Loggable.DEBUG)
 91  0
     @EqualsAndHashCode(of = { "release", "jsn" })
 92  
     final class Smart implements Release {
 93  
 
 94  
         /**
 95  
          * Encapsulated release.
 96  
          */
 97  
         private final transient Release release;
 98  
         /**
 99  
          * SmartJson object for convenient JSON parsing.
 100  
          */
 101  
         private final transient SmartJson jsn;
 102  
 
 103  
         /**
 104  
          * Public CTOR.
 105  
          * @param original Original release
 106  
          */
 107  
         public Smart(
 108  
             @NotNull(message = "original can't be NULL") final Release original
 109  25
         ) {
 110  25
             this.release = original;
 111  25
             this.jsn = new SmartJson(original);
 112  25
         }
 113  
 
 114  
         @Override
 115  
         @NotNull(message = "JSON is never NULL")
 116  
         public JsonObject json() throws IOException {
 117  2
             return this.release.json();
 118  
         }
 119  
 
 120  
         @Override
 121  
         public void patch(
 122  
             @NotNull(message = "json can't be NULL") final JsonObject json
 123  
         ) throws IOException {
 124  0
             this.release.patch(json);
 125  0
         }
 126  
 
 127  
         @Override
 128  
         @NotNull(message = "repo is never NULL")
 129  
         public Repo repo() {
 130  0
             return this.release.repo();
 131  
         }
 132  
 
 133  
         @Override
 134  
         public int number() {
 135  2
             return this.release.number();
 136  
         }
 137  
 
 138  
         @Override
 139  
         @NotNull(message = "assets is never NULL")
 140  
         public ReleaseAssets assets() {
 141  0
             return this.release.assets();
 142  
         }
 143  
 
 144  
         /**
 145  
          * Get release url.
 146  
          * @return Release url
 147  
          * @throws IOException If there is any I/O problem
 148  
          */
 149  
         @NotNull(message = "URL cannot be NULL")
 150  
         public URL url() throws IOException {
 151  4
             return new URL(this.jsn.text("url"));
 152  
         }
 153  
 
 154  
         /**
 155  
          * Get release html url.
 156  
          * @return Release html url
 157  
          * @throws IOException If there is any I/O problem
 158  
          */
 159  
         @NotNull(message = "URL cannot possibly be NULL")
 160  
         public URL htmlUrl() throws IOException {
 161  4
             return new URL(this.jsn.text("html_url"));
 162  
         }
 163  
 
 164  
         /**
 165  
          * Get release assets url.
 166  
          * @return Release assets url
 167  
          * @throws IOException If there is any I/O problem
 168  
          */
 169  
         @NotNull(message = "URL isn't ever NULL")
 170  
         public URL assetsUrl() throws IOException {
 171  4
             return new URL(this.jsn.text("assets_url"));
 172  
         }
 173  
 
 174  
         /**
 175  
          * Get release upload url.
 176  
          * @return Release upload url
 177  
          * @throws IOException If there is any I/O problem
 178  
          */
 179  
         @NotNull(message = "URL is never NULL")
 180  
         public URL uploadUrl() throws IOException {
 181  4
             return new URL(this.jsn.text("upload_url"));
 182  
         }
 183  
 
 184  
         /**
 185  
          * Get release tag name.
 186  
          * @return The release tag name
 187  
          * @throws IOException If there is any I/O problem
 188  
          */
 189  
         @NotNull(message = "tag is never NULL")
 190  
         public String tag() throws IOException {
 191  10
             return this.jsn.text("tag_name");
 192  
         }
 193  
 
 194  
         /**
 195  
          * Has release tag?
 196  
          * @return TRUE if tag exists
 197  
          * @throws IOException If there is any I/O problem
 198  
          * @since 0.21
 199  
          */
 200  
         public boolean hasTag() throws IOException {
 201  0
             return this.jsn.hasNotNull("tag_name");
 202  
         }
 203  
 
 204  
         /**
 205  
          * Change its tag name.
 206  
          * @param text Tag name
 207  
          * @throws IOException If there is any I/O problem
 208  
          */
 209  
         public void tag(
 210  
             @NotNull(message = "text cannot be NULL") final String text
 211  
         ) throws IOException {
 212  0
             this.release.patch(
 213  
                 Json.createObjectBuilder().add("tag_name", text).build()
 214  
             );
 215  0
         }
 216  
 
 217  
         /**
 218  
          * Get release target commitish.
 219  
          * @return Release target commitish value
 220  
          * @throws IOException If there is any I/O problem
 221  
          */
 222  
         @NotNull(message = "commitish can't be NULL")
 223  
         public String commitish() throws IOException {
 224  4
             return this.jsn.text("target_commitish");
 225  
         }
 226  
 
 227  
         /**
 228  
          * Change its target commitish.
 229  
          * @param text Target commitish.
 230  
          * @throws IOException If there is any I/O problem
 231  
          */
 232  
         public void commitish(
 233  
             @NotNull(message = "text shouldn't be NULL") final String text
 234  
         ) throws IOException {
 235  0
             this.release.patch(
 236  
                 Json.createObjectBuilder()
 237  
                     .add("target_commitish", text)
 238  
                     .build()
 239  
             );
 240  0
         }
 241  
 
 242  
         /**
 243  
          * Does this release have a name?
 244  
          * @return Whether this release has a name
 245  
          * @throws IOException If there is any I/O problem
 246  
          */
 247  
         public boolean hasName() throws IOException {
 248  4
             return this.jsn.hasNotNull("name");
 249  
         }
 250  
 
 251  
         /**
 252  
          * Get release name. Note that there may not be one, so make sure to
 253  
          * check with {@link Release.Smart#hasName()} first.
 254  
          * @return Release name
 255  
          * @throws IOException If there is any I/O problem
 256  
          */
 257  
         @NotNull(message = "name is never NULL")
 258  
         public String name() throws IOException {
 259  4
             return this.jsn.text("name");
 260  
         }
 261  
 
 262  
         /**
 263  
          * Change its name.
 264  
          * @param text Name of release.
 265  
          * @throws IOException If there is any I/O problem
 266  
          */
 267  
         public void name(
 268  
             @NotNull(message = "text should not be NULL") final String text
 269  
         ) throws IOException {
 270  0
             this.release.patch(
 271  
                 Json.createObjectBuilder().add("name", text).build()
 272  
             );
 273  0
         }
 274  
 
 275  
         /**
 276  
          * Has release body.
 277  
          * @return TRUE if release body exists
 278  
          * @throws IOException If there is any I/O problem
 279  
          */
 280  
         public boolean hasBody() throws IOException {
 281  4
             return this.jsn.hasNotNull("body");
 282  
         }
 283  
 
 284  
         /**
 285  
          * Get release body.
 286  
          * @return Release body
 287  
          * @throws IOException If there is any I/O problem
 288  
          */
 289  
         @NotNull(message = "body is never NULL")
 290  
         public String body() throws IOException {
 291  
             final String body;
 292  4
             if (this.hasBody()) {
 293  2
                 body = this.jsn.text("body");
 294  
             } else {
 295  0
                 body = "";
 296  
             }
 297  2
             return body;
 298  
         }
 299  
 
 300  
         /**
 301  
          * Change its body.
 302  
          * @param text Text describing the contents of the tag
 303  
          * @throws IOException If there is any I/O problem
 304  
          */
 305  
         public void body(
 306  
             @NotNull(message = "text can't be NULL") final String text
 307  
         ) throws IOException {
 308  0
             this.release.patch(
 309  
                 Json.createObjectBuilder().add("body", text).build()
 310  
             );
 311  0
         }
 312  
 
 313  
         /**
 314  
          * Get release creation date.
 315  
          * @return Release creation date
 316  
          * @throws IOException If there is any I/O problem
 317  
          */
 318  
         @NotNull(message = "date is never NULL")
 319  
         public Date createdAt() throws IOException {
 320  
             try {
 321  4
                 return new Github.Time(this.jsn.text("created_at"))
 322  
                     .date();
 323  0
             } catch (final ParseException ex) {
 324  0
                 throw new IOException(ex);
 325  
             }
 326  
         }
 327  
 
 328  
         /**
 329  
          * Get release publication date.
 330  
          * @return Release publication date
 331  
          * @throws IOException If there is any I/O problem
 332  
          */
 333  
         @NotNull(message = "date is never NULL")
 334  
         public Date publishedAt() throws IOException {
 335  
             try {
 336  4
                 return new Github.Time(this.jsn.text("published_at"))
 337  
                     .date();
 338  0
             } catch (final ParseException ex) {
 339  0
                 throw new IOException(ex);
 340  
             }
 341  
         }
 342  
 
 343  
         /**
 344  
          * Is release draft.
 345  
          * @return Returns true if it's draft
 346  
          * @throws IOException If there is any I/O problem
 347  
          */
 348  
         public boolean draft() throws IOException {
 349  0
             return this.booleanValue("draft");
 350  
         }
 351  
 
 352  
         /**
 353  
          * Change its status.
 354  
          * @param draft True makes the release a draft.
 355  
          * @throws IOException If there is any I/O problem
 356  
          */
 357  
         public void draft(final boolean draft) throws IOException {
 358  0
             this.release.patch(
 359  
                 Json.createObjectBuilder().add("draft", draft).build()
 360  
             );
 361  0
         }
 362  
 
 363  
         /**
 364  
          * Is it prerelease.
 365  
          * @return Returns true if it's prerelease
 366  
          * @throws IOException If there is any I/O problem
 367  
          */
 368  
         public boolean prerelease() throws IOException {
 369  0
             return this.booleanValue("prerelease");
 370  
         }
 371  
 
 372  
         /**
 373  
          * Change its prerelease.
 374  
          * @param pre True to identify the release as a prerelease.
 375  
          * @throws IOException If there is any I/O problem
 376  
          */
 377  
         public void prerelease(final boolean pre) throws IOException {
 378  0
             this.release.patch(
 379  
                 Json.createObjectBuilder().add("prerelease", pre).build()
 380  
             );
 381  0
         }
 382  
 
 383  
         @Override
 384  
         public void delete() throws IOException {
 385  0
             this.release.delete();
 386  0
         }
 387  
 
 388  
         /**
 389  
          * Get a property as boolean.
 390  
          * @param name Parameter name
 391  
          * @return Returns boolean property value
 392  
          * @throws IOException If there is any I/O problem
 393  
          */
 394  
         private boolean booleanValue(final String name) throws IOException {
 395  0
             return JsonValue.TRUE.equals(this.json().get(name));
 396  
         }
 397  
     }
 398  
 
 399  
 }