dk.netarkivet.harvester.datamodel
Class HarvestDefinitionDAO

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.HarvestDefinitionDAO
All Implemented Interfaces:
java.lang.Iterable<HarvestDefinition>
Direct Known Subclasses:
HarvestDefinitionDBDAO

public abstract class HarvestDefinitionDAO
extends java.lang.Object
implements java.lang.Iterable<HarvestDefinition>

A Data Access Object for harvest definitions. This object is a singleton to ensure thread-safety. It handles the transformation from harvest definitions to persistent storage.


Field Summary
protected  org.apache.commons.logging.Log log
          The log.
 
Constructor Summary
protected HarvestDefinitionDAO()
          Default constructor.
 
Method Summary
abstract  java.lang.Long create(HarvestDefinition harvestDefinition)
          Create a harvest definition in persistent storage.
abstract  boolean exists(java.lang.Long oid)
          Check, if there exists a HarvestDefinition identified by a given OID.
abstract  void flipActive(SparsePartialHarvest harvestDefinition)
          Activates or deactivates a partial harvest definition, depending on its activation status.
abstract  java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
          Get a list of all existing harvest definitions.
abstract  java.lang.Iterable<SparseFullHarvest> getAllSparseFullHarvestDefinitions()
          Get all sparse versions of full harvests for GUI purposes.
abstract  java.lang.Iterable<SparsePartialHarvest> getAllSparsePartialHarvestDefinitions()
          Get all sparse versions of partial harvests for GUI purposes.
abstract  HarvestDefinition getHarvestDefinition(java.lang.String name)
          Get the harvest definition that has the given name, or null, if no harvestdefinition exist with this name.
abstract  java.lang.String getHarvestName(java.lang.Long harvestDefinitionID)
          Get the name of a harvest given its ID.
abstract  java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
          Returns a list with information on the runs of a particular harvest.
static HarvestDefinitionDAO getInstance()
          Creates the singleton.
abstract  java.util.Set<java.lang.Long> getJobIdsForSnapshotDeduplicationIndex(java.lang.Long harvestId)
          Get a collection of jobIds for snapshot deduplication index.
abstract  java.util.List<java.lang.String> getListOfDomainsOfHarvestDefinition(java.lang.String harvestName)
          Get a sorted list of all domainnames of a HarvestDefintion
abstract  java.util.List<java.lang.String> getListOfSeedsOfDomainOfHarvestDefinition(java.lang.String harvestName, java.lang.String domainName)
          Get a sorted list of all seeds of a Domain in a HarvestDefinition.
abstract  java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
          Get the IDs of the harvest definitions that are ready to run.
abstract  java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
          Gets default configurations for all domains.
abstract  java.util.List<SparseDomainConfiguration> getSparseDomainConfigurations(java.lang.Long harvestDefinitionID)
          Get all domain,configuration pairs for a harvest definition in sparse version for GUI purposes.
abstract  SparseFullHarvest getSparseFullHarvest(java.lang.String harvestName)
          Get a sparse version of a full harvest for GUI purposes.
abstract  SparsePartialHarvest getSparsePartialHarvest(java.lang.String harvestName)
          Get a sparse version of a partial harvest for GUI purposes.
abstract  boolean isSnapshot(java.lang.Long harvestDefinitionID)
          Get whether a given harvest is a snapshot or selective harvest.
 java.util.Iterator<HarvestDefinition> iterator()
          Get an iterator of all harvest definitions.
abstract  HarvestDefinition read(java.lang.Long harvestDefinitionID)
          Read the stored harvest definition for the given ID.
(package private) static void reset()
          Reset the DAO instance.
abstract  void setIndexIsReady(java.lang.Long harvestId, boolean newValue)
          Set the isindexready field available for snapshot harvests.
abstract  void update(HarvestDefinition harvestDefinition)
          Update an existing harvest definition with new info in persistent storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
The log.

Constructor Detail

HarvestDefinitionDAO

protected HarvestDefinitionDAO()
Default constructor. Does not do anything, however.

Method Detail

getInstance

public static HarvestDefinitionDAO getInstance()
Creates the singleton.

Returns:
the HarvestDefinitionDAO singleton.
Throws:
IOFailure - if unable to create the singleton.

create

public abstract java.lang.Long create(HarvestDefinition harvestDefinition)
Create a harvest definition in persistent storage.

Parameters:
harvestDefinition - A new harvest definition to write out.
Returns:
The harvestId for the just created harvest definition.

read

public abstract HarvestDefinition read(java.lang.Long harvestDefinitionID)
                                throws UnknownID,
                                       IOFailure
Read the stored harvest definition for the given ID.

Parameters:
harvestDefinitionID - An ID number for a harvest definition
Returns:
A harvest definition that has been read from persistent storage.
Throws:
UnknownID - if no file with that ID exists
IOFailure - if the File does not exist, does not have the correct ID, or otherwise fails to load correctly.

update

public abstract void update(HarvestDefinition harvestDefinition)
Update an existing harvest definition with new info in persistent storage.

Parameters:
harvestDefinition - An updated harvest definition object to be persisted.

flipActive

public abstract void flipActive(SparsePartialHarvest harvestDefinition)
Activates or deactivates a partial harvest definition, depending on its activation status.

Parameters:
harvestDefinition - the harvest definition object

exists

public abstract boolean exists(java.lang.Long oid)
Check, if there exists a HarvestDefinition identified by a given OID.

Parameters:
oid - a given OID
Returns:
true, if such a harvestdefinition exists.

getAllHarvestDefinitions

public abstract java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
Get a list of all existing harvest definitions.

Returns:
An iterator that give the existing harvest definitions in turn

iterator

public java.util.Iterator<HarvestDefinition> iterator()
Get an iterator of all harvest definitions. Implements the Iterable interface.

Specified by:
iterator in interface java.lang.Iterable<HarvestDefinition>
Returns:
Iterator of all harvest definitions, Selective and Full both.

getSnapShotConfigurations

public abstract java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
Gets default configurations for all domains.

Returns:
Iterator containing the default DomainConfiguration for all domains

getReadyHarvestDefinitions

public abstract java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
Get the IDs of the harvest definitions that are ready to run.

Parameters:
now -
Returns:
IDs of the harvest definitions that are currently ready to be scheduled. Some of these might already be in the process of being scheduled.

getHarvestDefinition

public abstract HarvestDefinition getHarvestDefinition(java.lang.String name)
Get the harvest definition that has the given name, or null, if no harvestdefinition exist with this name.

Parameters:
name - The name of a harvest definition.
Returns:
The HarvestDefinition object with that name, or null if none has that name.

getHarvestRunInfo

public abstract java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
Returns a list with information on the runs of a particular harvest. The list is ordered by descending run number.

Parameters:
harvestID - ID of an existing harvest
Returns:
List of objects with selected information.

reset

static void reset()
Reset the DAO instance. Only for use in tests.


getSparseDomainConfigurations

public abstract java.util.List<SparseDomainConfiguration> getSparseDomainConfigurations(java.lang.Long harvestDefinitionID)
Get all domain,configuration pairs for a harvest definition in sparse version for GUI purposes.

Parameters:
harvestDefinitionID - The ID of the harvest definition.
Returns:
Domain,configuration pairs for that HD. Returns an empty list for unknown harvest definitions.
Throws:
ArgumentNotValid - on null argument.

getSparsePartialHarvest

public abstract SparsePartialHarvest getSparsePartialHarvest(java.lang.String harvestName)
Get a sparse version of a partial harvest for GUI purposes.

Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of partial harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.

getAllSparsePartialHarvestDefinitions

public abstract java.lang.Iterable<SparsePartialHarvest> getAllSparsePartialHarvestDefinitions()
Get all sparse versions of partial harvests for GUI purposes.

Returns:
An iterable (possibly empty) of SparsePartialHarvests

getSparseFullHarvest

public abstract SparseFullHarvest getSparseFullHarvest(java.lang.String harvestName)
Get a sparse version of a full harvest for GUI purposes.

Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of full harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.

getAllSparseFullHarvestDefinitions

public abstract java.lang.Iterable<SparseFullHarvest> getAllSparseFullHarvestDefinitions()
Get all sparse versions of full harvests for GUI purposes.

Returns:
An iterable (possibly empty) of SparseFullHarvests

getHarvestName

public abstract java.lang.String getHarvestName(java.lang.Long harvestDefinitionID)
Get the name of a harvest given its ID.

Parameters:
harvestDefinitionID - The ID of a harvest
Returns:
The name of the given harvest.
Throws:
ArgumentNotValid - on null argument
UnknownID - if no harvest has the given ID.
IOFailure - on any other error talking to the database

isSnapshot

public abstract boolean isSnapshot(java.lang.Long harvestDefinitionID)
Get whether a given harvest is a snapshot or selective harvest.

Parameters:
harvestDefinitionID - ID of a harvest
Returns:
True if the given harvest is a snapshot harvest, false otherwise.
Throws:
ArgumentNotValid - on null argument
UnknownID - if no harvest has the given ID.
IOFailure - on any other error talking to the database

getListOfDomainsOfHarvestDefinition

public abstract java.util.List<java.lang.String> getListOfDomainsOfHarvestDefinition(java.lang.String harvestName)
Get a sorted list of all domainnames of a HarvestDefintion

Parameters:
harvestName - of HarvestDefintion
Returns:
List of all domains of the HarvestDefinition.
Throws:
ArgumentNotValid - on null argument
IOFailure - on any other error talking to the database

getListOfSeedsOfDomainOfHarvestDefinition

public abstract java.util.List<java.lang.String> getListOfSeedsOfDomainOfHarvestDefinition(java.lang.String harvestName,
                                                                                           java.lang.String domainName)
Get a sorted list of all seeds of a Domain in a HarvestDefinition.

Parameters:
harvestName - of HarvestDefintion
domainName - of Domain
Returns:
List of all seeds of the Domain in the HarvestDefinition.
Throws:
ArgumentNotValid - on null argument
IOFailure - on any other error talking to the database

getJobIdsForSnapshotDeduplicationIndex

public abstract java.util.Set<java.lang.Long> getJobIdsForSnapshotDeduplicationIndex(java.lang.Long harvestId)
Get a collection of jobIds for snapshot deduplication index.

Parameters:
harvestId - the id of the harvest
Returns:
a collection of jobIds to create a deduplication index.

setIndexIsReady

public abstract void setIndexIsReady(java.lang.Long harvestId,
                                     boolean newValue)
Set the isindexready field available for snapshot harvests.

Parameters:
harvestId - the ID of the harvest.
newValue - the new isindexready value