mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 23:43:06 +00:00
Fix dspace-api module per new code style
This commit is contained in:
@@ -7,8 +7,16 @@
|
||||
*/
|
||||
package org.dspace.discovery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.OptionBuilder;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
@@ -20,10 +28,6 @@ import org.dspace.core.Context;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Class used to reindex dspace communities/collections/items into discovery
|
||||
*
|
||||
@@ -33,18 +37,20 @@ import java.util.Iterator;
|
||||
*/
|
||||
public class IndexClient {
|
||||
|
||||
|
||||
private static final Logger log = Logger.getLogger(IndexClient.class);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private IndexClient() { }
|
||||
|
||||
/**
|
||||
* When invoked as a command-line tool, creates, updates, removes content
|
||||
* from the whole index
|
||||
*
|
||||
* @param args the command-line arguments, none used
|
||||
* @throws SQLException
|
||||
* An exception that provides information on a database access error or other errors.
|
||||
* @throws IOException
|
||||
* A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @throws SearchServiceException if something went wrong with querying the solr server
|
||||
*/
|
||||
public static void main(String[] args) throws SQLException, IOException, SearchServiceException {
|
||||
@@ -52,57 +58,58 @@ public class IndexClient {
|
||||
Context context = new Context(Context.Mode.READ_ONLY);
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
String usage = "org.dspace.discovery.IndexClient [-cbhf] | [-r <handle>] | [-i <handle>] or nothing to update/clean an existing index.";
|
||||
String usage = "org.dspace.discovery.IndexClient [-cbhf] | [-r <handle>] | [-i <handle>] or nothing to " +
|
||||
"update/clean an existing index.";
|
||||
Options options = new Options();
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
CommandLine line = null;
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.withArgName("handle to remove")
|
||||
.hasArg(true)
|
||||
.withDescription(
|
||||
"remove an Item, Collection or Community from index based on its handle")
|
||||
.create("r"));
|
||||
.withArgName("handle to remove")
|
||||
.hasArg(true)
|
||||
.withDescription(
|
||||
"remove an Item, Collection or Community from index based on its handle")
|
||||
.create("r"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.withArgName("handle to add or update")
|
||||
.hasArg(true)
|
||||
.withDescription(
|
||||
"add or update an Item, Collection or Community based on its handle")
|
||||
.create("i"));
|
||||
.withArgName("handle to add or update")
|
||||
.hasArg(true)
|
||||
.withDescription(
|
||||
"add or update an Item, Collection or Community based on its handle")
|
||||
.create("i"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"clean existing index removing any documents that no longer exist in the db")
|
||||
.create("c"));
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"clean existing index removing any documents that no longer exist in the db")
|
||||
.create("c"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"(re)build index, wiping out current one if it exists")
|
||||
.create("b"));
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"(re)build index, wiping out current one if it exists")
|
||||
.create("b"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"Rebuild the spellchecker, can be combined with -b and -f.")
|
||||
.create("s"));
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"Rebuild the spellchecker, can be combined with -b and -f.")
|
||||
.create("s"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"if updating existing index, force each handle to be reindexed even if uptodate")
|
||||
.create("f"));
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"if updating existing index, force each handle to be reindexed even if uptodate")
|
||||
.create("f"));
|
||||
|
||||
options.addOption(OptionBuilder
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"print this help message")
|
||||
.create("h"));
|
||||
.isRequired(false)
|
||||
.withDescription(
|
||||
"print this help message")
|
||||
.create("h"));
|
||||
|
||||
options.addOption(OptionBuilder.isRequired(false).withDescription(
|
||||
"optimize search core").create("o"));
|
||||
"optimize search core").create("o"));
|
||||
|
||||
try {
|
||||
line = new PosixParser().parse(options, args);
|
||||
@@ -145,14 +152,15 @@ public class IndexClient {
|
||||
checkRebuildSpellCheck(line, indexer);
|
||||
} else if (line.hasOption('i')) {
|
||||
final String handle = line.getOptionValue('i');
|
||||
final DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService().resolveToObject(context, handle);
|
||||
final DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService()
|
||||
.resolveToObject(context, handle);
|
||||
if (dso == null) {
|
||||
throw new IllegalArgumentException("Cannot resolve " + handle + " to a DSpace object");
|
||||
}
|
||||
log.info("Forcibly Indexing " + handle);
|
||||
final long startTimeMillis = System.currentTimeMillis();
|
||||
final long count = indexAll(indexer, ContentServiceFactory.getInstance().getItemService(), context, dso);
|
||||
final long seconds = (System.currentTimeMillis() - startTimeMillis ) / 1000;
|
||||
final long count = indexAll(indexer, ContentServiceFactory.getInstance().getItemService(), context, dso);
|
||||
final long seconds = (System.currentTimeMillis() - startTimeMillis) / 1000;
|
||||
log.info("Indexed " + count + " DSpace object" + (count > 1 ? "s" : "") + " in " + seconds + " seconds");
|
||||
} else {
|
||||
log.info("Updating and Cleaning Index");
|
||||
@@ -168,25 +176,18 @@ public class IndexClient {
|
||||
* Indexes the given object and all children, if applicable.
|
||||
*
|
||||
* @param indexingService
|
||||
*
|
||||
* @param itemService
|
||||
*
|
||||
* @param context
|
||||
* The relevant DSpace Context.
|
||||
* @param dso
|
||||
* DSpace object to index recursively
|
||||
* @throws IOException
|
||||
* A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @param context The relevant DSpace Context.
|
||||
* @param dso DSpace object to index recursively
|
||||
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @throws SearchServiceException in case of a solr exception
|
||||
* @throws SQLException
|
||||
* An exception that provides information on a database access error or other errors.
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
*/
|
||||
private static long indexAll(final IndexingService indexingService,
|
||||
final ItemService itemService,
|
||||
final Context context,
|
||||
final DSpaceObject dso)
|
||||
throws IOException, SearchServiceException, SQLException
|
||||
{
|
||||
throws IOException, SearchServiceException, SQLException {
|
||||
long count = 0;
|
||||
|
||||
indexingService.indexContent(context, dso, true, true);
|
||||
@@ -199,7 +200,9 @@ public class IndexClient {
|
||||
//To prevent memory issues, discard an object from the cache after processing
|
||||
context.uncacheEntity(subcommunity);
|
||||
}
|
||||
final Community reloadedCommunity = (Community) HandleServiceFactory.getInstance().getHandleService().resolveToObject(context, communityHandle);
|
||||
final Community reloadedCommunity = (Community) HandleServiceFactory.getInstance().getHandleService()
|
||||
.resolveToObject(context,
|
||||
communityHandle);
|
||||
for (final Collection collection : reloadedCommunity.getCollections()) {
|
||||
count++;
|
||||
indexingService.indexContent(context, collection, true, true);
|
||||
@@ -218,25 +221,18 @@ public class IndexClient {
|
||||
* Indexes all items in the given collection.
|
||||
*
|
||||
* @param indexingService
|
||||
*
|
||||
* @param itemService
|
||||
*
|
||||
* @param context
|
||||
* The relevant DSpace Context.
|
||||
* @param collection
|
||||
* collection to index
|
||||
* @throws IOException
|
||||
* A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @param context The relevant DSpace Context.
|
||||
* @param collection collection to index
|
||||
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @throws SearchServiceException in case of a solr exception
|
||||
* @throws SQLException
|
||||
* An exception that provides information on a database access error or other errors.
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
*/
|
||||
private static long indexItems(final IndexingService indexingService,
|
||||
final ItemService itemService,
|
||||
final Context context,
|
||||
final Collection collection)
|
||||
throws IOException, SearchServiceException, SQLException
|
||||
{
|
||||
throws IOException, SearchServiceException, SQLException {
|
||||
long count = 0;
|
||||
|
||||
final Iterator<Item> itemIterator = itemService.findByCollection(context, collection);
|
||||
@@ -254,13 +250,13 @@ public class IndexClient {
|
||||
|
||||
/**
|
||||
* Check the command line options and rebuild the spell check if active.
|
||||
* @param line the command line options
|
||||
*
|
||||
* @param line the command line options
|
||||
* @param indexer the solr indexer
|
||||
* @throws SearchServiceException in case of a solr exception
|
||||
*/
|
||||
protected static void checkRebuildSpellCheck(CommandLine line, IndexingService indexer)
|
||||
throws SearchServiceException
|
||||
{
|
||||
throws SearchServiceException {
|
||||
if (line.hasOption("s")) {
|
||||
log.info("Rebuilding spell checker.");
|
||||
indexer.buildSpellCheck();
|
||||
|
Reference in New Issue
Block a user