mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Refactor several beans (and related classes) to use ConfigurationService on init once it is injected.
This commit is contained in:
@@ -15,7 +15,7 @@ import org.w3c.dom.*;
|
|||||||
import javax.xml.parsers.*;
|
import javax.xml.parsers.*;
|
||||||
|
|
||||||
import org.dspace.content.MetadataSchema;
|
import org.dspace.content.MetadataSchema;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.utils.DSpace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submission form generator for DSpace. Reads and parses the installation
|
* Submission form generator for DSpace. Reads and parses the installation
|
||||||
@@ -53,10 +53,6 @@ public class DCInputsReader
|
|||||||
/** Keyname for storing dropdown value-pair set name */
|
/** Keyname for storing dropdown value-pair set name */
|
||||||
static final String PAIR_TYPE_NAME = "value-pairs-name";
|
static final String PAIR_TYPE_NAME = "value-pairs-name";
|
||||||
|
|
||||||
/** The fully qualified pathname of the form definition XML file */
|
|
||||||
private String defsFile = ConfigurationManager.getProperty("dspace.dir")
|
|
||||||
+ File.separator + "config" + File.separator + FORM_DEF_FILE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the collections to forms map, computed from the forms
|
* Reference to the collections to forms map, computed from the forms
|
||||||
* definition file
|
* definition file
|
||||||
@@ -91,6 +87,10 @@ public class DCInputsReader
|
|||||||
public DCInputsReader()
|
public DCInputsReader()
|
||||||
throws DCInputsReaderException
|
throws DCInputsReaderException
|
||||||
{
|
{
|
||||||
|
// Load from default file
|
||||||
|
String defsFile = new DSpace().getConfigurationService().getProperty("dspace.dir")
|
||||||
|
+ File.separator + "config" + File.separator + FORM_DEF_FILE;
|
||||||
|
|
||||||
buildInputs(defsFile);
|
buildInputs(defsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@ import org.apache.log4j.Logger;
|
|||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.service.CollectionService;
|
import org.dspace.content.service.CollectionService;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.LogManager;
|
import org.dspace.core.LogManager;
|
||||||
import org.dspace.curate.service.WorkflowCuratorService;
|
import org.dspace.curate.service.WorkflowCuratorService;
|
||||||
@@ -33,17 +32,18 @@ import org.dspace.eperson.EPerson;
|
|||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.service.EPersonService;
|
import org.dspace.eperson.service.EPersonService;
|
||||||
import org.dspace.eperson.service.GroupService;
|
import org.dspace.eperson.service.GroupService;
|
||||||
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||||
import org.dspace.workflowbasic.BasicWorkflowItem;
|
import org.dspace.workflowbasic.BasicWorkflowItem;
|
||||||
import org.dspace.workflowbasic.BasicWorkflowServiceImpl;
|
import org.dspace.workflowbasic.BasicWorkflowServiceImpl;
|
||||||
import org.dspace.workflowbasic.service.BasicWorkflowItemService;
|
import org.dspace.workflowbasic.service.BasicWorkflowItemService;
|
||||||
import org.dspace.workflowbasic.service.BasicWorkflowService;
|
import org.dspace.workflowbasic.service.BasicWorkflowService;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
// Warning - static import ahead!
|
// Warning - static import ahead!
|
||||||
import static javax.xml.stream.XMLStreamConstants.*;
|
import static javax.xml.stream.XMLStreamConstants.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorkflowCurator manages interactions between curation and workflow.
|
* WorkflowCurator manages interactions between curation and workflow.
|
||||||
* Specifically, it is invoked in WorkflowManager to allow the
|
* Specifically, it is invoked in WorkflowManager to allow the
|
||||||
@@ -51,15 +51,12 @@ import static javax.xml.stream.XMLStreamConstants.*;
|
|||||||
*
|
*
|
||||||
* @author richardrodgers
|
* @author richardrodgers
|
||||||
*/
|
*/
|
||||||
public class WorkflowCuratorServiceImpl implements WorkflowCuratorService, InitializingBean {
|
public class WorkflowCuratorServiceImpl implements WorkflowCuratorService
|
||||||
|
{
|
||||||
|
|
||||||
/** log4j logger */
|
/** log4j logger */
|
||||||
private Logger log = Logger.getLogger(WorkflowCuratorServiceImpl.class);
|
private Logger log = Logger.getLogger(WorkflowCuratorServiceImpl.class);
|
||||||
|
|
||||||
protected File cfgFile = new File(ConfigurationManager.getProperty("dspace.dir") +
|
|
||||||
File.separator + "config" + File.separator +
|
|
||||||
"workflow-curation.xml");
|
|
||||||
|
|
||||||
protected Map<String, TaskSet> tsMap = new HashMap<String, TaskSet>();
|
protected Map<String, TaskSet> tsMap = new HashMap<String, TaskSet>();
|
||||||
|
|
||||||
protected final String[] flowSteps = { "step1", "step2", "step3", "archive" };
|
protected final String[] flowSteps = { "step1", "step2", "step3", "archive" };
|
||||||
@@ -74,11 +71,22 @@ public class WorkflowCuratorServiceImpl implements WorkflowCuratorService, Initi
|
|||||||
protected BasicWorkflowService basicWorkflowService;
|
protected BasicWorkflowService basicWorkflowService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected WorkflowServiceFactory workflowServiceFactory;
|
protected WorkflowServiceFactory workflowServiceFactory;
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected ConfigurationService configurationService;
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void afterPropertiesSet() throws Exception {
|
* Initialize the bean (after dependency injection has already taken place).
|
||||||
try {
|
* Ensures the configurationService is injected, so that we can read the
|
||||||
loadTaskConfig();
|
* settings from configuration
|
||||||
|
* Called by "init-method" in Spring config.
|
||||||
|
*/
|
||||||
|
public void init() throws Exception {
|
||||||
|
File cfgFile = new File(configurationService.getProperty("dspace.dir") +
|
||||||
|
File.separator + "config" + File.separator +
|
||||||
|
"workflow-curation.xml");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loadTaskConfig(cfgFile);
|
||||||
if(workflowServiceFactory.getWorkflowService() instanceof BasicWorkflowItemService)
|
if(workflowServiceFactory.getWorkflowService() instanceof BasicWorkflowItemService)
|
||||||
{
|
{
|
||||||
basicWorkflowService = (BasicWorkflowService) workflowServiceFactory.getWorkflowService();
|
basicWorkflowService = (BasicWorkflowService) workflowServiceFactory.getWorkflowService();
|
||||||
@@ -208,7 +216,7 @@ public class WorkflowCuratorServiceImpl implements WorkflowCuratorService, Initi
|
|||||||
}
|
}
|
||||||
} else if ("$siteadmin".equals(contact)) {
|
} else if ("$siteadmin".equals(contact)) {
|
||||||
EPerson siteEp = ePersonService.findByEmail(c,
|
EPerson siteEp = ePersonService.findByEmail(c,
|
||||||
ConfigurationManager.getProperty("mail.admin"));
|
configurationService.getProperty("mail.admin"));
|
||||||
if (siteEp != null) {
|
if (siteEp != null) {
|
||||||
epList.add(siteEp);
|
epList.add(siteEp);
|
||||||
}
|
}
|
||||||
@@ -271,7 +279,7 @@ public class WorkflowCuratorServiceImpl implements WorkflowCuratorService, Initi
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadTaskConfig() throws IOException {
|
protected void loadTaskConfig(File cfgFile) throws IOException {
|
||||||
Map<String, String> collMap = new HashMap<String, String>();
|
Map<String, String> collMap = new HashMap<String, String>();
|
||||||
Map<String, TaskSet> setMap = new HashMap<String, TaskSet>();
|
Map<String, TaskSet> setMap = new HashMap<String, TaskSet>();
|
||||||
TaskSet taskSet = null;
|
TaskSet taskSet = null;
|
||||||
|
@@ -14,8 +14,8 @@ import java.util.Properties;
|
|||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DCDate;
|
import org.dspace.content.DCDate;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.utils.DSpace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin implementation of the embargo setting function. The parseTerms()
|
* Plugin implementation of the embargo setting function. The parseTerms()
|
||||||
@@ -35,18 +35,8 @@ import org.dspace.core.Context;
|
|||||||
*/
|
*/
|
||||||
public class DayTableEmbargoSetter extends DefaultEmbargoSetter
|
public class DayTableEmbargoSetter extends DefaultEmbargoSetter
|
||||||
{
|
{
|
||||||
private Properties termProps = new Properties();
|
|
||||||
|
|
||||||
public DayTableEmbargoSetter() {
|
public DayTableEmbargoSetter() {
|
||||||
super();
|
super();
|
||||||
// load properties
|
|
||||||
String terms = ConfigurationManager.getProperty("embargo.terms.days");
|
|
||||||
if (terms != null && terms.length() > 0) {
|
|
||||||
for (String term : terms.split(",")) {
|
|
||||||
String[] parts = term.trim().split(":");
|
|
||||||
termProps.setProperty(parts[0].trim(), parts[1].trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +51,10 @@ public class DayTableEmbargoSetter extends DefaultEmbargoSetter
|
|||||||
@Override
|
@Override
|
||||||
public DCDate parseTerms(Context context, Item item, String terms)
|
public DCDate parseTerms(Context context, Item item, String terms)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
String termsOpen = new DSpace().getConfigurationService().getProperty("embargo.terms.open");
|
||||||
|
Properties termProps = getTermProperties();
|
||||||
|
|
||||||
if (terms != null) {
|
if (terms != null) {
|
||||||
if (termsOpen.equals(terms)) {
|
if (termsOpen.equals(terms)) {
|
||||||
return EmbargoServiceImpl.FOREVER;
|
return EmbargoServiceImpl.FOREVER;
|
||||||
@@ -74,4 +68,23 @@ public class DayTableEmbargoSetter extends DefaultEmbargoSetter
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get term properties from configuration
|
||||||
|
* @return Properties
|
||||||
|
*/
|
||||||
|
private Properties getTermProperties()
|
||||||
|
{
|
||||||
|
Properties termProps = new Properties();
|
||||||
|
|
||||||
|
String terms = new DSpace().getConfigurationService().getProperty("embargo.terms.days");
|
||||||
|
if (terms != null && terms.length() > 0) {
|
||||||
|
for (String term : terms.split(",")) {
|
||||||
|
String[] parts = term.trim().split(":");
|
||||||
|
termProps.setProperty(parts[0].trim(), parts[1].trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return termProps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
|||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.authorize.service.ResourcePolicyService;
|
import org.dspace.authorize.service.ResourcePolicyService;
|
||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.embargo.factory.EmbargoServiceFactory;
|
import org.dspace.embargo.factory.EmbargoServiceFactory;
|
||||||
@@ -27,6 +26,7 @@ import org.dspace.embargo.service.EmbargoService;
|
|||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
import org.dspace.license.CreativeCommonsServiceImpl;
|
import org.dspace.license.CreativeCommonsServiceImpl;
|
||||||
|
import org.dspace.utils.DSpace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default plugin implementation of the embargo setting function.
|
* Default plugin implementation of the embargo setting function.
|
||||||
@@ -40,17 +40,14 @@ import org.dspace.license.CreativeCommonsServiceImpl;
|
|||||||
*/
|
*/
|
||||||
public class DefaultEmbargoSetter implements EmbargoSetter
|
public class DefaultEmbargoSetter implements EmbargoSetter
|
||||||
{
|
{
|
||||||
protected String termsOpen = null;
|
|
||||||
|
|
||||||
protected AuthorizeService authorizeService;
|
protected AuthorizeService authorizeService;
|
||||||
protected ResourcePolicyService resourcePolicyService;
|
protected ResourcePolicyService resourcePolicyService;
|
||||||
|
|
||||||
public DefaultEmbargoSetter()
|
public DefaultEmbargoSetter()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
termsOpen = ConfigurationManager.getProperty("embargo.terms.open");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the terms into a definite date. Terms are expected to consist of
|
* Parse the terms into a definite date. Terms are expected to consist of
|
||||||
* either: a token (value configured in 'embargo.terms.open' property) to indicate
|
* either: a token (value configured in 'embargo.terms.open' property) to indicate
|
||||||
@@ -65,6 +62,8 @@ public class DefaultEmbargoSetter implements EmbargoSetter
|
|||||||
public DCDate parseTerms(Context context, Item item, String terms)
|
public DCDate parseTerms(Context context, Item item, String terms)
|
||||||
throws SQLException, AuthorizeException
|
throws SQLException, AuthorizeException
|
||||||
{
|
{
|
||||||
|
String termsOpen = new DSpace().getConfigurationService().getProperty("embargo.terms.open");
|
||||||
|
|
||||||
if (terms != null && terms.length() > 0)
|
if (terms != null && terms.length() > 0)
|
||||||
{
|
{
|
||||||
if (termsOpen.equals(terms))
|
if (termsOpen.equals(terms))
|
||||||
|
@@ -17,11 +17,10 @@ import org.apache.log4j.Logger;
|
|||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.PluginManager;
|
import org.dspace.core.service.PluginService;
|
||||||
import org.dspace.embargo.service.EmbargoService;
|
import org.dspace.embargo.service.EmbargoService;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* @author Larry Stone
|
* @author Larry Stone
|
||||||
* @author Richard Rodgers
|
* @author Richard Rodgers
|
||||||
*/
|
*/
|
||||||
public class EmbargoServiceImpl implements EmbargoService, InitializingBean
|
public class EmbargoServiceImpl implements EmbargoService
|
||||||
{
|
{
|
||||||
|
|
||||||
/** log4j category */
|
/** log4j category */
|
||||||
@@ -68,6 +67,12 @@ public class EmbargoServiceImpl implements EmbargoService, InitializingBean
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected ItemService itemService;
|
protected ItemService itemService;
|
||||||
|
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected ConfigurationService configurationService;
|
||||||
|
|
||||||
|
@Autowired(required = true)
|
||||||
|
protected PluginService pluginService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEmbargo(Context context, Item item)
|
public void setEmbargo(Context context, Item item)
|
||||||
throws SQLException, AuthorizeException
|
throws SQLException, AuthorizeException
|
||||||
@@ -156,14 +161,18 @@ public class EmbargoServiceImpl implements EmbargoService, InitializingBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// initialize - get plugins and MD field settings from config
|
/**
|
||||||
@Override
|
* Initialize the bean (after dependency injection has already taken place).
|
||||||
public void afterPropertiesSet() throws Exception
|
* Ensures the configurationService is injected, so that we can
|
||||||
|
* get plugins and MD field settings from config.
|
||||||
|
* Called by "init-method" in Spring config.
|
||||||
|
*/
|
||||||
|
public void init() throws Exception
|
||||||
{
|
{
|
||||||
if (terms_schema == null)
|
if (terms_schema == null)
|
||||||
{
|
{
|
||||||
String terms = ConfigurationManager.getProperty("embargo.field.terms");
|
String terms = configurationService.getProperty("embargo.field.terms");
|
||||||
String lift = ConfigurationManager.getProperty("embargo.field.lift");
|
String lift = configurationService.getProperty("embargo.field.lift");
|
||||||
if (terms == null || lift == null)
|
if (terms == null || lift == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Missing one or more of the required DSpace configuration properties for EmbargoManager, check your configuration file.");
|
throw new IllegalStateException("Missing one or more of the required DSpace configuration properties for EmbargoManager, check your configuration file.");
|
||||||
@@ -175,12 +184,12 @@ public class EmbargoServiceImpl implements EmbargoService, InitializingBean
|
|||||||
lift_element = getElementOf(lift);
|
lift_element = getElementOf(lift);
|
||||||
lift_qualifier = getQualifierOf(lift);
|
lift_qualifier = getQualifierOf(lift);
|
||||||
|
|
||||||
setter = (EmbargoSetter)PluginManager.getSinglePlugin(EmbargoSetter.class);
|
setter = (EmbargoSetter)pluginService.getSinglePlugin(EmbargoSetter.class);
|
||||||
if (setter == null)
|
if (setter == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("The EmbargoSetter plugin was not defined in DSpace configuration.");
|
throw new IllegalStateException("The EmbargoSetter plugin was not defined in DSpace configuration.");
|
||||||
}
|
}
|
||||||
lifter = (EmbargoLifter)PluginManager.getSinglePlugin(EmbargoLifter.class);
|
lifter = (EmbargoLifter)pluginService.getSinglePlugin(EmbargoLifter.class);
|
||||||
if (lifter == null)
|
if (lifter == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("The EmbargoLifter plugin was not defined in DSpace configuration.");
|
throw new IllegalStateException("The EmbargoLifter plugin was not defined in DSpace configuration.");
|
||||||
|
@@ -53,14 +53,18 @@
|
|||||||
<bean class="org.dspace.content.authority.ChoiceAuthorityServiceImpl"/>
|
<bean class="org.dspace.content.authority.ChoiceAuthorityServiceImpl"/>
|
||||||
<bean class="org.dspace.content.authority.MetadataAuthorityServiceImpl" lazy-init="true"/>
|
<bean class="org.dspace.content.authority.MetadataAuthorityServiceImpl" lazy-init="true"/>
|
||||||
|
|
||||||
|
<!-- Ensure PluginService is initialized properly via init() method -->
|
||||||
|
<bean class="org.dspace.core.LegacyPluginServiceImpl" init-method="init"/>
|
||||||
<bean class="org.dspace.core.LicenseServiceImpl"/>
|
<bean class="org.dspace.core.LicenseServiceImpl"/>
|
||||||
<bean class="org.dspace.core.NewsServiceImpl"/>
|
<bean class="org.dspace.core.NewsServiceImpl"/>
|
||||||
|
|
||||||
<bean class="org.dspace.curate.WorkflowCuratorServiceImpl"/>
|
<!-- Ensure WorkflowCuratorService is initialized properly via init() method -->
|
||||||
|
<bean class="org.dspace.curate.WorkflowCuratorServiceImpl" init-method="init"/>
|
||||||
|
|
||||||
<bean class="org.dspace.disseminate.CitationDocumentServiceImpl"/>
|
<bean class="org.dspace.disseminate.CitationDocumentServiceImpl"/>
|
||||||
|
|
||||||
<bean class="org.dspace.embargo.EmbargoServiceImpl"/>
|
<!-- Ensure EmbargoService is initialized properly via init() method -->
|
||||||
|
<bean class="org.dspace.embargo.EmbargoServiceImpl" init-method="init"/>
|
||||||
|
|
||||||
<bean class="org.dspace.eperson.AccountServiceImpl"/>
|
<bean class="org.dspace.eperson.AccountServiceImpl"/>
|
||||||
<bean class="org.dspace.eperson.EPersonServiceImpl"/>
|
<bean class="org.dspace.eperson.EPersonServiceImpl"/>
|
||||||
|
Reference in New Issue
Block a user