mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
67694: Exception handling improvements and /search moved to repository
This commit is contained in:
@@ -375,11 +375,11 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
|
||||
@Override
|
||||
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
||||
throws SQLException, AuthorizeException {
|
||||
throws SQLException {
|
||||
Workflow workflow = null;
|
||||
try {
|
||||
workflow = workflowFactory.getWorkflow(collection);
|
||||
} catch (IOException | WorkflowConfigurationException e) {
|
||||
} catch (WorkflowConfigurationException e) {
|
||||
log.error(LogManager.getHeader(context, "setWorkflowGroup",
|
||||
"collection_id=" + collection.getID() + " " + e.getMessage()), e);
|
||||
}
|
||||
|
@@ -164,10 +164,10 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
||||
File xmlFile = new File(path);
|
||||
Document input = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
|
||||
Node mainNode = input.getFirstChild();
|
||||
NodeList allWorkflowNodes = XPathAPI.selectNodeList(mainNode, "//workflow-map/name-map");
|
||||
NodeList allWorkflowNodes = XPathAPI.selectNodeList(mainNode, "//workflow");
|
||||
for (int i = 0; i < allWorkflowNodes.getLength(); i++) {
|
||||
String workflowID =
|
||||
allWorkflowNodes.item(i).getAttributes().getNamedItem("workflow").getTextContent();
|
||||
allWorkflowNodes.item(i).getAttributes().getNamedItem("id").getTextContent();
|
||||
Node workflowNode = XPathAPI.selectSingleNode(mainNode, "//workflow[@id='" + workflowID + "']");
|
||||
Workflow wf = new Workflow(workflowID, getRoles(workflowNode));
|
||||
Step step = createFirstStep(wf, workflowNode);
|
||||
@@ -218,7 +218,11 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
||||
"Error while getting collections mapped to this workflow: " + workflowName);
|
||||
}
|
||||
}
|
||||
if (workflowNameToCollectionHandlesCache.get(workflowName) != null) {
|
||||
return workflowNameToCollectionHandlesCache.get(workflowName);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
protected Step createFirstStep(Workflow workflow, Node workflowNode)
|
||||
|
@@ -8,7 +8,6 @@
|
||||
package org.dspace.xmlworkflow.factory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
@@ -32,7 +31,7 @@ public interface XmlWorkflowFactory {
|
||||
|
||||
public final String LEGACY_WORKFLOW_NAME = "default";
|
||||
|
||||
public Workflow getWorkflow(Collection collection) throws IOException, WorkflowConfigurationException, SQLException;
|
||||
public Workflow getWorkflow(Collection collection) throws WorkflowConfigurationException;
|
||||
|
||||
public Workflow getWorkflowByName(String workflowName) throws WorkflowConfigurationException;
|
||||
|
||||
|
@@ -7,11 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -21,18 +19,18 @@ import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||
import org.dspace.xmlworkflow.state.Workflow;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -53,32 +51,6 @@ public class WorkflowDefinitionController {
|
||||
@Autowired
|
||||
protected Utils utils;
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
/**
|
||||
* GET endpoint that returns the workflow definition that applies to a specific collection eventually fallback
|
||||
* to the default configuration.
|
||||
*
|
||||
* @param request The request object
|
||||
* @param response The response object
|
||||
* @param uuid Uuid of the collection
|
||||
* @return the workflow definition for this collection
|
||||
*/
|
||||
@GetMapping("/search/findByCollection")
|
||||
public WorkflowDefinitionRest get(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam(name = "uuid", required = true) UUID uuid)
|
||||
throws SQLException, IOException {
|
||||
try {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Collection collectionFromUuid = collectionService.find(context, uuid);
|
||||
return converter.toRest(xmlWorkflowFactory.getWorkflow(collectionFromUuid), utils.obtainProjection());
|
||||
} catch (WorkflowConfigurationException e) {
|
||||
// TODO ? Better exception?
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET endpoint that returns the list of collections that make an explicit use of the workflow-definition.
|
||||
* If a collection doesn't specify the workflow-definition to be used, the default mapping applies,
|
||||
@@ -94,6 +66,7 @@ public class WorkflowDefinitionController {
|
||||
public List<CollectionRest> get(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable String workflowName) throws SQLException {
|
||||
try {
|
||||
if (this.workflowByThisNameExists(workflowName)) {
|
||||
List<String> collectionsHandlesMappedToWorkflow
|
||||
= xmlWorkflowFactory.getCollectionHandlesMappedToWorklow(workflowName);
|
||||
List<CollectionRest> collectionResourcesFromHandles = new ArrayList<>();
|
||||
@@ -105,9 +78,28 @@ public class WorkflowDefinitionController {
|
||||
}
|
||||
}
|
||||
return collectionResourcesFromHandles;
|
||||
} else {
|
||||
throw new ResourceNotFoundException("No workflow with name " + workflowName + " is configured");
|
||||
}
|
||||
} catch (WorkflowConfigurationException e) {
|
||||
// TODO ? Better exception?
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if there is a workflow configured by the given name
|
||||
* @param workflowName Name of a possible configured workflow
|
||||
* @return True if there is a workflow configured by this name, false otherwise
|
||||
* @throws WorkflowConfigurationException
|
||||
*/
|
||||
private boolean workflowByThisNameExists(String workflowName) throws WorkflowConfigurationException {
|
||||
List<Workflow> allConfiguredWorkflows = xmlWorkflowFactory.getAllConfiguredWorkflows();
|
||||
for (Workflow workflow: allConfiguredWorkflows) {
|
||||
if (workflow.getID().equalsIgnoreCase(workflowName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -7,16 +7,24 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.Parameter;
|
||||
import org.dspace.app.rest.SearchRestMethod;
|
||||
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||
import org.dspace.xmlworkflow.state.Workflow;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -29,6 +37,9 @@ public class WorkflowDefinitionRestRepository extends DSpaceRestRepository<Workf
|
||||
|
||||
protected XmlWorkflowFactory xmlWorkflowFactory = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory();
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
|
||||
@Override
|
||||
public WorkflowDefinitionRest findOne(Context context, String s) {
|
||||
try {
|
||||
@@ -49,6 +60,28 @@ public class WorkflowDefinitionRestRepository extends DSpaceRestRepository<Workf
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* GET endpoint that returns the workflow definition that applies to a specific collection eventually fallback
|
||||
* to the default configuration.
|
||||
*
|
||||
* @param collectionId Uuid of the collection
|
||||
* @return the workflow definition for this collection
|
||||
*/
|
||||
@SearchRestMethod(name = "findByCollection")
|
||||
public WorkflowDefinitionRest findByCollection(@Parameter(value = "uuid") UUID collectionId) throws SQLException {
|
||||
try {
|
||||
Context context = obtainContext();
|
||||
Collection collectionFromUuid = collectionService.find(context, collectionId);
|
||||
if (collectionFromUuid != null) {
|
||||
return converter.toRest(xmlWorkflowFactory.getWorkflow(collectionFromUuid), utils.obtainProjection());
|
||||
} else {
|
||||
throw new ResourceNotFoundException("Collection with id " + collectionId + " not found");
|
||||
}
|
||||
} catch (WorkflowConfigurationException e) {
|
||||
// TODO ? Better exception?
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WorkflowDefinitionRest> getDomainClass() {
|
||||
|
@@ -2,8 +2,8 @@
|
||||
<wf-config>
|
||||
<workflow-map>
|
||||
<name-map collection="default" workflow="default"/>
|
||||
<name-map collection="123456789/4" workflow="selectSingleReviewer"/>
|
||||
<name-map collection="123456789/5" workflow="scoreReview"/>
|
||||
<!--<name-map collection="123456789/4" workflow="selectSingleReviewer"/>-->
|
||||
<!--<name-map collection="123456789/5" workflow="scoreReview"/>-->
|
||||
</workflow-map>
|
||||
|
||||
<!--Standard workflow step-->
|
||||
|
Reference in New Issue
Block a user