mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Found a few more deprecated PosixParser, GnuParser, OptionBuilder. #2956
This commit is contained in:
@@ -24,10 +24,10 @@ import java.util.UUID;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -109,7 +109,7 @@ public class ItemUpdate {
|
||||
|
||||
// instance variables
|
||||
protected ActionManager actionMgr = new ActionManager();
|
||||
protected List<String> undoActionList = new ArrayList<String>();
|
||||
protected List<String> undoActionList = new ArrayList<>();
|
||||
protected String eperson;
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ public class ItemUpdate {
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
// create an options object and populate it
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
|
@@ -17,10 +17,10 @@ import javax.mail.MessagingException;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.checker.factory.CheckerServiceFactory;
|
||||
@@ -102,7 +102,7 @@ public class DailyReportEmailer {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// set up command line parser
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine line = null;
|
||||
|
||||
// create an options object and populate it
|
||||
|
@@ -15,7 +15,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.OptionGroup;
|
||||
@@ -83,7 +84,7 @@ public class EPersonCLITool {
|
||||
globalOptions.addOptionGroup(VERBS);
|
||||
globalOptions.addOption("h", "help", false, "explain options");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine command = parser.parse(globalOptions, argv, true);
|
||||
|
||||
Context context = new Context();
|
||||
@@ -145,7 +146,7 @@ public class EPersonCLITool {
|
||||
options.addOption("h", "help", false, "explain --add options");
|
||||
|
||||
// Rescan the command for more details.
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine command;
|
||||
try {
|
||||
command = parser.parse(options, argv);
|
||||
@@ -225,7 +226,7 @@ public class EPersonCLITool {
|
||||
|
||||
options.addOption("h", "help", false, "explain --delete options");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine command;
|
||||
try {
|
||||
command = parser.parse(options, argv);
|
||||
@@ -314,7 +315,7 @@ public class EPersonCLITool {
|
||||
|
||||
options.addOption("h", "help", false, "explain --modify options");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine command;
|
||||
try {
|
||||
command = parser.parse(options, argv);
|
||||
|
@@ -19,12 +19,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.OptionBuilder;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -73,7 +72,7 @@ public class RDFizer {
|
||||
/**
|
||||
* Set to remember with DSpaceObject were converted or deleted from the
|
||||
* triplestore already. This set is helpful when converting or deleting
|
||||
* multiple DSpaceObjects (e.g. Communities with all Subcommunities and
|
||||
* multiple DSpaceObjects (e.g. Communities with all sub-Communities and
|
||||
* Items).
|
||||
*/
|
||||
protected Set<UUID> processed;
|
||||
@@ -83,7 +82,7 @@ public class RDFizer {
|
||||
this.verbose = false;
|
||||
this.dryrun = false;
|
||||
this.lang = "TURTLE";
|
||||
this.processed = new CopyOnWriteArraySet<UUID>();
|
||||
this.processed = new CopyOnWriteArraySet<>();
|
||||
this.context = new Context(Context.Mode.READ_ONLY);
|
||||
|
||||
this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
@@ -473,7 +472,7 @@ public class RDFizer {
|
||||
protected void runCLI(String[] args) {
|
||||
// prepare CLI and parse arguments
|
||||
Options options = createOptions();
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine line = null;
|
||||
try {
|
||||
line = parser.parse(options, args);
|
||||
@@ -487,7 +486,7 @@ public class RDFizer {
|
||||
|
||||
String[] remainingArgs = line.getArgs();
|
||||
if (remainingArgs.length > 0) {
|
||||
this.usage(options);
|
||||
usage(options);
|
||||
System.err.println();
|
||||
StringBuilder builder = new StringBuilder(100);
|
||||
for (String argument : remainingArgs) {
|
||||
@@ -647,7 +646,7 @@ public class RDFizer {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
this.usage(options);
|
||||
usage(options);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@@ -708,24 +707,25 @@ public class RDFizer {
|
||||
"depending on the number of stored communties, collections and " +
|
||||
"items. Existing information in the triple store will be updated.");
|
||||
|
||||
Option optIdentifiers = OptionBuilder.withLongOpt("identifiers")
|
||||
Option optIdentifiers = Option.builder("i")
|
||||
.longOpt("identifiers")
|
||||
.hasArgs()
|
||||
.withArgName("handle")
|
||||
.withValueSeparator(' ')
|
||||
.withDescription("Only convert these DSpace Objects. If you specify "
|
||||
+ "a Community or Collection all of their Items " +
|
||||
"will be "
|
||||
+ "converted as well. Separate multiple identifiers" +
|
||||
" with a "
|
||||
+ "space.")
|
||||
.create('i');
|
||||
.argName("handle")
|
||||
.valueSeparator(' ')
|
||||
.desc("Only convert these DSpace Objects. If you specify "
|
||||
+ "a Community or Collection all of their Items "
|
||||
+ "will be "
|
||||
+ "converted as well. Separate multiple identifiers"
|
||||
+ " with a space.")
|
||||
.build();
|
||||
options.addOption(optIdentifiers);
|
||||
|
||||
Option optDelete = OptionBuilder.withLongOpt("delete")
|
||||
Option optDelete = Option.builder()
|
||||
.longOpt("delete")
|
||||
.hasArgs()
|
||||
.withArgName("hdl:handle | URI")
|
||||
.withValueSeparator(' ')
|
||||
.withDescription("Delete previously converted data. Specify "
|
||||
.argName("hdl:handle | URI")
|
||||
.valueSeparator(' ')
|
||||
.desc("Delete previously converted data. Specify "
|
||||
+ "either the handle of a DSpaceObject in the format "
|
||||
+ "'hdl:<handle>' or the URI used to identify the rdf "
|
||||
+ "data in the triplestore. If you specify a Community, "
|
||||
@@ -734,12 +734,13 @@ public class RDFizer {
|
||||
+ "Collections, Items, Bundles and Bitstreams will be "
|
||||
+ "deleted as well. Separate multiple identifiers with "
|
||||
+ "a space.")
|
||||
.create();
|
||||
.build();
|
||||
options.addOption(optDelete);
|
||||
|
||||
Option optDeleteAll = OptionBuilder.withLongOpt("delete-all")
|
||||
.withDescription("Delete all converted data from the triplestore.")
|
||||
.create();
|
||||
Option optDeleteAll = Option.builder()
|
||||
.longOpt("delete-all")
|
||||
.desc("Delete all converted data from the triplestore.")
|
||||
.build();
|
||||
options.addOption(optDeleteAll);
|
||||
|
||||
return options;
|
||||
@@ -768,8 +769,7 @@ public class RDFizer {
|
||||
// We won't change the database => read_only context will assure this.
|
||||
Context context = new Context(Context.Mode.READ_ONLY);
|
||||
|
||||
RDFizer myself = null;
|
||||
myself = new RDFizer();
|
||||
RDFizer myself = new RDFizer();
|
||||
myself.overrideContext(context);
|
||||
myself.runCLI(args);
|
||||
|
||||
|
@@ -0,0 +1,105 @@
|
||||
package org.dspace.content;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwood
|
||||
*/
|
||||
public class MetadataFieldNameTest {
|
||||
private static final String STRING_NAME_3 = "one.two.three";
|
||||
private static final String STRING_NAME_2 = "one.two";
|
||||
|
||||
public MetadataFieldNameTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstruct3() {
|
||||
MetadataFieldName instance = new MetadataFieldName("one", "two", "three");
|
||||
assertEquals("Incorrect schema", "one", instance.SCHEMA);
|
||||
assertEquals("Incorrect element", "two", instance.ELEMENT);
|
||||
assertEquals("Incorrect qualifier", "three", instance.QUALIFIER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstruct2() {
|
||||
MetadataFieldName instance = new MetadataFieldName("one", "two");
|
||||
assertEquals("Incorrect schema", "one", instance.SCHEMA);
|
||||
assertEquals("Incorrect element", "two", instance.ELEMENT);
|
||||
assertNull("Incorrect qualifier", instance.QUALIFIER);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testConstructNull() {
|
||||
MetadataFieldName instance = new MetadataFieldName("one", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of parse method using a 3-part name.
|
||||
*/
|
||||
@Test
|
||||
public void testParse3() {
|
||||
String[] results = MetadataFieldName.parse(STRING_NAME_3);
|
||||
assertEquals(STRING_NAME_3, "one", results[0]);
|
||||
assertEquals(STRING_NAME_3, "two", results[1]);
|
||||
assertEquals(STRING_NAME_3, "three", results[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of parse method using a 2-part name.
|
||||
*/
|
||||
@Test
|
||||
public void TestParse2() {
|
||||
String[] results = MetadataFieldName.parse(STRING_NAME_2);
|
||||
assertEquals(STRING_NAME_2, "one", results[0]);
|
||||
assertEquals(STRING_NAME_2, "two", results[1]);
|
||||
assertNull(STRING_NAME_2, results[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of parse method using an illegal 1-part name.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void TestParse1() {
|
||||
String[] results = MetadataFieldName.parse("one");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of parse method using an illegal 0-part (empty) name.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void TestParse0() {
|
||||
String[] results = MetadataFieldName.parse("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of parse method using an illegal null name.
|
||||
*/
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void TestParseNull() {
|
||||
String[] results = MetadataFieldName.parse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of toString method using a 3-part name.
|
||||
*/
|
||||
@Test
|
||||
public void testToString3() {
|
||||
MetadataFieldName instance = new MetadataFieldName("one", "two", "three");
|
||||
String name = instance.toString();
|
||||
assertEquals("Stringified name not assembled correctly", "one.two.three", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of toString method using a 2-part name.
|
||||
*/
|
||||
@Test
|
||||
public void testToString2() {
|
||||
MetadataFieldName instance = new MetadataFieldName("one", "two");
|
||||
String name = instance.toString();
|
||||
assertEquals("Stringified name not assembled correctly", "one.two", name);
|
||||
}
|
||||
}
|
@@ -29,8 +29,8 @@ import com.lyncode.xoai.dataprovider.exceptions.WritingXmlException;
|
||||
import com.lyncode.xoai.dataprovider.xml.XmlOutputContext;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
@@ -211,7 +211,7 @@ public class XOAI {
|
||||
try {
|
||||
SolrQuery params = new SolrQuery("item.willChangeStatus:true").addField("item.id");
|
||||
SolrDocumentList documents = DSpaceSolrSearch.query(solrServerResolver.getServer(), params);
|
||||
List<Item> items = new LinkedList<Item>();
|
||||
List<Item> items = new LinkedList<>();
|
||||
for (int i = 0; i < documents.getNumFound(); i++) {
|
||||
Item item = itemService.find(context,
|
||||
UUID.fromString((String) documents.get(i).getFieldValue("item.id")));
|
||||
@@ -336,7 +336,7 @@ public class XOAI {
|
||||
* @throws SQLException
|
||||
*/
|
||||
private Date getMostRecentModificationDate(Item item) throws SQLException {
|
||||
List<Date> dates = new LinkedList<Date>();
|
||||
List<Date> dates = new LinkedList<>();
|
||||
List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, item, Constants.READ);
|
||||
for (ResourcePolicy policy : policies) {
|
||||
if ((policy.getGroup() != null) && (policy.getGroup().getName().equals("Anonymous"))) {
|
||||
@@ -553,7 +553,7 @@ public class XOAI {
|
||||
Context ctx = null;
|
||||
|
||||
try {
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
Options options = new Options();
|
||||
options.addOption("c", "clear", false, "Clear index before indexing");
|
||||
options.addOption("o", "optimize", false,
|
||||
|
Reference in New Issue
Block a user