mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
[Task 64926] applied feedback and change request to response code and id on scripts
This commit is contained in:
@@ -21,6 +21,7 @@ import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.ProcessRest;
|
||||
import org.dspace.app.rest.model.hateoas.ProcessResource;
|
||||
import org.dspace.app.rest.repository.ProcessRestRepository;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -102,7 +103,8 @@ public class ProcessRestController implements InitializingBean {
|
||||
* @throws SQLException If something goes wrong
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{processId}")
|
||||
public ProcessResource getProcessById(@PathVariable(name = "processId") Integer processId) throws SQLException {
|
||||
public ProcessResource getProcessById(@PathVariable(name = "processId") Integer processId)
|
||||
throws SQLException, AuthorizeException {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Retrieving Process with ID: " + processId);
|
||||
}
|
||||
|
@@ -14,6 +14,10 @@ import org.dspace.app.rest.model.ScriptRest;
|
||||
import org.dspace.app.rest.model.hateoas.ProcessResource;
|
||||
import org.dspace.app.rest.repository.ScriptRestRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.ControllerUtils;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -41,13 +45,13 @@ public class ScriptRestController {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{name}/processes")
|
||||
@PreAuthorize("hasAuthority('ADMIN')")
|
||||
public ProcessResource startProcess(@PathVariable(name = "name") String scriptName) throws Exception {
|
||||
public ResponseEntity<ResourceSupport> startProcess(@PathVariable(name = "name") String scriptName) throws Exception {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Starting Process for Script with name: " + scriptName);
|
||||
}
|
||||
ProcessRest processRest = scriptRestRepository.startProcess(scriptName);
|
||||
ProcessResource processResource = new ProcessResource(processRest);
|
||||
return processResource;
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.ACCEPTED, null, processResource);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ public class ParameterConverter {
|
||||
for (Option option : CollectionUtils.emptyIfNull(options.getOptions())) {
|
||||
ParameterRest parameterRest = new ParameterRest();
|
||||
parameterRest.setDescription(option.getDescription());
|
||||
parameterRest.setName("-" + (option.getOpt() != null ? option.getOpt() : "-" + option.getLongOpt()));
|
||||
parameterRest.setName((option.getOpt() != null ? "-" + option.getOpt() : "--" + option.getLongOpt()));
|
||||
parameterRest.setType(((Class) option.getType()).getSimpleName());
|
||||
listToReturn.add(parameterRest);
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ package org.dspace.app.rest.model;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
@@ -68,9 +67,4 @@ public class ScriptRest extends BaseObjectRest<String> {
|
||||
parameterRestList.add(parameter);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.processes.ProcessConverter;
|
||||
import org.dspace.app.rest.model.ProcessRest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Process;
|
||||
import org.dspace.content.service.ProcessService;
|
||||
import org.dspace.core.Context;
|
||||
@@ -32,6 +34,9 @@ public class ProcessRestRepository extends AbstractDSpaceRestRepository {
|
||||
@Autowired
|
||||
private ProcessConverter processConverter;
|
||||
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
|
||||
/**
|
||||
* This method will return a list of all Process objects converted to ProcessRest objects
|
||||
* @return The list of ProcessRest objects coming forth from all Process objects in the database
|
||||
@@ -56,9 +61,12 @@ public class ProcessRestRepository extends AbstractDSpaceRestRepository {
|
||||
* @return The converted ProcessRest object
|
||||
* @throws SQLException If something goes wrong
|
||||
*/
|
||||
public ProcessRest getProcessById(Integer processId) throws SQLException {
|
||||
public ProcessRest getProcessById(Integer processId) throws SQLException, AuthorizeException {
|
||||
Context context = obtainContext();
|
||||
Process process = processService.find(context, processId);
|
||||
if ((context.getCurrentUser() == null) || (!context.getCurrentUser().equals(process.getEPerson()) && !authorizeService.isAdmin(context))) {
|
||||
throw new AuthorizeException("The current user is not eligible to view the process with id: " + processId);
|
||||
}
|
||||
return processConverter.fromModel(process);
|
||||
}
|
||||
|
||||
|
@@ -76,10 +76,8 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
||||
|
||||
@Override
|
||||
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
||||
List list = dspaceRunnables.stream().skip(pageable.getOffset()).limit(pageable.getPageSize())
|
||||
.collect(Collectors.toList());
|
||||
Page<ScriptRest> scriptRestPage = new PageImpl<>(list, pageable, dspaceRunnables.size()).map(scriptConverter);
|
||||
return scriptRestPage;
|
||||
return utils.getPage(dspaceRunnables.stream().filter(dSpaceRunnable -> dSpaceRunnable.isAllowedToExecute(context)).collect(
|
||||
Collectors.toList()), pageable).map(scriptConverter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user