Skip to content

Commit

Permalink
#26002 Applying feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Sep 25, 2023
1 parent 85e1af7 commit 773dc8b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import org.jboss.logging.Logger;

/**
* The {@code FormatStatus} class is responsible for formatting the status of a push operation. It
Expand All @@ -31,6 +33,9 @@ public class FormatStatus {
private final String PUSH_MODIFIED_FORMAT = "@|bold," + COLOR_MODIFIED + " %s \u270E|@";
private final String PUSH_DELETE_FORMAT = "@|bold," + COLOR_DELETED + " %s \u2716|@";

@Inject
Logger logger;

/**
* Formats the push analysis results using the specified push handler.
*
Expand Down Expand Up @@ -86,19 +91,47 @@ private <T> StringBuilder formatResult(final String prefix,
switch (result.action()) {
case ADD:
contentFormat = PUSH_NEW_FORMAT;
contentName = result.localFile().get().getName();

if (result.localFile().isPresent()) {
contentName = result.localFile().get().getName();
} else {
var message = "Local file is missing for add action";
logger.error(message);
throw new PushException(message);
}
break;
case UPDATE:
contentFormat = PUSH_MODIFIED_FORMAT;
contentName = result.localFile().get().getName();

if (result.localFile().isPresent()) {
contentName = result.localFile().get().getName();
} else {
var message = "Local file is missing for update action";
logger.error(message);
throw new PushException(message);
}
break;
case REMOVE:
contentFormat = PUSH_DELETE_FORMAT;
contentName = pushHandler.contentSimpleDisplay(result.serverContent().get());

if (result.serverContent().isPresent()) {
contentName = pushHandler.contentSimpleDisplay(result.serverContent().get());
} else {
var message = "Server content is missing for remove action";
logger.error(message);
throw new PushException(message);
}
break;
case NO_ACTION:
contentFormat = REGULAR_FORMAT;
contentName = result.localFile().get().getName();

if (result.localFile().isPresent()) {
contentName = result.localFile().get().getName();
} else {
var message = "Local file is missing";
logger.error(message);
throw new PushException(message);
}
break;
default:
throw new PushException("Unknown action: " + result.action());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ public String title() {

@Override
public String contentSimpleDisplay(Language language) {
return String.format(
"id: [%s] code: [%s]",
language.id().get(),
language.isoCode()
);

if (language.id().isPresent()) {
return String.format(
"id: [%s] code: [%s]",
language.id().get(),
language.isoCode()
);
} else {
return String.format(
"code: [%s]",
language.isoCode()
);
}
}

@ActivateRequestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ProcessResultTask<T> extends RecursiveAction {

final boolean allowRemove;

private Logger logger;
private final Logger logger;

public ProcessResultTask(final PushAnalysisResult<T> result, final boolean allowRemove,
final PushHandler<T> pushHandler, final MapperService mapperService,
Expand Down Expand Up @@ -61,15 +61,27 @@ protected void compute() {
logger.debug(String.format("Pushing file [%s] for [%s] operation",
result.localFile().get().getAbsolutePath(), result.action()));

this.pushHandler.add(result.localFile().get(), localContent);
if (result.localFile().isPresent()) {
this.pushHandler.add(result.localFile().get(), localContent);
} else {
var message = "Local file is missing for add action";
logger.error(message);
throw new PushException(message);
}
break;
case UPDATE:

logger.debug(String.format("Pushing file [%s] for [%s] operation",
result.localFile().get().getAbsolutePath(), result.action()));

this.pushHandler.edit(result.localFile().get(), localContent,
result.serverContent().get());
if (result.localFile().isPresent() && result.serverContent().isPresent()) {
this.pushHandler.edit(result.localFile().get(), localContent,
result.serverContent().get());
} else {
String message = "Local file or server content is missing for update action";
logger.error(message);
throw new PushException(message);
}
break;
case REMOVE:

Expand All @@ -82,13 +94,30 @@ protected void compute() {
)
);

this.pushHandler.remove(result.serverContent().get());
if (result.serverContent().isPresent()) {

logger.debug(
String.format("Pushing [%s] operation for [%s]",
result.action(),
this.pushHandler.contentSimpleDisplay(
result.serverContent().get())
)
);

this.pushHandler.remove(result.serverContent().get());
} else {
var message = "Server content is missing for remove action";
logger.error(message);
throw new PushException(message);
}
}
break;
case NO_ACTION:

logger.debug(String.format("File [%s] requires no action",
result.localFile().get().getAbsolutePath()));
if (result.localFile().isPresent()) {
logger.debug(String.format("File [%s] requires no action",
result.localFile().get().getAbsolutePath()));
}

// Do nothing for now
break;
Expand Down

0 comments on commit 773dc8b

Please sign in to comment.