Skip to content

Commit

Permalink
#26002 Added an ignoreNoAction parameter in push service
Browse files Browse the repository at this point in the history
Incorporated a new feature in 'PushServiceImpl' and 'FormatStatus' to allow ignoring results with no action during push operation. If 'dryRun' is set in 'PushServiceImpl', the new optional 'ignoreNoAction' parameter would be taken into account while formatting the push analysis results. This enhancement caters for more efficient resource utilization as results with no action (NO_ACTION) are filtered out before the formatting operation.
  • Loading branch information
jgambarios committed Sep 20, 2023
1 parent e6b1de2 commit 7260343
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.dotcms.api.client.push;

import static com.dotcms.model.push.PushAction.NO_ACTION;

import com.dotcms.api.client.push.exception.PushException;
import com.dotcms.model.push.PushAnalysisResult;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.Dependent;

/**
Expand Down Expand Up @@ -31,19 +34,28 @@ public class FormatStatus {
/**
* Formats the push analysis results using the specified push handler.
*
* @param results the list of push analysis results
* @param pushHandler the push handler to use for formatting
* @param results the list of push analysis results
* @param pushHandler the push handler to use for formatting
* @param ignoreNoAction indicates whether to ignore results with no action
* @return a StringBuilder containing the formatted push analysis results
*/
public <T> StringBuilder format(final List<PushAnalysisResult<T>> results,
PushHandler<T> pushHandler) {
PushHandler<T> pushHandler, final boolean ignoreNoAction) {

var outputBuilder = new StringBuilder();

outputBuilder.append(String.format(" %s:", pushHandler.title())).append("\n");

Iterator<PushAnalysisResult<T>> iterator = results.iterator();
List<PushAnalysisResult<T>> filteredResults = results;
if (ignoreNoAction) {
filteredResults = results.stream()
.filter(result -> result.action() != NO_ACTION)
.collect(Collectors.toList());
}

Iterator<PushAnalysisResult<T>> iterator = filteredResults.iterator();
while (iterator.hasNext()) {

PushAnalysisResult<T> result = iterator.next();
boolean isLast = !iterator.hasNext();
outputBuilder.append(formatResult(" ", result, pushHandler, isLast));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public <T> void push(final File localFileOrFolder, final PushOptions options,
}

if (options.dryRun()) {
outputBuilder.append(formatStatus.format(analysisResults, pushHandler));
outputBuilder.append(formatStatus.format(analysisResults, pushHandler, true));
}

output.info(outputBuilder.toString());
Expand Down

0 comments on commit 7260343

Please sign in to comment.