Skip to content

Commit

Permalink
Added docs and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Dec 22, 2023
1 parent e32b9d6 commit 72fa41a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
10 changes: 7 additions & 3 deletions dspace-api/src/main/java/org/dspace/checker/CheckerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ protected void processBitstream(MostRecentChecksum info) throws SQLException {
info.setProcessStartDate(new Date());

try {
// 1. DB - S3 not match
// 2. DS - S3 not match - Synchronization
// 1. DB - Store not match
Bitstream bitstream = info.getBitstream();
Map<String, Object> checksumMap = bitstreamStorageService.computeChecksum(context, bitstream);
if (MapUtils.isNotEmpty(checksumMap)) {
Expand All @@ -271,6 +270,7 @@ protected void processBitstream(MostRecentChecksum info) throws SQLException {
info.setToBeProcessed(false);
}

// 2. Store1 - Synchronized store 2 not match
// Check checksum of synchronized store
if (bitstream.getStoreNumber() != SYNCHRONIZED_STORES_NUMBER) {
return;
Expand All @@ -279,14 +279,18 @@ protected void processBitstream(MostRecentChecksum info) throws SQLException {
return;
}

Map<String, Object> syncStoreChecksumMap = bitstreamStorageService.computeChecksumSpecStore(context, bitstream, bitstreamStorageService.getSynchronizedStoreNumber(bitstream));
Map<String, Object> syncStoreChecksumMap =
bitstreamStorageService.computeChecksumSpecStore(context, bitstream,
bitstreamStorageService.getSynchronizedStoreNumber(bitstream));
if (MapUtils.isNotEmpty(syncStoreChecksumMap)) {
String syncStoreChecksum = "";
if (checksumMap.containsKey("checksum")) {
syncStoreChecksum = syncStoreChecksumMap.get("checksum").toString();
}
// compare new checksum to previous checksum
ChecksumResult checksumResult = compareChecksums(info.getCurrentChecksum(), syncStoreChecksum);
// Do not override result with synchronization info if the checksums are not matching between
// DB and store
if (!Objects.equals(checksumResult.getResultCode(), ChecksumResultCode.CHECKSUM_NO_MATCH)) {
info.setChecksumResult(getChecksumResultByCode(ChecksumResultCode.CHECKSUM_SYNC_NO_MATCH));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -174,6 +172,14 @@ public Map computeChecksum(Context context, Bitstream bitstream) throws IOExcept
return this.getStore(storeNumber).about(bitstream, List.of("checksum", "checksum_algorithm"));
}

/**
* Compute the checksum of a bitstream in a specific store.
* @param context DSpace Context object
* @param bitstream Bitstream to compute checksum for
* @param storeNumber Store number to compute checksum for
* @return Map with checksum and checksum algorithm
* @throws IOException if IO error
*/
public Map computeChecksumSpecStore(Context context, Bitstream bitstream, int storeNumber) throws IOException {
return this.getStore(storeNumber).about(bitstream, List.of("checksum", "checksum_algorithm"));
}
Expand Down Expand Up @@ -335,9 +341,24 @@ public int whichStoreNumber(Bitstream bitstream) {
}
}

/**
* Check if the bitstream is synchronized (stored in more stores)
* The bitstream is synchronized if it has the static store number.
*
* @param bitstream to check if it is synchronized
* @return true if the bitstream is synchronized
*/
public boolean isBitstreamStoreSynchronized(Bitstream bitstream) {
return bitstream.getStoreNumber() == SYNCHRONIZED_STORES_NUMBER;
}


/**
* Get the store number where the bitstream is synchronized. It is not active (incoming) store.
*
* @param bitstream to get the synchronized store number
* @return store number
*/
public int getSynchronizedStoreNumber(Bitstream bitstream) {
int storeNumber = -1;
if (!isBitstreamStoreSynchronized(bitstream)) {
Expand Down

0 comments on commit 72fa41a

Please sign in to comment.