mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Undo overzealous reindentation.
I went overboard while trying to make things more readable. That can wait for another time. Some minor rewrapping, punctuation, etc. of comments stands.
This commit is contained in:
@@ -375,46 +375,44 @@ public class MetadataUtilities {
|
||||
}
|
||||
|
||||
/**
|
||||
* rewrite of ItemImport's functionality
|
||||
* Rewrite of ItemImport's functionality
|
||||
* but just the parsing of the file, not the processing of its elements.
|
||||
*
|
||||
* @param f file of item metadata.
|
||||
* @validate flag to verify matching files in tree.
|
||||
* @return parsed content of {@code f}.
|
||||
*
|
||||
* @validate flag to verify matching files in tree
|
||||
*/
|
||||
public static List<ContentsEntry> readContentsFile(File f)
|
||||
throws FileNotFoundException, IOException, ParseException
|
||||
{
|
||||
List<ContentsEntry> list = new ArrayList<ContentsEntry>();
|
||||
|
||||
|
||||
BufferedReader in = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
in = new BufferedReader(new FileReader(f));
|
||||
String line = null;
|
||||
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
line = line.trim();
|
||||
if ("".equals(line))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ItemUpdate.pr("Contents entry: " + line);
|
||||
list.add(ContentsEntry.parse(line));
|
||||
}
|
||||
in = new BufferedReader(new FileReader(f));
|
||||
String line = null;
|
||||
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
line = line.trim();
|
||||
if ("".equals(line))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ItemUpdate.pr("Contents entry: " + line);
|
||||
list.add(ContentsEntry.parse(line));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//skip
|
||||
}
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//skip
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -440,7 +438,7 @@ public class MetadataUtilities {
|
||||
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
line = line.trim();
|
||||
line = line.trim();
|
||||
if ("".equals(line))
|
||||
{
|
||||
continue;
|
||||
@@ -450,7 +448,7 @@ public class MetadataUtilities {
|
||||
try
|
||||
{
|
||||
n = Integer.parseInt(line);
|
||||
list.add(n);
|
||||
list.add(n);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
@@ -460,13 +458,13 @@ public class MetadataUtilities {
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
in.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//skip
|
||||
//skip
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,7 +473,7 @@ public class MetadataUtilities {
|
||||
|
||||
/**
|
||||
* Get display of DCValue
|
||||
*
|
||||
*
|
||||
* @param dcv
|
||||
* @return string displaying elements of the DCValue
|
||||
*/
|
||||
@@ -485,47 +483,47 @@ public class MetadataUtilities {
|
||||
"; language: " + dcv.language + "; value: " + dcv.value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a String representation of the two- or three-part form of a metadata element
|
||||
* e.g. dc.identifier.uri
|
||||
*/
|
||||
public static String getCompoundForm(String schema, String element, String qualifier)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(schema).append(".").append(element);
|
||||
|
||||
if (qualifier != null)
|
||||
{
|
||||
sb.append(".").append(qualifier);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return a String representation of the two- or three-part form of a metadata element
|
||||
* e.g. dc.identifier.uri
|
||||
*/
|
||||
public static String getCompoundForm(String schema, String element, String qualifier)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(schema).append(".").append(element);
|
||||
|
||||
if (qualifier != null)
|
||||
{
|
||||
sb.append(".").append(qualifier);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses metadata field given in the form "<schema>.<element>[.<qualifier>|.*]".
|
||||
* Checks for correct number of elements (2 or 3) and for empty strings.
|
||||
*
|
||||
* @return String Array
|
||||
* @throws ParseException if validity checks fail
|
||||
*
|
||||
*/
|
||||
public static String[] parseCompoundForm(String compoundForm)
|
||||
/**
|
||||
* Parses metadata field given in the form <schema>.<element>[.<qualifier>|.*]
|
||||
* checks for correct number of elements (2 or 3) and for empty strings
|
||||
*
|
||||
* @return String Array
|
||||
* @throws ParseException if validity checks fail
|
||||
*
|
||||
*/
|
||||
public static String[] parseCompoundForm(String compoundForm)
|
||||
throws ParseException
|
||||
{
|
||||
String[] ar = compoundForm.split("\\s*\\.\\s*"); //trim ends
|
||||
|
||||
if ("".equals(ar[0]))
|
||||
{
|
||||
throw new ParseException("schema is empty string: " + compoundForm, 0);
|
||||
}
|
||||
|
||||
if ((ar.length < 2) || (ar.length > 3) || "".equals(ar[1]))
|
||||
{
|
||||
throw new ParseException("element is malformed or empty string: " + compoundForm, 0);
|
||||
}
|
||||
|
||||
return ar;
|
||||
}
|
||||
|
||||
{
|
||||
String[] ar = compoundForm.split("\\s*\\.\\s*"); //trim ends
|
||||
|
||||
if ("".equals(ar[0]))
|
||||
{
|
||||
throw new ParseException("schema is empty string: " + compoundForm, 0);
|
||||
}
|
||||
|
||||
if ((ar.length < 2) || (ar.length > 3) || "".equals(ar[1]))
|
||||
{
|
||||
throw new ParseException("element is malformed or empty string: " + compoundForm, 0);
|
||||
}
|
||||
|
||||
return ar;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import org.dspace.sort.SortException;
|
||||
*/
|
||||
public final class BrowseIndex
|
||||
{
|
||||
/** the configuration number, as specified in the config */
|
||||
/** the configuration number, as specified in the config */
|
||||
/** used for single metadata browse tables for generating the table name */
|
||||
private int number;
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for creating generic / internal index objects.
|
||||
* Constructor for creating generic / internal index objects
|
||||
* @param baseName The base of the table name
|
||||
*/
|
||||
private BrowseIndex(String baseName)
|
||||
@@ -223,25 +223,25 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the datatype.
|
||||
*/
|
||||
public String getDataType()
|
||||
{
|
||||
* @return Returns the datatype.
|
||||
*/
|
||||
public String getDataType()
|
||||
{
|
||||
if (sortOption != null)
|
||||
{
|
||||
return sortOption.getType();
|
||||
}
|
||||
{
|
||||
return sortOption.getType();
|
||||
}
|
||||
|
||||
return datatype;
|
||||
}
|
||||
return datatype;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the displayType.
|
||||
*/
|
||||
public String getDisplayType()
|
||||
{
|
||||
/**
|
||||
* @return Returns the displayType.
|
||||
*/
|
||||
public String getDisplayType()
|
||||
{
|
||||
return displayType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the number of metadata fields for this index
|
||||
@@ -257,67 +257,67 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the mdBits.
|
||||
*/
|
||||
public String[] getMdBits(int idx)
|
||||
{
|
||||
if (isMetadataIndex())
|
||||
{
|
||||
return mdBits[idx];
|
||||
}
|
||||
* @return Returns the mdBits.
|
||||
*/
|
||||
public String[] getMdBits(int idx)
|
||||
{
|
||||
if (isMetadataIndex())
|
||||
{
|
||||
return mdBits[idx];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the metadata.
|
||||
*/
|
||||
public String getMetadata()
|
||||
{
|
||||
/**
|
||||
* @return Returns the metadata.
|
||||
*/
|
||||
public String getMetadata()
|
||||
{
|
||||
return metadataAll;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMetadata(int idx)
|
||||
{
|
||||
return metadata[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
// public void setName(String name)
|
||||
// {
|
||||
// this.name = name;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the SortOption associated with this index.
|
||||
*/
|
||||
public SortOption getSortOption()
|
||||
{
|
||||
return sortOption;
|
||||
}
|
||||
/**
|
||||
* Get the SortOption associated with this index.
|
||||
*/
|
||||
public SortOption getSortOption()
|
||||
{
|
||||
return sortOption;
|
||||
}
|
||||
|
||||
public boolean isDisplayFrequencies() {
|
||||
return displayFrequencies;
|
||||
}
|
||||
|
||||
public boolean isDisplayFrequencies() {
|
||||
return displayFrequencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the internal array containing the bits of metadata, for
|
||||
* ease of use later
|
||||
*/
|
||||
public void generateMdBits()
|
||||
/**
|
||||
* Populate the internal array containing the bits of metadata, for
|
||||
* ease of use later
|
||||
*/
|
||||
public void generateMdBits()
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
if (isMetadataIndex())
|
||||
{
|
||||
mdBits = new String[metadata.length][];
|
||||
@@ -334,13 +334,13 @@ public final class BrowseIndex
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the sequence that will be used in the given circumstances
|
||||
*
|
||||
* @param isDistinct is a distinct table
|
||||
* @param isMap is a map table
|
||||
* @return the name of the sequence
|
||||
*/
|
||||
/**
|
||||
* Get the name of the sequence that will be used in the given circumstances
|
||||
*
|
||||
* @param isDistinct is a distinct table
|
||||
* @param isMap is a map table
|
||||
* @return the name of the sequence
|
||||
*/
|
||||
public String getSequenceName(boolean isDistinct, boolean isMap)
|
||||
{
|
||||
if (isDistinct || isMap)
|
||||
@@ -369,6 +369,7 @@ public final class BrowseIndex
|
||||
* @param baseName
|
||||
* @param isDistinct
|
||||
* @param isMap
|
||||
* @return
|
||||
*/
|
||||
private static String getSequenceName(String baseName, boolean isDistinct, boolean isMap)
|
||||
{
|
||||
@@ -411,7 +412,7 @@ public final class BrowseIndex
|
||||
* @param isCollection
|
||||
* @param isDistinct
|
||||
* @param isMap
|
||||
* @return the name of the table.
|
||||
* @return
|
||||
*/
|
||||
private static String getTableName(String baseName, boolean isCommunity, boolean isCollection, boolean isDistinct, boolean isMap)
|
||||
{
|
||||
@@ -442,7 +443,7 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the table in the given circumstances.
|
||||
* Get the name of the table in the given circumstances
|
||||
*
|
||||
* @param isCommunity whether this is a community constrained index (view)
|
||||
* @param isCollection whether this is a collection constrained index (view)
|
||||
@@ -484,8 +485,6 @@ public final class BrowseIndex
|
||||
* <code>
|
||||
* getTableName(false, false, false, false);
|
||||
* </code>
|
||||
*
|
||||
* @return the name of the table.
|
||||
*/
|
||||
public String getTableName()
|
||||
{
|
||||
@@ -493,7 +492,7 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table name for the given set of circumstances
|
||||
* Get the table name for the given set of circumstances.
|
||||
*
|
||||
* This is the same as calling:
|
||||
*
|
||||
@@ -504,7 +503,6 @@ public final class BrowseIndex
|
||||
* @param isDistinct is this a distinct table
|
||||
* @param isCommunity
|
||||
* @param isCollection
|
||||
* @return the name of the table.
|
||||
* @deprecated 1.5
|
||||
*/
|
||||
public String getTableName(boolean isDistinct, boolean isCommunity, boolean isCollection)
|
||||
@@ -518,8 +516,6 @@ public final class BrowseIndex
|
||||
* <code>
|
||||
* getTableName(false, false, false, true);
|
||||
* </code>
|
||||
*
|
||||
* @return the name of the table.
|
||||
*/
|
||||
public String getMapTableName()
|
||||
{
|
||||
@@ -532,8 +528,6 @@ public final class BrowseIndex
|
||||
* <code>
|
||||
* getTableName(false, false, true, false);
|
||||
* </code>
|
||||
*
|
||||
* @return the name of the table.
|
||||
*/
|
||||
public String getDistinctTableName()
|
||||
{
|
||||
@@ -629,7 +623,6 @@ public final class BrowseIndex
|
||||
|
||||
/**
|
||||
* Get the field for sorting associated with this index.
|
||||
* @return the name of the field.
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public String getSortField(boolean isSecondLevel) throws BrowseException
|
||||
@@ -655,11 +648,7 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of the names of all the browse index tables in the current
|
||||
* configuration.
|
||||
*
|
||||
* @deprecated
|
||||
* @return names of all the current browse index tables.
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public static String[] tables()
|
||||
@@ -730,10 +719,9 @@ public final class BrowseIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configured browse index that is defined to use this sort option
|
||||
* Get the configured browse index that is defined to use this sort option.
|
||||
*
|
||||
* @param so
|
||||
* @return the associated BrowseIndex.
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public static BrowseIndex getBrowseIndex(SortOption so) throws BrowseException
|
||||
|
@@ -37,17 +37,17 @@ import java.util.List;
|
||||
*/
|
||||
public class BrowseItem extends DSpaceObject
|
||||
{
|
||||
/** Logger */
|
||||
/** Logger */
|
||||
private static Logger log = Logger.getLogger(BrowseItem.class);
|
||||
|
||||
/** DSpace context */
|
||||
private Context context;
|
||||
private Context context;
|
||||
|
||||
/** a List of all the metadata */
|
||||
private List<DCValue> metadata = new ArrayList<DCValue>();
|
||||
/** a List of all the metadata */
|
||||
private List<DCValue> metadata = new ArrayList<DCValue>();
|
||||
|
||||
/** database id of the item */
|
||||
private int id = -1;
|
||||
/** database id of the item */
|
||||
private int id = -1;
|
||||
|
||||
/** is the item in the archive */
|
||||
private boolean in_archive = true;
|
||||
@@ -56,37 +56,37 @@ public class BrowseItem extends DSpaceObject
|
||||
private boolean withdrawn = false;
|
||||
|
||||
/** item handle */
|
||||
private String handle = null;
|
||||
private String handle = null;
|
||||
|
||||
/**
|
||||
* Construct a new browse item with the given context and the database id
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* Construct a new browse item with the given context and the database id
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param id the database id of the item
|
||||
* @param in_archive
|
||||
* @param withdrawn
|
||||
*/
|
||||
public BrowseItem(Context context, int id, boolean in_archive, boolean withdrawn)
|
||||
{
|
||||
this.context = context;
|
||||
this.id = id;
|
||||
public BrowseItem(Context context, int id, boolean in_archive, boolean withdrawn)
|
||||
{
|
||||
this.context = context;
|
||||
this.id = id;
|
||||
this.in_archive = in_archive;
|
||||
this.withdrawn = withdrawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get String array of metadata values matching the given parameters
|
||||
*
|
||||
* @param schema metadata schema
|
||||
* @param element metadata element
|
||||
* @param qualifier metadata qualifier
|
||||
* @param lang metadata language
|
||||
* @return array of matching values
|
||||
* @throws SQLException
|
||||
*/
|
||||
public DCValue[] getMetadata(String schema, String element, String qualifier, String lang)
|
||||
throws SQLException
|
||||
{
|
||||
/**
|
||||
* Get String array of metadata values matching the given parameters
|
||||
*
|
||||
* @param schema metadata schema
|
||||
* @param element metadata element
|
||||
* @param qualifier metadata qualifier
|
||||
* @param lang metadata language
|
||||
* @return array of matching values
|
||||
* @throws SQLException
|
||||
*/
|
||||
public DCValue[] getMetadata(String schema, String element, String qualifier, String lang)
|
||||
throws SQLException
|
||||
{
|
||||
try
|
||||
{
|
||||
BrowseItemDAO dao = BrowseDAOFactory.getItemInstance(context);
|
||||
@@ -146,55 +146,54 @@ public class BrowseItem extends DSpaceObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of object. This object masquerades as an Item, so this
|
||||
* returns the value of Constants.ITEM
|
||||
*
|
||||
*@return Constants.ITEM
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return Constants.ITEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param real
|
||||
* @return real type, or Constants.ITEM.
|
||||
*/
|
||||
public int getType(boolean real)
|
||||
{
|
||||
if (!real)
|
||||
{
|
||||
/**
|
||||
* Get the type of object. This object masquerades as an Item, so this
|
||||
* returns the value of Constants.ITEM
|
||||
*
|
||||
*@return Constants.ITEM
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return Constants.ITEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the database id of the item
|
||||
*
|
||||
* @return database id of item
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param real
|
||||
*/
|
||||
public int getType(boolean real)
|
||||
{
|
||||
if (!real)
|
||||
{
|
||||
return Constants.ITEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getType();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the database id of the item
|
||||
*
|
||||
* @return database id of item
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database id of the item
|
||||
*
|
||||
* @param id the database id of the item
|
||||
*/
|
||||
public void setID(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the database id of the item
|
||||
*
|
||||
* @param id the database id of the item
|
||||
*/
|
||||
public void setID(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for pattern-matching metadata elements. This
|
||||
* method will return <code>true</code> if the given schema,
|
||||
* element, qualifier and language match the schema, element,
|
||||
@@ -273,36 +272,36 @@ public class BrowseItem extends DSpaceObject
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.dspace.content.DSpaceObject#getHandle()
|
||||
*/
|
||||
public String getHandle()
|
||||
{
|
||||
// Get our Handle if any
|
||||
if (this.handle == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.handle = HandleManager.findHandle(context, this);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
}
|
||||
}
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a thumbnail object out of the item.
|
||||
*
|
||||
* Warning: using this method actually instantiates an Item, which has a
|
||||
* corresponding performance hit on the database during browse listing
|
||||
* rendering. That's your own fault for wanting to put images on your
|
||||
* browse page!
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see org.dspace.content.DSpaceObject#getHandle()
|
||||
*/
|
||||
public String getHandle()
|
||||
{
|
||||
// Get our Handle if any
|
||||
if (this.handle == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.handle = HandleManager.findHandle(context, this);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
}
|
||||
}
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a thumbnail object out of the item.
|
||||
*
|
||||
* Warning: using this method actually instantiates an Item, which has a
|
||||
* corresponding performance hit on the database during browse listing
|
||||
* rendering. That's your own fault for wanting to put images on your
|
||||
* browse page!
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Thumbnail getThumbnail()
|
||||
throws SQLException
|
||||
{
|
||||
@@ -369,19 +368,19 @@ public class BrowseItem extends DSpaceObject
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
public String getName()
|
||||
{
|
||||
// FIXME: there is an exception handling problem here
|
||||
try
|
||||
{
|
||||
DCValue t[] = getMetadata("dc", "title", null, Item.ANY);
|
||||
return (t.length >= 1) ? t[0].value : null;
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
try
|
||||
{
|
||||
DCValue t[] = getMetadata("dc", "title", null, Item.ANY);
|
||||
return (t.length >= 1) ? t[0].value : null;
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
log.error("caught exception: ", sqle);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -22,55 +22,54 @@ import org.dspace.core.ConfigurationManager;
|
||||
*/
|
||||
public class CrossLinks
|
||||
{
|
||||
/** a map of the desired links */
|
||||
private Map<String, String> links = new HashMap<String, String>();
|
||||
/** a map of the desired links */
|
||||
private Map<String, String> links = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Construct a new object which will obtain the configuration for itself
|
||||
*
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public CrossLinks()
|
||||
throws BrowseException
|
||||
{
|
||||
int i = 1;
|
||||
while (true)
|
||||
{
|
||||
String field = "webui.browse.link." + i;
|
||||
String config = ConfigurationManager.getProperty(field);
|
||||
if (config == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* Construct a new object which will obtain the configuration for itself.
|
||||
*
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public CrossLinks()
|
||||
throws BrowseException
|
||||
{
|
||||
int i = 1;
|
||||
while (true)
|
||||
{
|
||||
String field = "webui.browse.link." + i;
|
||||
String config = ConfigurationManager.getProperty(field);
|
||||
if (config == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
String[] parts = config.split(":");
|
||||
if (parts.length != 2)
|
||||
{
|
||||
throw new BrowseException("Invalid configuration for " + field + ": " + config);
|
||||
}
|
||||
links.put(parts[1], parts[0]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a link for the given canonical form of metadata (i.e. schema.element.qualifier)?
|
||||
*
|
||||
* @param metadata the metadata to check for a link on
|
||||
*/
|
||||
public boolean hasLink(String metadata)
|
||||
{
|
||||
return links.containsKey(metadata);
|
||||
}
|
||||
|
||||
String[] parts = config.split(":");
|
||||
if (parts.length != 2)
|
||||
{
|
||||
throw new BrowseException("Invalid configuration for " + field + ": " + config);
|
||||
}
|
||||
links.put(parts[1], parts[0]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a link for the given canonical form of metadata (i.e.
|
||||
* schema.element.qualifier)?
|
||||
*
|
||||
* @param metadata the metadata to check for a link on
|
||||
*/
|
||||
public boolean hasLink(String metadata)
|
||||
{
|
||||
return links.containsKey(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the type of link that the bit of metadata has.
|
||||
*
|
||||
* @param metadata the metadata to get the link type for
|
||||
*/
|
||||
public String getLinkType(String metadata)
|
||||
{
|
||||
return links.get(metadata);
|
||||
}
|
||||
/**
|
||||
* Get the type of link that the bit of metadata has.
|
||||
*
|
||||
* @param metadata the metadata to get the link type for
|
||||
*/
|
||||
public String getLinkType(String metadata)
|
||||
{
|
||||
return links.get(metadata);
|
||||
}
|
||||
}
|
||||
|
@@ -594,27 +594,26 @@ public class IndexBrowse
|
||||
throw new BrowseException("Error in SortOptions", se);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove all the indices for the given item
|
||||
*
|
||||
* @param item the item to be removed
|
||||
* @return true if removed.
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public boolean itemRemoved(Item item)
|
||||
throws BrowseException
|
||||
|
||||
/**
|
||||
* remove all the indices for the given item
|
||||
*
|
||||
* @param item the item to be removed
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public boolean itemRemoved(Item item)
|
||||
throws BrowseException
|
||||
{
|
||||
return itemRemoved(item.getID());
|
||||
}
|
||||
|
||||
public boolean itemRemoved(int itemID)
|
||||
throws BrowseException
|
||||
{
|
||||
// go over the indices and index the item
|
||||
for (int i = 0; i < bis.length; i++)
|
||||
{
|
||||
if (bis[i].isMetadataIndex())
|
||||
{
|
||||
// go over the indices and index the item
|
||||
for (int i = 0; i < bis.length; i++)
|
||||
{
|
||||
if (bis[i].isMetadataIndex())
|
||||
{
|
||||
log.debug("Removing indexing for removed item " + itemID + ", for index: " + bis[i].getTableName());
|
||||
dao.deleteByItemID(bis[i].getMapTableName(), itemID);
|
||||
@@ -628,127 +627,127 @@ public class IndexBrowse
|
||||
dao.deleteCommunityMappings(itemID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Browse indexes, destroying the old ones.
|
||||
*
|
||||
* @param argv
|
||||
* Command-line arguments
|
||||
*/
|
||||
public static void main(String[] argv)
|
||||
throws SQLException, BrowseException, ParseException
|
||||
{
|
||||
/**
|
||||
* Creates Browse indexes, destroying the old ones.
|
||||
*
|
||||
* @param argv
|
||||
* Command-line arguments
|
||||
*/
|
||||
public static void main(String[] argv)
|
||||
throws SQLException, BrowseException, ParseException
|
||||
{
|
||||
Date startTime = new Date();
|
||||
try
|
||||
{
|
||||
Context context = new Context();
|
||||
context.turnOffAuthorisationSystem();
|
||||
IndexBrowse indexer = new IndexBrowse(context);
|
||||
{
|
||||
Context context = new Context();
|
||||
context.turnOffAuthorisationSystem();
|
||||
IndexBrowse indexer = new IndexBrowse(context);
|
||||
|
||||
// create an options object and populate it
|
||||
CommandLineParser parser = new PosixParser();
|
||||
Options options = new Options();
|
||||
// create an options object and populate it
|
||||
CommandLineParser parser = new PosixParser();
|
||||
Options options = new Options();
|
||||
|
||||
// these are mutually exclusive, and represent the primary actions
|
||||
options.addOption("t", "tables", false, "create the tables only, do not attempt to index. Mutually exclusive with -f and -i");
|
||||
options.addOption("i", "index", false, "actually do the indexing. Mutually exclusive with -t and -f");
|
||||
options.addOption("f", "full", false, "make the tables, and do the indexing. This forces -x. Mutually exclusive with -t and -i");
|
||||
// these are mutually exclusive, and represent the primary actions
|
||||
options.addOption("t", "tables", false, "create the tables only, do not attempt to index. Mutually exclusive with -f and -i");
|
||||
options.addOption("i", "index", false, "actually do the indexing. Mutually exclusive with -t and -f");
|
||||
options.addOption("f", "full", false, "make the tables, and do the indexing. This forces -x. Mutually exclusive with -t and -i");
|
||||
|
||||
// these options can be specified only with the -f option
|
||||
options.addOption("r", "rebuild", false, "should we rebuild all the indices, which removes old index tables and creates new ones. For use with -f. Mutually exclusive with -d");
|
||||
options.addOption("d", "delete", false, "delete all the indices, but don't create new ones. For use with -f. This is mutually exclusive with -r");
|
||||
// these options can be specified only with the -f option
|
||||
options.addOption("r", "rebuild", false, "should we rebuild all the indices, which removes old index tables and creates new ones. For use with -f. Mutually exclusive with -d");
|
||||
options.addOption("d", "delete", false, "delete all the indices, but don't create new ones. For use with -f. This is mutually exclusive with -r");
|
||||
|
||||
// these options can be specified only with the -t and -f options
|
||||
options.addOption("o", "out", true, "[-o <filename>] write the remove and create SQL to the given file. For use with -t and -f"); // FIXME: not currently working
|
||||
options.addOption("p", "print", false, "write the remove and create SQL to the stdout. For use with -t and -f");
|
||||
options.addOption("x", "execute", false, "execute all the remove and create SQL against the database. For use with -t and -f");
|
||||
options.addOption("s", "start", true, "[-s <int>] start from this index number and work upward (mostly only useful for debugging). For use with -t and -f");
|
||||
// these options can be specified only with the -t and -f options
|
||||
options.addOption("o", "out", true, "[-o <filename>] write the remove and create SQL to the given file. For use with -t and -f"); // FIXME: not currently working
|
||||
options.addOption("p", "print", false, "write the remove and create SQL to the stdout. For use with -t and -f");
|
||||
options.addOption("x", "execute", false, "execute all the remove and create SQL against the database. For use with -t and -f");
|
||||
options.addOption("s", "start", true, "[-s <int>] start from this index number and work upward (mostly only useful for debugging). For use with -t and -f");
|
||||
|
||||
// this option can be used with any argument
|
||||
options.addOption("v", "verbose", false, "print extra information to the stdout. If used in conjunction with -p, you cannot use the stdout to generate your database structure");
|
||||
// this option can be used with any argument
|
||||
options.addOption("v", "verbose", false, "print extra information to the stdout. If used in conjunction with -p, you cannot use the stdout to generate your database structure");
|
||||
|
||||
// display the help. If this is spefified, it trumps all other arguments
|
||||
options.addOption("h", "help", false, "show this help documentation. Overrides all other arguments");
|
||||
// display the help. If this is spefified, it trumps all other arguments
|
||||
options.addOption("h", "help", false, "show this help documentation. Overrides all other arguments");
|
||||
|
||||
CommandLine line = parser.parse(options, argv);
|
||||
CommandLine line = parser.parse(options, argv);
|
||||
|
||||
// display the help
|
||||
if (line.hasOption("h"))
|
||||
{
|
||||
indexer.usage(options);
|
||||
return;
|
||||
}
|
||||
// display the help
|
||||
if (line.hasOption("h"))
|
||||
{
|
||||
indexer.usage(options);
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.hasOption("v"))
|
||||
{
|
||||
indexer.setVerbose(true);
|
||||
}
|
||||
if (line.hasOption("v"))
|
||||
{
|
||||
indexer.setVerbose(true);
|
||||
}
|
||||
|
||||
if (line.hasOption("i"))
|
||||
{
|
||||
indexer.createIndex();
|
||||
return;
|
||||
}
|
||||
if (line.hasOption("i"))
|
||||
{
|
||||
indexer.createIndex();
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.hasOption("f"))
|
||||
{
|
||||
if (line.hasOption('r'))
|
||||
{
|
||||
indexer.setRebuild(true);
|
||||
}
|
||||
else if (line.hasOption("d"))
|
||||
{
|
||||
indexer.setDelete(true);
|
||||
}
|
||||
}
|
||||
if (line.hasOption("f"))
|
||||
{
|
||||
if (line.hasOption('r'))
|
||||
{
|
||||
indexer.setRebuild(true);
|
||||
}
|
||||
else if (line.hasOption("d"))
|
||||
{
|
||||
indexer.setDelete(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (line.hasOption("f") || line.hasOption("t"))
|
||||
{
|
||||
if (line.hasOption("s"))
|
||||
{
|
||||
indexer.setStart(Integer.parseInt(line.getOptionValue("s")));
|
||||
}
|
||||
if (line.hasOption("x"))
|
||||
{
|
||||
indexer.setExecute(true);
|
||||
}
|
||||
if (line.hasOption("p"))
|
||||
{
|
||||
indexer.setStdOut(true);
|
||||
}
|
||||
if (line.hasOption("o"))
|
||||
{
|
||||
indexer.setFileOut(true);
|
||||
indexer.setOutFile(line.getOptionValue("o"));
|
||||
}
|
||||
}
|
||||
if (line.hasOption("f") || line.hasOption("t"))
|
||||
{
|
||||
if (line.hasOption("s"))
|
||||
{
|
||||
indexer.setStart(Integer.parseInt(line.getOptionValue("s")));
|
||||
}
|
||||
if (line.hasOption("x"))
|
||||
{
|
||||
indexer.setExecute(true);
|
||||
}
|
||||
if (line.hasOption("p"))
|
||||
{
|
||||
indexer.setStdOut(true);
|
||||
}
|
||||
if (line.hasOption("o"))
|
||||
{
|
||||
indexer.setFileOut(true);
|
||||
indexer.setOutFile(line.getOptionValue("o"));
|
||||
}
|
||||
}
|
||||
|
||||
if (line.hasOption("t"))
|
||||
{
|
||||
indexer.prepTables();
|
||||
return;
|
||||
}
|
||||
if (line.hasOption("t"))
|
||||
{
|
||||
indexer.prepTables();
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.hasOption("f"))
|
||||
{
|
||||
indexer.setExecute(true);
|
||||
indexer.initBrowse();
|
||||
return;
|
||||
}
|
||||
if (line.hasOption("f"))
|
||||
{
|
||||
indexer.setExecute(true);
|
||||
indexer.initBrowse();
|
||||
return;
|
||||
}
|
||||
|
||||
indexer.usage(options);
|
||||
context.complete();
|
||||
}
|
||||
indexer.usage(options);
|
||||
context.complete();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Date endTime = new Date();
|
||||
System.out.println("Started: " + startTime.getTime());
|
||||
System.out.println("Ended: " + endTime.getTime());
|
||||
System.out.println("Elapsed time: " + ((endTime.getTime() - startTime.getTime()) / 1000) + " secs (" + (endTime.getTime() - startTime.getTime()) + " msecs)");
|
||||
{
|
||||
Date endTime = new Date();
|
||||
System.out.println("Started: " + startTime.getTime());
|
||||
System.out.println("Ended: " + endTime.getTime());
|
||||
System.out.println("Elapsed time: " + ((endTime.getTime() - startTime.getTime()) / 1000) + " secs (" + (endTime.getTime() - startTime.getTime()) + " msecs)");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* output the usage information
|
||||
|
@@ -21,50 +21,49 @@ import org.dspace.content.DSpaceObject;
|
||||
*/
|
||||
public interface ItemCountDAO
|
||||
{
|
||||
/**
|
||||
* Set the DSpace Context to use during data access
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context) throws ItemCountException;
|
||||
/**
|
||||
* Set the DSpace Context to use during data access
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context) throws ItemCountException;
|
||||
|
||||
/**
|
||||
* Set the given count as the number of items in the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count) throws ItemCountException;
|
||||
/**
|
||||
* Set the given count as the number of items in the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count) throws ItemCountException;
|
||||
|
||||
/**
|
||||
* Set the given count as the number of items in the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count) throws ItemCountException;
|
||||
/**
|
||||
* Set the given count as the number of items in the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count) throws ItemCountException;
|
||||
|
||||
/**
|
||||
* Get the number of items in the given DSpaceObject container.
|
||||
* This method will only succeed if the DSpaceObject is an instance of
|
||||
* either a Community or a Collection. Otherwise it will throw an
|
||||
* exception.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso) throws ItemCountException;
|
||||
/**
|
||||
* Get the number of items in the given DSpaceObject container. This method will
|
||||
* only succeed if the DSpaceObject is an instance of either a Community or a
|
||||
* Collection. Otherwise it will throw an exception.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso) throws ItemCountException;
|
||||
|
||||
/**
|
||||
* Remove any cached data regarding the given DSpaceObject container. This method will
|
||||
* only succeed if the DSpaceObject is an instance of either a Community or a
|
||||
* Collection. Otherwise it will throw an exception
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException;
|
||||
/**
|
||||
* Remove any cached data regarding the given DSpaceObject container. This method will
|
||||
* only succeed if the DSpaceObject is an instance of either a Community or a
|
||||
* Collection. Otherwise it will throw an exception
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException;
|
||||
}
|
||||
|
@@ -19,32 +19,32 @@ import org.dspace.core.ConfigurationManager;
|
||||
*/
|
||||
public class ItemCountDAOFactory
|
||||
{
|
||||
/**
|
||||
* Get an instance of ItemCountDAO which supports the correct database
|
||||
* for the specific DSpace instance.
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public static ItemCountDAO getInstance(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
String db = ConfigurationManager.getProperty("db.name");
|
||||
ItemCountDAO dao;
|
||||
if ("postgres".equals(db))
|
||||
{
|
||||
dao = new ItemCountDAOPostgres();
|
||||
}
|
||||
else if ("oracle".equals(db))
|
||||
{
|
||||
dao = new ItemCountDAOOracle();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("Database type: " + db + " is not currently supported");
|
||||
}
|
||||
|
||||
dao.setContext(context);
|
||||
return dao;
|
||||
}
|
||||
/**
|
||||
* Get an instance of ItemCountDAO which supports the correct database
|
||||
* for the specific DSpace instance.
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public static ItemCountDAO getInstance(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
String db = ConfigurationManager.getProperty("db.name");
|
||||
ItemCountDAO dao;
|
||||
if ("postgres".equals(db))
|
||||
{
|
||||
dao = new ItemCountDAOPostgres();
|
||||
}
|
||||
else if ("oracle".equals(db))
|
||||
{
|
||||
dao = new ItemCountDAOOracle();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("Database type: " + db + " is not currently supported");
|
||||
}
|
||||
|
||||
dao.setContext(context);
|
||||
return dao;
|
||||
}
|
||||
}
|
||||
|
@@ -28,303 +28,304 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class ItemCountDAOOracle implements ItemCountDAO
|
||||
{
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCountDAOOracle.class);
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCountDAOOracle.class);
|
||||
|
||||
/** DSpace context */
|
||||
private Context context;
|
||||
/** DSpace context */
|
||||
private Context context;
|
||||
|
||||
/** SQL to select on a collection id */
|
||||
private String collectionSelect = "SELECT * FROM collection_item_count WHERE collection_id = ?";
|
||||
|
||||
/** SQL to insert a new collection record */
|
||||
private String collectionInsert = "INSERT INTO collection_item_count (collection_id, count) VALUES (?, ?)";
|
||||
/** SQL to select on a collection id */
|
||||
private String collectionSelect = "SELECT * FROM collection_item_count WHERE collection_id = ?";
|
||||
|
||||
/** SQL to update an existing collection record */
|
||||
private String collectionUpdate = "UPDATE collection_item_count SET count = ? WHERE collection_id = ?";
|
||||
/** SQL to insert a new collection record */
|
||||
private String collectionInsert = "INSERT INTO collection_item_count (collection_id, count) VALUES (?, ?)";
|
||||
|
||||
/** SQL to remove a collection record */
|
||||
private String collectionRemove = "DELETE FROM collection_item_count WHERE collection_id = ?";
|
||||
/** SQL to update an existing collection record */
|
||||
private String collectionUpdate = "UPDATE collection_item_count SET count = ? WHERE collection_id = ?";
|
||||
|
||||
/** SQL to select on a community id */
|
||||
private String communitySelect = "SELECT * FROM community_item_count WHERE community_id = ?";
|
||||
/** SQL to remove a collection record */
|
||||
private String collectionRemove = "DELETE FROM collection_item_count WHERE collection_id = ?";
|
||||
|
||||
/** SQL to insert a new community record */
|
||||
private String communityInsert = "INSERT INTO community_item_count (community_id, count) VALUES (?, ?)";
|
||||
/** SQL to select on a community id */
|
||||
private String communitySelect = "SELECT * FROM community_item_count WHERE community_id = ?";
|
||||
|
||||
/** SQL to update an existing community record */
|
||||
private String communityUpdate = "UPDATE community_item_count SET count = ? WHERE community_id = ?";
|
||||
/** SQL to insert a new community record */
|
||||
private String communityInsert = "INSERT INTO community_item_count (community_id, count) VALUES (?, ?)";
|
||||
|
||||
/** SQL to remove a community record */
|
||||
private String communityRemove = "DELETE FROM community_item_count WHERE community_id = ?";
|
||||
/** SQL to update an existing community record */
|
||||
private String communityUpdate = "UPDATE community_item_count SET count = ? WHERE community_id = ?";
|
||||
|
||||
/**
|
||||
* Store the count of the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
/** SQL to remove a community record */
|
||||
private String communityRemove = "DELETE FROM community_item_count WHERE community_id = ?";
|
||||
|
||||
/**
|
||||
* Store the count of the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, sparams);
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionUpdate, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, collectionInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionUpdate, params);
|
||||
}
|
||||
/**
|
||||
* Store the count of the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityUpdate, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, communityInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dspace context to use
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of the items in the given container.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
return getCollectionCount((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
return getCommunityCount((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, collectionInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
throw new ItemCountException("We can only count items in Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the count of the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityUpdate, params);
|
||||
}
|
||||
/**
|
||||
* remove the cache for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
removeCollection((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
removeCommunity((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, communityInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
throw new ItemCountException("We can only delete count of items from Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dspace context to use
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the count of the items in the given container.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
return getCollectionCount((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
return getCommunityCount((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("We can only count items in Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the cache for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
removeCollection((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
removeCommunity((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("We can only delete count of items from Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the cache for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCollection(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* remove the cache for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCollection(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCommunity(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove the cache for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCommunity(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @return
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCollectionCount(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
/**
|
||||
* Get the count for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @return
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCollectionCount(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, params);
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, params);
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the count for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCommunityCount(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
/**
|
||||
* get the count for the given community
|
||||
*
|
||||
* @param community
|
||||
* @return
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCommunityCount(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, params);
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, params);
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,302 +28,304 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class ItemCountDAOPostgres implements ItemCountDAO
|
||||
{
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCountDAOPostgres.class);
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCountDAOPostgres.class);
|
||||
|
||||
/** DSpace context */
|
||||
private Context context;
|
||||
/** DSpace context */
|
||||
private Context context;
|
||||
|
||||
/** SQL to select on a collection id */
|
||||
private String collectionSelect = "SELECT * FROM collection_item_count WHERE collection_id = ?";
|
||||
/** SQL to select on a collection id */
|
||||
private String collectionSelect = "SELECT * FROM collection_item_count WHERE collection_id = ?";
|
||||
|
||||
/** SQL to insert a new collection record */
|
||||
private String collectionInsert = "INSERT INTO collection_item_count (collection_id, count) VALUES (?, ?)";
|
||||
/** SQL to insert a new collection record */
|
||||
private String collectionInsert = "INSERT INTO collection_item_count (collection_id, count) VALUES (?, ?)";
|
||||
|
||||
/** SQL to update an existing collection record */
|
||||
private String collectionUpdate = "UPDATE collection_item_count SET count = ? WHERE collection_id = ?";
|
||||
/** SQL to update an existing collection record */
|
||||
private String collectionUpdate = "UPDATE collection_item_count SET count = ? WHERE collection_id = ?";
|
||||
|
||||
/** SQL to remove a collection record */
|
||||
private String collectionRemove = "DELETE FROM collection_item_count WHERE collection_id = ?";
|
||||
/** SQL to remove a collection record */
|
||||
private String collectionRemove = "DELETE FROM collection_item_count WHERE collection_id = ?";
|
||||
|
||||
/** SQL to select on a community id */
|
||||
private String communitySelect = "SELECT * FROM community_item_count WHERE community_id = ?";
|
||||
/** SQL to select on a community id */
|
||||
private String communitySelect = "SELECT * FROM community_item_count WHERE community_id = ?";
|
||||
|
||||
/** SQL to insert a new community record */
|
||||
private String communityInsert = "INSERT INTO community_item_count (community_id, count) VALUES (?, ?)";
|
||||
/** SQL to insert a new community record */
|
||||
private String communityInsert = "INSERT INTO community_item_count (community_id, count) VALUES (?, ?)";
|
||||
|
||||
/** SQL to update an existing community record */
|
||||
private String communityUpdate = "UPDATE community_item_count SET count = ? WHERE community_id = ?";
|
||||
/** SQL to update an existing community record */
|
||||
private String communityUpdate = "UPDATE community_item_count SET count = ? WHERE community_id = ?";
|
||||
|
||||
/** SQL to remove a community record */
|
||||
private String communityRemove = "DELETE FROM community_item_count WHERE community_id = ?";
|
||||
/** SQL to remove a community record */
|
||||
private String communityRemove = "DELETE FROM community_item_count WHERE community_id = ?";
|
||||
|
||||
/**
|
||||
* Store the count of the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
/**
|
||||
* Store the count of the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void collectionCount(Collection collection, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, sparams);
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionUpdate, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, collectionInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionUpdate, params);
|
||||
}
|
||||
/**
|
||||
* Store the count of the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityUpdate, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, communityInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dspace context to use
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of the items in the given container.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
return getCollectionCount((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
return getCommunityCount((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, collectionInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
throw new ItemCountException("We can only count items in Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the count of the given community
|
||||
*
|
||||
* @param community
|
||||
* @param count
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void communityCount(Community community, int count)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
// first find out if we have a record
|
||||
Object[] sparams = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, sparams);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
Object[] params = { Integer.valueOf(count), Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityUpdate, params);
|
||||
}
|
||||
/**
|
||||
* remove the cache for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
removeCollection((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
removeCommunity((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()), Integer.valueOf(count) };
|
||||
DatabaseManager.updateQuery(context, communityInsert, params);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
throw new ItemCountException("We can only delete count of items from Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dspace context to use
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void setContext(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the count of the items in the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
return getCollectionCount((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
return getCommunityCount((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("We can only count items in Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the cache for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso) throws ItemCountException
|
||||
{
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
removeCollection((Collection) dso);
|
||||
}
|
||||
else if (dso instanceof Community)
|
||||
{
|
||||
removeCommunity((Community) dso);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ItemCountException("We can only delete count of items from Communities or Collections");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the cache for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCollection(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* remove the cache for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCollection(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
DatabaseManager.updateQuery(context, collectionRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCommunity(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove the cache for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void removeCommunity(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
DatabaseManager.updateQuery(context, communityRemove, params);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCollectionCount(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
/**
|
||||
* Get the count for the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @return
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCollectionCount(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, params);
|
||||
{
|
||||
Object[] params = { Integer.valueOf(collection.getID()) };
|
||||
tri = DatabaseManager.query(context, collectionSelect, params);
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the count for the given community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCommunityCount(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
/**
|
||||
* get the count for the given community
|
||||
*
|
||||
* @param community
|
||||
* @return
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private int getCommunityCount(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
try
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, params);
|
||||
{
|
||||
Object[] params = { Integer.valueOf(community.getID()) };
|
||||
tri = DatabaseManager.query(context, communitySelect, params);
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
if (!tri.hasNext())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableRow tr = tri.next();
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
throw new ItemCountException("More than one count row in the database");
|
||||
}
|
||||
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
return tr.getIntColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (tri != null)
|
||||
{
|
||||
tri.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,185 +33,186 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class ItemCounter
|
||||
{
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCounter.class);
|
||||
/** Log4j logger */
|
||||
private static Logger log = Logger.getLogger(ItemCounter.class);
|
||||
|
||||
/** DAO to use to store and retrieve data */
|
||||
private ItemCountDAO dao;
|
||||
/** DAO to use to store and retrieve data */
|
||||
private ItemCountDAO dao;
|
||||
|
||||
/** DSpace Context */
|
||||
private Context context;
|
||||
/** DSpace Context */
|
||||
private Context context;
|
||||
|
||||
/**
|
||||
* method invoked by CLI which will result in the number of items
|
||||
* in each community and collection being cached. These counts will
|
||||
* not update themselves until this is run again.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws ItemCountException, SQLException
|
||||
{
|
||||
/**
|
||||
* method invoked by CLI which will result in the number of items
|
||||
* in each community and collection being cached. These counts will
|
||||
* not update themselves until this is run again.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws ItemCountException, SQLException
|
||||
{
|
||||
Context context = new Context();
|
||||
ItemCounter ic = new ItemCounter(context);
|
||||
ic.buildItemCounts();
|
||||
ic.buildItemCounts();
|
||||
context.complete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new item counter which will use the give DSpace Context
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public ItemCounter(Context context)
|
||||
throws ItemCountException
|
||||
{
|
||||
this.context = context;
|
||||
this.dao = ItemCountDAOFactory.getInstance(this.context);
|
||||
}
|
||||
/**
|
||||
* Construct a new item counter which will use the give DSpace Context
|
||||
*
|
||||
* @param context
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public ItemCounter(Context context)
|
||||
throws ItemCountException
|
||||
|
||||
{
|
||||
this.context = context;
|
||||
this.dao = ItemCountDAOFactory.getInstance(this.context);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does the grunt work of drilling through and iterating
|
||||
* over all of the communities and collections in the system and
|
||||
* obtaining and caching the item counts for each one.
|
||||
*
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void buildItemCounts()
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Community[] tlc = Community.findAllTop(context);
|
||||
for (int i = 0; i < tlc.length; i++)
|
||||
{
|
||||
count(tlc[i]);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of the items in the given container. If the configuration
|
||||
* value webui.strengths.cache is equal to 'true' this will return the
|
||||
* cached value if it exists. If it is equal to 'false' it will count
|
||||
* the number of items in the container in real time
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
|
||||
|
||||
if (useCache)
|
||||
{
|
||||
return dao.getCount(dso);
|
||||
}
|
||||
|
||||
// if we make it this far, we need to manually count
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
try {
|
||||
return ((Collection) dso).countItems();
|
||||
} catch (SQLException e) {
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
/**
|
||||
* This method does the grunt work of drilling through and iterating
|
||||
* over all of the communities and collections in the system and
|
||||
* obtaining and caching the item counts for each one.
|
||||
*
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void buildItemCounts()
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
Community[] tlc = Community.findAllTop(context);
|
||||
for (int i = 0; i < tlc.length; i++)
|
||||
{
|
||||
count(tlc[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dso instanceof Community)
|
||||
{
|
||||
try {
|
||||
return ((Community) dso).countItems();
|
||||
} catch (SQLException e) {
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any cached data for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
dao.remove(dso);
|
||||
}
|
||||
/**
|
||||
* Get the count of the items in the given container. If the configuration
|
||||
* value webui.strengths.cache is equal to 'true' this will return the
|
||||
* cached value if it exists. If it is equal to 'false' it will count
|
||||
* the number of items in the container in real time.
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int getCount(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
|
||||
|
||||
if (useCache)
|
||||
{
|
||||
return dao.getCount(dso);
|
||||
}
|
||||
|
||||
// if we make it this far, we need to manually count
|
||||
if (dso instanceof Collection)
|
||||
{
|
||||
try {
|
||||
return ((Collection) dso).countItems();
|
||||
} catch (SQLException e) {
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (dso instanceof Community)
|
||||
{
|
||||
try {
|
||||
return ((Community) dso).countItems();
|
||||
} catch (SQLException e) {
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* count and cache the number of items in the community. This
|
||||
* will include all sub-communities and collections in the
|
||||
* community. It will also recurse into sub-communities and
|
||||
* collections and call count() on them also.
|
||||
*
|
||||
* Therefore, the count the contents of the entire system, it is
|
||||
* necessary just to call this method on each top level community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void count(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
// first count the community we are in
|
||||
int count = community.countItems();
|
||||
dao.communityCount(community, count);
|
||||
|
||||
// now get the sub-communities
|
||||
Community[] scs = community.getSubcommunities();
|
||||
for (int i = 0; i < scs.length; i++)
|
||||
{
|
||||
count(scs[i]);
|
||||
}
|
||||
|
||||
// now get the collections
|
||||
Collection[] cols = community.getCollections();
|
||||
for (int i = 0; i < cols.length; i++)
|
||||
{
|
||||
count(cols[i]);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove any cached data for the given container
|
||||
*
|
||||
* @param dso
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
public void remove(DSpaceObject dso)
|
||||
throws ItemCountException
|
||||
{
|
||||
dao.remove(dso);
|
||||
}
|
||||
|
||||
/**
|
||||
* count and cache the number of items in the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void count(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
int ccount = collection.countItems();
|
||||
dao.collectionCount(collection, ccount);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* count and cache the number of items in the community. This
|
||||
* will include all sub-communities and collections in the
|
||||
* community. It will also recurse into sub-communities and
|
||||
* collections and call count() on them also.
|
||||
*
|
||||
* Therefore, the count the contents of the entire system, it is
|
||||
* necessary just to call this method on each top level community
|
||||
*
|
||||
* @param community
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void count(Community community)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
// first count the community we are in
|
||||
int count = community.countItems();
|
||||
dao.communityCount(community, count);
|
||||
|
||||
// now get the sub-communities
|
||||
Community[] scs = community.getSubcommunities();
|
||||
for (int i = 0; i < scs.length; i++)
|
||||
{
|
||||
count(scs[i]);
|
||||
}
|
||||
|
||||
// now get the collections
|
||||
Collection[] cols = community.getCollections();
|
||||
for (int i = 0; i < cols.length; i++)
|
||||
{
|
||||
count(cols[i]);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* count and cache the number of items in the given collection
|
||||
*
|
||||
* @param collection
|
||||
* @throws ItemCountException
|
||||
*/
|
||||
private void count(Collection collection)
|
||||
throws ItemCountException
|
||||
{
|
||||
try
|
||||
{
|
||||
int ccount = collection.countItems();
|
||||
dao.collectionCount(collection, ccount);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new ItemCountException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,89 +22,89 @@ import org.dspace.core.ConfigurationManager;
|
||||
*/
|
||||
public class ItemListConfig
|
||||
{
|
||||
/** a map of column number to metadata value */
|
||||
private Map<Integer, String[]> metadata = new HashMap<Integer, String[]>();
|
||||
/** a map of column number to metadata value */
|
||||
private Map<Integer, String[]> metadata = new HashMap<Integer, String[]>();
|
||||
|
||||
/** a map of column number to data type */
|
||||
private Map<Integer, Integer> types = new HashMap<Integer, Integer>();
|
||||
/** a map of column number to data type */
|
||||
private Map<Integer, Integer> types = new HashMap<Integer, Integer>();
|
||||
|
||||
/** constant for a DATE column */
|
||||
private static final int DATE = 1;
|
||||
/** constant for a DATE column */
|
||||
private static final int DATE = 1;
|
||||
|
||||
/** constant for a TEXT column */
|
||||
private static final int TEXT = 2;
|
||||
/** constant for a TEXT column */
|
||||
private static final int TEXT = 2;
|
||||
|
||||
/**
|
||||
* Create a new instance of the Item list configuration. This loads
|
||||
* all the required information from configuration
|
||||
*
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public ItemListConfig()
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
{
|
||||
String configLine = ConfigurationManager.getProperty("webui.itemlist.columns");
|
||||
/**
|
||||
* Create a new instance of the Item list configuration. This loads
|
||||
* all the required information from configuration
|
||||
*
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public ItemListConfig()
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
{
|
||||
String configLine = ConfigurationManager.getProperty("webui.itemlist.columns");
|
||||
|
||||
if (configLine == null || "".equals(configLine))
|
||||
{
|
||||
throw new BrowseException("There is no configuration for webui.itemlist.columns");
|
||||
}
|
||||
|
||||
// parse the config
|
||||
StringTokenizer st = new StringTokenizer(configLine, ",");
|
||||
int i = 1;
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
Integer key = Integer.valueOf(i);
|
||||
String token = st.nextToken();
|
||||
|
||||
// find out if the field is a date
|
||||
if (token.indexOf("(date)") > 0)
|
||||
{
|
||||
token = token.replaceAll("\\(date\\)", "");
|
||||
types.put(key, Integer.valueOf(ItemListConfig.DATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
types.put(key, Integer.valueOf(ItemListConfig.TEXT));
|
||||
}
|
||||
|
||||
String[] mdBits = interpretField(token.trim(), null);
|
||||
metadata.put(key, mdBits);
|
||||
|
||||
// don't forget to increment the key counter
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new BrowseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (configLine == null || "".equals(configLine))
|
||||
{
|
||||
throw new BrowseException("There is no configuration for webui.itemlist.columns");
|
||||
}
|
||||
|
||||
// parse the config
|
||||
StringTokenizer st = new StringTokenizer(configLine, ",");
|
||||
int i = 1;
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
Integer key = Integer.valueOf(i);
|
||||
String token = st.nextToken();
|
||||
|
||||
// find out if the field is a date
|
||||
if (token.indexOf("(date)") > 0)
|
||||
{
|
||||
token = token.replaceAll("\\(date\\)", "");
|
||||
types.put(key, Integer.valueOf(ItemListConfig.DATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
types.put(key, Integer.valueOf(ItemListConfig.TEXT));
|
||||
}
|
||||
|
||||
String[] mdBits = interpretField(token.trim(), null);
|
||||
metadata.put(key, mdBits);
|
||||
|
||||
// don't forget to increment the key counter
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new BrowseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* how many columns are there?
|
||||
*
|
||||
* @return the number of columns
|
||||
*/
|
||||
public int numCols()
|
||||
{
|
||||
return metadata.size();
|
||||
}
|
||||
/**
|
||||
* how many columns are there?
|
||||
*
|
||||
* @return the number of columns
|
||||
*/
|
||||
public int numCols()
|
||||
{
|
||||
return metadata.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* what metadata is to go in the given column number
|
||||
*
|
||||
* @param col
|
||||
*/
|
||||
public String[] getMetadata(int col)
|
||||
{
|
||||
return metadata.get(Integer.valueOf(col));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* What metadata is to go in the given column number?
|
||||
*
|
||||
* @param col
|
||||
*/
|
||||
public String[] getMetadata(int col)
|
||||
{
|
||||
return metadata.get(Integer.valueOf(col));
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a string representation of a metadata field, and return it as an array.
|
||||
* This is just a convenient utility method to basically break the metadata
|
||||
* representation up by its delimiter (.), and stick it in an array, inserting
|
||||
|
@@ -27,48 +27,48 @@ import java.util.List;
|
||||
|
||||
public class HarvestedCollection
|
||||
{
|
||||
private Context context;
|
||||
private TableRow harvestRow;
|
||||
private Context context;
|
||||
private TableRow harvestRow;
|
||||
|
||||
public static final int TYPE_NONE = 0;
|
||||
public static final int TYPE_DMD = 1;
|
||||
public static final int TYPE_DMDREF = 2;
|
||||
public static final int TYPE_FULL = 3;
|
||||
public static final int TYPE_NONE = 0;
|
||||
public static final int TYPE_DMD = 1;
|
||||
public static final int TYPE_DMDREF = 2;
|
||||
public static final int TYPE_FULL = 3;
|
||||
|
||||
public static final int STATUS_READY = 0;
|
||||
public static final int STATUS_BUSY = 1;
|
||||
public static final int STATUS_QUEUED = 2;
|
||||
public static final int STATUS_OAI_ERROR = 3;
|
||||
public static final int STATUS_UNKNOWN_ERROR = -1;
|
||||
public static final int STATUS_READY = 0;
|
||||
public static final int STATUS_BUSY = 1;
|
||||
public static final int STATUS_QUEUED = 2;
|
||||
public static final int STATUS_OAI_ERROR = 3;
|
||||
public static final int STATUS_UNKNOWN_ERROR = -1;
|
||||
|
||||
/*
|
||||
* collection_id | integer | not null
|
||||
* harvest_type | integer |
|
||||
* oai_source | text |
|
||||
* oai_set_id | text |
|
||||
* harvest_message | text |
|
||||
* metadata_config_id | text |
|
||||
* harvest_status | integer |
|
||||
* harvest_start_time | timestamp with time zone |
|
||||
*/
|
||||
/*
|
||||
* collection_id | integer | not null
|
||||
harvest_type | integer |
|
||||
oai_source | text |
|
||||
oai_set_id | text |
|
||||
harvest_message | text |
|
||||
metadata_config_id | text |
|
||||
harvest_status | integer |
|
||||
harvest_start_time | timestamp with time zone |
|
||||
*/
|
||||
|
||||
// TODO: make sure this guy knows to lock people out if the status is not zero.
|
||||
// i.e. someone editing a collection's setting from the admin menu should have
|
||||
// to stop an ongoing harvest before they can edit the settings.
|
||||
|
||||
|
||||
HarvestedCollection(Context c, TableRow row)
|
||||
// TODO: make sure this guy knows to lock people out if the status is not zero.
|
||||
// i.e. someone editing a collection's setting from the admin menu should have
|
||||
// to stop an ongoing harvest before they can edit the settings.
|
||||
|
||||
|
||||
HarvestedCollection(Context c, TableRow row)
|
||||
{
|
||||
context = c;
|
||||
harvestRow = row;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void exists(Context c) throws SQLException {
|
||||
DatabaseManager.queryTable(c, "harvested_collection", "SELECT COUNT(*) FROM harvested_collection");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Find the harvest settings corresponding to this collection
|
||||
* @return a HarvestInstance object corresponding to this collection's settings, null if not found.
|
||||
@@ -76,14 +76,14 @@ public class HarvestedCollection
|
||||
public static HarvestedCollection find(Context c, int collectionId) throws SQLException
|
||||
{
|
||||
TableRow row = DatabaseManager.findByUnique(c, "harvested_collection", "collection_id", collectionId);
|
||||
|
||||
|
||||
if (row == null) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return new HarvestedCollection(c, row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new harvest instance row for a specified collection.
|
||||
* @return a new HarvestInstance object
|
||||
@@ -93,10 +93,10 @@ public class HarvestedCollection
|
||||
row.setColumn("collection_id", collectionId);
|
||||
row.setColumn("harvest_type", 0);
|
||||
DatabaseManager.insert(c, row);
|
||||
|
||||
|
||||
return new HarvestedCollection(c, row);
|
||||
}
|
||||
|
||||
|
||||
/** Returns whether the specified collection is harvestable, i.e. whether its harvesting
|
||||
* options are set up correctly. This is distinct from "ready", since this collection may
|
||||
* be in process of being harvested.
|
||||
@@ -105,12 +105,12 @@ public class HarvestedCollection
|
||||
{
|
||||
HarvestedCollection hc = HarvestedCollection.find(c, collectionId);
|
||||
if (hc != null && hc.getHarvestType() > 0 && hc.getOaiSource() != null && hc.getOaiSetId() != null &&
|
||||
hc.getHarvestStatus() != HarvestedCollection.STATUS_UNKNOWN_ERROR) {
|
||||
return true;
|
||||
hc.getHarvestStatus() != HarvestedCollection.STATUS_UNKNOWN_ERROR) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Returns whether this harvest instance is actually harvestable, i.e. whether its settings
|
||||
* options are set up correctly. This is distinct from "ready", since this collection may
|
||||
* be in process of being harvested.
|
||||
@@ -118,13 +118,13 @@ public class HarvestedCollection
|
||||
public boolean isHarvestable() throws SQLException
|
||||
{
|
||||
if (this.getHarvestType() > 0 && this.getOaiSource() != null && this.getOaiSetId() != null &&
|
||||
this.getHarvestStatus() != HarvestedCollection.STATUS_UNKNOWN_ERROR) {
|
||||
return true;
|
||||
this.getHarvestStatus() != HarvestedCollection.STATUS_UNKNOWN_ERROR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Returns whether the specified collection is ready for immediate harvest.
|
||||
*/
|
||||
public static boolean isReady(Context c, int collectionId) throws SQLException
|
||||
@@ -132,18 +132,18 @@ public class HarvestedCollection
|
||||
HarvestedCollection hc = HarvestedCollection.find(c, collectionId);
|
||||
return hc.isReady();
|
||||
}
|
||||
|
||||
|
||||
public boolean isReady() throws SQLException
|
||||
{
|
||||
if (this.isHarvestable() && (this.getHarvestStatus() == HarvestedCollection.STATUS_READY || this.getHarvestStatus() == HarvestedCollection.STATUS_OAI_ERROR))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** Find all collections that are set up for harvesting
|
||||
*
|
||||
* return: list of collection id's
|
||||
@@ -152,18 +152,18 @@ public class HarvestedCollection
|
||||
public static List<Integer> findAll(Context c) throws SQLException
|
||||
{
|
||||
TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
|
||||
"SELECT * FROM harvested_collection");
|
||||
|
||||
"SELECT * FROM harvested_collection");
|
||||
|
||||
List<Integer> collectionIds = new ArrayList<Integer>();
|
||||
while (tri.hasNext())
|
||||
{
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
collectionIds.add(row.getIntColumn("collection_id"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return collectionIds;
|
||||
}
|
||||
|
||||
|
||||
/** Find all collections that are ready for harvesting
|
||||
*
|
||||
* return: list of collection id's
|
||||
@@ -173,10 +173,10 @@ public class HarvestedCollection
|
||||
{
|
||||
int harvestInterval = ConfigurationManager.getIntProperty("oai", "harvester.harvestFrequency");
|
||||
if (harvestInterval == 0)
|
||||
{
|
||||
harvestInterval = 720;
|
||||
}
|
||||
|
||||
{
|
||||
harvestInterval = 720;
|
||||
}
|
||||
|
||||
int expirationInterval = ConfigurationManager.getIntProperty("oai", "harvester.threadTimeout");
|
||||
if (expirationInterval == 0)
|
||||
{
|
||||
@@ -185,69 +185,68 @@ public class HarvestedCollection
|
||||
|
||||
Date startTime;
|
||||
Date expirationTime;
|
||||
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.MINUTE, -1 * harvestInterval);
|
||||
startTime = calendar.getTime();
|
||||
|
||||
calendar.setTime(startTime);
|
||||
calendar.add(Calendar.HOUR, -2 * expirationInterval);
|
||||
expirationTime = calendar.getTime();
|
||||
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.MINUTE, -1 * harvestInterval);
|
||||
startTime = calendar.getTime();
|
||||
|
||||
calendar.setTime(startTime);
|
||||
calendar.add(Calendar.HOUR, -2 * expirationInterval);
|
||||
expirationTime = calendar.getTime();
|
||||
|
||||
/* Select all collections whose last_harvest is before our start time, whose harvest_type *is not* 0 and whose status *is* 0 (available) or 3 (OAI Error). */
|
||||
TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
|
||||
"SELECT * FROM harvested_collection WHERE (last_harvested < ? or last_harvested is null) and harvest_type > ? and (harvest_status = ? or harvest_status = ? or (harvest_status=? and harvest_start_time < ?)) ORDER BY last_harvested",
|
||||
new java.sql.Timestamp(startTime.getTime()), 0, HarvestedCollection.STATUS_READY, HarvestedCollection.STATUS_OAI_ERROR, HarvestedCollection.STATUS_BUSY, new java.sql.Timestamp(expirationTime.getTime()));
|
||||
|
||||
|
||||
List<Integer> collectionIds = new ArrayList<Integer>();
|
||||
|
||||
while (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
collectionIds.add(row.getIntColumn("collection_id"));
|
||||
TableRow row = tri.next();
|
||||
collectionIds.add(row.getIntColumn("collection_id"));
|
||||
}
|
||||
|
||||
|
||||
return collectionIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find all collections with the specified status flag
|
||||
* Find all collections with the specified status flag.
|
||||
* @param c
|
||||
* @param status see HarvestInstance.STATUS_...
|
||||
* @return matching Collection IDs.
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static List<Integer> findByStatus(Context c, int status) throws SQLException {
|
||||
TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
|
||||
"SELECT * FROM harvested_collection WHERE harvest_status = ?", status);
|
||||
|
||||
List<Integer> collectionIds = new ArrayList<Integer>();
|
||||
while (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
collectionIds.add(row.getIntColumn("collection_id"));
|
||||
}
|
||||
|
||||
return collectionIds;
|
||||
|
||||
List<Integer> collectionIds = new ArrayList<Integer>();
|
||||
while (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
collectionIds.add(row.getIntColumn("collection_id"));
|
||||
}
|
||||
|
||||
return collectionIds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** Find the collection that was harvested the longest time ago.
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static Integer findOldestHarvest (Context c) throws SQLException {
|
||||
String query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? order by last_harvested asc limit 1";
|
||||
|
||||
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
{
|
||||
{
|
||||
query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? and rownum <= 1 order by last_harvested asc";
|
||||
}
|
||||
|
||||
|
||||
TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
|
||||
query, 0, 0);
|
||||
query, 0, 0);
|
||||
TableRow row = tri.next();
|
||||
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
return row.getIntColumn("collection_id");
|
||||
@@ -257,7 +256,7 @@ public class HarvestedCollection
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Find the collection that was harvested most recently.
|
||||
* @throws SQLException
|
||||
*/
|
||||
|
@@ -471,13 +471,13 @@ public class DiscoverySearchRequestProcessor implements SearchRequestProcessor
|
||||
public void doAdvancedSearch(Context context, HttpServletRequest request,
|
||||
HttpServletResponse response) throws SearchProcessorException,
|
||||
IOException, ServletException
|
||||
{
|
||||
// just redirect to the simple search servlet.
|
||||
// The advanced form is always displayed with Discovery togheter with
|
||||
// the search result
|
||||
// the first access to the advanced form performs a search for
|
||||
// "anythings" (SOLR *:*)
|
||||
response.sendRedirect(request.getContextPath() + "/simple-search");
|
||||
}
|
||||
{
|
||||
// just redirect to the simple search servlet.
|
||||
// The advanced form is always displayed with Discovery togheter with
|
||||
// the search result
|
||||
// the first access to the advanced form performs a search for
|
||||
// "anythings" (SOLR *:*)
|
||||
response.sendRedirect(request.getContextPath() + "/simple-search");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user