Fix API classes using comma-separated configs (and ensure they all use ConfigurationService)

This commit is contained in:
Tim Donohue
2016-02-23 15:57:31 -06:00
parent 2bd6b2d950
commit 0e4db531cf
13 changed files with 166 additions and 179 deletions

View File

@@ -11,15 +11,17 @@ import org.apache.log4j.Logger;
import org.dspace.content.MetadataValue; import org.dspace.content.MetadataValue;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator; import org.dspace.curate.Curator;
import org.dspace.curate.Distributive; import org.dspace.curate.Distributive;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* MicrosoftTranslator translates stuff * MicrosoftTranslator translates stuff
* *
@@ -43,6 +45,9 @@ public abstract class AbstractTranslator extends AbstractCurationTask
protected List<String> results = new ArrayList<String>(); protected List<String> results = new ArrayList<String>();
private final transient ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();
@Override @Override
public void init(Curator curator, String taskId) throws IOException public void init(Curator curator, String taskId) throws IOException
@@ -50,12 +55,10 @@ public abstract class AbstractTranslator extends AbstractCurationTask
super.init(curator, taskId); super.init(curator, taskId);
// Load configuration // Load configuration
authLang = ConfigurationManager.getProperty("default.locale"); authLang = configurationService.getProperty("default.locale");
authLangField = ConfigurationManager.getProperty(PLUGIN_PREFIX, "field.language"); authLangField = configurationService.getProperty(PLUGIN_PREFIX + ".field.language");
String toTranslateStr = ConfigurationManager.getProperty(PLUGIN_PREFIX, "field.targets"); String[] toTranslate = configurationService.getArrayProperty(PLUGIN_PREFIX + ".field.targets");
String langsStr = ConfigurationManager.getProperty(PLUGIN_PREFIX, "language.targets"); String[] langs = configurationService.getArrayProperty(PLUGIN_PREFIX + ".language.targets");
toTranslate = toTranslateStr.split(",");
langs = langsStr.split(",");
if(!(toTranslate.length > 0 && langs.length > 0)) if(!(toTranslate.length > 0 && langs.length > 0))
{ {

View File

@@ -25,7 +25,6 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*; import org.dspace.content.*;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService; import org.dspace.content.service.BitstreamService;
import org.dspace.core.ConfigurationManager;
import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator; import org.dspace.curate.Curator;
import org.dspace.curate.Suspendable; import org.dspace.curate.Suspendable;
@@ -74,10 +73,10 @@ public class ClamScan extends AbstractCurationTask
public void init(Curator curator, String taskId) throws IOException public void init(Curator curator, String taskId) throws IOException
{ {
super.init(curator, taskId); super.init(curator, taskId);
host = ConfigurationManager.getProperty(PLUGIN_PREFIX, "service.host"); host = configurationService.getProperty(PLUGIN_PREFIX + ".service.host");
port = ConfigurationManager.getIntProperty(PLUGIN_PREFIX, "service.port"); port = configurationService.getIntProperty(PLUGIN_PREFIX + ".service.port");
timeout = ConfigurationManager.getIntProperty(PLUGIN_PREFIX, "socket.timeout"); timeout = configurationService.getIntProperty(PLUGIN_PREFIX + ".socket.timeout");
failfast = ConfigurationManager.getBooleanProperty(PLUGIN_PREFIX, "scan.failfast"); failfast = configurationService.getBooleanProperty(PLUGIN_PREFIX + ".scan.failfast");
bitstreamService = ContentServiceFactory.getInstance().getBitstreamService(); bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
} }

View File

@@ -48,7 +48,6 @@ import org.xml.sax.SAXException;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.curate.AbstractCurationTask; import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator; import org.dspace.curate.Curator;
@@ -167,7 +166,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
@Override @Override
public void init(Curator curator, String taskId) throws IOException { public void init(Curator curator, String taskId) throws IOException {
super.init(curator, taskId); super.init(curator, taskId);
lang = ConfigurationManager.getProperty("default.language"); lang = configurationService.getProperty("default.language");
String fldSep = taskProperty("separator"); String fldSep = taskProperty("separator");
fieldSeparator = (fldSep != null) ? fldSep : " "; fieldSeparator = (fldSep != null) ? fldSep : " ";
urlTemplate = taskProperty("template"); urlTemplate = taskProperty("template");
@@ -177,7 +176,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
lookupField = parsed[0]; lookupField = parsed[0];
lookupTransform = parsed[1]; lookupTransform = parsed[1];
dataList = new ArrayList<DataInfo>(); dataList = new ArrayList<DataInfo>();
for (String entry : taskProperty("datamap").split(",")) { for (String entry : taskArrayProperty("datamap")) {
entry = entry.trim(); entry = entry.trim();
String src = entry; String src = entry;
String mapping = null; String mapping = null;

View File

@@ -11,8 +11,8 @@ import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.content.Collection; import org.dspace.content.Collection;
@@ -22,11 +22,12 @@ import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CommunityService; import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
* AbstractCurationTask encapsulates a few common patterns of task use, * AbstractCurationTask encapsulates a few common patterns of task use,
@@ -40,14 +41,12 @@ public abstract class AbstractCurationTask implements CurationTask
protected Curator curator = null; protected Curator curator = null;
// curator-assigned taskId // curator-assigned taskId
protected String taskId = null; protected String taskId = null;
// optional task configuration properties
private Properties taskProps = null;
// logger // logger
private static Logger log = Logger.getLogger(AbstractCurationTask.class); private static Logger log = Logger.getLogger(AbstractCurationTask.class);
protected CommunityService communityService; protected CommunityService communityService;
protected ItemService itemService; protected ItemService itemService;
protected HandleService handleService; protected HandleService handleService;
protected ConfigurationService configurationService;
@Override @Override
public void init(Curator curator, String taskId) throws IOException public void init(Curator curator, String taskId) throws IOException
@@ -57,6 +56,7 @@ public abstract class AbstractCurationTask implements CurationTask
communityService = ContentServiceFactory.getInstance().getCommunityService(); communityService = ContentServiceFactory.getInstance().getCommunityService();
itemService = ContentServiceFactory.getInstance().getItemService(); itemService = ContentServiceFactory.getInstance().getItemService();
handleService = HandleServiceFactory.getInstance().getHandleService(); handleService = HandleServiceFactory.getInstance().getHandleService();
configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
} }
@Override @Override
@@ -235,29 +235,15 @@ public abstract class AbstractCurationTask implements CurationTask
*/ */
protected String taskProperty(String name) protected String taskProperty(String name)
{ {
if (taskProps == null) // If a taskID/Name is specified, prepend it on the configuration name
if(StringUtils.isNotBlank(taskId))
{ {
// load properties return configurationService.getProperty(taskId + "." + name);
taskProps = new Properties(); }
StringBuilder modName = new StringBuilder(); else
for (String segment : taskId.split("\\."))
{ {
// load property segments if present return configurationService.getProperty(name);
modName.append(segment);
Properties modProps = ConfigurationManager.getProperties(modName.toString());
if (modProps != null)
{
taskProps.putAll(modProps);
} }
modName.append(".");
}
// warn if *no* properties found
if (taskProps.size() == 0)
{
log.warn("Warning: No configuration properties found for task: " + taskId);
}
}
return taskProps.getProperty(name);
} }
/** /**
@@ -274,20 +260,15 @@ public abstract class AbstractCurationTask implements CurationTask
*/ */
protected int taskIntProperty(String name, int defaultValue) protected int taskIntProperty(String name, int defaultValue)
{ {
int intVal = defaultValue; // If a taskID/Name is specified, prepend it on the configuration name
String strVal = taskProperty(name); if(StringUtils.isNotBlank(taskId))
if (strVal != null)
{ {
try return configurationService.getIntProperty(taskId + "." + name, defaultValue);
}
else
{ {
intVal = Integer.parseInt(strVal.trim()); return configurationService.getIntProperty(name, defaultValue);
} }
catch(NumberFormatException nfE)
{
log.warn("Warning: Number format error in module: " + taskId + " property: " + name);
}
}
return intVal;
} }
/** /**
@@ -304,20 +285,15 @@ public abstract class AbstractCurationTask implements CurationTask
*/ */
protected long taskLongProperty(String name, long defaultValue) protected long taskLongProperty(String name, long defaultValue)
{ {
long longVal = defaultValue; // If a taskID/Name is specified, prepend it on the configuration name
String strVal = taskProperty(name); if(StringUtils.isNotBlank(taskId))
if (strVal != null)
{ {
try return configurationService.getLongProperty(taskId + "." + name, defaultValue);
}
else
{ {
longVal = Long.parseLong(strVal.trim()); return configurationService.getLongProperty(name, defaultValue);
} }
catch(NumberFormatException nfE)
{
log.warn("Warning: Number format error in module: " + taskId + " property: " + name);
}
}
return longVal;
} }
/** /**
@@ -334,13 +310,37 @@ public abstract class AbstractCurationTask implements CurationTask
*/ */
protected boolean taskBooleanProperty(String name, boolean defaultValue) protected boolean taskBooleanProperty(String name, boolean defaultValue)
{ {
String strVal = taskProperty(name); // If a taskID/Name is specified, prepend it on the configuration name
if (strVal != null) if(StringUtils.isNotBlank(taskId))
{ {
strVal = strVal.trim(); return configurationService.getBooleanProperty(taskId + "." + name, defaultValue);
return strVal.equalsIgnoreCase("true") || }
strVal.equalsIgnoreCase("yes"); else
{
return configurationService.getBooleanProperty(name, defaultValue);
}
}
/**
* Returns task configuration Array property value for passed name, else
* <code>null</code> if no properties defined or no value for passed key.
*
* @param name
* the property name
* @return value
* the property value, or null
*
*/
protected String[] taskArrayProperty(String name)
{
// If a taskID/Name is specified, prepend it on the configuration name
if(StringUtils.isNotBlank(taskId))
{
return configurationService.getArrayProperty(taskId + "." + name);
}
else
{
return configurationService.getArrayProperty(name);
} }
return defaultValue;
} }
} }

View File

@@ -20,8 +20,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.core.ConfigurationManager;
/** /**
* FileTaskQueue provides a TaskQueue implementation based on flat files * FileTaskQueue provides a TaskQueue implementation based on flat files
@@ -33,7 +33,7 @@ public class FileTaskQueue implements TaskQueue
{ {
private static Logger log = Logger.getLogger(TaskQueue.class); private static Logger log = Logger.getLogger(TaskQueue.class);
// base directory for curation task queues // base directory for curation task queues
protected String tqDir = ConfigurationManager.getProperty("curate", "taskqueue.dir"); protected String tqDir;
// ticket for queue readers // ticket for queue readers
protected long readTicket = -1L; protected long readTicket = -1L;
@@ -42,6 +42,7 @@ public class FileTaskQueue implements TaskQueue
public FileTaskQueue() public FileTaskQueue()
{ {
tqDir = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate.taskqueue.dir");
} }
@Override @Override

View File

@@ -23,8 +23,8 @@ import javax.script.ScriptException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.factory.CoreServiceFactory; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
* TaskResolver takes a logical name of a curation task and attempts to deliver * TaskResolver takes a logical name of a curation task and attempts to deliver
@@ -71,13 +71,14 @@ public class TaskResolver
// base directory of task scripts & catalog name // base directory of task scripts & catalog name
protected static final String CATALOG = "task.catalog"; protected static final String CATALOG = "task.catalog";
protected static final String scriptDir = ConfigurationManager.getProperty("curate", "script.dir"); protected final String scriptDir;
// catalog of script tasks // catalog of script tasks
protected Properties catalog; protected Properties catalog;
public TaskResolver() public TaskResolver()
{ {
scriptDir = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("curate.script.dir");
} }
/** /**

View File

@@ -968,14 +968,10 @@ public class SolrServiceImpl implements SearchService, IndexingService {
List<String> toProjectionFields = new ArrayList<String>(); List<String> toProjectionFields = new ArrayList<String>();
String projectionFieldsString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("discovery.index.projection"); String[] projectionFields = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("discovery.index.projection");
if(projectionFieldsString != null){ if(projectionFields != null){
if(projectionFieldsString.indexOf(",") != -1){ for (String field : projectionFields) {
for (int i = 0; i < projectionFieldsString.split(",").length; i++) { toProjectionFields.add(field.trim());
toProjectionFields.add(projectionFieldsString.split(",")[i].trim());
}
} else {
toProjectionFields.add(projectionFieldsString);
} }
} }

View File

@@ -18,7 +18,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -37,7 +36,6 @@ import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.IngestionCrosswalk; import org.dspace.content.crosswalk.IngestionCrosswalk;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.*; import org.dspace.content.service.*;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.Email; import org.dspace.core.Email;
@@ -50,6 +48,8 @@ import org.dspace.handle.service.HandleService;
import org.dspace.harvest.factory.HarvestServiceFactory; import org.dspace.harvest.factory.HarvestServiceFactory;
import org.dspace.harvest.service.HarvestedCollectionService; import org.dspace.harvest.service.HarvestedCollectionService;
import org.dspace.harvest.service.HarvestedItemService; import org.dspace.harvest.service.HarvestedItemService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.Namespace; import org.jdom.Namespace;
@@ -90,6 +90,7 @@ public class OAIHarvester {
protected HarvestedItemService harvestedItemService; protected HarvestedItemService harvestedItemService;
protected WorkspaceItemService workspaceItemService; protected WorkspaceItemService workspaceItemService;
protected PluginService pluginService; protected PluginService pluginService;
protected ConfigurationService configurationService;
// The collection this harvester instance is dealing with // The collection this harvester instance is dealing with
Collection targetCollection; Collection targetCollection;
@@ -168,20 +169,17 @@ public class OAIHarvester {
private static Namespace getORENamespace() { private static Namespace getORENamespace() {
String ORESerializationString = null; String ORESerializationString = null;
String ORESeialKey = null; String ORESeialKey = null;
String oreString = "oai.harvester.oreSerializationFormat."; String oreString = "oai.harvester.oreSerializationFormat";
Enumeration pe = ConfigurationManager.propertyNames("oai"); List<String> keys = DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(oreString);
while (pe.hasMoreElements()) for(String key : keys)
{ {
String key = (String)pe.nextElement(); ORESeialKey = key.substring(oreString.length()+1);
if (key.startsWith(oreString)) { ORESerializationString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(key);
ORESeialKey = key.substring(oreString.length());
ORESerializationString = ConfigurationManager.getProperty("oai", key);
return Namespace.getNamespace(ORESeialKey, ORESerializationString); return Namespace.getNamespace(ORESeialKey, ORESerializationString);
} }
}
// Fallback if the configuration option is not present // Fallback if the configuration option is not present
return Namespace.getNamespace("ore", ATOM_NS.getURI()); return Namespace.getNamespace("ore", ATOM_NS.getURI());
@@ -195,16 +193,14 @@ public class OAIHarvester {
*/ */
private static Namespace getDMDNamespace(String metadataKey) { private static Namespace getDMDNamespace(String metadataKey) {
String metadataString = null; String metadataString = null;
String metaString = "oai.harvester.metadataformats."; String metaString = "oai.harvester.metadataformats";
Enumeration pe = ConfigurationManager.propertyNames("oai"); List<String> keys = DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(metaString);
while (pe.hasMoreElements()) for(String key : keys)
{ {
String key = (String)pe.nextElement(); if (key.substring(metaString.length()+1).equals((metadataKey))) {
metadataString = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(key);
if (key.startsWith(metaString) && key.substring(metaString.length()).equals((metadataKey))) {
metadataString = ConfigurationManager.getProperty("oai", key);
String namespacePiece; String namespacePiece;
if (metadataString.indexOf(',') != -1) if (metadataString.indexOf(',') != -1)
{ {
@@ -296,7 +292,7 @@ public class OAIHarvester {
harvestedCollection.update(ourContext, harvestRow); harvestedCollection.update(ourContext, harvestRow);
// expiration timer starts // expiration timer starts
int expirationInterval = ConfigurationManager.getIntProperty("oai", "harvester.threadTimeout"); int expirationInterval = configurationService.getIntProperty("oai.harvester.threadTimeout");
if (expirationInterval == 0) if (expirationInterval == 0)
{ {
expirationInterval = 24; expirationInterval = 24;
@@ -613,25 +609,22 @@ public class OAIHarvester {
*/ */
protected String extractHandle(Item item) protected String extractHandle(Item item)
{ {
String acceptedHandleServersString = ConfigurationManager.getProperty("oai", "harvester.acceptedHandleServer"); String[] acceptedHandleServers = configurationService.getArrayProperty("oai.harvester.acceptedHandleServer");
if (acceptedHandleServersString == null) if (acceptedHandleServers == null)
{ {
acceptedHandleServersString = "hdl.handle.net"; acceptedHandleServers = new String[]{"hdl.handle.net"};
} }
String rejectedHandlePrefixString = ConfigurationManager.getProperty("oai", "harvester.rejectedHandlePrefix"); String[] rejectedHandlePrefixes = configurationService.getArrayProperty("oai.harvester.rejectedHandlePrefix");
if (rejectedHandlePrefixString == null) if (rejectedHandlePrefixes == null)
{ {
rejectedHandlePrefixString = "123456789"; rejectedHandlePrefixes = new String[]{"123456789"};
} }
List<MetadataValue> values = itemService.getMetadata(item, "dc", "identifier", Item.ANY, Item.ANY); List<MetadataValue> values = itemService.getMetadata(item, "dc", "identifier", Item.ANY, Item.ANY);
if (values.size() > 0 && !acceptedHandleServersString.equals("")) if (values.size() > 0 && acceptedHandleServers != null)
{ {
String[] acceptedHandleServers = acceptedHandleServersString.split(",");
String[] rejectedHandlePrefixes = rejectedHandlePrefixString.split(",");
for (MetadataValue value : values) for (MetadataValue value : values)
{ {
// 0 1 2 3 4 // 0 1 2 3 4
@@ -667,7 +660,7 @@ public class OAIHarvester {
* @return a string in the format 'yyyy-mm-ddThh:mm:ssZ' and converted to UTC timezone * @return a string in the format 'yyyy-mm-ddThh:mm:ssZ' and converted to UTC timezone
*/ */
private String processDate(Date date) { private String processDate(Date date) {
Integer timePad = ConfigurationManager.getIntProperty("oai", "harvester.timePadding"); Integer timePad = configurationService.getIntProperty("oai.harvester.timePadding");
if (timePad == 0) { if (timePad == 0) {
timePad = 120; timePad = 120;
@@ -748,7 +741,7 @@ public class OAIHarvester {
protected void alertAdmin(int status, Exception ex) protected void alertAdmin(int status, Exception ex)
{ {
try { try {
String recipient = ConfigurationManager.getProperty("alert.recipient"); String recipient = configurationService.getProperty("alert.recipient");
if (StringUtils.isNotBlank(recipient)) { if (StringUtils.isNotBlank(recipient)) {
Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "harvesting_error")); Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "harvesting_error"));

View File

@@ -18,6 +18,7 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.dspace.core.factory.CoreServiceFactory; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService; import org.dspace.core.service.PluginService;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
* @author LINDAT/CLARIN dev team * @author LINDAT/CLARIN dev team
@@ -70,7 +71,7 @@ public class Report {
// create check list // create check list
public static LinkedHashMap<String, Check> checks() { public static LinkedHashMap<String, Check> checks() {
LinkedHashMap<String, Check> checks = new LinkedHashMap<>(); LinkedHashMap<String, Check> checks = new LinkedHashMap<>();
String check_names[] = ConfigurationManager.getProperty("healthcheck", "checks").split(","); String check_names[] = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("healthcheck.checks");
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService(); PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
for ( String check_name : check_names ) { for ( String check_name : check_names ) {
Check check = (Check) pluginService.getNamedPlugin( Check check = (Check) pluginService.getNamedPlugin(

View File

@@ -32,7 +32,8 @@ import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder; import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter; import org.jdom.output.XMLOutputter;
import org.dspace.core.ConfigurationManager; import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
@@ -45,9 +46,9 @@ public class CCLookup {
/** log4j logger */ /** log4j logger */
private static Logger log = Logger.getLogger(CCLookup.class); private static Logger log = Logger.getLogger(CCLookup.class);
private static String cc_root = ConfigurationManager.getProperty("cc.api.rooturl"); private String cc_root;
private static String jurisdiction; private String jurisdiction;
private static List<String> lcFilter = new ArrayList<String>(); private List<String> lcFilter = new ArrayList<String>();
private Document license_doc = null; private Document license_doc = null;
private String rdfString = null; private String rdfString = null;
@@ -58,24 +59,26 @@ public class CCLookup {
private List<CCLicense> licenses = new ArrayList<CCLicense>(); private List<CCLicense> licenses = new ArrayList<CCLicense>();
private List<CCLicenseField> licenseFields = new ArrayList<CCLicenseField>(); private List<CCLicenseField> licenseFields = new ArrayList<CCLicenseField>();
static {
String jurisProp = ConfigurationManager.getProperty("cc.license.jurisdiction");
jurisdiction = (jurisProp != null) ? jurisProp : "";
String filterList = ConfigurationManager.getProperty("cc.license.classfilter");
if (filterList != null) {
for (String name: filterList.split(",")) {
lcFilter.add(name.trim());
}
}
}
/** /**
* Constructs a new instance with the default web services root. * Constructs a new instance with the default web services root.
* *
*/ */
public CCLookup() { public CCLookup() {
super(); super();
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
cc_root = configurationService.getProperty("cc.api.rooturl");
String jurisProp = configurationService.getProperty("cc.license.jurisdiction");
jurisdiction = (jurisProp != null) ? jurisProp : "";
String[] filters = configurationService.getArrayProperty("cc.license.classfilter");
if (filters != null) {
for (String name: filters) {
lcFilter.add(name.trim());
}
}
} }
/** /**

View File

@@ -11,7 +11,6 @@ import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter; import au.com.bytecode.opencsv.CSVWriter;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import com.maxmind.geoip.LookupService; import com.maxmind.geoip.LookupService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -39,11 +38,11 @@ import org.dspace.content.Collection;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService; import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.DSpaceObjectLegacySupportService; import org.dspace.content.service.DSpaceObjectLegacySupportService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.services.ConfigurationService;
import org.dspace.statistics.service.SolrLoggerService; import org.dspace.statistics.service.SolrLoggerService;
import org.dspace.statistics.util.DnsLookup; import org.dspace.statistics.util.DnsLookup;
import org.dspace.statistics.util.LocationUtils; import org.dspace.statistics.util.LocationUtils;
@@ -90,6 +89,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
protected BitstreamService bitstreamService; protected BitstreamService bitstreamService;
@Autowired(required = true) @Autowired(required = true)
protected ContentServiceFactory contentServiceFactory; protected ContentServiceFactory contentServiceFactory;
@Autowired(required = true)
private ConfigurationService configurationService;
public static enum StatisticsType { public static enum StatisticsType {
VIEW ("view"), VIEW ("view"),
@@ -114,20 +115,20 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
@Override @Override
public void afterPropertiesSet() throws Exception public void afterPropertiesSet() throws Exception
{ {
log.info("solr-statistics.spidersfile:" + ConfigurationManager.getProperty("solr-statistics", "spidersfile")); log.info("solr-statistics.spidersfile:" + configurationService.getProperty("solr-statistics.spidersfile"));
log.info("solr-statistics.server:" + ConfigurationManager.getProperty("solr-statistics", "server")); log.info("solr-statistics.server:" + configurationService.getProperty("solr-statistics.server"));
log.info("usage-statistics.dbfile:" + ConfigurationManager.getProperty("usage-statistics", "dbfile")); log.info("usage-statistics.dbfile:" + configurationService.getProperty("usage-statistics.dbfile"));
HttpSolrServer server = null; HttpSolrServer server = null;
if (ConfigurationManager.getProperty("solr-statistics", "server") != null) if (configurationService.getProperty("solr-statistics.server") != null)
{ {
try try
{ {
server = new HttpSolrServer(ConfigurationManager.getProperty("solr-statistics", "server")); server = new HttpSolrServer(configurationService.getProperty("solr-statistics.server"));
//Attempt to retrieve all the statistic year cores //Attempt to retrieve all the statistic year cores
File solrDir = new File(ConfigurationManager.getProperty("dspace.dir") + "/solr/"); File solrDir = new File(configurationService.getProperty("dspace.dir") + File.separator + "solr" + File.separator);
File[] solrCoreFiles = solrDir.listFiles(new FileFilter() { File[] solrCoreFiles = solrDir.listFiles(new FileFilter() {
@Override @Override
@@ -158,7 +159,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
LookupService service = null; LookupService service = null;
// Get the db file for the location // Get the db file for the location
String dbfile = ConfigurationManager.getProperty("usage-statistics", "dbfile"); String dbfile = configurationService.getProperty("usage-statistics.dbfile");
if (dbfile != null) if (dbfile != null)
{ {
try try
@@ -181,15 +182,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
} }
locationService = service; locationService = service;
if ("true".equals(ConfigurationManager.getProperty("useProxies"))) useProxies = configurationService.getBooleanProperty("useProxies");
{
useProxies = true;
}
else
{
useProxies = false;
}
log.info("useProxies=" + useProxies); log.info("useProxies=" + useProxies);
} }
@@ -287,7 +280,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, HttpServletRequest request, EPerson currentUser) throws SQLException { protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, HttpServletRequest request, EPerson currentUser) throws SQLException {
boolean isSpiderBot = request != null && SpiderDetector.isSpider(request); boolean isSpiderBot = request != null && SpiderDetector.isSpider(request);
if(isSpiderBot && if(isSpiderBot &&
!ConfigurationManager.getBooleanProperty("usage-statistics", "logBots", true)) !configurationService.getBooleanProperty("usage-statistics.logBots", true))
{ {
return null; return null;
} }
@@ -381,7 +374,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, String ip, String userAgent, String xforwardedfor, EPerson currentUser) throws SQLException { protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, String ip, String userAgent, String xforwardedfor, EPerson currentUser) throws SQLException {
boolean isSpiderBot = SpiderDetector.isSpider(ip); boolean isSpiderBot = SpiderDetector.isSpider(ip);
if(isSpiderBot && if(isSpiderBot &&
!ConfigurationManager.getBooleanProperty("usage-statistics", "logBots", true)) !configurationService.getBooleanProperty("usage-statistics.logBots", true))
{ {
return null; return null;
} }
@@ -1088,14 +1081,14 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
// not be influenced // not be influenced
// Choose to filter by the Legacy spider IP list (may get too long to properly filter all IP's // Choose to filter by the Legacy spider IP list (may get too long to properly filter all IP's
if(ConfigurationManager.getBooleanProperty("solr-statistics", "query.filter.spiderIp",false)) if(configurationService.getBooleanProperty("solr-statistics.query.filter.spiderIp",false))
{ {
solrQuery.addFilterQuery(getIgnoreSpiderIPs()); solrQuery.addFilterQuery(getIgnoreSpiderIPs());
} }
// Choose to filter by isBot field, may be overriden in future // Choose to filter by isBot field, may be overriden in future
// to allow views on stats based on bots. // to allow views on stats based on bots.
if(ConfigurationManager.getBooleanProperty("solr-statistics", "query.filter.isBot",true)) if(configurationService.getBooleanProperty("solr-statistics.query.filter.isBot",true))
{ {
solrQuery.addFilterQuery("-isBot:true"); solrQuery.addFilterQuery("-isBot:true");
} }
@@ -1104,8 +1097,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
solrQuery.setSortField(sort, (ascending ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc)); solrQuery.setSortField(sort, (ascending ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc));
} }
String bundles; String[] bundles = configurationService.getArrayProperty("solr-statistics.query.filter.bundles");
if((bundles = ConfigurationManager.getProperty("solr-statistics", "query.filter.bundles")) != null && 0 < bundles.length()){ if(bundles != null && bundles.length > 0){
/** /**
* The code below creates a query that will allow only records which do not have a bundlename * The code below creates a query that will allow only records which do not have a bundlename
@@ -1114,11 +1107,10 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
StringBuffer bundleQuery = new StringBuffer(); StringBuffer bundleQuery = new StringBuffer();
//Also add the possibility that if no bundle name is there these results will also be returned ! //Also add the possibility that if no bundle name is there these results will also be returned !
bundleQuery.append("-(bundleName:[* TO *]"); bundleQuery.append("-(bundleName:[* TO *]");
String[] split = bundles.split(","); for (int i = 0; i < bundles.length; i++) {
for (int i = 0; i < split.length; i++) { String bundle = bundles[i].trim();
String bundle = split[i].trim();
bundleQuery.append("-bundleName:").append(bundle); bundleQuery.append("-bundleName:").append(bundle);
if(i != split.length - 1){ if(i != bundles.length - 1){
bundleQuery.append(" AND "); bundleQuery.append(" AND ");
} }
} }
@@ -1207,7 +1199,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1)); yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1));
//Create a temp directory to store our files in ! //Create a temp directory to store our files in !
File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
tempDirectory.mkdirs(); tempDirectory.mkdirs();
@@ -1292,7 +1284,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
} }
protected HttpSolrServer createCore(HttpSolrServer solr, String coreName) throws IOException, SolrServerException { protected HttpSolrServer createCore(HttpSolrServer solr, String coreName) throws IOException, SolrServerException {
String solrDir = ConfigurationManager.getProperty("dspace.dir") + File.separator + "solr" +File.separator; String solrDir = configurationService.getProperty("dspace.dir") + File.separator + "solr" +File.separator;
String baseSolrUrl = solr.getBaseURL().replace("statistics", ""); String baseSolrUrl = solr.getBaseURL().replace("statistics", "");
CoreAdminRequest.Create create = new CoreAdminRequest.Create(); CoreAdminRequest.Create create = new CoreAdminRequest.Create();
create.setCoreName(coreName); create.setCoreName(coreName);
@@ -1320,7 +1312,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
addAdditionalSolrYearCores(query); addAdditionalSolrYearCores(query);
long totalRecords = solr.query(query).getResults().getNumFound(); long totalRecords = solr.query(query).getResults().getNumFound();
File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
tempDirectory.mkdirs(); tempDirectory.mkdirs();
List<File> tempCsvFiles = new ArrayList<File>(); List<File> tempCsvFiles = new ArrayList<File>();
for(int i = 0; i < totalRecords; i+=10000){ for(int i = 0; i < totalRecords; i+=10000){
@@ -1432,7 +1424,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
public void exportHits() throws Exception { public void exportHits() throws Exception {
Context context = new Context(); Context context = new Context();
File tempDirectory = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
tempDirectory.mkdirs(); tempDirectory.mkdirs();
try { try {

View File

@@ -18,7 +18,7 @@ import java.util.Set;
import java.util.Collections; import java.util.Collections;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.dspace.core.ConfigurationManager; import org.dspace.services.factory.DSpaceServicesFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -107,7 +107,7 @@ public class SpiderDetector {
if (table == null) { if (table == null) {
table = new IPTable(); table = new IPTable();
String filePath = ConfigurationManager.getProperty("dspace.dir"); String filePath = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir");
try { try {
File spidersDir = new File(filePath, "config/spiders"); File spidersDir = new File(filePath, "config/spiders");
@@ -156,7 +156,7 @@ public class SpiderDetector {
*/ */
private static void loadPatterns(String directory, List<Pattern> patternList) private static void loadPatterns(String directory, List<Pattern> patternList)
{ {
String dspaceHome = ConfigurationManager.getProperty("dspace.dir"); String dspaceHome = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir");
File spidersDir = new File(dspaceHome, "config/spiders"); File spidersDir = new File(dspaceHome, "config/spiders");
File patternsDir = new File(spidersDir, directory); File patternsDir = new File(spidersDir, directory);
if (patternsDir.exists() && patternsDir.isDirectory()) if (patternsDir.exists() && patternsDir.isDirectory())
@@ -296,7 +296,7 @@ public class SpiderDetector {
private static boolean isUseProxies() { private static boolean isUseProxies() {
if(useProxies == null) { if(useProxies == null) {
useProxies = "true".equals(ConfigurationManager.getProperty("useProxies")); useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies");
} }
return useProxies; return useProxies;

View File

@@ -10,12 +10,12 @@ package org.dspace.statistics.util;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.tools.ant.taskdefs.Get; import org.apache.tools.ant.taskdefs.Get;
import org.dspace.core.ConfigurationManager;
import org.dspace.statistics.factory.StatisticsServiceFactory; import org.dspace.statistics.factory.StatisticsServiceFactory;
import org.dspace.statistics.service.SolrLoggerService; import org.dspace.statistics.service.SolrLoggerService;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
* Class to load intermediate statistics files into solr * Class to load intermediate statistics files into solr
@@ -54,7 +54,7 @@ public class StatisticsClient
options.addOption("u", "update-spider-files", false, options.addOption("u", "update-spider-files", false,
"Update Spider IP Files from internet into " + "Update Spider IP Files from internet into " +
ConfigurationManager.getProperty("dspace.dir") + "/config/spiders"); DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir") + "/config/spiders");
options.addOption("m", "mark-spiders", false, "Update isBot Flag in Solr"); options.addOption("m", "mark-spiders", false, "Update isBot Flag in Solr");
options.addOption("f", "delete-spiders-by-flag", false, "Delete Spiders in Solr By isBot Flag"); options.addOption("f", "delete-spiders-by-flag", false, "Delete Spiders in Solr By isBot Flag");
@@ -123,23 +123,22 @@ public class StatisticsClient
System.out.println("Downloading latest spider IP addresses:"); System.out.println("Downloading latest spider IP addresses:");
// Get the list URLs to download from // Get the list URLs to download from
String urls = ConfigurationManager.getProperty("solr-statistics", "spiderips.urls"); String[] urls = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("solr-statistics.spiderips.urls");
if ((urls == null) || ("".equals(urls))) if((urls == null) || (urls.length==0))
{ {
System.err.println(" - Missing setting from dspace.cfg: solr.spiderips.urls"); System.err.println(" - Missing setting from dspace.cfg: solr.spiderips.urls");
System.exit(0); System.exit(0);
} }
// Get the location of spiders directory // Get the location of spiders directory
File spiders = new File(ConfigurationManager.getProperty("dspace.dir"),"config/spiders"); File spiders = new File(DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir"),"config/spiders");
if (!spiders.exists() && !spiders.mkdirs()) if (!spiders.exists() && !spiders.mkdirs())
{ {
log.error("Unable to create spiders directory"); log.error("Unable to create spiders directory");
} }
String[] values = urls.split(","); for (String value : urls)
for (String value : values)
{ {
value = value.trim(); value = value.trim();
System.out.println(" Downloading: " + value); System.out.println(" Downloading: " + value);