Skip to content

Commit

Permalink
[Task 70911] applied feedback on the Process endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Raf-atmire committed May 28, 2020
1 parent bc7cf14 commit 8045194
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/" + ProcessRest.CATEGORY + "/" + ProcessRest.PLURAL_NAME)
public class ProcessRestController {
@RequestMapping("/api/" + ProcessRest.CATEGORY + "/" + ProcessRest.PLURAL_NAME + "/{processId}/files")
public class ProcessFilesRestController {

private static final Logger log = LogManager.getLogger();

Expand All @@ -53,7 +54,8 @@ public class ProcessRestController {
@Autowired
ProcessResourceHalLinkFactory processResourceHalLinkFactory;

@RequestMapping(method = RequestMethod.GET, value = "/{processId}/files/{fileType}")
@RequestMapping(method = RequestMethod.GET, value = "/{fileType}")
@PreAuthorize("hasAuthority('ADMIN')")
public PagedModel<BitstreamResource> listFilesWithTypeFromProcess(
@PathVariable(name = "processId") Integer processId,
@PathVariable(name = "fileType") String fileType,
Expand All @@ -79,7 +81,8 @@ public PagedModel<BitstreamResource> listFilesWithTypeFromProcess(
}


@RequestMapping(method = RequestMethod.GET, value = "/{processId}/files/name/{fileName:.+}")
@RequestMapping(method = RequestMethod.GET, value = "/name/{fileName:.+}")
@PreAuthorize("hasAuthority('ADMIN')")
public BitstreamResource getBitstreamByName(@PathVariable(name = "processId") Integer processId,
@PathVariable(name = "fileName") String fileName)
throws SQLException, AuthorizeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/
package org.dspace.app.rest.link.process;

import org.dspace.app.rest.ProcessRestController;
import org.dspace.app.rest.ProcessFilesRestController;
import org.dspace.app.rest.link.HalLinkFactory;

/**
* This abstract class offers an easily extendable HalLinkFactory class to use methods on the ProcessRestController
* and make it more easy to read or define which methods should be found in the getMethodOn methods when building links
* @param <T> This parameter should be of type {@link org.dspace.app.rest.model.hateoas.HALResource}
*/
public abstract class ProcessHalLinkFactory<T> extends HalLinkFactory<T, ProcessRestController> {
public abstract class ProcessHalLinkFactory<T> extends HalLinkFactory<T, ProcessFilesRestController> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.LinkedList;

import org.dspace.app.rest.ProcessRestController;
import org.dspace.app.rest.ProcessFilesRestController;
import org.dspace.app.rest.model.hateoas.ProcessResource;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,8 +35,8 @@ protected void addLinks(ProcessResource halResource, Pageable pageable, LinkedLi
}

@Override
protected Class<ProcessRestController> getControllerClass() {
return ProcessRestController.class;
protected Class<ProcessFilesRestController> getControllerClass() {
return ProcessFilesRestController.class;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,32 @@
import org.dspace.authorize.AuthorizeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

/**
* This is the {@link LinkRestRepository} implementation that takes care of retrieving the
* {@link ProcessFileWrapperRest} for the Process endpoints
*
*/
@Component(ProcessRest.CATEGORY + "." + ProcessRest.NAME + "." + ProcessRest.FILES)
public class ProcessFilesLinkRepository extends AbstractDSpaceRestRepository implements LinkRestRepository {

@Autowired
private ProcessRestRepository processRestRepository;

/**
* This method will retrieve all the files from the process and wrap them into a {@link ProcessFileWrapperRest}
* object to return
* @param request The current request
* @param processId The processId for the Process to use
* @param optionalPageable Pageable if applicable
* @param projection Projection if applicable
* @return A {@link ProcessFileWrapperRest} object filled with the bitstreams from the process
* @throws SQLException If something goes wrong
* @throws AuthorizeException If something goes wrong
*/
@PreAuthorize("hasAuthority('ADMIN')")
public ProcessFileWrapperRest getFilesFromProcess(@Nullable HttpServletRequest request,
Integer processId,
@Nullable Pageable optionalPageable,
Expand Down

0 comments on commit 8045194

Please sign in to comment.