Coverage Report - com.jcabi.github.Event
 
Classes in this File Line Coverage Branch Coverage Complexity
Event
N/A
N/A
1.25
Event$Smart
63%
12/19
0%
0/18
1.25
Event$Smart$AjcClosure1
0%
0/1
N/A
1.25
Event$Smart$AjcClosure11
100%
1/1
N/A
1.25
Event$Smart$AjcClosure13
100%
1/1
N/A
1.25
Event$Smart$AjcClosure15
100%
1/1
N/A
1.25
Event$Smart$AjcClosure17
0%
0/1
N/A
1.25
Event$Smart$AjcClosure3
100%
1/1
N/A
1.25
Event$Smart$AjcClosure5
100%
1/1
N/A
1.25
Event$Smart$AjcClosure7
100%
1/1
N/A
1.25
Event$Smart$AjcClosure9
100%
1/1
N/A
1.25
 
 1  8
 /**
 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.JsonObject;
 39  
 import javax.validation.constraints.NotNull;
 40  
 import lombok.EqualsAndHashCode;
 41  
 import lombok.ToString;
 42  
 
 43  
 /**
 44  
  * Github event.
 45  
  *
 46  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 47  
  * @version $Id$
 48  
  * @since 0.4
 49  
  * @see <a href="http://developer.github.com/v3/issues/events/">Issue Events API</a>
 50  
  * @checkstyle MultipleStringLiterals (500 lines)
 51  
  */
 52  
 @Immutable
 53  
 @SuppressWarnings("PMD.TooManyMethods")
 54  
 public interface Event extends Comparable<Event>, JsonReadable {
 55  
 
 56  
     /**
 57  
      * Event type.
 58  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 59  
      */
 60  
     String CLOSED = "closed";
 61  
 
 62  
     /**
 63  
      * Event type.
 64  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 65  
      */
 66  
     String REOPENED = "reopened";
 67  
 
 68  
     /**
 69  
      * Event type.
 70  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 71  
      */
 72  
     String SUBSCRIBED = "subscribed";
 73  
 
 74  
     /**
 75  
      * Event type.
 76  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 77  
      */
 78  
     String MERGED = "merged";
 79  
 
 80  
     /**
 81  
      * Event type.
 82  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 83  
      */
 84  
     String REFERENCED = "referenced";
 85  
 
 86  
     /**
 87  
      * Event type.
 88  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 89  
      */
 90  
     String MENTIONED = "mentioned";
 91  
 
 92  
     /**
 93  
      * Event type.
 94  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 95  
      */
 96  
     String ASSIGNED = "assigned";
 97  
 
 98  
     /**
 99  
      * Event type.
 100  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 101  
      */
 102  
     String UNASSIGNED = "unassigned";
 103  
 
 104  
     /**
 105  
      * Event type.
 106  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 107  
      */
 108  
     String LABELED = "labeled";
 109  
 
 110  
     /**
 111  
      * Event type.
 112  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 113  
      */
 114  
     String UNLABELED = "unlabeled";
 115  
 
 116  
     /**
 117  
      * Event type.
 118  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 119  
      */
 120  
     String MILESTONED = "milestoned";
 121  
 
 122  
     /**
 123  
      * Event type.
 124  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 125  
      */
 126  
     String DEMILESTONED = "demilestoned";
 127  
 
 128  
     /**
 129  
      * Event type.
 130  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 131  
      */
 132  
     String RENAMED = "renamed";
 133  
 
 134  
     /**
 135  
      * Event type.
 136  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 137  
      */
 138  
     String LOCKED = "locked";
 139  
 
 140  
     /**
 141  
      * Event type.
 142  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 143  
      */
 144  
     String UNLOCKED = "unlocked";
 145  
 
 146  
     /**
 147  
      * Event type.
 148  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 149  
      */
 150  
     String HEAD_REF_DELETED = "head_ref_deleted";
 151  
 
 152  
     /**
 153  
      * Event type.
 154  
      * @see <a href="http://developer.github.com/v3/issues/events/">Event Types</a>
 155  
      */
 156  
     String HEAD_REF_RESTORED = "head_ref_restored";
 157  
 
 158  
     /**
 159  
      * Repository we're in.
 160  
      * @return Repo
 161  
      */
 162  
     @NotNull(message = "repository is never NULL")
 163  
     Repo repo();
 164  
 
 165  
     /**
 166  
      * Get its number.
 167  
      * @return Issue number
 168  
      */
 169  
     int number();
 170  
 
 171  
     /**
 172  
      * Smart event with extra features.
 173  
      */
 174  0
     @Immutable
 175  0
     @ToString
 176  
     @Loggable(Loggable.DEBUG)
 177  0
     @EqualsAndHashCode(of = { "event", "jsn" })
 178  
     final class Smart implements Event {
 179  
         /**
 180  
          * Encapsulated event.
 181  
          */
 182  
         private final transient Event event;
 183  
         /**
 184  
          * SmartJson object for convenient JSON parsing.
 185  
          */
 186  
         private final transient SmartJson jsn;
 187  
         /**
 188  
          * Public ctor.
 189  
          * @param evt Event
 190  
          */
 191  
         public Smart(
 192  
             @NotNull(message = "evt can't be NULL") final Event evt
 193  7
         ) {
 194  7
             this.event = evt;
 195  7
             this.jsn = new SmartJson(evt);
 196  7
         }
 197  
         /**
 198  
          * Does it have an author?
 199  
          * @return TRUE if the author exists
 200  
          * @throws IOException If there is any I/O problem
 201  
          */
 202  
         public boolean hasAuthor() throws IOException {
 203  0
             return !this.event.json().isNull("actor");
 204  
         }
 205  
         /**
 206  
          * Get its author.
 207  
          * @return Author of comment
 208  
          * @throws IOException If there is any I/O problem
 209  
          */
 210  
         @NotNull(message = "user is never NULL")
 211  
         public User author() throws IOException {
 212  8
             return this.event.repo().github().users().get(
 213  
                 this.event.json().getJsonObject("actor").getString("login")
 214  
             );
 215  
         }
 216  
         /**
 217  
          * Get its type.
 218  
          * @return State of issue
 219  
          * @throws IOException If there is any I/O problem
 220  
          */
 221  
         @NotNull(message = "type can't be NULL")
 222  
         public String type() throws IOException {
 223  14
             return this.jsn.text("event");
 224  
         }
 225  
         /**
 226  
          * Get its URL.
 227  
          * @return URL of issue
 228  
          * @throws IOException If there is any I/O problem
 229  
          */
 230  
         @NotNull(message = "URL is never NULL")
 231  
         public URL url() throws IOException {
 232  2
             return new URL(this.jsn.text("url"));
 233  
         }
 234  
         /**
 235  
          * When this issue was created.
 236  
          * @return Date of creation
 237  
          * @throws IOException If there is any I/O problem
 238  
          */
 239  
         @NotNull(message = "Date is never NULL")
 240  
         public Date createdAt() throws IOException {
 241  
             try {
 242  4
                 return new Github.Time(
 243  
                     this.jsn.text("created_at")
 244  
                 ).date();
 245  0
             } catch (final ParseException ex) {
 246  0
                 throw new IllegalStateException(ex);
 247  
             }
 248  
         }
 249  
         @Override
 250  
         @NotNull(message = "Repository is never NULL")
 251  
         public Repo repo() {
 252  4
             return this.event.repo();
 253  
         }
 254  
         @Override
 255  
         public int number() {
 256  2
             return this.event.number();
 257  
         }
 258  
         @Override
 259  
         @NotNull(message = "JSON is never NULL")
 260  
         public JsonObject json() throws IOException {
 261  4
             return this.event.json();
 262  
         }
 263  
         @Override
 264  
         public int compareTo(
 265  
             @NotNull(message = "obj can't be NULL") final Event obj
 266  
         ) {
 267  0
             return this.event.compareTo(obj);
 268  
         }
 269  
     }
 270  
 
 271  
 }