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.webinterface;
025
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029import dk.netarkivet.common.exceptions.UnknownID;
030import dk.netarkivet.common.utils.Settings;
031import dk.netarkivet.common.webinterface.SiteSection;
032import dk.netarkivet.harvester.HarvesterSettings;
033import dk.netarkivet.harvester.datamodel.DomainDAO;
034import dk.netarkivet.harvester.datamodel.GlobalCrawlerTrapListDAO;
035import dk.netarkivet.harvester.datamodel.HarvestDBConnection;
036import dk.netarkivet.harvester.datamodel.HarvestDefinitionDAO;
037import dk.netarkivet.harvester.datamodel.JobDAO;
038import dk.netarkivet.harvester.datamodel.ScheduleDAO;
039import dk.netarkivet.harvester.datamodel.TemplateDAO;
040import dk.netarkivet.harvester.harvesting.monitor.HarvestMonitor;
041import dk.netarkivet.harvester.tools.HarvestTemplateApplication;
042
043/**
044 * Site section that creates the menu for data definitions.
045 */
046public class DefinitionsSiteSection extends SiteSection {
047    /** Logger for this class. */
048    //private Log log = LogFactory.getLog(getClass().getName());
049    protected static final Logger log = LoggerFactory.getLogger(DefinitionsSiteSection.class);
050    /** number of pages visible in the left menu. */
051    private static final int PAGES_VISIBLE_IN_MENU = 10;
052
053    /**
054     * Create a new definition SiteSection object.
055     */
056    public DefinitionsSiteSection() {
057        super("sitesection;definitions", "Definitions", PAGES_VISIBLE_IN_MENU, new String[][] {
058                {"selective-harvests", "pagetitle;selective.harvests"},
059                {"snapshot-harvests", "pagetitle;snapshot.harvests"},
060                {"schedules", "pagetitle;schedules"},
061                {"find-domains", "pagetitle;find.domains"},
062                {"create-domain", "pagetitle;create.domain"},
063                {"domain-statistics", "pagetitle;domain.statistics"},
064                {"alias-summary", "pagetitle;alias.summary"},
065                {"edit-harvest-templates", "pagetitle;edit.harvest.templates"},
066                {"edit-global-crawler-traps", "pagetitle;edit.global.crawler.traps"},
067                {"list-extendedfields", "pagetitle;list-extendedfields"},
068                // The pages listed below are not visible in the left menu
069                {"upload-harvest-template", "pagetitle;upload.template"},
070                {"download-harvest-template", "pagetitle;download.template"},
071                {"edit-snapshot-harvest", "pagetitle;snapshot.harvest"},
072                {"edit-selective-harvest", "pagetitle;selective.harvest"}, {"edit-domain", "pagetitle;edit.domain"},
073                {"ingest-domains", "pagetitle;ingest.domains"}, {"add-event-seeds", "pagetitle;add.seeds"},
074                {"edit-domain-config", "pagetitle;edit.configuration"},
075                {"edit-domain-seedlist", "pagetitle;edit.seed.list"}, {"edit-schedule", "pagetitle;edit.schedule"},
076                {"edit-extendedfield", "pagetitle;edit.extendedfield"}}, "HarvestDefinition",
077                dk.netarkivet.harvester.Constants.TRANSLATIONS_BUNDLE);
078    }
079
080    /**
081     * Initialise the site section.
082     *
083     * @throws UnknownID If the default order.xml does not exist.
084     */
085    public void initialize() {
086        // Force migration if needed
087        TemplateDAO templateDao = TemplateDAO.getInstance();
088        // Enforce, that the default harvest-template set by
089        // Settings.DOMAIN_DEFAULT_ORDERXML should exist.
090        if (!templateDao.exists(Settings.get(HarvesterSettings.DOMAIN_DEFAULT_ORDERXML))) {
091            String message = "The default order template '" + Settings.get(HarvesterSettings.DOMAIN_DEFAULT_ORDERXML)
092                    + "' does not exist in the template DAO. Please use the "
093                    + HarvestTemplateApplication.class.getName() + " tool to upload this template before"
094                    + " loading the Definitions site section in the" + " GUIApplication";
095            log.error(message);
096            throw new UnknownID(message);
097        }
098
099        DomainDAO.getInstance();
100        ScheduleDAO.getInstance();
101        HarvestDefinitionDAO.getInstance();
102        JobDAO.getInstance();
103        GlobalCrawlerTrapListDAO.getInstance();
104        // Start the harvest monitor sever
105        HarvestMonitor.getInstance();
106    }
107
108    /** Release DB resources. */
109    public void close() {
110        HarvestDBConnection.cleanup();
111    }
112}