net.datacrow.core.services
Class SearchTask

java.lang.Object
  extended by java.lang.Thread
      extended by net.datacrow.core.services.SearchTask
All Implemented Interfaces:
java.lang.Runnable

public abstract class SearchTask
extends java.lang.Thread

A search task performs the actual online search. The search task is used by the online search form (see OnlineSearchForm) and by processed such as the mass update. The search is performed in multiple steps. 1) First the online service (web page or web server) is queried using the input of the user (getItemKeys()). 2) For each result the item details are retrieved. See (run()) and #getItems(String, boolean) 3) The in step 2 retrieved items only contain the bare minimum of information. When the user (or any other process) selects one of the items the full details need to be retrieved (getItem(URL)) This class needs to be extended for specific implementations.

Author:
Robert Jan van der Waals

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int _ITEM_MODE_FULL
           
static int _ITEM_MODE_SIMPLE
           
protected  IOnlineSearchClient listener
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SearchTask(IOnlineSearchClient listener, IServer server, Region region, SearchMode mode, java.lang.String query)
          Creates the search task.
 
Method Summary
 void cancel()
          Cancel the search.
 java.lang.String getAddress()
          The currently used URL or address.
 DcObject getClient()
           
protected abstract  DcObject getItem(java.lang.Object key, boolean full)
          Query for the item using the web key.
protected abstract  DcObject getItem(java.net.URL url)
          Query for the item via the URL
protected abstract  java.util.Collection<java.lang.Object> getItemKeys()
          Get every web ID from the page.
 int getItemMode()
          Returns the retrieval mode: _ITEM_MODE_FULL or _ITEM_MODE_SIMPLE.
protected  java.util.Collection<DcObject> getItems(java.lang.Object key, boolean full)
          Query for the item(s) using the web key.
 int getMaximum()
          The maximum amount of items to be retrieved.
 SearchMode getMode()
          The currently used search mode.
 java.lang.String getQuery()
          The used query as specified by the user.
 Region getRegion()
          The currently used region
 IServer getServer()
          The currently used server
 java.lang.String getWhiteSpaceSubst()
          The character used to substitute white spaces from the query (see getQuery()).
 boolean isCancelled()
          Indicates if the search was (attempted) to be canceled.
 boolean isItemModeSupported()
           
protected  void preSearchCheck()
           
 DcObject query(DcObject dco)
          Queries for the specified item.
 void run()
          Here the actual search is performed.
 void setClient(DcObject client)
           
 void setItemMode(int mode)
          Sets the item retrieval mode: _ITEM_MODE_FULL or _ITEM_MODE_SIMPLE.
 void setMaximum(int maximum)
          Set the maximum amount of items to be retrieved.
 void setMode(SearchMode searchMode)
           
 void setQuery(java.lang.String query)
           
protected  void setServiceInfo(DcObject dco)
          Sets the service info.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_ITEM_MODE_SIMPLE

public static final int _ITEM_MODE_SIMPLE
See Also:
Constant Field Values

_ITEM_MODE_FULL

public static final int _ITEM_MODE_FULL
See Also:
Constant Field Values

listener

protected IOnlineSearchClient listener
Constructor Detail

SearchTask

public SearchTask(IOnlineSearchClient listener,
                  IServer server,
                  Region region,
                  SearchMode mode,
                  java.lang.String query)
Creates the search task.

Parameters:
listener -
server -
region -
mode -
query -
Method Detail

setServiceInfo

protected final void setServiceInfo(DcObject dco)
Sets the service info. This information is set on every item. This way Data Crow knows where the retrieved information originally came from.


setItemMode

public final void setItemMode(int mode)
Sets the item retrieval mode: _ITEM_MODE_FULL or _ITEM_MODE_SIMPLE.


isItemModeSupported

public boolean isItemModeSupported()

getItemMode

public final int getItemMode()
Returns the retrieval mode: _ITEM_MODE_FULL or _ITEM_MODE_SIMPLE.


setMaximum

public final void setMaximum(int maximum)
Set the maximum amount of items to be retrieved.


cancel

public final void cancel()
Cancel the search.


isCancelled

public final boolean isCancelled()
Indicates if the search was (attempted) to be canceled.


getAddress

public final java.lang.String getAddress()
The currently used URL or address.


getMode

public final SearchMode getMode()
The currently used search mode.

See Also:
SearchMode

getRegion

public final Region getRegion()
The currently used region

See Also:
Region.

getClient

public DcObject getClient()

setClient

public void setClient(DcObject client)

setQuery

public void setQuery(java.lang.String query)

setMode

public void setMode(SearchMode searchMode)

getQuery

public java.lang.String getQuery()
The used query as specified by the user.


getServer

public final IServer getServer()
The currently used server

See Also:
IServer

getMaximum

public final int getMaximum()
The maximum amount of items to be retrieved.


getWhiteSpaceSubst

public java.lang.String getWhiteSpaceSubst()
The character used to substitute white spaces from the query (see getQuery()). Should be overridden by specific implementations.


query

public DcObject query(DcObject dco)
               throws java.lang.Exception
Queries for the specified item. The service information (see setServiceInfo(DcObject)) is used to retrieve the information.

Parameters:
dco - The item to be updated.
Returns:
The retrieved item or null if no item could be found.
Throws:
java.lang.Exception

getItems

protected java.util.Collection<DcObject> getItems(java.lang.Object key,
                                                  boolean full)
                                           throws java.lang.Exception
Query for the item(s) using the web key. Note that a key is can be a fully qualified URL, an external ID or something else.

Parameters:
key - The item key (The specific implementation decides the meaning of a key)
full - Indicates if the full details should be retrieved.
Throws:
java.lang.Exception

getItem

protected abstract DcObject getItem(java.lang.Object key,
                                    boolean full)
                             throws java.lang.Exception
Query for the item using the web key.

Parameters:
key - The item key (The specific implementation decides the meaning of a key)
full - Indicates if the full details should be retrieved.
Throws:
java.lang.Exception

getItem

protected abstract DcObject getItem(java.net.URL url)
                             throws java.lang.Exception
Query for the item via the URL

Parameters:
url - The direct link to the external item details.
Throws:
java.lang.Exception

getItemKeys

protected abstract java.util.Collection<java.lang.Object> getItemKeys()
                                                               throws java.lang.Exception
Get every web ID from the page. With these IDs it should be possible to get to the detailed item information.

Returns:
The item keys or an empty collection.
Throws:
java.lang.Exception

preSearchCheck

protected void preSearchCheck()

run

public void run()
Here the actual search is performed. This is a standard implementation suited for all online searches.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread