Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MkUserOrganizations |
|
| 1.5;1.5 | ||||
MkUserOrganizations$AjcClosure1 |
|
| 1.5;1.5 | ||||
MkUserOrganizations$AjcClosure3 |
|
| 1.5;1.5 | ||||
MkUserOrganizations$AjcClosure5 |
|
| 1.5;1.5 | ||||
MkUserOrganizations$OrganizationMapping |
|
| 1.5;1.5 |
1 | 2 | /** |
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.mock; | |
31 | ||
32 | import com.jcabi.aspects.Immutable; | |
33 | import com.jcabi.aspects.Loggable; | |
34 | import com.jcabi.github.Github; | |
35 | import com.jcabi.github.Organization; | |
36 | import com.jcabi.github.Organizations; | |
37 | import com.jcabi.github.User; | |
38 | import com.jcabi.github.UserOrganizations; | |
39 | import com.jcabi.xml.XML; | |
40 | import java.io.IOException; | |
41 | import lombok.EqualsAndHashCode; | |
42 | import lombok.ToString; | |
43 | import org.xembly.Directives; | |
44 | ||
45 | /** | |
46 | * Github user organizations. | |
47 | * @author Paul Polishchuk (ppol@ua.fm) | |
48 | * @author Chris Rebert (github@chrisrebert.com) | |
49 | * @version $Id: ac294756bb096fef948567fadae48a3832012b71 $ | |
50 | * @see <a href="http://developer.github.com/v3/orgs/">Organizations API</a> | |
51 | * @since 0.24 | |
52 | * @checkstyle MultipleStringLiteralsCheck (200 lines) | |
53 | * @checkstyle ClassDataAbstractionCoupling (200 lines) | |
54 | */ | |
55 | @Immutable | |
56 | @Loggable(Loggable.DEBUG) | |
57 | 0 | @ToString |
58 | 0 | @EqualsAndHashCode(of = { "storage", "self" }) |
59 | @SuppressWarnings("PMD.TooManyMethods") | |
60 | final class MkUserOrganizations implements UserOrganizations { | |
61 | /** | |
62 | * Storage. | |
63 | */ | |
64 | private final transient MkStorage storage; | |
65 | ||
66 | /** | |
67 | * Login of the user logged in. | |
68 | */ | |
69 | private final transient String self; | |
70 | ||
71 | /** | |
72 | * Public ctor. | |
73 | * @param stg Storage | |
74 | * @param login User to login | |
75 | * @throws IOException If there is any I/O problem | |
76 | */ | |
77 | MkUserOrganizations( | |
78 | final MkStorage stg, | |
79 | final String login | |
80 | ) | |
81 | 2 | throws IOException { |
82 | 2 | this.storage = stg; |
83 | 2 | this.self = login; |
84 | 4 | this.storage.apply( |
85 | 2 | new Directives().xpath("/github").addIf("orgs") |
86 | ); | |
87 | 2 | } |
88 | ||
89 | @Override | |
90 | public Github github() { | |
91 | 0 | return new MkGithub(this.storage, this.self); |
92 | } | |
93 | ||
94 | @Override | |
95 | public User user() { | |
96 | try { | |
97 | 0 | return new MkUser(this.storage, this.self); |
98 | 0 | } catch (final IOException ex) { |
99 | 0 | throw new IllegalStateException(ex); |
100 | } | |
101 | } | |
102 | ||
103 | @Override | |
104 | public Iterable<Organization> iterate() throws IOException { | |
105 | 2 | return new MkIterable<Organization>( |
106 | this.storage, | |
107 | "/github/orgs/org", | |
108 | new OrganizationMapping(new MkOrganizations(this.storage)) | |
109 | ); | |
110 | } | |
111 | ||
112 | 1 | private static final class OrganizationMapping |
113 | implements MkIterable.Mapping<Organization> { | |
114 | /** | |
115 | * Organizations. | |
116 | */ | |
117 | private final transient Organizations organizations; | |
118 | ||
119 | /** | |
120 | * Ctor. | |
121 | * @param orgs Organizations | |
122 | */ | |
123 | 1 | OrganizationMapping(final Organizations orgs) { |
124 | 1 | this.organizations = orgs; |
125 | 1 | } |
126 | ||
127 | @Override | |
128 | public Organization map(final XML xml) { | |
129 | 2 | return this.organizations.get( |
130 | 1 | xml.xpath("login/text()").get(0) |
131 | ); | |
132 | } | |
133 | } | |
134 | } |