Merge pull request #1313 from KevinVdV/DS-3062-fix-xml-workflow

[DS-3062] Fixing issues that prevented the xmlworkflow from being enabled
This commit is contained in:
Tim Donohue
2016-03-09 09:17:59 -06:00
7 changed files with 36 additions and 17 deletions

View File

@@ -31,6 +31,7 @@ import org.dspace.discovery.IndexingService;
import org.dspace.discovery.SearchServiceException;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.MigrationInfo;
@@ -406,14 +407,9 @@ public class DatabaseUtils
// NOTE: this also loads migrations from any sub-package
scriptLocations.add("classpath:org.dspace.storage.rdbms.migration");
// Special scenario: If XMLWorkflows are enabled, we need to run its migration(s)
// as it REQUIRES database schema changes. XMLWorkflow uses Java migrations
// which first check whether the XMLWorkflow tables already exist
String framework = config.getProperty("workflow.framework");
if (framework!=null && framework.equals("xmlworkflow"))
{
scriptLocations.add("classpath:org.dspace.storage.rdbms.xmlworkflow");
}
//Add all potential workflow migration paths
List<String> workflowFlywayMigrationLocations = WorkflowServiceFactory.getInstance().getWorkflowService().getFlywayMigrationLocations();
scriptLocations.addAll(workflowFlywayMigrationLocations);
// Now tell Flyway which locations to load SQL / Java migrations from
log.info("Loading Flyway DB migrations from: " + StringUtils.join(scriptLocations, ", "));

View File

@@ -10,10 +10,10 @@ package org.dspace.storage.rdbms.xmlworkflow;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.storage.rdbms.DatabaseUtils;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.flywaydb.core.api.migration.MigrationChecksumProvider;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource;
@@ -53,8 +53,8 @@ public class V5_0_2014_11_04__Enable_XMLWorkflow_Migration
public void migrate(Connection connection)
throws IOException, SQLException
{
// Make sure XML Workflow is enabled in workflow.cfg before proceeding
if (StringUtils.equals(ConfigurationManager.getProperty("workflow.framework"), "xmlworkflow")
// Make sure XML Workflow is enabled, shouldn't even be needed since this class is only loaded if the service is enabled.
if (WorkflowServiceFactory.getInstance().getWorkflowService() instanceof XmlWorkflowService
// If your database was upgraded to DSpace 6 prior to enabling XML Workflow, we MUST skip this 5.x migration, as it is incompatible
// with a 6.x database. In that scenario the corresponding 6.x XML Workflow migration will create necessary tables.
&& DatabaseUtils.getCurrentFlywayDSpaceState(connection) < 6)

View File

@@ -10,12 +10,13 @@ package org.dspace.storage.rdbms.xmlworkflow;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.storage.rdbms.DatabaseUtils;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.flywaydb.core.api.migration.MigrationChecksumProvider;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource;
import java.sql.Connection;
import org.apache.commons.lang.StringUtils;
/**
* User: kevin (kevin at atmire.com)
@@ -30,8 +31,8 @@ public class V6_0_2015_09_01__DS_2701_Enable_XMLWorkflow_Migration implements Jd
@Override
public void migrate(Connection connection) throws Exception {
// Make sure XML Workflow is enabled in workflow.cfg before proceeding
if (StringUtils.equals(ConfigurationManager.getProperty("workflow.framework"), "xmlworkflow"))
// Make sure XML Workflow is enabled, shouldn't even be needed since this class is only loaded if the service is enabled.
if (WorkflowServiceFactory.getInstance().getWorkflowService() instanceof XmlWorkflowService)
{
// Now, check if the XMLWorkflow table (cwf_workflowitem) already exists in this database
// If XMLWorkflow Table does NOT exist in this database, then lets do the migration!

View File

@@ -75,4 +75,6 @@ public interface WorkflowService<T extends WorkflowItem> {
public List<String> getEPersonDeleteConstraints(Context context, EPerson ePerson) throws SQLException;
public Group getWorkflowRoleGroup(Context context, Collection collection, String roleName, Group roleGroup) throws SQLException, IOException, WorkflowConfigurationException, AuthorizeException, WorkflowException;
public List<String> getFlywayMigrationLocations();
}

View File

@@ -1089,4 +1089,9 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService
}
return roleGroup;
}
@Override
public List<String> getFlywayMigrationLocations() {
return Collections.emptyList();
}
}

View File

@@ -10,17 +10,19 @@ package org.dspace.xmlworkflow;
import org.apache.log4j.Logger;
import org.apache.xpath.XPathAPI;
import org.dspace.content.Collection;
import org.dspace.core.ConfigurationManager;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.actions.UserSelectionActionConfig;
import org.dspace.xmlworkflow.state.Workflow;
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.annotation.PostConstruct;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerException;
import java.io.File;
@@ -41,8 +43,16 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
private Logger log = Logger.getLogger(XmlWorkflowFactoryImpl.class);
@Autowired(required = true)
protected ConfigurationService configurationService;
protected HashMap<String, Workflow> workflowCache;
protected String path = ConfigurationManager.getProperty("dspace.dir")+"/config/workflow.xml";
protected String path;
@PostConstruct
protected void init()
{
path = configurationService.getProperty("dspace.dir")+ File.separator + "config" + File.separator + "workflow.xml";
}
// private static String pathActions = ConfigurationManager.getProperty("dspace.dir")+"/config/workflow-actions.xml";
protected XmlWorkflowFactoryImpl()

View File

@@ -150,6 +150,11 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
}
}
@Override
public List<String> getFlywayMigrationLocations() {
return Collections.singletonList("classpath:org.dspace.storage.rdbms.xmlworkflow");
}
@Override
public XmlWorkflowItem start(Context context, WorkspaceItem wsi) throws SQLException, AuthorizeException, IOException, WorkflowException {
try {