-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(CLI): Fixing RemoteTraversalServiceIT intermittent tests (#27527)
* #26633 Update dotCMS remote folder traversal process and tests Modified the dotCMS remote location traversal process to incorporate parallel execution of tasks using a ManagedExecutor. Removed unnecessary imports, adjusted the exception handling methods, enhanced test stability by sorting files and folders before assertion, and other necessary logic modifications. * #27540 Replacing direct usage of CompletableFuture and other native Java concurrency mechanisms with ManagedExecutor * #27540 Removing all @disabled annotations in tests * #27540 Replacing direct usage of CompletableFuture and other native Java concurrency mechanisms with ManagedExecutor * #27540 The code change modifies the `metadata` method in `ContentType` class to return an empty map instead of null allowing proper comparison between local descriptors and server content types. * #27540 Refactor file listing commands for modularity Moved common functionality of FilesTree and FilesLs into new AbstractFilesListingCommand for code reuse and simplified their implementations appropriately. The changes aim to improve maintainability and code clarity by avoiding repetition. * #27540 Refactor glob pattern options into a mixin Glob pattern options for including or excluding files and folders have been refactored into a mixin class, FilesGlobMixin. This change enhances code reusability and modularity, making the pattern options more accessible across different classes without the need for replication. * #27540 Refactor FilePullMixin to FilesPullMixin * #27540 Adding NOSCAN to avoid attributes of some builders to be marked as duplicated. * #27540 Applying sonarlint feedback to avoid duplicated code * #27540 Applying code review feedback: FileHashCalculatorService service exposed as an interface.
- Loading branch information
1 parent
bc6f253
commit 3bd21f7
Showing
51 changed files
with
1,889 additions
and
1,015 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
package com.dotcms.api.client; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* This is a service interface for calculating file hashes. It is responsible for providing a method | ||
* to calculate the SHA-256 hash of a given file. | ||
*/ | ||
public interface FileHashCalculatorService { | ||
|
||
/** | ||
* Calculates the SHA-256 hash of the content of the supplied file represented by the provided | ||
* {@link Path}. | ||
* | ||
* @param path the path to the file whose content hash needs to be calculated | ||
* @return the SHA-256 hash as a UNIX-formatted string | ||
*/ | ||
String sha256toUnixHash(Path path); | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
tools/dotcms-cli/cli/src/main/java/com/dotcms/api/client/FileHashCalculatorServiceImpl.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,63 @@ | ||
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.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 FileHashCalculatorServiceImpl implements FileHashCalculatorService { | ||
|
||
@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
Oops, something went wrong.