Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public int getAclChanges() {

@Override
public int compareTo(AcToolExecution otherExecution) {
return -getInstallationDate().compareTo(otherExecution.getInstallationDate());
int compareByDate = -getInstallationDate().compareTo(otherExecution.getInstallationDate());
if (compareByDate != 0) {
return compareByDate;
}
return getId().compareTo(otherExecution.getId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class HistoryUtils {
public static final String PROPERTY_CONFIG_ROOT_PATH = "configurationRootPath";
public static final String PROPERTY_ACL_CHANGES = "aclsChanges";
public static final String PROPERTY_AUTHORIZABLES_CHANGES = "authorizableChanges";
static final String TRIGGER_INSTALL_HOOK = "installhook";
static final String TRIGGER_STARTUP_HOOK_PREFIX = "startup_hook";

private static final String AC_TOOL_STARTUPHOOK_CLASS = "biz.netcentric.cq.tools.actool.startuphook.impl.AcToolStartupHookServiceImpl";
private static final String BUNDLE_START_TASK_CLASS = "org.apache.sling.installer.core.impl.tasks.BundleStartTask";
Expand Down Expand Up @@ -114,7 +116,7 @@ public static Node persistHistory(final Session session,

String trigger;
if (StringUtils.isNotBlank(installLog.getCrxPackageName())) {
trigger = "installhook";
trigger = TRIGGER_INSTALL_HOOK;
} else if(isInStrackTracke(stackTrace, AceServiceMBeanImpl.class)) {
trigger = "jmx";
} else if(isInStrackTracke(stackTrace, AC_TOOL_TOUCH_UI_SERVLET_CLASS)) {
Expand Down Expand Up @@ -273,6 +275,11 @@ static List<AcToolExecution> getAcToolExecutions(final Session session)
String configRoot = node.hasProperty(PROPERTY_CONFIG_ROOT_PATH)? node.getProperty(PROPERTY_CONFIG_ROOT_PATH).getString() : null;
int authorizableChanges = node.hasProperty(PROPERTY_AUTHORIZABLES_CHANGES) ? (int) node.getProperty(PROPERTY_AUTHORIZABLES_CHANGES).getLong() : -1;
int aclChanges = node.hasProperty(PROPERTY_ACL_CHANGES) ? (int) node.getProperty(PROPERTY_ACL_CHANGES).getLong() : -1;
String trigger = node.hasProperty(PROPERTY_TRIGGER) ? node.getProperty(PROPERTY_TRIGGER).getString() : null;

if (!shouldExposeExecution(trigger, authorizableChanges, aclChanges)) {
continue;
}

historyInfos.add(new AcToolExecutionImpl(getIdFromPath(node.getPath()),
node.getPath(),
Expand All @@ -285,6 +292,13 @@ static List<AcToolExecution> getAcToolExecutions(final Session session)
return new ArrayList<>(historyInfos);
}

static boolean shouldExposeExecution(String trigger, int authorizableChanges, int aclChanges) {
boolean hasNoChanges = authorizableChanges == 0 && aclChanges == 0;
boolean isAutomaticExecution = StringUtils.equals(trigger, TRIGGER_INSTALL_HOOK)
|| StringUtils.startsWith(trigger, TRIGGER_STARTUP_HOOK_PREFIX);
return !hasNoChanges || !isAutomaticExecution;
}

static String getIdFromPath(String path) {
return StringUtils.removeStart(Text.getName(path), HISTORY_NODE_NAME_PREFIX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

import static org.junit.jupiter.api.Assertions.*;

import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import org.junit.jupiter.api.Test;

import biz.netcentric.cq.tools.actool.history.AcToolExecution;

class HistoryUtilsTest {

@Test
Expand All @@ -31,4 +37,37 @@ void testGetPathFromId() {
assertEquals("/base/history_test", HistoryUtils.getPathFromId("test", "/base"));
assertEquals("/deeply/nested/base/history_test", HistoryUtils.getPathFromId("test", "/deeply/nested/base"));
}

@Test
void testExecutionsWithSameTimestampAreBothRetained() {
Date sameTimestamp = new Date();
Set<AcToolExecution> executions = new TreeSet<>();
executions.add(new AcToolExecutionImpl("100_via_jmx",
"/var/statistics/achistory/history_100_via_jmx", sameTimestamp, true, "/apps/test", 0, 0));
executions.add(new AcToolExecutionImpl("101_via_jmx",
"/var/statistics/achistory/history_101_via_jmx", sameTimestamp, true, "/apps/test", 0, 0));

assertEquals(2, executions.size());
assertEquals("100_via_jmx", executions.iterator().next().getId());
}

@Test
void testShouldExposeExecutionForManualNoChangeRun() {
assertTrue(HistoryUtils.shouldExposeExecution("jmx", 0, 0));
assertTrue(HistoryUtils.shouldExposeExecution("aem_admin_ui", 0, 0));
assertTrue(HistoryUtils.shouldExposeExecution("webconsole", 0, 0));
}

@Test
void testShouldNotExposeExecutionForAutomaticNoChangeRun() {
assertFalse(HistoryUtils.shouldExposeExecution("installhook", 0, 0));
assertFalse(HistoryUtils.shouldExposeExecution("startup_hook", 0, 0));
assertFalse(HistoryUtils.shouldExposeExecution("startup_hook_image_build", 0, 0));
}

@Test
void testShouldExposeExecutionWhenChangesExist() {
assertTrue(HistoryUtils.shouldExposeExecution("installhook", 1, 0));
assertTrue(HistoryUtils.shouldExposeExecution("startup_hook", 0, 1));
}
}