001/*
002 * #%L
003 * Netarchivesuite - harvester
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish 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    protected static final Logger log = LoggerFactory.getLogger(DefinitionsSiteSection.class);
049    /** number of pages visible in the left menu. */
050    private static final int PAGES_VISIBLE_IN_MENU = 10;
051
052    /**
053     * Create a new definition SiteSection object.
054     */
055    public DefinitionsSiteSection() {
056        super("sitesection;definitions", "Definitions", PAGES_VISIBLE_IN_MENU, new String[][] {
057                {"selective-harvests", "pagetitle;selective.harvests"},
058                {"snapshot-harvests", "pagetitle;snapshot.harvests"},
059                {"schedules", "pagetitle;schedules"},
060                {"find-domains", "pagetitle;find.domains"},
061                {"create-domain", "pagetitle;create.domain"},
062                {"domain-statistics", "pagetitle;domain.statistics"},
063                {"alias-summary", "pagetitle;alias.summary"},
064                {"edit-harvest-templates", "pagetitle;edit.harvest.templates"},
065                {"edit-global-crawler-traps", "pagetitle;edit.global.crawler.traps"},
066                {"list-extendedfields", "pagetitle;list-extendedfields"},
067                // The pages listed below are not visible in the left menu
068                {"upload-harvest-template", "pagetitle;upload.template"},
069                {"download-harvest-template", "pagetitle;download.template"},
070                {"edit-snapshot-harvest", "pagetitle;snapshot.harvest"},
071                {"edit-selective-harvest", "pagetitle;selective.harvest"}, {"edit-domain", "pagetitle;edit.domain"},
072                {"ingest-domains", "pagetitle;ingest.domains"}, {"add-event-seeds", "pagetitle;add.seeds"},
073                {"edit-domain-config", "pagetitle;edit.configuration"},
074                {"edit-domain-seedlist", "pagetitle;edit.seed.list"}, {"edit-schedule", "pagetitle;edit.schedule"},
075                {"edit-extendedfield", "pagetitle;edit.extendedfield"}}, "HarvestDefinition",
076                dk.netarkivet.harvester.Constants.TRANSLATIONS_BUNDLE);
077    }
078
079    /**
080     * Initialise the site section.
081     *
082     * @throws UnknownID If the default order.xml does not exist.
083     */
084    public void initialize() {
085        // Force migration if needed
086        TemplateDAO templateDao = TemplateDAO.getInstance();
087        // Enforce, that the default harvest-template set by
088        // Settings.DOMAIN_DEFAULT_ORDERXML should exist.
089        if (!templateDao.exists(Settings.get(HarvesterSettings.DOMAIN_DEFAULT_ORDERXML))) {
090            String message = "The default order template '" + Settings.get(HarvesterSettings.DOMAIN_DEFAULT_ORDERXML)
091                    + "' does not exist in the template DAO. Please use the "
092                    + HarvestTemplateApplication.class.getName() + " tool to upload this template before"
093                    + " loading the Definitions site section in the" + " GUIApplication";
094            log.error(message);
095            throw new UnknownID(message);
096        }
097
098        DomainDAO.getInstance();
099        ScheduleDAO.getInstance();
100        HarvestDefinitionDAO.getInstance();
101        JobDAO.getInstance();
102        GlobalCrawlerTrapListDAO.getInstance();
103        // Start the harvest monitor sever
104        HarvestMonitor.getInstance();
105    }
106
107    /** Release DB resources. */
108    public void close() {
109        HarvestDBConnection.cleanup();
110    }
111}