2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner.portal;
19 import java.util.ArrayList;
20 import java.util.List;
23 import org.hedgecode.chess.scanner.ChessHogScannerException;
24 import org.hedgecode.chess.scanner.entity.PGNGame;
25 import org.hedgecode.chess.scanner.entity.PGNTournament;
30 * @author Dmitry Samoshin aka gotty
32 public class ChessGamesScanner extends AbstractSettingsScanner {
34 private static final String SETTINGS_FILENAME = "chessgames.settings";
37 protected String getResourceName() {
38 return SETTINGS_FILENAME;
42 public PGNTournament getTournament(String tournamentId) throws ChessHogScannerException {
43 PGNTournament tournament = new PGNTournament(tournamentId);
44 assignTournamentGames(tournament);
49 public PGNTournament findTournament(String tournamentName) throws ChessHogScannerException {
50 Map<String, String> result = matchMap(
54 getSettings().getTournamentQueryUrlRegex(),
57 PGNTournament tournament = null;
58 for (Map.Entry<String, String> entry : result.entrySet()) {
59 if (entry.getValue().contains(tournamentName)) { // todo: contains?
60 tournament = new PGNTournament(
66 if (tournament != null) {
67 assignTournamentGames(tournament);
73 public PGNGame getGame(String gameId) throws ChessHogScannerException {
82 private void assignTournamentGames(PGNTournament tournament) throws ChessHogScannerException {
83 tournament.clearGames();
84 List<String> gamesId = new ArrayList<>();
86 List<String> pageGamesId;
92 Integer.toString(++pageId)
94 getSettings().getTournamentGamesUrlRegex(),
100 } while (!pageGamesId.isEmpty());
102 for (String gameId : gamesId) {