001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023 024package dk.netarkivet.harvester.datamodel; 025 026import java.util.List; 027 028import dk.netarkivet.common.exceptions.ArgumentNotValid; 029import dk.netarkivet.common.exceptions.UnknownID; 030 031/** 032 * A Data Access Object for managing persistent collections of global crawler traps. 033 */ 034public abstract class GlobalCrawlerTrapListDAO implements DAO { 035 036 /** The database singleton model. */ 037 private static GlobalCrawlerTrapListDAO instance; 038 039 /** 040 * Factory method to return the singleton instance of this class. 041 * 042 * @return the singleton instance of this class. 043 */ 044 public static synchronized GlobalCrawlerTrapListDAO getInstance() { 045 if (instance == null) { 046 instance = new GlobalCrawlerTrapListDBDAO(); 047 } 048 return instance; 049 } 050 051 /** 052 * Resets the singleton instance of this class. Mostly for testing. 053 */ 054 public static void reset() { 055 instance = null; 056 } 057 058 /** 059 * Get all active crawler traps. 060 * 061 * @return a list of all active crawler traps. 062 */ 063 public abstract List<GlobalCrawlerTrapList> getAllActive(); 064 065 /** 066 * Get all inactive crawler traps. 067 * 068 * @return a list of all inactive crawler traps. 069 */ 070 public abstract List<GlobalCrawlerTrapList> getAllInActive(); 071 072 /** 073 * Get a merged list (without duplicates) of all currently-active crawler trap expressions. 074 * 075 * @return a list os all active crawler trap expressions. 076 */ 077 public abstract List<String> getAllActiveTrapExpressions(); 078 079 // CRUD methods for this DAO. 080 081 /** 082 * This method creates the object in the database and has the side effect of setting the trapLists id field to the 083 * auto-generated id in the database. 084 * 085 * @param trapList The list to persist 086 * @return the id of the created list 087 * @throws ArgumentNotValid if the trapList is null. 088 */ 089 public abstract int create(GlobalCrawlerTrapList trapList) throws ArgumentNotValid; 090 091 /** 092 * Deletes a crawler trap list from the database. 093 * 094 * @param id the id of the list to be deleted 095 * @throws UnknownID if the argument doesn not correspond to a known trap list. 096 */ 097 public abstract void delete(int id) throws UnknownID; 098 099 /** 100 * Updates a given global crawler trap list. 101 * 102 * @param trapList the trap list to update 103 * @throws UnknownID if the id of the trapList argument does not correspond to an existing trap list in the 104 * database. 105 */ 106 public abstract void update(GlobalCrawlerTrapList trapList) throws UnknownID; 107 108 /** 109 * Get a traplist from the database. 110 * 111 * @param id the id of the traplist to be read. 112 * @return the trap list. 113 * @throws UnknownID if the id does not correspond to a known traplist in the database. 114 */ 115 public abstract GlobalCrawlerTrapList read(int id) throws UnknownID; 116 117 /** 118 * Does crawlertrap with this name already exist. 119 * 120 * @param name The name for a crawlertrap 121 * @return true, if a crawlertrap with the given name already exists in the database; otherwise false 122 */ 123 public abstract boolean exists(String name); 124 125 /** 126 * Reads a list of all active global crawler trap expressions from the database and adds them to the crawl template. 127 */ 128 public abstract void addGlobalCrawlerTraps(HeritrixTemplate orderXmlDoc); 129}