-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27540 Replacing direct usage of CompletableFuture and other native J…
…ava concurrency mechanisms with ManagedExecutor
- Loading branch information
1 parent
9fa4d33
commit efef5a5
Showing
24 changed files
with
933 additions
and
383 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
tools/dotcms-cli/cli/src/main/java/com/dotcms/api/client/FileHashCalculatorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.dotcms.api.client; | ||
|
||
import com.dotcms.api.client.files.traversal.exception.TraversalTaskException; | ||
import com.dotcms.security.Encryptor; | ||
import com.dotcms.security.HashBuilder; | ||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.security.NoSuchAlgorithmException; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* This is a service class for calculating file hashes. It is responsible for providing a method to | ||
* calculate the SHA-256 hash of a given file. This class is marked as | ||
* {@link javax.enterprise.context.ApplicationScoped}, meaning that a single instance is shared | ||
* across the entire application. | ||
*/ | ||
@ApplicationScoped | ||
public class FileHashCalculatorService implements Serializable { | ||
|
||
@Inject | ||
Logger logger; | ||
|
||
/** | ||
* Calculates the SHA-256 hash of the content of the supplied file represented by the provided | ||
* {@link Path}. The function will throw a {@link TraversalTaskException} if the SHA-256 | ||
* algorithm is not found or there is an error reading the file. | ||
* | ||
* @param path the path to the file whose content hash needs to be calculated | ||
* @return the SHA-256 hash as a UNIX-formatted string | ||
* @throws TraversalTaskException if there is an error calculating the hash | ||
*/ | ||
public String sha256toUnixHash(final Path path) { | ||
|
||
try { | ||
|
||
final HashBuilder sha256Builder = Encryptor.Hashing.sha256(); | ||
final byte[] buffer = new byte[4096]; | ||
int countBytes; | ||
|
||
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(path))) { | ||
|
||
countBytes = inputStream.read(buffer); | ||
while (countBytes > 0) { | ||
|
||
sha256Builder.append(buffer, countBytes); | ||
countBytes = inputStream.read(buffer); | ||
} | ||
} | ||
|
||
return sha256Builder.buildUnixHash(); | ||
} catch (NoSuchAlgorithmException | IOException e) { | ||
var errorMessage = String.format("Error calculating sha256 for file [%s]", path); | ||
logger.error(errorMessage, e); | ||
throw new TraversalTaskException(errorMessage, e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...va/com/dotcms/api/client/files/traversal/task/AbstractLocalFolderTraversalTaskParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.dotcms.api.client.files.traversal.task; | ||
|
||
import com.dotcms.model.annotation.ValueType; | ||
import java.io.File; | ||
import java.io.Serializable; | ||
import org.immutables.value.Value; | ||
import org.immutables.value.Value.Default; | ||
|
||
/** | ||
* This interface represents the parameters for a {@link LocalFolderTraversalTask}. | ||
*/ | ||
@ValueType | ||
@Value.Immutable | ||
public interface AbstractLocalFolderTraversalTaskParams extends Serializable { | ||
|
||
/** | ||
* Returns a boolean indicating whether the site exists. | ||
* | ||
* @return true if the site exists, false otherwise. Default is false. | ||
*/ | ||
@Default | ||
default boolean siteExists() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the source path for the traversal process. | ||
* | ||
* @return String representing the source path. | ||
*/ | ||
String sourcePath(); | ||
|
||
/** | ||
* Returns the workspace file. | ||
* | ||
* @return File representing the workspace. | ||
*/ | ||
File workspace(); | ||
|
||
/** | ||
* Returns a boolean flag indicating whether to remove assets. | ||
* | ||
* @return true if the assets should be removed, false otherwise. | ||
*/ | ||
boolean removeAssets(); | ||
|
||
/** | ||
* Returns a boolean flag indicating whether to remove folders. | ||
* | ||
* @return true if the folders should be removed, false otherwise. | ||
*/ | ||
boolean removeFolders(); | ||
|
||
/** | ||
* Returns a boolean flag indicating whether to ignore empty folders. | ||
* | ||
* @return true if the empty folders should be ignored, false otherwise. | ||
*/ | ||
boolean ignoreEmptyFolders(); | ||
|
||
/** | ||
* Returns a boolean flag indicating whether to fail fast. | ||
* | ||
* @return true if the operation should fail fast, false otherwise. | ||
*/ | ||
boolean failFast(); | ||
} |
Oops, something went wrong.