mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
LinkRepositories so that subresources paths work without projection=full (for workflowdefinitions/defaultWorkflow/steps and /workflowsteps/editstep/actions)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||
import org.dspace.app.rest.model.WorkflowStepRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.repository.AbstractDSpaceRestRepository;
|
||||
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.state.Step;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Link repository for "steps" subresource of an individual workflow definition.
|
||||
*
|
||||
* @author Maria Verdonck (Atmire) on 24/02/2020
|
||||
*/
|
||||
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.NAME + "."
|
||||
+ WorkflowDefinitionRest.STEPS)
|
||||
public class WorkflowDefinitionStepsLinkRepository extends AbstractDSpaceRestRepository
|
||||
implements LinkRestRepository {
|
||||
|
||||
@Autowired
|
||||
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||
|
||||
/**
|
||||
* GET endpoint that returns the list of steps of a workflow-definition.
|
||||
*
|
||||
* @param request The request object
|
||||
* @param workflowName Name of workflow we want the steps from
|
||||
* @return List of steps of the requested workflow
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public Page<WorkflowStepRest> getSteps(@Nullable HttpServletRequest request,
|
||||
String workflowName,
|
||||
@Nullable Pageable optionalPageable,
|
||||
Projection projection) {
|
||||
try {
|
||||
List<Step> steps = xmlWorkflowFactory.getWorkflowByName(workflowName).getSteps();
|
||||
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
|
||||
return converter.toRestPage(utils.getPage(steps, pageable), projection);
|
||||
} catch (WorkflowConfigurationException e) {
|
||||
throw new ResourceNotFoundException("No workflow with name " + workflowName + " is configured");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.WorkflowActionRest;
|
||||
import org.dspace.app.rest.model.WorkflowStepRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.repository.AbstractDSpaceRestRepository;
|
||||
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Link repository for "actions" subresource of an individual workflow step.
|
||||
*
|
||||
* @author Maria Verdonck (Atmire) on 24/02/2020
|
||||
*/
|
||||
@Component(WorkflowStepRest.CATEGORY + "." + WorkflowStepRest.NAME + "."
|
||||
+ WorkflowStepRest.ACTIONS)
|
||||
public class WorkflowStepActionsLinkRepository extends AbstractDSpaceRestRepository
|
||||
implements LinkRestRepository {
|
||||
|
||||
@Autowired
|
||||
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||
|
||||
/**
|
||||
* GET endpoint that returns the list of actions of a workflow step.
|
||||
*
|
||||
* @param request The request object
|
||||
* @param workflowStepName Name of workflow step we want the actions from
|
||||
* @return List of actions of the requested workflow step
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public Page<WorkflowActionRest> getActions(@Nullable HttpServletRequest request,
|
||||
String workflowStepName,
|
||||
@Nullable Pageable optionalPageable,
|
||||
Projection projection) {
|
||||
List<WorkflowActionConfig> actions = xmlWorkflowFactory.getStepByName(workflowStepName).getActions();
|
||||
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
|
||||
return converter.toRestPage(utils.getPage(actions, pageable), projection);
|
||||
}
|
||||
}
|
@@ -21,6 +21,10 @@ import org.dspace.app.rest.RestResourceController;
|
||||
@LinkRest(
|
||||
name = WorkflowDefinitionRest.COLLECTIONS_MAPPED_TO,
|
||||
method = "getCollections"
|
||||
),
|
||||
@LinkRest(
|
||||
name = WorkflowDefinitionRest.STEPS,
|
||||
method = "getSteps"
|
||||
)
|
||||
})
|
||||
public class WorkflowDefinitionRest extends BaseObjectRest<String> {
|
||||
@@ -28,7 +32,9 @@ public class WorkflowDefinitionRest extends BaseObjectRest<String> {
|
||||
public static final String CATEGORY = "config";
|
||||
public static final String NAME = "workflowdefinition";
|
||||
public static final String NAME_PLURAL = "workflowdefinitions";
|
||||
|
||||
public static final String COLLECTIONS_MAPPED_TO = "collections";
|
||||
public static final String STEPS = "steps";
|
||||
|
||||
private String name;
|
||||
private boolean isDefault;
|
||||
@@ -71,7 +77,6 @@ public class WorkflowDefinitionRest extends BaseObjectRest<String> {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@LinkRest
|
||||
@JsonIgnore
|
||||
public List<WorkflowStepRest> getSteps() {
|
||||
return steps;
|
||||
|
@@ -17,12 +17,20 @@ import org.dspace.app.rest.RestResourceController;
|
||||
*
|
||||
* @author Maria Verdonck (Atmire) on 10/01/2020
|
||||
*/
|
||||
@LinksRest(links = {
|
||||
@LinkRest(
|
||||
name = WorkflowStepRest.ACTIONS,
|
||||
method = "getActions"
|
||||
),
|
||||
})
|
||||
public class WorkflowStepRest extends BaseObjectRest {
|
||||
|
||||
public static final String CATEGORY = "config";
|
||||
public static final String NAME = "workflowstep";
|
||||
public static final String NAME_PLURAL = "workflowsteps";
|
||||
|
||||
public static final String ACTIONS = "workflowactions";
|
||||
|
||||
private List<WorkflowActionRest> workflowactions;
|
||||
|
||||
@Override
|
||||
@@ -40,7 +48,6 @@ public class WorkflowStepRest extends BaseObjectRest {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@LinkRest
|
||||
@JsonIgnore
|
||||
public List<WorkflowActionRest> getWorkflowactions() {
|
||||
return workflowactions;
|
||||
|
Reference in New Issue
Block a user