Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RqDeck |
|
| 2.5;2.5 |
1 | /** | |
2 | * Copyright (c) 2014-2015, Thindeck.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 thindeck.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.thindeck.cockpit.deck; | |
31 | ||
32 | import com.thindeck.api.Base; | |
33 | import com.thindeck.api.Deck; | |
34 | import com.thindeck.api.User; | |
35 | import com.thindeck.cockpit.RqUser; | |
36 | import java.io.IOException; | |
37 | import java.net.HttpURLConnection; | |
38 | import lombok.EqualsAndHashCode; | |
39 | import org.takes.Request; | |
40 | import org.takes.facets.forward.RsForward; | |
41 | import org.takes.rq.RqHeaders; | |
42 | import org.takes.rq.RqWrap; | |
43 | import org.takes.rs.RsText; | |
44 | ||
45 | /** | |
46 | * Deck fork. | |
47 | * | |
48 | * @author Yegor Bugayenko (yegor@teamed.io) | |
49 | * @version $Id$ | |
50 | * @since 0.5 | |
51 | */ | |
52 | 0 | @EqualsAndHashCode(callSuper = true) |
53 | public final class RqDeck extends RqWrap { | |
54 | ||
55 | /** | |
56 | * Base. | |
57 | */ | |
58 | private final transient Base base; | |
59 | ||
60 | /** | |
61 | * Ctor. | |
62 | * @param bse The base | |
63 | * @param req Request | |
64 | */ | |
65 | public RqDeck(final Base bse, final Request req) { | |
66 | 0 | super(req); |
67 | 0 | this.base = bse; |
68 | 0 | } |
69 | ||
70 | /** | |
71 | * Get deck. | |
72 | * @return The deck | |
73 | * @throws IOException If fails | |
74 | */ | |
75 | @SuppressWarnings("PMD.PreserveStackTrace") | |
76 | public Deck deck() throws IOException { | |
77 | 0 | final User user = new RqUser(this, this.base).get(); |
78 | 0 | final String name = new RqHeaders.Smart( |
79 | new RqHeaders.Base(this) | |
80 | ).single("X-Thindeck-Deck"); | |
81 | try { | |
82 | 0 | return user.decks().get(name); |
83 | 0 | } catch (final IOException ex) { |
84 | 0 | throw new RsForward( |
85 | new RsText(ex.getLocalizedMessage()), | |
86 | HttpURLConnection.HTTP_NOT_FOUND | |
87 | ); | |
88 | } | |
89 | } | |
90 | ||
91 | } |