Skip to content

Commit

Permalink
reformat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Oct 29, 2023
1 parent e350447 commit ad33395
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.cognifide.apm.main.utils.MessagingUtils;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,8 +63,7 @@ private ActionResult process(Context context, boolean execute) {
try {
group = context.getCurrentGroup();
actionResult.setAuthorizable(group.getID());
LOGGER.info(String.format("Adding authorizables %s to group with id = %s",
StringUtils.join(authorizableIds, ", "), group.getID()));
LOGGER.info("Adding authorizables {} to group with id={}", String.join(", ", authorizableIds), group.getID());
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ private ActionResult process(Context context, boolean execute) {
if (authorizable.isGroup()) {
ActionUtils.checkCyclicRelations(group, (Group) authorizable);
}
LOGGER.info(String.format("Adding Authorizable with id = %s to group with id = %s",
authorizable.getID(), group.getID()));
LOGGER.info("Adding Authorizable with id={} to group with id={}", authorizable.getID(), group.getID());

boolean flag = true;
if (execute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private ActionResult process(Context context, boolean simulate) {
context.getSession().getNode(path);
PermissionActionHelper permissionActionHelper = new PermissionActionHelper(
context.getValueFactory(), path, permissions, restrictions);
LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s",
permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions));
LOGGER.info("Adding permissions {} for authorizable with id={} for path={} {}",
permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions);
if (simulate) {
permissionActionHelper.checkPermissions(context.getAccessControlManager());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private ActionResult process(Context context, boolean execute) {
if (context.isCompositeNodeStore() && PathUtils.isAppsOrLibsPath(path)) {
actionResult.changeStatus(Status.SKIPPED, "Skipped purging privileges for " + authorizable.getID() + " on " + path);
} else {
LOGGER.info(String.format("Purging privileges for authorizable with id=%s under path=%s",
authorizable.getID(), path));
LOGGER.info("Purging privileges for authorizable with id={} under path={}", authorizable.getID(), path);
if (execute) {
purge(context, actionResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private ActionResult process(final Context context, boolean execute) {
if (context.isCompositeNodeStore() && PathUtils.isAppsOrLibsPath(path)) {
actionResult.changeStatus(Status.SKIPPED, "Skipped removing all privileges for " + authorizable.getID() + " on " + path);
} else {
LOGGER.info(String.format("Removing all priveleges for authorizable with id = %s on path = %s",
authorizable.getID(), path));
LOGGER.info("Removing all priveleges for authorizable with id={} on path={}", authorizable.getID(), path);
if (execute) {
removeAll(context, authorizable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.cognifide.apm.main.utils.MessagingUtils;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.security.user.Group;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -56,7 +55,7 @@ public ActionResult execute(Context context) {
private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();

LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", ")));
LOGGER.info("Removing groups with ids={}", String.join(", ", ids));
for (String id : ids) {
try {
Group group = context.getAuthorizableManager().getGroup(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.cognifide.apm.main.utils.MessagingUtils;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.security.user.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -55,7 +54,7 @@ public ActionResult execute(Context context) {

private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
LOGGER.info(String.format("Removing users with ids = %s", StringUtils.join(ids, ", ")));
LOGGER.info("Removing users with ids={}", String.join(", ", ids));
for (String id : ids) {
try {
User user = context.getAuthorizableManager().getUser(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private ActionResult process(Context context, boolean simulate) {
context.getSession().getNode(path);
PermissionActionHelper permissionActionHelper = new PermissionActionHelper(
context.getValueFactory(), path, permissions, restrictions);
LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s",
permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions));
LOGGER.info("Denying permissions {} for authorizable with id={} for path={} {}",
permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions);
if (simulate) {
permissionActionHelper.checkPermissions(context.getAccessControlManager());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.cognifide.apm.main.utils.MessagingUtils;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.slf4j.Logger;
Expand Down Expand Up @@ -60,8 +59,7 @@ private ActionResult process(Context context, boolean execute) {
try {
group = context.getCurrentGroup();
actionResult.setAuthorizable(group.getID());
LOGGER.info(String.format("Removing authorizables %s from group with id = %s",
StringUtils.join(authorizableIds, ", "), group.getID()));
LOGGER.info("Removing authorizables {} from group with id={}", String.join(", ", authorizableIds), group.getID());
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ActionResult detachMembersFromGroup() {

if (authorizable.isGroup()) {
final Group group = context.getCurrentGroup();
LOGGER.info(String.format("Removing all members of group with id = %s", group.getID()));
LOGGER.info("Removing all members of group with id={}", group.getID());
Iterator<Authorizable> groupMembers = getGroupMembers(actionResult, group);

detachAllMembers(actionResult, group, groupMembers);
Expand All @@ -71,8 +71,7 @@ public ActionResult detachAuthorizableFromParents() {
Authorizable currentAuthorizable = context.getCurrentAuthorizable();
Iterator<Group> groups = getGroupParents(actionResult, currentAuthorizable);

LOGGER.info(String.format("Removing all memberships of authorizable with id = %s",
currentAuthorizable.getID()));
LOGGER.info("Removing all memberships of authorizable with id={}", currentAuthorizable.getID());
detachFromParents(actionResult, currentAuthorizable, groups);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public ActionResult process(Context context, boolean execute) {
try {
authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(
String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(),
groupIds));
LOGGER.info("Removing authorizable with id={} from groups {}", authorizable.getID(), groupIds);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private ActionResult process(final Context context, boolean simulate) {
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Removing property %s from authorizable with id = %s", nameProperty,
authorizable.getID()));
LOGGER.info("Removing property {} from authorizable with id={}", nameProperty, authorizable.getID());
if (!simulate) {
authorizable.removeProperty(nameProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ActionResult process(final Context context, boolean execute) {
try {
User user = context.getCurrentUser();
actionResult.setAuthorizable(user.getID());
LOGGER.info(String.format("Setting password for user with id = %s", user.getID()));
LOGGER.info("Setting password for user with id={}", user.getID());
if (execute) {
user.changePassword(password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ private ActionResult process(final Context context, boolean simulate) {
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty,
authorizable.getID()));
LOGGER.info("Setting property {} for authorizable with id={}", nameProperty, authorizable.getID());
final Value value = context.getValueFactory().createValue(valueProperty);

if (!simulate) {
authorizable.setProperty(nameProperty, value);
}

actionResult.logMessage(
"Property " + nameProperty + " for " + authorizable.getID() + " added vith value: "
"Property " + nameProperty + " for " + authorizable.getID() + " added with value: "
+ valueProperty);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static String describeScripts(List<Script> scripts) {
paths.add(script.getPath());
}

return StringUtils.join(paths, "\n");
return String.join("\n", paths);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ interface Entry {

List<String> getMessages();

List<String> getPrettyMessages();

List<String> getParameters();

List<String> getPrettyParameters();

Status getStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Status visitForEach(ForEachContext ctx) {
String valueStr = value.entrySet()
.stream()
.map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue()))
.collect(Collectors.joining());
.collect(Collectors.joining("\n"));
progress(ctx, Status.SUCCESS, "for-each", String.format("%d. Begin: %s", index, valueStr));
value.forEach(executionContext::setVariable);
visit(ctx.body());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class ProgressEntry implements Entry {

Expand Down Expand Up @@ -70,11 +71,25 @@ public List<String> getMessages() {
return messages;
}

@Override
public List<String> getPrettyMessages() {
return messages.stream()
.map(message -> message.replaceAll("\n", "<br>").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"))
.collect(Collectors.toList());
}

@Override
public List<String> getParameters() {
return parameters;
}

@Override
public List<String> getPrettyParameters() {
return parameters.stream()
.map(message -> message.replaceAll("\n", "<br>").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"))
.collect(Collectors.toList());
}

@Override
public Status getStatus() {
return status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void afterCreated() {
try {
scriptManager.process(this, ExecutionMode.VALIDATION, resource.getResourceResolver());
} catch (RepositoryException | PersistenceException e) {
LOGGER.error("", e);
LOGGER.error(e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<Script> findAll(Predicate<Script> filter, ResourceResolver resolver)
modified.add(script);
}
} catch (ScriptExecutionException e) {
LOGGER.error(e.getMessage());
LOGGER.error(e.getMessage(), e);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void updateVersionIfNeeded(ResourceResolver resolver, Script... scripts)
createVersion(resolver, script);
}
} catch (ScriptExecutionException | PersistenceException e) {
LOGGER.error(e.getMessage());
LOGGER.error(e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void logStatus(InstallContext context, String scriptPath, ExecutionResul
} else {
PackageException packageException = new PackageException(String.format("Script cannot be executed properly: %s", scriptPath));
onError(context, ProgressTrackerListener.Mode.TEXT, "", packageException);
LOGGER.error("", packageException);
LOGGER.error(packageException.getMessage(), packageException);
result.getEntries()
.stream()
.filter(entry -> entry.getStatus() == Status.ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static String describeScripts(List<Script> scripts) {
paths.add(script.getPath());
}

return StringUtils.join(paths, "\n");
return String.join("\n", paths);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h3><a name="available-commands">Available commands</a></h3>
<p>${map.description}</p>
<div data-sly-test="${map.examples}" class="code-example">
<strong>Examples</strong>
<code data-sly-repeat.example="${map.examples}">${example}</code>
<code data-sly-repeat.example="${map.examples}">${example @ context='html'}</code>
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
<td class="_coral-Table-cell">${execution.command.toUpperCase}</td>
<td class="_coral-Table-cell">
<ul>
<li data-sly-repeat.text="${execution.parameters}">${text}</li>
<li data-sly-repeat.text="${execution.prettyParameters}">${text @ context='html'}</li>
</ul>
</td>
<td class="_coral-Table-cell">
<coral-icon title="${execution.status.iconTitle}" icon="${execution.status.iconType}"/>
</td>
<td class="_coral-Table-cell">
<ul>
<li data-sly-repeat.text="${execution.messages}">${text}</li>
<li data-sly-repeat.text="${execution.prettyMessages}">${text @ context='html'}</li>
</ul>
</td>
</tr>
Expand Down

0 comments on commit ad33395

Please sign in to comment.