mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 23:43:06 +00:00
Merge remote-tracking branch 'upstream/master' into DS-861
This commit is contained in:
@@ -111,6 +111,7 @@
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<dspace.dir>${project.build.directory}/testing/dspace</dspace.dir>
|
||||
<dspace.dir.static>${basedir}/src/test/data/dspaceFolder</dspace.dir.static>
|
||||
<dspace.configuration>${project.build.directory}/testing/dspace.cfg.woven</dspace.configuration>
|
||||
<db.schema.path>${project.build.directory}/testing/dspace/etc/h2/database_schema.sql</db.schema.path>
|
||||
<dspace.log.init.disable>true</dspace.log.init.disable>
|
||||
|
@@ -87,12 +87,14 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
{
|
||||
class xmlFilter implements java.io.FilenameFilter
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
return name.endsWith(".xml");
|
||||
}
|
||||
}
|
||||
String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir") + "/config/controlled-vocabularies/";
|
||||
String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir")
|
||||
+ "/config/controlled-vocabularies/";
|
||||
String[] xmlFiles = (new File(vocabulariesPath)).list(new xmlFilter());
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (String filename : xmlFiles)
|
||||
@@ -154,6 +156,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale)
|
||||
{
|
||||
init();
|
||||
@@ -162,7 +165,8 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
Choice[] choices;
|
||||
try {
|
||||
NodeList results = (NodeList)xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET);
|
||||
NodeList results = (NodeList) xpath.evaluate(xpathExpression,
|
||||
vocabulary, XPathConstants.NODESET);
|
||||
String[] authorities = new String[results.getLength()];
|
||||
String[] values = new String[results.getLength()];
|
||||
String[] labels = new String[results.getLength()];
|
||||
@@ -186,15 +190,20 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
{
|
||||
values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
|
||||
}
|
||||
authorities[i] = node.getAttributes().getNamedItem("id").getNodeValue();
|
||||
Node idAttr = node.getAttributes().getNamedItem("id");
|
||||
if (null != idAttr) // 'id' is optional
|
||||
authorities[i] = idAttr.getNodeValue();
|
||||
}
|
||||
int resultCount = Math.min(labels.length-start, limit);
|
||||
int resultCount = labels.length - start;
|
||||
if ((limit > 0) && (resultCount > limit)) // limit = 0 means no limit
|
||||
resultCount = limit;
|
||||
choices = new Choice[resultCount];
|
||||
if (resultCount > 0)
|
||||
{
|
||||
for (int i = 0; i < resultCount; i++)
|
||||
{
|
||||
choices[i] = new Choice(authorities[start+i],values[start+i],labels[start+i]);
|
||||
choices[i] = new Choice(authorities[start + i], values[start
|
||||
+ i], labels[start + i]);
|
||||
}
|
||||
}
|
||||
} catch(XPathExpressionException e) {
|
||||
@@ -203,6 +212,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Choices getBestMatch(String field, String text, int collection, String locale)
|
||||
{
|
||||
init();
|
||||
@@ -210,6 +220,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
||||
return getMatches(field, text, collection, 0, 2, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(String field, String key, String locale)
|
||||
{
|
||||
init();
|
||||
|
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node label='the farm'>
|
||||
<isComposedBy>
|
||||
<node label='north 40'/>
|
||||
<node id='s40' label='south 40'/>
|
||||
</isComposedBy>
|
||||
</node>
|
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
||||
package org.dspace;
|
||||
|
||||
import java.util.Properties;
|
||||
import mockit.Mock;
|
||||
import mockit.MockClass;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Dummy ConfigurationManager with a setter instead of external storage for
|
||||
* values. Call {@link setProperty} to create configuration.
|
||||
*
|
||||
* <p>Please note that this implementation is incomplete!</p>
|
||||
*
|
||||
* @author mwood
|
||||
*/
|
||||
@MockClass(realClass=ConfigurationManager.class)
|
||||
public class MockConfigurationManager {
|
||||
private static final Properties properties = new Properties();
|
||||
private static final Logger log = LoggerFactory.getLogger(MockConfigurationManager.class);
|
||||
|
||||
/**
|
||||
* Set a value in the configuration map.
|
||||
*
|
||||
* @param key name of the configuration datum.
|
||||
* @param value value to be assigned to the name.
|
||||
*/
|
||||
public static void setProperty(String key, String value)
|
||||
{
|
||||
log.info("setProperty({}, {});", key, value);
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a value from the map.
|
||||
*
|
||||
* @param key name of the configuration property desired.
|
||||
* @return value bound to that name, or null if not set.
|
||||
*/
|
||||
@Mock
|
||||
public static String getProperty(String key)
|
||||
{
|
||||
log.info("getProperty({});", key);
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
}
|
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.content.authority;
|
||||
|
||||
import java.io.IOException;
|
||||
import mockit.UsingMocksAndStubs;
|
||||
import org.dspace.MockConfigurationManager;
|
||||
import org.dspace.core.PluginManager;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.*;
|
||||
|
||||
/**
|
||||
* Unit tests for DSpaceControlledVocabulary.
|
||||
*
|
||||
* @author mwood
|
||||
*/
|
||||
@UsingMocksAndStubs(value=MockConfigurationManager.class)
|
||||
public class DSpaceControlledVocabularyTest
|
||||
{
|
||||
public DSpaceControlledVocabularyTest()
|
||||
{
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getPluginNames method, of class DSpaceControlledVocabulary.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetPluginNames()
|
||||
{
|
||||
System.out.println("getPluginNames");
|
||||
String[] expResult = null;
|
||||
String[] result = DSpaceControlledVocabulary.getPluginNames();
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getMatches method, of class DSpaceControlledVocabulary.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMatches() throws IOException, ClassNotFoundException
|
||||
{
|
||||
System.out.println("getMatches");
|
||||
|
||||
// Set up the PluginManager
|
||||
final String PLUGIN_INTERFACE = "org.dspace.content.authority.ChoiceAuthority";
|
||||
final String PLUGIN_NAME = "org.dspace.content.authority.DSpaceControlledVocabulary";
|
||||
|
||||
MockConfigurationManager.setProperty("dspace.dir",
|
||||
System.getProperty("dspace.dir.static"));
|
||||
MockConfigurationManager.setProperty(
|
||||
"plugin.selfnamed." + PLUGIN_INTERFACE, PLUGIN_NAME);
|
||||
|
||||
// Ensure that 'id' attribute is optional
|
||||
String field = null; // not used
|
||||
String text = "north 40";
|
||||
int collection = 0;
|
||||
int start = 0;
|
||||
int limit = 0;
|
||||
String locale = null;
|
||||
DSpaceControlledVocabulary instance = (DSpaceControlledVocabulary)
|
||||
PluginManager.getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm");
|
||||
assertNotNull(instance);
|
||||
Choices result = instance.getMatches(field, text, collection, start,
|
||||
limit, locale);
|
||||
assertEquals("the farm::north 40", result.values[0].value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getBestMatch method, of class DSpaceControlledVocabulary.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetBestMatch()
|
||||
{
|
||||
System.out.println("getBestMatch");
|
||||
String field = "";
|
||||
String text = "";
|
||||
int collection = 0;
|
||||
String locale = "";
|
||||
DSpaceControlledVocabulary instance = new DSpaceControlledVocabulary();
|
||||
Choices expResult = null;
|
||||
Choices result = instance.getBestMatch(field, text, collection, locale);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getLabel method, of class DSpaceControlledVocabulary.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetLabel()
|
||||
{
|
||||
System.out.println("getLabel");
|
||||
String field = "";
|
||||
String key = "";
|
||||
String locale = "";
|
||||
DSpaceControlledVocabulary instance = new DSpaceControlledVocabulary();
|
||||
String expResult = "";
|
||||
String result = instance.getLabel(field, key, locale);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
}
|
@@ -45,29 +45,39 @@ public class ApacheLogRobotsProcessor {
|
||||
|
||||
CommandLine line = parser.parse(options, args);
|
||||
|
||||
// Log source
|
||||
String logFileLoc;
|
||||
String spiderIpPath;
|
||||
if (line.hasOption("l"))
|
||||
{
|
||||
logFileLoc = line.getOptionValue("l");
|
||||
}
|
||||
else {
|
||||
System.out.println("We need our log file");
|
||||
return;
|
||||
logFileLoc = "-";
|
||||
}
|
||||
|
||||
// Spider IP list
|
||||
String spiderIpPath;
|
||||
if (line.hasOption("s"))
|
||||
{
|
||||
spiderIpPath = line.getOptionValue("s");
|
||||
}
|
||||
else {
|
||||
System.out.println("We need a spider IP output file");
|
||||
return;
|
||||
spiderIpPath = "-";
|
||||
}
|
||||
|
||||
File spiderIpFile = new File(spiderIpPath);
|
||||
|
||||
//Get the IPs already added in our file
|
||||
Set<String> logSpiders;
|
||||
Writer output;
|
||||
|
||||
if ("-".equals(spiderIpPath))
|
||||
{
|
||||
logSpiders = new HashSet<String>();
|
||||
output = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
}
|
||||
else
|
||||
{
|
||||
File spiderIpFile = new File(spiderIpPath);
|
||||
|
||||
if (spiderIpFile.exists())
|
||||
{
|
||||
logSpiders = SpiderDetector.readIpAddresses(spiderIpFile);
|
||||
@@ -76,9 +86,16 @@ public class ApacheLogRobotsProcessor {
|
||||
{
|
||||
logSpiders = new HashSet<String>();
|
||||
}
|
||||
output = new BufferedWriter(new FileWriter(spiderIpFile));
|
||||
}
|
||||
|
||||
//First read in our log file line per line
|
||||
BufferedReader in = new BufferedReader(new FileReader(logFileLoc));
|
||||
BufferedReader in;
|
||||
if ("-".equals(logFileLoc))
|
||||
in = new BufferedReader(new InputStreamReader(System.in));
|
||||
else
|
||||
in = new BufferedReader(new FileReader(logFileLoc));
|
||||
|
||||
String logLine;
|
||||
while ((logLine = in.readLine()) != null) {
|
||||
//Currently only check if robot.txt is present in our line
|
||||
@@ -92,11 +109,8 @@ public class ApacheLogRobotsProcessor {
|
||||
in.close();
|
||||
|
||||
//Last but not least add the IPs to our file
|
||||
BufferedWriter output = new BufferedWriter(new FileWriter(spiderIpFile));
|
||||
|
||||
//Second write the new IPs
|
||||
for (String ip : logSpiders) {
|
||||
System.out.println("Adding new ip: " + ip);
|
||||
System.err.println("Adding new ip: " + ip);
|
||||
//Write each new IP on a separate line
|
||||
output.write(ip + "\n");
|
||||
}
|
||||
|
@@ -85,16 +85,37 @@ public class ClassicDSpaceLogConverter {
|
||||
int counter = 0;
|
||||
int lines = 0;
|
||||
|
||||
// Figure out input, output
|
||||
BufferedReader input;
|
||||
Writer output;
|
||||
try {
|
||||
if (null == in || in.isEmpty() || "-".equals(in))
|
||||
{
|
||||
input = new BufferedReader(new InputStreamReader(System.in));
|
||||
in = "standard input";
|
||||
}
|
||||
else
|
||||
input = new BufferedReader(new FileReader(in));
|
||||
|
||||
if (null == out || out.isEmpty() || "-".equals(out))
|
||||
{
|
||||
output = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
out = "standard output";
|
||||
}
|
||||
else
|
||||
output = new BufferedWriter(new FileWriter(out));
|
||||
} catch (IOException ie) {
|
||||
log.error("File access problem", ie);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Say what we're going to do
|
||||
System.out.println(" About to convert '" + in + "' to '" + out + "'");
|
||||
System.err.println(" About to convert '" + in + "' to '" + out + "'");
|
||||
|
||||
// Setup the regular expressions for the log file
|
||||
LogAnalyser.setRegex(in);
|
||||
|
||||
// Open the file and read it line by line
|
||||
BufferedReader input = null;
|
||||
Writer output = null;
|
||||
|
||||
try {
|
||||
String line;
|
||||
LogLine lline;
|
||||
@@ -107,9 +128,6 @@ public class ClassicDSpaceLogConverter {
|
||||
String uid;
|
||||
String lastLine = "";
|
||||
|
||||
input = new BufferedReader(new FileReader(new File(in)));
|
||||
output = new BufferedWriter(new FileWriter(new File(out)));
|
||||
|
||||
while ((line = input.readLine()) != null)
|
||||
{
|
||||
// Read inthe line and covnert it to a LogLine
|
||||
@@ -236,7 +254,7 @@ public class ClassicDSpaceLogConverter {
|
||||
}
|
||||
|
||||
// Tell the user what we have done
|
||||
System.out.println(" Read " + lines + " lines and recorded " + counter + " events");
|
||||
System.err.println(" Read " + lines + " lines and recorded " + counter + " events");
|
||||
return counter;
|
||||
}
|
||||
|
||||
@@ -251,7 +269,7 @@ public class ClassicDSpaceLogConverter {
|
||||
// print the help message
|
||||
HelpFormatter myhelp = new HelpFormatter();
|
||||
myhelp.printHelp("ClassicDSpaceLogConverter\n", options);
|
||||
System.out.println("\n\tClassicDSpaceLogConverter -i infilename -o outfilename -v (for verbose output)");
|
||||
System.err.println("\n\tClassicDSpaceLogConverter -i infilename -o outfilename -v (for verbose output)");
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
@@ -266,8 +284,8 @@ public class ClassicDSpaceLogConverter {
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption("i", "in", true, "source file");
|
||||
options.addOption("o", "out", true, "destination directory");
|
||||
options.addOption("i", "in", true, "source file ('-' or omit for standard input)");
|
||||
options.addOption("o", "out", true, "destination file or directory ('-' or omit for standard output)");
|
||||
options.addOption("m", "multiple",false, "treat the input file as having a wildcard ending");
|
||||
options.addOption("n", "newformat",false, "process new format log lines (1.6+)");
|
||||
options.addOption("v", "verbose", false, "display verbose output (useful for debugging)");
|
||||
@@ -292,24 +310,6 @@ public class ClassicDSpaceLogConverter {
|
||||
printHelp(options, 0);
|
||||
}
|
||||
|
||||
// Check we have an input and output file
|
||||
if ((!line.hasOption('i')) && (!line.hasOption('o')))
|
||||
{
|
||||
System.err.println("-i and -o input and output file names are required");
|
||||
printHelp(options, 1);
|
||||
}
|
||||
else if (!line.hasOption('i'))
|
||||
{
|
||||
System.err.println("-i input file name is required");
|
||||
printHelp(options, 1);
|
||||
}
|
||||
|
||||
if (!line.hasOption('o'))
|
||||
{
|
||||
System.err.println("-o output file names is required");
|
||||
printHelp(options, 1);
|
||||
}
|
||||
|
||||
// Whether or not to include event created by org.dspace.usage.LoggerUsageEventListener
|
||||
boolean newEvents = line.hasOption('n');
|
||||
|
||||
@@ -357,7 +357,7 @@ public class ClassicDSpaceLogConverter {
|
||||
String[] children = dir.list(filter);
|
||||
for (String in : children)
|
||||
{
|
||||
System.out.println(in);
|
||||
System.err.println(in);
|
||||
String out = line.getOptionValue('o') +
|
||||
(dir.getAbsolutePath() +
|
||||
System.getProperty("file.separator") + in).substring(line.getOptionValue('i').length());
|
||||
|
@@ -13,7 +13,6 @@ import org.apache.log4j.Logger;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.Context;
|
||||
@@ -22,7 +21,6 @@ import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.statistics.SolrLogger;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -135,7 +133,7 @@ public class StatisticsImporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load the lines from the statics file and load them into solr
|
||||
* Read lines from the statistics file and load their data into solr.
|
||||
*
|
||||
* @param filename The filename of the file to load
|
||||
* @param context The DSpace Context
|
||||
@@ -143,9 +141,6 @@ public class StatisticsImporter
|
||||
*/
|
||||
private void load(String filename, Context context, boolean verbose)
|
||||
{
|
||||
// Print out the filename for confirmation
|
||||
System.out.println("Processing file: " + filename);
|
||||
|
||||
// Item counter
|
||||
int counter = 0;
|
||||
int errors = 0;
|
||||
@@ -153,7 +148,17 @@ public class StatisticsImporter
|
||||
|
||||
try
|
||||
{
|
||||
BufferedReader input = new BufferedReader(new FileReader(new File(filename)));
|
||||
BufferedReader input;
|
||||
if (null == filename || "-".equals(filename))
|
||||
{
|
||||
input = new BufferedReader(new InputStreamReader(System.in));
|
||||
filename = "standard input";
|
||||
}
|
||||
else
|
||||
input = new BufferedReader(new FileReader(new File(filename)));
|
||||
|
||||
// Print out the filename for confirmation
|
||||
System.out.println("Processing file: " + filename);
|
||||
|
||||
String line;
|
||||
// String uuid;
|
||||
@@ -426,7 +431,7 @@ public class StatisticsImporter
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption("i", "in", true, "the inpout file");
|
||||
options.addOption("i", "in", true, "the input file ('-' or omit for standard input)");
|
||||
options.addOption("l", "local", false, "developers tool - map external log file to local handles");
|
||||
options.addOption("m", "multiple", false, "treat the input file as having a wildcard ending");
|
||||
options.addOption("s", "skipdns", false, "skip performing reverse DNS lookups on IP addresses");
|
||||
@@ -441,12 +446,6 @@ public class StatisticsImporter
|
||||
printHelp(options, 0);
|
||||
}
|
||||
|
||||
if (!line.hasOption('i'))
|
||||
{
|
||||
System.err.println("You must specify an input file using the -i flag");
|
||||
printHelp(options, 1);
|
||||
}
|
||||
|
||||
if (line.hasOption('s'))
|
||||
{
|
||||
skipReverseDNS = true;
|
||||
|
@@ -94,7 +94,6 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ant-contrib</groupId>
|
||||
|
Reference in New Issue
Block a user