This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new c03dbbb Updating to work across a broader range of Sling versions and
cleaning up the UI a bit
c03dbbb is described below
commit c03dbbbc8eaf66f94a11e9fbcd76b68234aa25d1
Author: Dan Klco <[email protected]>
AuthorDate: Mon Aug 2 21:24:32 2021 -0400
Updating to work across a broader range of Sling versions and cleaning up
the UI a bit
---
org.apache.sling.repoinit.webconsole/README.md | 2 ++
org.apache.sling.repoinit.webconsole/pom.xml | 4 +--
.../repoinit/webconsole/RepoInitWebConsole.java | 37 +++++++++++++---------
.../src/main/resources/res/ui/repoinit.js | 17 +++++++---
.../src/main/resources/tpl/main.html | 17 ++++++----
.../webconsole/RepoInitWebConsoleTest.java | 19 +++++++----
6 files changed, 62 insertions(+), 34 deletions(-)
diff --git a/org.apache.sling.repoinit.webconsole/README.md
b/org.apache.sling.repoinit.webconsole/README.md
index ae33136..ca23c66 100644
--- a/org.apache.sling.repoinit.webconsole/README.md
+++ b/org.apache.sling.repoinit.webconsole/README.md
@@ -18,6 +18,8 @@ Either download the latest version of this bundle from the
[Sling Downloads page
Note installing from source requires Java 11 or later and Maven 3.x or later.
+This project has been tested to work with Sling 11+.
+
## Configuration
To enable execute functionality of the web console, you must add a Apache
Sling Login Admin Whitelist entry. Open the OSGi console to
[/system/console/configMgr](http://localhost:8080/system/console/configMgr) and
add an entry for `org.apache.sling.repoinit.webconsole` either to an existing
configuration fragment or a new one.
diff --git a/org.apache.sling.repoinit.webconsole/pom.xml
b/org.apache.sling.repoinit.webconsole/pom.xml
index 571d87c..20c2c9d 100644
--- a/org.apache.sling.repoinit.webconsole/pom.xml
+++ b/org.apache.sling.repoinit.webconsole/pom.xml
@@ -127,13 +127,13 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
- <version>1.4.0</version>
+ <version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
- <version>1.4.0</version>
+ <version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git
a/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
b/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
index 89c3bdc..716f64b 100644
---
a/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
+++
b/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
@@ -21,6 +21,7 @@ import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.List;
import javax.jcr.Session;
@@ -51,20 +52,21 @@ import org.osgi.service.component.annotations.Reference;
Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
WebConsoleConstants.PLUGIN_LABEL + "=" +
RepoInitWebConsole.CONSOLE_LABEL,
WebConsoleConstants.PLUGIN_TITLE + "=" +
RepoInitWebConsole.CONSOLE_TITLE,
- WebConsoleConstants.CONFIG_PRINTER_MODES + "=always",
WebConsoleConstants.PLUGIN_CATEGORY + "=Sling" }, service = {
Servlet.class })
public class RepoInitWebConsole extends AbstractWebConsolePlugin {
public static final String CONSOLE_LABEL = "repoinit";
- public static final String CONSOLE_TITLE = "Repository Initialization";
- private final SlingRepository slingRepository;
- private final BundleContext context;
+ public static final String CONSOLE_TITLE = "RepoInit";
static final String RES_LOC = CONSOLE_LABEL + "/res/ui";
+ @Reference
+ protected SlingRepository slingRepository;
+
+ private BundleContext context;
+
@Activate
- public RepoInitWebConsole(ComponentContext context, @Reference
SlingRepository slingRepository) throws IOException {
+ public void activate(ComponentContext context) {
this.context = context.getBundleContext();
- this.slingRepository = slingRepository;
}
@SuppressWarnings("unchecked")
@@ -131,18 +133,19 @@ public class RepoInitWebConsole extends
AbstractWebConsolePlugin {
try {
operations = parse(request.getReader());
} catch (InvocationTargetException e) {
- handleException(response, "Failed to parse RepoInit Statement: ",
(Exception) e.getCause());
+ handleException(response, "Failed to parse RepoInit script: ",
(Exception) e.getCause());
return;
} catch (Exception e) {
- handleException(response, "Failed to parse RepoInit Statement: ",
e);
+ handleException(response, "Failed to parse RepoInit script: ", e);
return;
}
- ApiResponse apiResponse = new ApiResponse(operations);
+ ApiResponse apiResponse = new ApiResponse("Parsed Repoinit script
successfully!", operations);
if ("true".equals(request.getParameter("execute"))) {
try {
process(slingRepository.loginAdministrative(null), operations);
+ apiResponse.addMessage("Executed statements successfully!");
} catch (InvocationTargetException e) {
response.setStatus(400);
apiResponse.setErrorMessage("Failed to apply statements",
(Exception) e.getCause());
@@ -182,12 +185,12 @@ public class RepoInitWebConsole extends
AbstractWebConsolePlugin {
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use =
JsonTypeInfo.Id.NAME)
protected final List<?> operations;
- protected String errorMessage;
+ protected List<String> messages = new ArrayList<>();
- public ApiResponse(List<?> operations) {
+ public ApiResponse(String message, List<?> operations) {
this.succeeded = true;
this.operations = operations;
- errorMessage = null;
+ messages.add(message);
}
public ApiResponse(String message, Exception e) {
@@ -195,12 +198,16 @@ public class RepoInitWebConsole extends
AbstractWebConsolePlugin {
setErrorMessage(message, e);
}
+ public void addMessage(String message) {
+ this.messages.add(message);
+ }
+
public boolean isSucceeded() {
return succeeded;
}
- public String getErrorMessage() {
- return errorMessage;
+ public List<String> getMessages() {
+ return messages;
}
public List<?> getOperations() {
@@ -209,7 +216,7 @@ public class RepoInitWebConsole extends
AbstractWebConsolePlugin {
public void setErrorMessage(String message, Exception e) {
this.succeeded = false;
- this.errorMessage = message + " [" + e.getClass().getSimpleName()
+ "]: " + e.getMessage();
+ this.messages.add(message + " [" + e.getClass().getSimpleName() +
"]: " + e.getMessage());
}
}
}
diff --git
a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
index f5ed477..935139c 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
@@ -17,23 +17,32 @@
TLN.append_line_numbers("source");
const sourceEl = document.getElementById("source");
-const parsedContainerEl = document.getElementById("parsed-container");
+const resultsContainer = document.getElementById("results-container");
const parsedEl = document.getElementById("parsed");
const featureEl = document.getElementById("feature");
const featureContainerEl = document.getElementById("feature-container");
const goButton = document.getElementById("evaluate-repoinit");
const executeCbx = document.getElementById("execute");
+const messagesEl = document.getElementById("messages");
goButton.addEventListener("click", async function () {
goButton.disabled = true;
sourceEl.disabled = true;
- parsedContainerEl.classList.add("d-none");
+ resultsContainer.classList.add("d-none");
featureContainerEl.classList.add("d-none");
const res = await fetch(`repoinit?execute=${executeCbx.checked}`, {
method: "post",
body: sourceEl.value,
});
const json = await res.json();
+
+ messagesEl.innerHTML = "";
+ json.messages.forEach((m) => {
+ const par = document.createElement("p");
+ par.innerText = m;
+ messagesEl.appendChild(par);
+ });
+
if (json.succeeded) {
parsedEl.innerText = JSON.stringify(json.operations, null, 2);
featureEl.innerText = JSON.stringify(
@@ -45,10 +54,10 @@ goButton.addEventListener("click", async function () {
);
featureContainerEl.classList.remove("d-none");
} else {
- parsedEl.innerText = json.errorMessage;
+ parsedEl.innerText = "";
featureEl.innerText = "";
}
- parsedContainerEl.classList.remove("d-none");
+ resultsContainer.classList.remove("d-none");
goButton.disabled = false;
sourceEl.disabled = false;
});
diff --git
a/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
b/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
index f6b1ebe..3e7560c 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
@@ -28,13 +28,16 @@
<button id="evaluate-repoinit">Evaluate</button>
<input type="checkbox" id="execute" name="execute" />
<label for="execute">Execute</label>
-<div class="d-none" id="parsed-container">
- <p class="statline ui-state-highlight">Parsed Statements</p>
- <pre id="parsed"></pre>
-</div>
-<div class="d-none" id="feature-container">
- <p class="statline ui-state-highlight">Feature Model JSON</p>
- <pre id="feature"></pre>
+<div class="d-none" id="results-container">
+ <div class="statline ui-state-highlight" id="messages"></div>
+ <div id="parsed-container">
+ <p class="statline ui-state-highlight">Parsed Statements</p>
+ <pre id="parsed"></pre>
+ </div>
+ <div class="d-none" id="feature-container">
+ <p class="statline ui-state-highlight">Feature Model JSON</p>
+ <pre id="feature"></pre>
+ </div>
</div>
<script src="repoinit/res/ui/tln.min.js"></script>
<script src="repoinit/res/ui/repoinit.js"></script>
diff --git
a/org.apache.sling.repoinit.webconsole/src/test/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsoleTest.java
b/org.apache.sling.repoinit.webconsole/src/test/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsoleTest.java
index 1b3a6e2..90c7c01 100644
---
a/org.apache.sling.repoinit.webconsole/src/test/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsoleTest.java
+++
b/org.apache.sling.repoinit.webconsole/src/test/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsoleTest.java
@@ -63,8 +63,11 @@ public class RepoInitWebConsoleTest {
when(parser.parse(any())).thenReturn(Collections.emptyList());
context.registerService(JcrRepoInitOpsProcessor.class, processor);
- webConsole = new RepoInitWebConsole(context.componentContext(),
slingRepository);
-
+ webConsole = new RepoInitWebConsole();
+
+ webConsole.slingRepository = slingRepository;
+ webConsole.activate(context.componentContext());
+
}
public void testDoGetRequest(String resource, String type) throws
ServletException, IOException {
@@ -115,7 +118,7 @@ public class RepoInitWebConsoleTest {
assertEquals(200, context.response().getStatus());
assertEquals("application/json", context.response().getContentType());
- assertEquals("{\"succeeded\":true,\"operations\":[]}",
context.response().getOutputAsString());
+
assertEquals("{\"succeeded\":true,\"operations\":[],\"messages\":[\"Parsed
Repoinit script successfully!\"]}", context.response().getOutputAsString());
}
@Test
@@ -128,7 +131,7 @@ public class RepoInitWebConsoleTest {
assertEquals(400, context.response().getStatus());
assertEquals("application/json", context.response().getContentType());
assertEquals(
- "{\"succeeded\":false,\"errorMessage\":\"Failed to parse
RepoInit Statement: [RepoInitParsingException]: Failed because bad\"}",
+ "{\"succeeded\":false,\"messages\":[\"Failed to parse RepoInit
script: [RepoInitParsingException]: Failed because bad\"]}",
context.response().getOutputAsString());
}
@@ -141,7 +144,9 @@ public class RepoInitWebConsoleTest {
assertEquals(200, context.response().getStatus());
assertEquals("application/json", context.response().getContentType());
- assertEquals("{\"succeeded\":true,\"operations\":[]}",
context.response().getOutputAsString());
+ assertEquals(
+ "{\"succeeded\":true,\"operations\":[],\"messages\":[\"Parsed
Repoinit script successfully!\",\"Executed statements successfully!\"]}",
+ context.response().getOutputAsString());
verify(processor).apply(any(), any());
}
@@ -155,7 +160,9 @@ public class RepoInitWebConsoleTest {
assertEquals(400, context.response().getStatus());
assertEquals("application/json", context.response().getContentType());
-
assertEquals("{\"succeeded\":false,\"operations\":[],\"errorMessage\":\"Failed
to apply statements [RuntimeException]: ERROR\"}",
context.response().getOutputAsString());
+ assertEquals(
+ "{\"succeeded\":false,\"operations\":[],\"messages\":[\"Parsed
Repoinit script successfully!\",\"Failed to apply statements
[RuntimeException]: ERROR\"]}",
+ context.response().getOutputAsString());
}
}