mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 07:53:08 +00:00
Merge remote-tracking branch 'upstream/master' into DS-861
This commit is contained in:
@@ -111,6 +111,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<dspace.dir>${project.build.directory}/testing/dspace</dspace.dir>
|
<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>
|
<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>
|
<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>
|
<dspace.log.init.disable>true</dspace.log.init.disable>
|
||||||
|
@@ -55,7 +55,7 @@ import org.dspace.core.SelfNamedPlugin;
|
|||||||
public class DSpaceControlledVocabulary extends SelfNamedPlugin implements ChoiceAuthority
|
public class DSpaceControlledVocabulary extends SelfNamedPlugin implements ChoiceAuthority
|
||||||
{
|
{
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class);
|
private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class);
|
||||||
private static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]";
|
private static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]";
|
||||||
private static String idTemplate = "//node[@id = '%s']";
|
private static String idTemplate = "//node[@id = '%s']";
|
||||||
private static String pluginNames[] = null;
|
private static String pluginNames[] = null;
|
||||||
@@ -85,22 +85,24 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
|||||||
{
|
{
|
||||||
if (pluginNames == null)
|
if (pluginNames == null)
|
||||||
{
|
{
|
||||||
class xmlFilter implements java.io.FilenameFilter
|
class xmlFilter implements java.io.FilenameFilter
|
||||||
{
|
{
|
||||||
public boolean accept(File dir, String name)
|
@Override
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
{
|
{
|
||||||
return name.endsWith(".xml");
|
return name.endsWith(".xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir") + "/config/controlled-vocabularies/";
|
String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir")
|
||||||
String[] xmlFiles = (new File(vocabulariesPath)).list(new xmlFilter());
|
+ "/config/controlled-vocabularies/";
|
||||||
List<String> names = new ArrayList<String>();
|
String[] xmlFiles = (new File(vocabulariesPath)).list(new xmlFilter());
|
||||||
for (String filename : xmlFiles)
|
List<String> names = new ArrayList<String>();
|
||||||
|
for (String filename : xmlFiles)
|
||||||
{
|
{
|
||||||
names.add((new File(filename)).getName().replace(".xml",""));
|
names.add((new File(filename)).getName().replace(".xml", ""));
|
||||||
}
|
}
|
||||||
pluginNames = names.toArray(new String[names.size()]);
|
pluginNames = names.toArray(new String[names.size()]);
|
||||||
log.info("Got plugin names = "+Arrays.deepToString(pluginNames));
|
log.info("Got plugin names = " + Arrays.deepToString(pluginNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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)
|
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -162,47 +165,54 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
|||||||
XPath xpath = XPathFactory.newInstance().newXPath();
|
XPath xpath = XPathFactory.newInstance().newXPath();
|
||||||
Choice[] choices;
|
Choice[] choices;
|
||||||
try {
|
try {
|
||||||
NodeList results = (NodeList)xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET);
|
NodeList results = (NodeList) xpath.evaluate(xpathExpression,
|
||||||
String[] authorities = new String[results.getLength()];
|
vocabulary, XPathConstants.NODESET);
|
||||||
String[] values = new String[results.getLength()];
|
String[] authorities = new String[results.getLength()];
|
||||||
String[] labels = new String[results.getLength()];
|
String[] values = new String[results.getLength()];
|
||||||
for (int i=0; i<results.getLength(); i++)
|
String[] labels = new String[results.getLength()];
|
||||||
|
for (int i = 0; i < results.getLength(); i++)
|
||||||
{
|
{
|
||||||
Node node = results.item(i);
|
Node node = results.item(i);
|
||||||
String hierarchy = this.buildString(node);
|
String hierarchy = this.buildString(node);
|
||||||
if (this.suggestHierarchy)
|
if (this.suggestHierarchy)
|
||||||
{
|
{
|
||||||
labels[i] = hierarchy;
|
labels[i] = hierarchy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
|
labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
|
||||||
}
|
}
|
||||||
if (this.storeHierarchy)
|
if (this.storeHierarchy)
|
||||||
{
|
{
|
||||||
values[i] = hierarchy;
|
values[i] = hierarchy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
|
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
|
||||||
int resultCount = Math.min(labels.length-start, limit);
|
authorities[i] = idAttr.getNodeValue();
|
||||||
choices = new Choice[resultCount];
|
}
|
||||||
if (resultCount > 0)
|
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++)
|
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) {
|
} catch(XPathExpressionException e) {
|
||||||
choices = new Choice[0];
|
choices = new Choice[0];
|
||||||
}
|
}
|
||||||
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
|
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Choices getBestMatch(String field, String text, int collection, String locale)
|
public Choices getBestMatch(String field, String text, int collection, String locale)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -210,6 +220,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
|
|||||||
return getMatches(field, text, collection, 0, 2, locale);
|
return getMatches(field, text, collection, 0, 2, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLabel(String field, String key, String locale)
|
public String getLabel(String field, String key, String locale)
|
||||||
{
|
{
|
||||||
init();
|
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,40 +45,57 @@ public class ApacheLogRobotsProcessor {
|
|||||||
|
|
||||||
CommandLine line = parser.parse(options, args);
|
CommandLine line = parser.parse(options, args);
|
||||||
|
|
||||||
|
// Log source
|
||||||
String logFileLoc;
|
String logFileLoc;
|
||||||
String spiderIpPath;
|
|
||||||
if (line.hasOption("l"))
|
if (line.hasOption("l"))
|
||||||
{
|
{
|
||||||
logFileLoc = line.getOptionValue("l");
|
logFileLoc = line.getOptionValue("l");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("We need our log file");
|
logFileLoc = "-";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spider IP list
|
||||||
|
String spiderIpPath;
|
||||||
if (line.hasOption("s"))
|
if (line.hasOption("s"))
|
||||||
{
|
{
|
||||||
spiderIpPath = line.getOptionValue("s");
|
spiderIpPath = line.getOptionValue("s");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("We need a spider IP output file");
|
spiderIpPath = "-";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File spiderIpFile = new File(spiderIpPath);
|
|
||||||
|
|
||||||
//Get the IPs already added in our file
|
//Get the IPs already added in our file
|
||||||
Set<String> logSpiders;
|
Set<String> logSpiders;
|
||||||
if (spiderIpFile.exists())
|
Writer output;
|
||||||
|
|
||||||
|
if ("-".equals(spiderIpPath))
|
||||||
{
|
{
|
||||||
logSpiders = SpiderDetector.readIpAddresses(spiderIpFile);
|
logSpiders = new HashSet<String>();
|
||||||
|
output = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logSpiders = new HashSet<String>();
|
File spiderIpFile = new File(spiderIpPath);
|
||||||
|
|
||||||
|
if (spiderIpFile.exists())
|
||||||
|
{
|
||||||
|
logSpiders = SpiderDetector.readIpAddresses(spiderIpFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logSpiders = new HashSet<String>();
|
||||||
|
}
|
||||||
|
output = new BufferedWriter(new FileWriter(spiderIpFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
//First read in our log file line per line
|
//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;
|
String logLine;
|
||||||
while ((logLine = in.readLine()) != null) {
|
while ((logLine = in.readLine()) != null) {
|
||||||
//Currently only check if robot.txt is present in our line
|
//Currently only check if robot.txt is present in our line
|
||||||
@@ -92,11 +109,8 @@ public class ApacheLogRobotsProcessor {
|
|||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
//Last but not least add the IPs to our file
|
//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) {
|
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
|
//Write each new IP on a separate line
|
||||||
output.write(ip + "\n");
|
output.write(ip + "\n");
|
||||||
}
|
}
|
||||||
|
@@ -85,16 +85,37 @@ public class ClassicDSpaceLogConverter {
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
int lines = 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
|
// 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
|
// Setup the regular expressions for the log file
|
||||||
LogAnalyser.setRegex(in);
|
LogAnalyser.setRegex(in);
|
||||||
|
|
||||||
// Open the file and read it line by line
|
// Open the file and read it line by line
|
||||||
BufferedReader input = null;
|
|
||||||
Writer output = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String line;
|
String line;
|
||||||
LogLine lline;
|
LogLine lline;
|
||||||
@@ -107,9 +128,6 @@ public class ClassicDSpaceLogConverter {
|
|||||||
String uid;
|
String uid;
|
||||||
String lastLine = "";
|
String lastLine = "";
|
||||||
|
|
||||||
input = new BufferedReader(new FileReader(new File(in)));
|
|
||||||
output = new BufferedWriter(new FileWriter(new File(out)));
|
|
||||||
|
|
||||||
while ((line = input.readLine()) != null)
|
while ((line = input.readLine()) != null)
|
||||||
{
|
{
|
||||||
// Read inthe line and covnert it to a LogLine
|
// Read inthe line and covnert it to a LogLine
|
||||||
@@ -236,7 +254,7 @@ public class ClassicDSpaceLogConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tell the user what we have done
|
// 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;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +269,7 @@ public class ClassicDSpaceLogConverter {
|
|||||||
// print the help message
|
// print the help message
|
||||||
HelpFormatter myhelp = new HelpFormatter();
|
HelpFormatter myhelp = new HelpFormatter();
|
||||||
myhelp.printHelp("ClassicDSpaceLogConverter\n", options);
|
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);
|
System.exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,8 +284,8 @@ public class ClassicDSpaceLogConverter {
|
|||||||
|
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
options.addOption("i", "in", true, "source file");
|
options.addOption("i", "in", true, "source file ('-' or omit for standard input)");
|
||||||
options.addOption("o", "out", true, "destination directory");
|
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("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("n", "newformat",false, "process new format log lines (1.6+)");
|
||||||
options.addOption("v", "verbose", false, "display verbose output (useful for debugging)");
|
options.addOption("v", "verbose", false, "display verbose output (useful for debugging)");
|
||||||
@@ -292,24 +310,6 @@ public class ClassicDSpaceLogConverter {
|
|||||||
printHelp(options, 0);
|
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
|
// Whether or not to include event created by org.dspace.usage.LoggerUsageEventListener
|
||||||
boolean newEvents = line.hasOption('n');
|
boolean newEvents = line.hasOption('n');
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ public class ClassicDSpaceLogConverter {
|
|||||||
String[] children = dir.list(filter);
|
String[] children = dir.list(filter);
|
||||||
for (String in : children)
|
for (String in : children)
|
||||||
{
|
{
|
||||||
System.out.println(in);
|
System.err.println(in);
|
||||||
String out = line.getOptionValue('o') +
|
String out = line.getOptionValue('o') +
|
||||||
(dir.getAbsolutePath() +
|
(dir.getAbsolutePath() +
|
||||||
System.getProperty("file.separator") + in).substring(line.getOptionValue('i').length());
|
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.common.SolrInputDocument;
|
||||||
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
|
||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -22,7 +21,6 @@ import org.dspace.core.ConfigurationManager;
|
|||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.statistics.SolrLogger;
|
import org.dspace.statistics.SolrLogger;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
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 filename The filename of the file to load
|
||||||
* @param context The DSpace Context
|
* @param context The DSpace Context
|
||||||
@@ -143,9 +141,6 @@ public class StatisticsImporter
|
|||||||
*/
|
*/
|
||||||
private void load(String filename, Context context, boolean verbose)
|
private void load(String filename, Context context, boolean verbose)
|
||||||
{
|
{
|
||||||
// Print out the filename for confirmation
|
|
||||||
System.out.println("Processing file: " + filename);
|
|
||||||
|
|
||||||
// Item counter
|
// Item counter
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
@@ -153,7 +148,17 @@ public class StatisticsImporter
|
|||||||
|
|
||||||
try
|
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 line;
|
||||||
// String uuid;
|
// String uuid;
|
||||||
@@ -426,7 +431,7 @@ public class StatisticsImporter
|
|||||||
|
|
||||||
Options options = new Options();
|
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("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("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");
|
options.addOption("s", "skipdns", false, "skip performing reverse DNS lookups on IP addresses");
|
||||||
@@ -441,12 +446,6 @@ public class StatisticsImporter
|
|||||||
printHelp(options, 0);
|
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'))
|
if (line.hasOption('s'))
|
||||||
{
|
{
|
||||||
skipReverseDNS = true;
|
skipReverseDNS = true;
|
||||||
|
@@ -94,7 +94,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ant-contrib</groupId>
|
<groupId>ant-contrib</groupId>
|
||||||
|
2
pom.xml
2
pom.xml
@@ -844,7 +844,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>postgresql</groupId>
|
<groupId>postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<version>8.1-408.jdbc3</version>
|
<version>9.1-901-1.jdbc4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.oracle</groupId>
|
<groupId>com.oracle</groupId>
|
||||||
|
Reference in New Issue
Block a user