Informar del lineaje cuando se mostraria tambien el path de un fichero.

This commit is contained in:
andrei committed 2026-11-17 17:03:26 +01:00
1 parent 374d5d6157
commit a7397355ed
6 files changed
+91 -22

No files matched your search

@@ -44,6 +44,19 @@ public class ProjectService {
}
}
/**
* The name of the project for display, such as in dialogs; its folder name when it cannot be read,
* without alerting: the dialog showing it is not about reading it.
*/
public static String nameOf(Path projectPath) {
try {
return ProjectRepository.get(projectPath).getName();
} catch (RepositoryException unreadable) {
log.log(Level.FINE, "Cannot read name of project %s.".formatted(projectPath), unreadable);
return projectPath.getParent().getFileName().toString();
}
}
public static void write(Path projectPath, Project project) {
removeBlankHeaders(project);
try {
@@ -10,6 +10,8 @@ import com.molnarandrei.sopa.events.SoapJobEvent;
import com.molnarandrei.sopa.calllog.CallLogService;
import com.molnarandrei.sopa.project.ProjectService;
import com.molnarandrei.sopa.testcase.TestCaseService;
import com.molnarandrei.sopa.data.yaml.Kind;
import com.molnarandrei.sopa.ui.lib.Lineage;
import com.molnarandrei.sopa.wsdl.WsdlValidations;
import javafx.scene.control.Alert;
@@ -155,7 +157,7 @@ public class SoapJob extends LinkedList<SoapCall> implements Runnable {
Alert.AlertType.WARNING,
"Aserción no cumplida",
"La respuesta del paso no cumple la aserción %s:\n%s"
.formatted(assertion.getType(), call.getPath()),
.formatted(assertion.getType(), Lineage.withPath(Kind.step, call.getPath())),
"%s\n\nLa respuesta se ha guardado en el historial del paso para revisarla. %s"
.formatted(unmetDetail(call, assertion, httpResponse), REMAINING_SKIPPED)
);
@@ -182,7 +184,7 @@ public class SoapJob extends LinkedList<SoapCall> implements Runnable {
Utils.alert(
Alert.AlertType.WARNING,
"Llamada incompleta",
"No podemos realizar la llamada SOAP:\n%s".formatted(call.getPath()),
"No podemos realizar la llamada SOAP:\n%s".formatted(Lineage.withPath(Kind.step, call.getPath())),
"Falta la propiedad: %s".formatted(prop.getMissingKey())
);
} catch (MalformedEndpointException malformed) {
@@ -6,6 +6,7 @@ import com.molnarandrei.sopa.trash.TrashService;
import com.molnarandrei.sopa.Utils;
import com.molnarandrei.sopa.data.RepositoryException;
import com.molnarandrei.sopa.data.yaml.Step;
import com.molnarandrei.sopa.ui.lib.Lineage;
import com.molnarandrei.sopa.ui.lib.Packing;
import javafx.scene.control.TextInputDialog;
@@ -37,10 +38,24 @@ public class StepService {
}
}
/**
* The name of the step for display, such as in dialogs; its folder name when it cannot be read,
* without alerting: the dialog showing it is not about reading it.
*/
public static String nameOf(Path stepPath) {
try {
return StepRepository.get(stepPath).getName();
} catch (RepositoryException unreadable) {
log.log(Level.FINE, "Cannot read name of step %s.".formatted(stepPath), unreadable);
return stepPath.getParent().getFileName().toString();
}
}
public static void create(Path testCasePath) {
var input = Packing.pack(new TextInputDialog());
input.setTitle("Crear paso en prueba");
input.setHeaderText("Nombre del paso");
input.setHeaderText(Lineage.withPath(Kind.testcase, testCasePath));
input.setContentText("Nombre del paso:");
var name = input.showAndWait().orElse("");
if (name.isBlank()) return;
@@ -6,6 +6,7 @@ import com.molnarandrei.sopa.step.StepService;
import com.molnarandrei.sopa.Utils;
import com.molnarandrei.sopa.data.RepositoryException;
import com.molnarandrei.sopa.data.yaml.TestCase;
import com.molnarandrei.sopa.ui.lib.Lineage;
import com.molnarandrei.sopa.ui.lib.Packing;
import javafx.scene.control.TextInputDialog;
@@ -38,10 +39,24 @@ public class TestCaseService {
}
}
/**
* The name of the testcase for display, such as in dialogs; its folder name when it cannot be read,
* without alerting: the dialog showing it is not about reading it.
*/
public static String nameOf(Path testCasePath) {
try {
return TestCaseRepository.get(testCasePath).getName();
} catch (RepositoryException unreadable) {
log.log(Level.FINE, "Cannot read name of testcase %s.".formatted(testCasePath), unreadable);
return testCasePath.getParent().getFileName().toString();
}
}
public static void create(Path projectPath) {
var input = Packing.pack(new TextInputDialog());
input.setTitle("Crear caso de prueba");
input.setHeaderText("Nombre del caso");
input.setHeaderText(Lineage.withPath(Kind.project, projectPath));
input.setContentText("Nombre del caso:");
var name = input.showAndWait().orElse("");
if (name.isBlank()) return;
@@ -0,0 +1,34 @@
package com.molnarandrei.sopa.ui.lib;
import com.molnarandrei.sopa.data.yaml.Kind;
import com.molnarandrei.sopa.project.ProjectService;
import com.molnarandrei.sopa.step.StepService;
import com.molnarandrei.sopa.testcase.TestCaseService;
import java.nio.file.Path;
public final class Lineage {
private static final String SEPARATOR = " > ";
private Lineage() {}
public static String of(Kind kind, Path path) {
return switch (kind) {
case project -> ProjectService.nameOf(path);
case testcase -> of(Kind.project, projectOf(path)) + SEPARATOR + TestCaseService.nameOf(path);
case step -> of(Kind.testcase, testCaseOf(path)) + SEPARATOR + StepService.nameOf(path);
};
}
public static String withPath(Kind kind, Path path) {
return of(kind, path) + "\n" + path.getParent();
}
private static Path projectOf(Path testCasePath) {
return testCasePath.getParent().getParent().resolve("project.yml");
}
private static Path testCaseOf(Path stepPath) {
return stepPath.getParent().getParent().resolve("testcase.yml");
}
}
@@ -1,11 +1,9 @@
package com.molnarandrei.sopa.ui.navpane;
import com.molnarandrei.sopa.project.ProjectRepository;
import com.molnarandrei.sopa.project.ProjectService;
import com.molnarandrei.sopa.step.StepRepository;
import com.molnarandrei.sopa.step.StepService;
import com.molnarandrei.sopa.testcase.TestCaseRepository;
import com.molnarandrei.sopa.testcase.TestCaseService;
import com.molnarandrei.sopa.ui.lib.Lineage;
import com.molnarandrei.sopa.ui.lib.Packing;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
@@ -19,8 +17,13 @@ public class DeleteDialog {
public static void confirmAndDelete(TreeIdentity identity) {
var alert = Packing.pack(new Alert(Alert.AlertType.CONFIRMATION, "", DELETE, CANCEL));
alert.setTitle("Eliminar");
alert.setHeaderText("Seguro que desea eliminar el %s %s?".formatted(kindName(identity), nameOf(identity)));
alert.setContentText(identity.path().getParent().toString());
var name = switch (identity.kind()) {
case project -> ProjectService.nameOf(identity.path());
case testcase -> TestCaseService.nameOf(identity.path());
case step -> StepService.nameOf(identity.path());
};
alert.setHeaderText("Seguro que desea eliminar el %s %s?".formatted(kindName(identity), name));
alert.setContentText(Lineage.withPath(identity.kind(), identity.path()));
// Delete is the default: enter confirms what the delete key started, escape cancels.
if (alert.showAndWait().orElse(CANCEL) == DELETE)
switch (identity.kind()) {
@@ -37,17 +40,4 @@ public class DeleteDialog {
case step -> "paso";
};
}
private static String nameOf(TreeIdentity identity) {
var path = identity.path();
try {
return switch (identity.kind()) {
case project -> ProjectRepository.get(path).getName();
case testcase -> TestCaseRepository.get(path).getName();
case step -> StepRepository.get(path).getName();
};
} catch (Exception unreadable) {
return path.getParent().getFileName().toString();
}
}
}