2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Martin Rexa
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
19 package cz.xelfi.quoridor.statistics.resources;
21 import cz.xelfi.quoridor.IllegalPositionException;
22 import cz.xelfi.quoridor.webidor.Game;
23 import cz.xelfi.quoridor.webidor.GameId;
24 import cz.xelfi.quoridor.statistics.OpeningTree;
25 import cz.xelfi.quoridor.statistics.OpeningTreeNode;
26 import cz.xelfi.quoridor.statistics.OpeningNodeView;
27 import cz.xelfi.quoridor.webidor.GameStatus;
28 import java.util.List;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.QueryParam;
34 import javax.ws.rs.DefaultValue;
35 import javax.ws.rs.core.MediaType;
41 public class Openings {
45 tree = new OpeningTree();
48 public void processGame(Game game) {
50 tree.processGame(game);
51 }catch (IllegalPositionException e){
58 @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
59 public OpeningNodeView getNode(@QueryParam("loginID") @DefaultValue("") String loginId,
60 @PathParam("nodeId") String nodeId){
61 OpeningTreeNode node = tree.getNode(nodeId);
63 node = tree.getRoot();
64 return node.getView(loginId);
68 @Path("{nodeId}.check")
69 @Produces({ MediaType.TEXT_PLAIN })
70 public String checkNode(@QueryParam("loginID") @DefaultValue("") String loginId,
71 @PathParam("nodeId") String nodeId){
72 OpeningTreeNode node = tree.getNode(nodeId);
75 if(node.getView(loginId).isEmpty())
82 @Path("{nodeId}/{status}")
83 @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
84 public List<GameId> listGames(
85 @DefaultValue("") @QueryParam("loginID") String loginId,
86 @PathParam("nodeId") String nodeId,
87 @DefaultValue("") @PathParam("status") String status
89 OpeningTreeNode node = tree.getNode(nodeId);
92 if("white".equals(status))
93 return node.filterGames(loginId, GameStatus.whiteWon);
94 else if("black".equals(status))
95 return node.filterGames(loginId, GameStatus.blackWon);