Skip to content

Commit

Permalink
114022: remove filepath from response & register in HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout-atmire committed Apr 15, 2024
1 parent b0f1136 commit 7495e2d
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
Expand All @@ -12,6 +14,8 @@
import org.dspace.app.rest.utils.HttpHeadersInitializer;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,10 +31,19 @@ public class AtmireVersionsController {
protected ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

public static final String ATMIRE_VERSIONS_CONFIG = "atmire-versions.file";
public static final String ATMIRE_VERSIONS_CONFIG = "atmire-versions.file";
public static final int BUFFER_SIZE = 4096 * 10;
private static final String mimetype = MediaType.APPLICATION_JSON;

@Autowired
private DiscoverableEndpointsService discoverableEndpointsService;


@PostConstruct
public void afterPropertiesSet() {
discoverableEndpointsService.register(this, List.of(Link.of("/api/atmire-versions", "atmire-versions")));
}

@PreAuthorize("hasAuthority('ADMIN')")
@RequestMapping(value = "/atmire-versions", method = RequestMethod.GET)
public ResponseEntity<String> atmireVersioning(HttpServletRequest request, HttpServletResponse response) {
Expand All @@ -57,22 +70,23 @@ public ResponseEntity<String> atmireVersioning(HttpServletRequest request, HttpS
return ResponseEntity.ok().body(json);

} catch (FileNotFoundException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Could not find " + file);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Could not find the versions-file");
} catch (IOException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Something went wrong reading " + file);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Something went wrong reading the versions-file");
}
}

private String getFilePath() {
String file = configurationService.getProperty(ATMIRE_VERSIONS_CONFIG);
if (StringUtils.isBlank(file)) {
throw new IllegalArgumentException(ATMIRE_VERSIONS_CONFIG + " was not correctly defined in the config.");
throw new IllegalArgumentException("versions-file was not correctly defined in the config.");
}
return file;
}

/**
* This method will give the filename that is specified at the end of a path to a file
*
* @param path the path to the file
* @return the filename at the end of the path
*/
Expand All @@ -84,6 +98,7 @@ private static String getFileNameFromPath(String path) {

/**
* This method reads a json file and returns it's content
*
* @param filePath file to read
* @return content of the file
* @throws IOException file not found, something went wrong trying to read the file
Expand Down

0 comments on commit 7495e2d

Please sign in to comment.