Skip to content

Commit

Permalink
feat(webUI): simple command invocation (no arguments)
Browse files Browse the repository at this point in the history
Refs: #9
  • Loading branch information
nergal-perm committed May 18, 2024
1 parent 6615bc1 commit e9e1ba1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ru/ewc/checklogic/LogicChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.yaml.snakeyaml.Yaml;
import ru.ewc.checklogic.server.CommandPage;
import ru.ewc.checklogic.server.StatePage;
import ru.ewc.commands.CommandsFacade;
import ru.ewc.decisions.api.DecitaFacade;
Expand All @@ -71,6 +72,7 @@ private LogicChecker() {
// Utility class
}

// @todo #20 Implement a registry of pages and their endpoints
public static void main(final String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("Please provide the path to the resources");
Expand All @@ -91,6 +93,8 @@ public static void main(final String[] args) {
final WebFramework web = minum.getWebFramework();
final StatePage state = new StatePage(initial);
web.registerPath(RequestLine.Method.GET, "", state::statePage);
final CommandPage command = new CommandPage(initial);
web.registerPath(RequestLine.Method.POST, "command", command::commandPage);
minum.block();
} else {
System.setProperty("sources", root);
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/ru/ewc/checklogic/server/CommandPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* MIT License
*
* Copyright (c) 2024 Decision-Driven Development
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package ru.ewc.checklogic.server;

import com.renomad.minum.web.Request;
import com.renomad.minum.web.Response;
import java.util.Map;
import ru.ewc.checklogic.Computation;
import ru.ewc.checklogic.Transition;
import ru.ewc.decisions.api.Locators;

/**
* I am a configuration object for all the command-related endpoints.
*
* @since 0.3.0
*/
public final class CommandPage {
/**
* The computation to be used for the command processing.
*/
private final Computation computation;

/**
* Ctor.
*
* @param computation The computation to be used for the command processing.
*/
public CommandPage(final Computation computation) {
this.computation = computation;
}

public Response commandPage(final Request request) {
final String command = request.body().asString("command");
this.computation.perform(new Transition(command, new Locators(Map.of())));
return Response.redirectTo("/");
}
}
3 changes: 0 additions & 3 deletions src/main/java/ru/ewc/checklogic/server/StatePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.Map;
import java.util.stream.Collectors;
import ru.ewc.checklogic.Computation;
import ru.ewc.checklogic.Transition;
import ru.ewc.decisions.api.Locators;

/**
* I am the configuration and logic for the state web page.
Expand Down Expand Up @@ -64,7 +62,6 @@ public StatePage(final Computation computation) {
// @todo #9 Get a modal with command description and parameters on button click
// @todo #9 Implement an endpoint to run a command
public Response statePage(final Request request) {
this.computation.perform(new Transition("initialize", new Locators(Map.of())));
final StoredState stored = new StoredState(this.computation.storedState());
return Response.htmlOk(this.template.renderTemplate(Map.of("state", stored.asHtmlList())));
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/templates/state.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
<body>
<h1>State entities</h1>
{{ state }}
<form method="post" action="/command">
<input type="hidden" name="command" value="initialize">
<input type="submit" value="Initialize">
</form>
</body>
</html>

1 comment on commit e9e1ba1

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on e9e1ba1 May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 20-b050ce20 discovered in src/main/java/ru/ewc/checklogic/LogicChecker.java) and submitted as #21. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.