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 */
023package dk.netarkivet.harvester.datamodel;
024
025import dk.netarkivet.common.exceptions.ArgumentNotValid;
026import dk.netarkivet.harvester.datamodel.dao.DAOProviderFactory;
027import dk.netarkivet.harvester.datamodel.extendedfield.ExtendableEntity;
028import dk.netarkivet.harvester.datamodel.extendedfield.ExtendedFieldTypes;
029
030/**
031 * Sparse version of FullHarvest to be used for GUI purposes only. Immutable. For GUI purposes only.
032 *
033 * @see FullHarvest
034 */
035public class SparseFullHarvest extends ExtendableEntity {
036
037    /** ID of this harvest. */
038    private final Long oid;
039    /** Name of this harvest. */
040    private final String name;
041    /** Comments on this harvest. */
042    private final String comments;
043    /** Number of times this harvest has run. */
044    private final int numEvents;
045    /** True if harvest is active. */
046    private final boolean active;
047    /** Current edition of harvest. */
048    private final long edition;
049    /** The maximum number of objects retrieved from each domain during a snapshot harvest. */
050    private long maxCountObjects;
051    /** The maximum number of bytes retrieved from each domain during a snapshot harvest. */
052    private long maxBytes;
053
054    /** The maximum number of time available to the harvester for each job generated by this harvestdefinition. */
055    private long maxJobRunningTime;
056
057    /** The ID for the harvestdefinition, this FullHarvest is based upon. */
058    private Long previousHarvestDefinitionOid;
059
060    /** The id of the associated harvest channel, or null if the default one is to be used. */
061    private Long channelId;
062
063    /**
064     * Create new instance of SparseFullHarvest.
065     *
066     * @param oid id of this harvest.
067     * @param harvestDefName the name of the harvest definition.
068     * @param comments comments.
069     * @param numEvents Number of times this harvest has run.
070     * @param active Whether this harvest definition is active.
071     * @param edition DAO edition of harvest.
072     * @param maxCountObjects Limit for how many objects can be harvested
073     * @param maxBytes Limit for how many bytes can be harvested
074     * @param maxJobRunningTime Limit on how much time can be used for this job. See {@link #getMaxJobRunningTime()}
075     * @param previousFullHarvest This id of the harvestDefinition used to create this Fullharvest definition. May be
076     * null for none
077     * @param channelId the channel id, or null for the default one
078     * @throws ArgumentNotValid if oid, name or comments is null, or name is empty.
079     */
080    public SparseFullHarvest(Long oid, String harvestDefName, String comments, int numEvents, boolean active,
081            long edition, long maxCountObjects, long maxBytes, long maxJobRunningTime, Long previousFullHarvest,
082            Long channelId) {
083        super(DAOProviderFactory.getExtendedFieldDAOProvider());
084        ArgumentNotValid.checkNotNull(oid, "oid");
085        ArgumentNotValid.checkNotNullOrEmpty(harvestDefName, "harvestDefName");
086        ArgumentNotValid.checkNotNull(comments, "comments");
087
088        this.oid = oid;
089        this.name = harvestDefName;
090        this.comments = comments;
091        this.numEvents = numEvents;
092        this.active = active;
093        this.edition = edition;
094        this.maxCountObjects = maxCountObjects;
095        this.maxBytes = maxBytes;
096        this.maxJobRunningTime = maxJobRunningTime;
097        this.previousHarvestDefinitionOid = previousFullHarvest;
098        this.channelId = channelId;
099    }
100
101    /**
102     * Get ID of HarvestDefinition which this is based on, or null for none.
103     *
104     * @return The previous HarvestDefinition, or null for none
105     */
106    public Long getPreviousHarvestDefinitionOid() {
107        return previousHarvestDefinitionOid;
108    }
109
110    /**
111     * Get the maximum number of objects that this fullharvest will harvest per domain, -1 for no limit.
112     *
113     * @return Total download limit in objects per domain.
114     */
115    public long getMaxCountObjects() {
116        return maxCountObjects;
117    }
118
119    /**
120     * Get the maximum number of bytes that this fullharvest will harvest per domain, -1 for no limit.
121     *
122     * @return Total download limit in bytes per domain.
123     */
124    public long getMaxBytes() {
125        return maxBytes;
126    }
127
128    /**
129     * Get the maximum number of time in seconds that each job in this fullharvest will take. 0 for no limit.
130     *
131     * @return the maximum number of time in seconds for each job in this fullharvest.
132     */
133    public long getMaxJobRunningTime() {
134        return maxJobRunningTime;
135    }
136
137    /**
138     * Name of harvest definition.
139     *
140     * @return Name of harvest definition.
141     */
142    public String getName() {
143        return name;
144    }
145
146    /**
147     * Comments for harvest definition.
148     *
149     * @return Comments for harvest definition.
150     */
151    public String getComments() {
152        return comments;
153    }
154
155    /**
156     * Number of times this harvest has run.
157     *
158     * @return Number of times this harvest has run.
159     */
160    public int getNumEvents() {
161        return numEvents;
162    }
163
164    /**
165     * ID of this harvest.
166     *
167     * @return ID of this harvest.
168     */
169    public Long getOid() {
170        return oid;
171    }
172
173    /**
174     * Whether harvest is active.
175     *
176     * @return Whether harvest is active.
177     */
178    public boolean isActive() {
179        return active;
180    }
181
182    /**
183     * DAO edition of harvest definition.
184     *
185     * @return DAO edition of harvest definition.
186     */
187    public long getEdition() {
188        return edition;
189    }
190
191    protected Long getChannelId() {
192        return channelId;
193    }
194
195    @Override
196    protected int getExtendedFieldType() {
197        return ExtendedFieldTypes.HARVESTDEFINITION;
198    }
199
200}