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.Date;
027import java.util.HashMap;
028import java.util.Map;
029
030/**
031 * Information on a single run of a harvest.
032 */
033public class HarvestRunInfo {
034
035    /** Which harvest def ID this is a run of. */
036    private final long harvestID;
037    /** The name of the harvest def. */
038    private final String harvestName;
039    /** Which run this is of the harvest. */
040    private final int runNr;
041    /** When the first job for this harvest started. */
042    private Date startDate;
043    /** When the last job for this harvest ended. */
044    private Date endDate;
045    /** How many bytes were harvested total. */
046    private long bytesHarvested;
047    /** How many documents were harvested total. */
048    private long docsHarvested;
049    /** Status of the jobs used to run this harvest. */
050    private final Map<JobStatus, Integer> jobCounts = new HashMap<JobStatus, Integer>();
051
052    /**
053     * Constructor used to read harvest run information from database.
054     *
055     * @param harvestID the ID of the harvest job
056     * @param harvestName the name of the harvest job
057     * @param runNr the run number of this harvest job
058     */
059    HarvestRunInfo(long harvestID, String harvestName, int runNr) {
060        this.harvestID = harvestID;
061        this.harvestName = harvestName;
062        this.runNr = runNr;
063    }
064
065    /** @return the harvest id of this job */
066    public long getHarvestID() {
067        return harvestID;
068    }
069
070    /** @return the harvest name of this job */
071    public String getHarvestName() {
072        return harvestName;
073    }
074
075    /** @return the harvest run number of this job */
076    public int getRunNr() {
077        return runNr;
078    }
079
080    /** @return the date when this job started */
081    public Date getStartDate() {
082        return startDate;
083    }
084
085    /** @return the date when this job ended */
086    public Date getEndDate() {
087        return endDate;
088    }
089
090    /** @return bytes harvested by the job */
091    public long getBytesHarvested() {
092        return bytesHarvested;
093    }
094
095    /** @return documents harvested by the job */
096    public long getDocsHarvested() {
097        return docsHarvested;
098    }
099
100    /**
101     * Get the total number of jobs created for this run.
102     *
103     * @return the total number of jobs created for this run.
104     */
105    public int getJobCount() {
106        int count = 0;
107        for (int c : jobCounts.values()) {
108            count += c;
109        }
110        return count;
111    }
112
113    /**
114     * Get the number of jobs for this run that are in a specific status.
115     *
116     * @param status the specific status
117     * @return the number of jobs for this run that are in a specific status.
118     */
119    public int getJobCount(JobStatus status) {
120        if (jobCounts.containsKey(status)) {
121            return jobCounts.get(status);
122        } else {
123            return 0;
124        }
125    }
126
127    /**
128     * Set the start Date for this harvest job.
129     *
130     * @param startDate the start date
131     */
132    public void setStartDate(Date startDate) {
133        this.startDate = startDate;
134    }
135
136    /**
137     * Set the end Date for this harvest job.
138     *
139     * @param endDate The end date
140     */
141    public void setEndDate(Date endDate) {
142        this.endDate = endDate;
143    }
144
145    /**
146     * Set the number of bytes harvested by this job.
147     *
148     * @param bytesHarvested number of bytes harvested
149     */
150    public void setBytesHarvested(long bytesHarvested) {
151        this.bytesHarvested = bytesHarvested;
152    }
153
154    /**
155     * Set the number of documents harvested by this job.
156     *
157     * @param docsHarvested number of documents harvested
158     */
159    public void setDocsHarvested(long docsHarvested) {
160        this.docsHarvested = docsHarvested;
161    }
162
163    /**
164     * Update the count for a specific jobstatus.
165     *
166     * @param status a certain JobStatus
167     * @param count the new count for this JobStatus.
168     */
169    public void setStatusCount(JobStatus status, int count) {
170        jobCounts.put(status, count);
171    }
172
173}