Skip to content

Commit

Permalink
Added docs and fixed checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Dec 27, 2023
1 parent d31b046 commit fd2cf6f
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/**
* 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
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.converter;

import org.dspace.app.rest.authorization.Authorization;
import org.dspace.app.rest.model.AuthorizationRest;
import org.dspace.app.rest.model.BitstreamChecksum;
import org.dspace.app.rest.model.BitstreamChecksumRest;
import org.dspace.app.rest.projection.Projection;
import org.springframework.stereotype.Component;

/**
* Convert the BitstreamChecksum to appropriate REST data model
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
@Component
public class BitstreamChecksumConverter implements DSpaceConverter<BitstreamChecksum, BitstreamChecksumRest> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
/**
* 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
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.model;

/**
* This class handles the checksums of a bitstream (local, S3, database)
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
public class BitstreamChecksum {
CheckSumRest activeStore = null;
CheckSumRest synchronizedStore = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/**
* 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
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* The BitstreamChecksum REST Resource.
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
public class BitstreamChecksumRest extends RestAddressableModel implements RestModel {
private static final long serialVersionUID = -3415049466402327251L;
public static final String NAME = "bitstreamchecksum";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
/**
* 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
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.model.hateoas;

import org.dspace.app.rest.model.AuthrnRest;
import org.dspace.app.rest.model.BitstreamChecksumRest;
import org.dspace.app.rest.model.BitstreamFormatRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;

/**
* Bitstream Checksum Rest HAL Resource. The HAL Resource wraps the REST Resource
* adding support for the links and embedded resources
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
@RelNameDSpaceResource(BitstreamChecksumRest.NAME)
public class BitstreamChecksumResource extends DSpaceResource<BitstreamChecksumRest> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/**
* 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
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

import org.dspace.app.rest.model.BitstreamChecksum;
import org.dspace.app.rest.model.BitstreamChecksumRest;
import org.dspace.app.rest.model.BitstreamRest;
Expand All @@ -15,14 +30,11 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
* Link repository for "checksum" subresource of an individual bitstream.
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
@Component(BitstreamRest.CATEGORY + "." + BitstreamRest.NAME + "." + BitstreamRest.CHECKSUM)
public class BitstreamCheckSumLinkRepository extends AbstractDSpaceRestRepository implements LinkRestRepository {

Expand Down Expand Up @@ -66,11 +78,6 @@ public BitstreamChecksumRest getChecksum(@Nullable HttpServletRequest request,
bitstreamChecksum.setDatabaseChecksum(databaseChecksum);
bitstreamChecksum.setSynchronizedStore(synchronizedStoreChecksum);

// BitstreamChecksumRest bitstreamChecksumRest = new BitstreamChecksumRest();
// bitstreamChecksumRest.setActiveStore(activeStoreChecksum);
// bitstreamChecksumRest.setDatabaseChecksum(databaseChecksum);
// bitstreamChecksumRest.setSynchronizedStore(synchronizedStoreChecksum);

return converter.toRest(bitstreamChecksum, projection);
} catch (SQLException e) {
throw new RuntimeException(e);
Expand All @@ -79,6 +86,9 @@ public BitstreamChecksumRest getChecksum(@Nullable HttpServletRequest request,
}
}

/**
* Compose the checksum rest object from the checksum map
*/
private void composeChecksumRest(CheckSumRest checksumRest, Map<String, Object> checksumMap) {
if (Objects.isNull(checksumMap)) {
return;
Expand All @@ -91,6 +101,4 @@ private void composeChecksumRest(CheckSumRest checksumRest, Map<String, Object>
checksumRest.setCheckSumAlgorithm(checksumMap.get("checksum_algorithm").toString());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

/**
* Link repository for "format" subresource of an individual bitstream.
*
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
@Component(BitstreamRest.CATEGORY + "." + BitstreamRest.NAME + "." + BitstreamRest.FORMAT)
public class BitstreamFormatLinkRepository extends AbstractDSpaceRestRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -1178,4 +1179,50 @@ public void closeInputStreamsDownloadWithCoverPage() throws Exception {
Mockito.verify(inputStreamSpy, times(1)).close();
}

@Test
public void testChecksumLinkRepository() throws Exception {
context.turnOffAuthorisationSystem();

//** GIVEN **
//1. A community-collection structure with one parent community and one collections.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();

Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build();

//2. A public item with a bitstream
String bitstreamContent = "0123456789";

try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {

Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test bitstream")
.withDescription("This is a bitstream to test range requests")
.withMimeType("text/plain")
.build();
}
context.restoreAuthSystemState();

getClient()
.perform(get("/api/core/bitstreams/" + bitstream.getID() + "/checksum"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.activeStore.value", is(bitstream.getChecksum())))
.andExpect(jsonPath("$.activeStore.checkSumAlgorithm", is(bitstream.getChecksumAlgorithm())))
.andExpect(jsonPath("$.databaseChecksum.value", is(bitstream.getChecksum())))
.andExpect(jsonPath("$.databaseChecksum.checkSumAlgorithm",
is(bitstream.getChecksumAlgorithm())))
.andExpect(jsonPath("$.synchronizedStore.value", nullValue()))
.andExpect(jsonPath("$.synchronizedStore.checkSumAlgorithm", nullValue()));


}

}

0 comments on commit fd2cf6f

Please sign in to comment.