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
|
@Override
|
||||||
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException {
|
||||||
Workflow workflow = null;
|
Workflow workflow = null;
|
||||||
try {
|
try {
|
||||||
workflow = workflowFactory.getWorkflow(collection);
|
workflow = workflowFactory.getWorkflow(collection);
|
||||||
} catch (IOException | WorkflowConfigurationException e) {
|
} catch (WorkflowConfigurationException e) {
|
||||||
log.error(LogManager.getHeader(context, "setWorkflowGroup",
|
log.error(LogManager.getHeader(context, "setWorkflowGroup",
|
||||||
"collection_id=" + collection.getID() + " " + e.getMessage()), e);
|
"collection_id=" + collection.getID() + " " + e.getMessage()), e);
|
||||||
}
|
}
|
||||||
@@ -906,4 +906,4 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
throws SQLException {
|
throws SQLException {
|
||||||
return collectionDAO.getCollectionsWithBitstreamSizesTotal(context);
|
return collectionDAO.getCollectionsWithBitstreamSizesTotal(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -164,10 +164,10 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
|||||||
File xmlFile = new File(path);
|
File xmlFile = new File(path);
|
||||||
Document input = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
|
Document input = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
|
||||||
Node mainNode = input.getFirstChild();
|
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++) {
|
for (int i = 0; i < allWorkflowNodes.getLength(); i++) {
|
||||||
String workflowID =
|
String workflowID =
|
||||||
allWorkflowNodes.item(i).getAttributes().getNamedItem("workflow").getTextContent();
|
allWorkflowNodes.item(i).getAttributes().getNamedItem("id").getTextContent();
|
||||||
Node workflowNode = XPathAPI.selectSingleNode(mainNode, "//workflow[@id='" + workflowID + "']");
|
Node workflowNode = XPathAPI.selectSingleNode(mainNode, "//workflow[@id='" + workflowID + "']");
|
||||||
Workflow wf = new Workflow(workflowID, getRoles(workflowNode));
|
Workflow wf = new Workflow(workflowID, getRoles(workflowNode));
|
||||||
Step step = createFirstStep(wf, workflowNode);
|
Step step = createFirstStep(wf, workflowNode);
|
||||||
@@ -218,7 +218,11 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
|||||||
"Error while getting collections mapped to this workflow: " + workflowName);
|
"Error while getting collections mapped to this workflow: " + workflowName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return workflowNameToCollectionHandlesCache.get(workflowName);
|
if (workflowNameToCollectionHandlesCache.get(workflowName) != null) {
|
||||||
|
return workflowNameToCollectionHandlesCache.get(workflowName);
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Step createFirstStep(Workflow workflow, Node workflowNode)
|
protected Step createFirstStep(Workflow workflow, Node workflowNode)
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
package org.dspace.xmlworkflow.factory;
|
package org.dspace.xmlworkflow.factory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
@@ -32,7 +31,7 @@ public interface XmlWorkflowFactory {
|
|||||||
|
|
||||||
public final String LEGACY_WORKFLOW_NAME = "default";
|
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;
|
public Workflow getWorkflowByName(String workflowName) throws WorkflowConfigurationException;
|
||||||
|
|
||||||
|
@@ -7,11 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest;
|
package org.dspace.app.rest;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.service.CollectionService;
|
|
||||||
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.xmlworkflow.WorkflowConfigurationException;
|
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||||
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,32 +51,6 @@ public class WorkflowDefinitionController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected Utils utils;
|
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.
|
* 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,
|
* If a collection doesn't specify the workflow-definition to be used, the default mapping applies,
|
||||||
@@ -94,20 +66,40 @@ public class WorkflowDefinitionController {
|
|||||||
public List<CollectionRest> get(HttpServletRequest request, HttpServletResponse response,
|
public List<CollectionRest> get(HttpServletRequest request, HttpServletResponse response,
|
||||||
@PathVariable String workflowName) throws SQLException {
|
@PathVariable String workflowName) throws SQLException {
|
||||||
try {
|
try {
|
||||||
List<String> collectionsHandlesMappedToWorkflow
|
if (this.workflowByThisNameExists(workflowName)) {
|
||||||
= xmlWorkflowFactory.getCollectionHandlesMappedToWorklow(workflowName);
|
List<String> collectionsHandlesMappedToWorkflow
|
||||||
List<CollectionRest> collectionResourcesFromHandles = new ArrayList<>();
|
= xmlWorkflowFactory.getCollectionHandlesMappedToWorklow(workflowName);
|
||||||
for (String handle : collectionsHandlesMappedToWorkflow) {
|
List<CollectionRest> collectionResourcesFromHandles = new ArrayList<>();
|
||||||
Context context = ContextUtil.obtainContext(request);
|
for (String handle : collectionsHandlesMappedToWorkflow) {
|
||||||
Collection collection = (Collection) handleService.resolveToObject(context, handle);
|
Context context = ContextUtil.obtainContext(request);
|
||||||
if (collection != null) {
|
Collection collection = (Collection) handleService.resolveToObject(context, handle);
|
||||||
collectionResourcesFromHandles.add(converter.toRest(collection, utils.obtainProjection()));
|
if (collection != null) {
|
||||||
|
collectionResourcesFromHandles.add(converter.toRest(collection, utils.obtainProjection()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return collectionResourcesFromHandles;
|
||||||
|
} else {
|
||||||
|
throw new ResourceNotFoundException("No workflow with name " + workflowName + " is configured");
|
||||||
}
|
}
|
||||||
return collectionResourcesFromHandles;
|
|
||||||
} catch (WorkflowConfigurationException e) {
|
} catch (WorkflowConfigurationException e) {
|
||||||
// TODO ? Better exception?
|
// TODO ? Better exception?
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
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;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
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.app.rest.model.WorkflowDefinitionRest;
|
||||||
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.service.CollectionService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||||
import org.dspace.xmlworkflow.state.Workflow;
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +37,9 @@ public class WorkflowDefinitionRestRepository extends DSpaceRestRepository<Workf
|
|||||||
|
|
||||||
protected XmlWorkflowFactory xmlWorkflowFactory = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory();
|
protected XmlWorkflowFactory xmlWorkflowFactory = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectionService collectionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkflowDefinitionRest findOne(Context context, String s) {
|
public WorkflowDefinitionRest findOne(Context context, String s) {
|
||||||
try {
|
try {
|
||||||
@@ -49,6 +60,28 @@ public class WorkflowDefinitionRestRepository extends DSpaceRestRepository<Workf
|
|||||||
throw new RuntimeException(e.getMessage(), e);
|
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
|
@Override
|
||||||
public Class<WorkflowDefinitionRest> getDomainClass() {
|
public Class<WorkflowDefinitionRest> getDomainClass() {
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
<wf-config>
|
<wf-config>
|
||||||
<workflow-map>
|
<workflow-map>
|
||||||
<name-map collection="default" workflow="default"/>
|
<name-map collection="default" workflow="default"/>
|
||||||
<name-map collection="123456789/4" workflow="selectSingleReviewer"/>
|
<!--<name-map collection="123456789/4" workflow="selectSingleReviewer"/>-->
|
||||||
<name-map collection="123456789/5" workflow="scoreReview"/>
|
<!--<name-map collection="123456789/5" workflow="scoreReview"/>-->
|
||||||
</workflow-map>
|
</workflow-map>
|
||||||
|
|
||||||
<!--Standard workflow step-->
|
<!--Standard workflow step-->
|
||||||
|
Reference in New Issue
Block a user