68253: GET /api/config/workflowsteps/<:step-name> endpoint

This commit is contained in:
Marie Verdonck
2020-01-10 17:01:33 +01:00
parent 22b1f6231d
commit 766d021a1a
9 changed files with 188 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ import org.dspace.core.Context;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.utils.DSpace; import org.dspace.utils.DSpace;
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory; import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.Workflow; import org.dspace.xmlworkflow.state.Workflow;
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig; import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -47,10 +48,10 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
private Map<String, Workflow> workflowMapping; private Map<String, Workflow> workflowMapping;
@Autowired(required = true) @Autowired
protected CollectionService collectionService; protected CollectionService collectionService;
@Autowired(required = true) @Autowired
protected HandleService handleService; protected HandleService handleService;
@Override @Override
@@ -154,9 +155,12 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
@Override @Override
public WorkflowActionConfig getActionByName(String workflowActionName) { public WorkflowActionConfig getActionByName(String workflowActionName) {
WorkflowActionConfig actionConfig return new DSpace().getServiceManager().getServiceByName(workflowActionName, WorkflowActionConfig.class);
= new DSpace().getServiceManager().getServiceByName(workflowActionName, WorkflowActionConfig.class); }
return actionConfig;
@Override
public Step getStepByName(String workflowStepName) {
return new DSpace().getServiceManager().getServiceByName(workflowStepName, Step.class);
} }
} }

View File

@@ -12,6 +12,7 @@ import java.util.List;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.xmlworkflow.WorkflowConfigurationException; import org.dspace.xmlworkflow.WorkflowConfigurationException;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.Workflow; import org.dspace.xmlworkflow.state.Workflow;
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig; import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
@@ -95,10 +96,18 @@ public interface XmlWorkflowFactory {
public List<Collection> getAllNonMappedCollectionsHandles(Context context); public List<Collection> getAllNonMappedCollectionsHandles(Context context);
/** /**
* Retrieve a WorkflowActionConfig object based on its name, should correspond with bean id in workflow-actions.xml * Retrieves a {@link WorkflowActionConfig} object based on its name, should correspond with bean id in workflow-actions.xml
* *
* @param workflowActionName Name of workflow action we want to retrieve * @param workflowActionName Name of workflow action we want to retrieve
* @return WorkflowActionConfig object corresponding to the given workflowActionName * @return Workflow action object corresponding to the given workflowActionName
*/ */
public WorkflowActionConfig getActionByName(String workflowActionName); public WorkflowActionConfig getActionByName(String workflowActionName);
/**
* Retrieves a {@link Step} object based on its name, should correspond with bean id in workflow.xml
*
* @param workflowStepName Name of workflow step we want to retrieve
* @return Workflow step object corresponding to the given workflowStepName
*/
public Step getStepByName(String workflowStepName);
} }

View File

@@ -13,7 +13,7 @@ import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* Converter to translate WorkflowActionConfig to a WorkflowActionRest object * Converter to translate {@link WorkflowActionConfig} to a {@link WorkflowActionRest} object
* *
* @author Maria Verdonck (Atmire) on 06/01/2020 * @author Maria Verdonck (Atmire) on 06/01/2020
*/ */

View File

@@ -0,0 +1,44 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.converter;
import org.dspace.app.rest.model.WorkflowActionRest;
import org.dspace.app.rest.model.WorkflowStepRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.xmlworkflow.state.Step;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.stream.Collectors;
/**
* Converter to translate {@link Step} to a {@link WorkflowStepRest} object
*
* @author Maria Verdonck (Atmire) on 10/01/2020
*/
@Component
public class WorkflowStepConverter implements DSpaceConverter<Step, WorkflowStepRest> {
@Autowired
ConverterService converter;
@Override
public WorkflowStepRest convert(Step modelObject, Projection projection) {
WorkflowStepRest restModel = new WorkflowStepRest();
restModel.setId(modelObject.getId());
restModel.setActions(modelObject.getActions().stream()
.map(x -> (WorkflowActionRest) converter.toRest(x, projection))
.collect(Collectors.toList()));
return restModel;
}
@Override
public Class<Step> getModelClass() {
return Step.class;
}
}

View File

@@ -0,0 +1,53 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
import org.dspace.app.rest.RestResourceController;
import java.util.List;
/**
* The rest resource used for workflow steps
*
* @author Maria Verdonck (Atmire) on 10/01/2020
*/
public class WorkflowStepRest extends BaseObjectRest {
public static final String CATEGORY = "config";
public static final String NAME = "workflowstep";
public static final String NAME_PLURAL = "workflowsteps";
private List<WorkflowActionRest> actions;
@Override
public String getCategory() {
return CATEGORY;
}
@Override
public Class getController() {
return RestResourceController.class;
}
@Override
public String getType() {
return NAME;
}
@LinkRest(linkClass = WorkflowActionConfig.class)
@JsonIgnore
public List<WorkflowActionRest> getActions() {
return actions;
}
public void setActions(List<WorkflowActionRest> actions) {
this.actions = actions;
}
}

View File

@@ -11,7 +11,7 @@ import org.dspace.app.rest.model.WorkflowActionRest;
import org.dspace.app.rest.utils.Utils; import org.dspace.app.rest.utils.Utils;
/** /**
* WorkflowAction Rest HAL Resource. The HAL Resource wraps the REST Resource * {@link WorkflowActionRest} HAL Resource. The HAL Resource wraps the REST Resource
* adding support for the links and embedded resources * adding support for the links and embedded resources
* *
* @author Maria Verdonck (Atmire) on 06/01/2020 * @author Maria Verdonck (Atmire) on 06/01/2020

View File

@@ -0,0 +1,16 @@
package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.WorkflowStepRest;
import org.dspace.app.rest.utils.Utils;
/**
* {@link WorkflowStepRest} HAL Resource. The HAL Resource wraps the REST Resource
* adding support for the links and embedded resources
*
* @author Maria Verdonck (Atmire) on 10/01/2020
*/
public class WorkflowStepResource extends DSpaceResource<WorkflowStepRest> {
public WorkflowStepResource(WorkflowStepRest data, Utils utils) {
super(data, utils);
}
}

View File

@@ -19,7 +19,7 @@ import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* This is the rest repository responsible for managing WorkflowAction Rest objects * This is the rest repository responsible for managing {@link WorkflowActionRest} objects
* *
* @author Maria Verdonck (Atmire) on 06/01/2020 * @author Maria Verdonck (Atmire) on 06/01/2020
*/ */

View File

@@ -0,0 +1,52 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.model.WorkflowStepRest;
import org.dspace.core.Context;
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.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Component;
/**
* This is the rest repository responsible for managing {@link WorkflowStepRest} objects
*
* @author Maria Verdonck (Atmire) on 10/01/2020
*/
@Component(WorkflowStepRest.CATEGORY + "." + WorkflowStepRest.NAME)
public class WorkflowStepRestRepository extends DSpaceRestRepository<WorkflowStepRest, String> {
@Autowired
protected XmlWorkflowFactory xmlWorkflowFactory;
@Override
public WorkflowStepRest findOne(Context context, String workflowStepName) {
Step step = this.xmlWorkflowFactory.getStepByName(workflowStepName);
if (step != null) {
return converter.toRest(step, utils.obtainProjection(true));
} else {
throw new ResourceNotFoundException("No workflow step with name " + workflowStepName
+ " is configured");
}
}
@Override
public Page<WorkflowStepRest> findAll(Context context, Pageable pageable) {
throw new RepositoryMethodNotImplementedException(WorkflowStepRest.NAME, "findAll");
}
@Override
public Class<WorkflowStepRest> getDomainClass() {
return WorkflowStepRest.class;
}
}