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/.
18 package cz.xelfi.quoridor.statistics.resources;
20 import cz.xelfi.quoridor.IllegalPositionException;
21 import cz.xelfi.quoridor.webidor.Game;
22 import cz.xelfi.quoridor.webidor.GameId;
23 import cz.xelfi.quoridor.statistics.OpeningTree;
24 import cz.xelfi.quoridor.statistics.OpeningTreeNode;
25 import cz.xelfi.quoridor.statistics.OpeningNodeView;
26 import cz.xelfi.quoridor.webidor.GameStatus;
27 import java.util.List;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.QueryParam;
33 import javax.ws.rs.DefaultValue;
34 import javax.ws.rs.core.MediaType;
40 public class Openings {
44 tree = new OpeningTree();
47 public void processGame(Game game) {
49 tree.processGame(game);
50 }catch (IllegalPositionException e){
57 @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
58 public OpeningNodeView getNode(@QueryParam("loginID") @DefaultValue("") String loginId,
59 @PathParam("nodeId") String nodeId){
60 OpeningTreeNode node = tree.getNode(nodeId);
62 node = tree.getRoot();
63 return node.getView(loginId);
67 @Path("{nodeId}.check")
68 @Produces({ MediaType.TEXT_PLAIN })
69 public String checkNode(@QueryParam("loginID") @DefaultValue("") String loginId,
70 @PathParam("nodeId") String nodeId){
71 OpeningTreeNode node = tree.getNode(nodeId);
74 if(node.getView(loginId).isEmpty())
81 @Path("{nodeId}/{status}")
82 @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
83 public List<GameId> listGames(
84 @DefaultValue("") @QueryParam("loginID") String loginId,
85 @PathParam("nodeId") String nodeId,
86 @DefaultValue("") @PathParam("status") String status
88 OpeningTreeNode node = tree.getNode(nodeId);
91 if("white".equals(status))
92 return node.filterGames(loginId, GameStatus.whiteWon);
93 else if("black".equals(status))
94 return node.filterGames(loginId, GameStatus.blackWon);