Skip to content

Commit

Permalink
Updated endpoints and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Oct 4, 2023
1 parent 44dce44 commit c45960d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* 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
Expand All @@ -24,6 +24,7 @@
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.MissingLicenseAgreementException;
Expand Down Expand Up @@ -54,7 +55,7 @@
* This CLARIN Controller download a single file or a ZIP file from the Item's bitstream.
*/
@RestController
@RequestMapping("/bitstream")
@RequestMapping("/api/" + BitstreamRest.CATEGORY + "/" + BitstreamRest.PLURAL_NAME)
public class MetadataBitstreamController {

private static Logger log = org.apache.logging.log4j.LogManager.getLogger(MetadataBitstreamController.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.dspace.app.rest.converter.MetadataBitstreamWrapperConverter;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.MetadataBitstreamWrapperRest;
import org.dspace.app.rest.model.wrapper.MetadataBitstreamWrapper;
import org.dspace.app.util.Util;
Expand Down Expand Up @@ -199,7 +200,11 @@ private List<FileInfo> getFilePreviewContent(Context context, Bitstream bitstrea
} catch (MissingLicenseAgreementException e) { /* Do nothing */ }

if (Objects.nonNull(inputStream)) {
fileInfos = processInputStreamToFilePreview(context, bitstream, fileInfos, inputStream);
try {
fileInfos = processInputStreamToFilePreview(context, bitstream, fileInfos, inputStream);
} catch (IllegalStateException e) {
log.error("Cannot process Input Stream to file preview because: " + e.getMessage());
}
}
return fileInfos;
}
Expand Down Expand Up @@ -252,7 +257,8 @@ private String composePreviewURL(Context context, Item item, Bitstream bitstream
} else {
identifier = "id/" + bitstream.getID();
}
String url = contextPath + "/bitstream/" + identifier;
String url = contextPath + "/api/" + BitstreamRest.CATEGORY + "/" + BitstreamRest.PLURAL_NAME + "/"
+ identifier;
try {
if (bitstream.getName() != null) {
url += "/" + Util.encodeBitstreamName(bitstream.getName(), "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.beans.factory.annotation.Autowired;

public class MetadataBitstreamControllerIT extends AbstractControllerIntegrationTest {
private static final String METADATABITSTREAM_ENDPOINT = "/bitstream/";
private static final String METADATABITSTREAM_ENDPOINT = "/api/core/bitstreams/";
private static final String METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT = METADATABITSTREAM_ENDPOINT + "/handle";
private static final String METADATABITSTREAM_DOWNLOAD_ALL_ENDPOINT = METADATABITSTREAM_ENDPOINT + "/allzip";
private static final String AUTHOR = "Test author name";
Expand Down Expand Up @@ -77,7 +77,7 @@ public void setUp() throws Exception {

@Test
public void downloadSingleFileNullPathVariable() throws Exception {
getClient().perform(get(METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT)).andExpect(status().isNotFound());
getClient().perform(get(METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT)).andExpect(status().is4xxClientError());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void composeURL() {
} else {
identifier = "id/" + bts.getID();
}
url = "/bitstream/" + identifier + "/";
url = "/api/core/bitstreams/" + identifier + "/";
try {
if (bts.getName() != null) {
url += Util.encodeBitstreamName(bts.getName(), "UTF-8");
Expand Down

0 comments on commit c45960d

Please sign in to comment.