mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +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.ProcessRest;
|
||||||
import org.dspace.app.rest.model.hateoas.ProcessResource;
|
import org.dspace.app.rest.model.hateoas.ProcessResource;
|
||||||
import org.dspace.app.rest.repository.ProcessRestRepository;
|
import org.dspace.app.rest.repository.ProcessRestRepository;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -102,7 +103,8 @@ public class ProcessRestController implements InitializingBean {
|
|||||||
* @throws SQLException If something goes wrong
|
* @throws SQLException If something goes wrong
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/{processId}")
|
@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()) {
|
if (log.isTraceEnabled()) {
|
||||||
log.trace("Retrieving Process with ID: " + processId);
|
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.model.hateoas.ProcessResource;
|
||||||
import org.dspace.app.rest.repository.ScriptRestRepository;
|
import org.dspace.app.rest.repository.ScriptRestRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.security.access.prepost.PreAuthorize;
|
||||||
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;
|
||||||
@@ -41,13 +45,13 @@ public class ScriptRestController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/{name}/processes")
|
@RequestMapping(method = RequestMethod.POST, value = "/{name}/processes")
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@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()) {
|
if (log.isTraceEnabled()) {
|
||||||
log.trace("Starting Process for Script with name: " + scriptName);
|
log.trace("Starting Process for Script with name: " + scriptName);
|
||||||
}
|
}
|
||||||
ProcessRest processRest = scriptRestRepository.startProcess(scriptName);
|
ProcessRest processRest = scriptRestRepository.startProcess(scriptName);
|
||||||
ProcessResource processResource = new ProcessResource(processRest);
|
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())) {
|
for (Option option : CollectionUtils.emptyIfNull(options.getOptions())) {
|
||||||
ParameterRest parameterRest = new ParameterRest();
|
ParameterRest parameterRest = new ParameterRest();
|
||||||
parameterRest.setDescription(option.getDescription());
|
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());
|
parameterRest.setType(((Class) option.getType()).getSimpleName());
|
||||||
listToReturn.add(parameterRest);
|
listToReturn.add(parameterRest);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@ package org.dspace.app.rest.model;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.dspace.app.rest.RestResourceController;
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
@@ -68,9 +67,4 @@ public class ScriptRest extends BaseObjectRest<String> {
|
|||||||
parameterRestList.add(parameter);
|
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.converter.processes.ProcessConverter;
|
||||||
import org.dspace.app.rest.model.ProcessRest;
|
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.Process;
|
||||||
import org.dspace.content.service.ProcessService;
|
import org.dspace.content.service.ProcessService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -32,6 +34,9 @@ public class ProcessRestRepository extends AbstractDSpaceRestRepository {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProcessConverter processConverter;
|
private ProcessConverter processConverter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthorizeService authorizeService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will return a list of all Process objects converted to ProcessRest objects
|
* 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
|
* @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
|
* @return The converted ProcessRest object
|
||||||
* @throws SQLException If something goes wrong
|
* @throws SQLException If something goes wrong
|
||||||
*/
|
*/
|
||||||
public ProcessRest getProcessById(Integer processId) throws SQLException {
|
public ProcessRest getProcessById(Integer processId) throws SQLException, AuthorizeException {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
Process process = processService.find(context, processId);
|
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);
|
return processConverter.fromModel(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,10 +76,8 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
||||||
List list = dspaceRunnables.stream().skip(pageable.getOffset()).limit(pageable.getPageSize())
|
return utils.getPage(dspaceRunnables.stream().filter(dSpaceRunnable -> dSpaceRunnable.isAllowedToExecute(context)).collect(
|
||||||
.collect(Collectors.toList());
|
Collectors.toList()), pageable).map(scriptConverter);
|
||||||
Page<ScriptRest> scriptRestPage = new PageImpl<>(list, pageable, dspaceRunnables.size()).map(scriptConverter);
|
|
||||||
return scriptRestPage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user