Skip to content

Commit

Permalink
Merge pull request #58 from DataONEorg/feature-57-deleteobj-refactor
Browse files Browse the repository at this point in the history
Feature-57: `deleteObject` Refactor
  • Loading branch information
doulikecookiedough authored Aug 16, 2024
2 parents c105193 + d61d9c3 commit 21bcd62
Show file tree
Hide file tree
Showing 31 changed files with 5,279 additions and 3,384 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
Expand Down
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

255 changes: 169 additions & 86 deletions README.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.3</version>
<version>42.7.2</version>
</dependency>
</dependencies>

Expand All @@ -71,8 +71,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -86,6 +86,8 @@
<goal>shade</goal>
</goals>
<configuration>
<outputFile>${basedir}/target/${project.name}-${project.version}-shaded.jar</outputFile>
<outputDirectory>${basedir}</outputDirectory>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
Expand Down
512 changes: 240 additions & 272 deletions src/main/java/org/dataone/hashstore/HashStore.java

Large diffs are not rendered by default.

284 changes: 117 additions & 167 deletions src/main/java/org/dataone/hashstore/HashStoreClient.java

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/main/java/org/dataone/hashstore/HashStoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ public class HashStoreFactory {

/**
* Factory method to generate a HashStore
*
*
* @param classPackage String of the package name, ex.
* "org.dataone.hashstore.filehashstore.FileHashStore"
* @param storeProperties Properties object with the following keys: storePath, storeDepth,
* storeWidth, storeAlgorithm, storeMetadataNamespace
*
* @return HashStore instance ready to store objects and metadata
* @throws HashStoreFactoryException When HashStore failÏs to initialize due to permissions or
* class-related issues
Expand Down Expand Up @@ -52,34 +51,35 @@ public static HashStore getHashStore(String classPackage, Properties storeProper
hashstore = (HashStore) constructor.newInstance(storeProperties);

} catch (ClassNotFoundException cnfe) {
String errMsg = "HashStoreFactory - Unable to find 'FileHashStore' classPackage: "
+ classPackage + " - " + cnfe.fillInStackTrace();
String errMsg =
"HashStoreFactory - Unable to find 'FileHashStore' classPackage: " + classPackage
+ " - " + cnfe.getCause();
logHashStore.error(errMsg);
throw new HashStoreFactoryException(errMsg);

} catch (NoSuchMethodException nsme) {
String errMsg = "HashStoreFactory - Constructor not found for 'FileHashStore': "
+ classPackage + " - " + nsme.fillInStackTrace();
String errMsg =
"HashStoreFactory - Constructor not found for 'FileHashStore': " + classPackage
+ " - " + nsme.getCause();
logHashStore.error(errMsg);
throw new HashStoreFactoryException(errMsg);

} catch (IllegalAccessException iae) {
String errMsg =
"HashStoreFactory - Executing method does not have access to the definition of"
+ " the specified class , field, method or constructor. " + iae
.fillInStackTrace();
+ " the specified class , field, method or constructor. " + iae.getCause();
logHashStore.error(errMsg);
throw new HashStoreFactoryException(errMsg);

} catch (InstantiationException ie) {
String errMsg = "HashStoreFactory - Error instantiating 'FileHashStore'"
+ "(likely related to `.newInstance()`): " + ie.fillInStackTrace();
+ "(likely related to `.newInstance()`): " + ie.getCause();
logHashStore.error(errMsg);
throw new HashStoreFactoryException(errMsg);

} catch (InvocationTargetException ite) {
String errMsg = "HashStoreFactory - Error creating 'FileHashStore' instance: " + ite
.fillInStackTrace();
String errMsg =
"HashStoreFactory - Error creating 'FileHashStore' instance: " + ite.getCause();
logHashStore.error(errMsg);
throw new HashStoreFactoryException(errMsg);

Expand Down
54 changes: 5 additions & 49 deletions src/main/java/org/dataone/hashstore/ObjectMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,10 @@
import java.util.Map;

/**
* ObjectMetadata is a class that models a unique identifier for an object in the HashStore. It
* encapsulates information about a file's content identifier (cid), size, and associated hash
* digest values. By using ObjectMetadata objects, client code can easily obtain metadata of a store
* object in HashStore without needing to know the underlying file system details.
* ObjectMetadata is a record that that contains metadata about an object in the HashStore. It
* encapsulates information about a file's authority-based/persistent identifier (pid), content
* identifier (cid), size, and associated hash digest values.
*/
public class ObjectMetadata {
private final String cid;
private final long size;
private final Map<String, String> hexDigests;
public record ObjectMetadata(String pid, String cid, long size, Map<String, String> hexDigests) {

/**
* Creates a new instance of ObjectMetadata with the given properties.
*
* @param cid Unique identifier for the file
* @param size Size of stored file
* @param hexDigests A map of hash algorithm names to their hex-encoded digest values for the
* file
*/
public ObjectMetadata(String cid, long size, Map<String, String> hexDigests) {
this.cid = cid;
this.size = size;
this.hexDigests = hexDigests;
}

/**
* Return the cid (content identifier) of the file
*
* @return cid
*/
public String getCid() {
return cid;
}

/**
* Return the size of the file
*
* @return size
*/
public long getSize() {
return size;
}

/**
* Return a map of hex digests (checksums)
*
* @return hexDigests
*/
public Map<String, String> getHexDigests() {
return hexDigests;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.dataone.hashstore.exceptions;

/**
* Custom exception class for FileHashStore when the expected cid is not found in the pid refs file.
*/
public class CidNotFoundInPidRefsFileException extends IllegalArgumentException {

public CidNotFoundInPidRefsFileException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.dataone.hashstore.exceptions;

import java.nio.file.FileAlreadyExistsException;

/**
* Custom exception thrown when called to tag a pid and cid, and reference files already exist
*/
public class HashStoreRefsAlreadyExistException extends FileAlreadyExistsException {

public HashStoreRefsAlreadyExistException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dataone.hashstore.exceptions;

/**
* An exception that encapsulates errors from the HashStore Runnable Test Class
*/
public class HashStoreServiceException extends Exception {
public HashStoreServiceException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.dataone.hashstore.exceptions;

import java.util.NoSuchElementException;

/**
* An exception thrown when hexDigests from a supplied ObjectMetadata object is empty.
*/
public class MissingHexDigestsException extends NoSuchElementException {

public MissingHexDigestsException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.dataone.hashstore.exceptions;

/**
* An exception thrown when a checksum does not match what is expected.
*/

public class NonMatchingChecksumException extends IllegalArgumentException {

public NonMatchingChecksumException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.dataone.hashstore.exceptions;

/**
* An exception thrown when a data object size does not match what is expected.
*/

public class NonMatchingObjSizeException extends IllegalArgumentException {

public NonMatchingObjSizeException(String message) {
super(message);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.dataone.hashstore.exceptions;

import java.io.IOException;

/**
* Custom exception class for FileHashStore when both a pid and cid reference file is found
* but object does not exist.
*/
public class OrphanRefsFilesException extends IOException {
public OrphanRefsFilesException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Custom exception class for FileHashStore when a pid is not found in a cid refs file.
*/
public class PidNotFoundInCidRefsFileException extends IOException {
public class PidNotFoundInCidRefsFileException extends IllegalArgumentException {
public PidNotFoundInCidRefsFileException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.io.IOException;

/**
* Custom exception class for FileHashStore pidObjects
* Custom exception class thrown when a pid refs file already exists (a single pid can only ever
* reference one cid)
*/
public class PidRefsFileExistsException extends IOException {
public PidRefsFileExistsException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dataone.hashstore.exceptions;

import java.io.FileNotFoundException;

public class PidRefsFileNotFoundException extends FileNotFoundException {
public PidRefsFileNotFoundException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.dataone.hashstore.exceptions;

/**
* An exception thrown when a given algorithm is not supported by FileHashStore java
*/

public class UnsupportedHashAlgorithmException extends IllegalArgumentException {

public UnsupportedHashAlgorithmException(String message) {
super(message);
}

}
Loading

0 comments on commit 21bcd62

Please sign in to comment.