Skip to content

Commit

Permalink
change checkCompatibility to use verbose mode
Browse files Browse the repository at this point in the history
Added very basic dialog to display messages retuned by verbose check
prevent exceptions from opening very large alert windows
  • Loading branch information
patschuh committed Mar 15, 2024
1 parent b0520c8 commit 3585b2a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
@@ -1,6 +1,7 @@
package at.esque.kafka;

import at.esque.kafka.alerts.ErrorAlert;
import at.esque.kafka.alerts.IncompatibleSchemaAlert;
import at.esque.kafka.controls.KafkaEsqueCodeArea;
import io.confluent.kafka.schemaregistry.client.rest.RestService;
import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
Expand All @@ -12,6 +13,8 @@
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.kordamp.ikonli.fontawesome.FontAwesome;
import org.kordamp.ikonli.javafx.FontIcon;

import java.io.File;
import java.io.IOException;
Expand All @@ -21,7 +24,6 @@

public class SchemaCompatibilityCheckController {


@FXML
private TextField subjectTextField;

Expand All @@ -42,17 +44,20 @@ public void addSchema(ActionEvent actionEvent) {

try {
Schema schema = restService.getVersion(subjectTextField.getText(), Integer.parseInt(versionTextField.getText()));
List<String> compatibility = restService.testCompatibility(schemaTextArea.getText(), schema.getSchemaType(), null, subjectTextField.getText(), versionTextField.getText(), false);
List<String> compatibility = restService.testCompatibility(schemaTextArea.getText(), schema.getSchemaType(), null, subjectTextField.getText(), versionTextField.getText(), true);

if (compatibility.isEmpty()) {
resultLabel.setTextFill(Color.web("#3d7a3d"));
resultLabel.setText("Schema is compatible");
} else {
resultLabel.setTextFill(Color.web("#bd362f"));
resultLabel.setText("Schema is incompatible");
resultLabel.setGraphic(FontIcon.of(FontAwesome.QUESTION_CIRCLE, Color.CADETBLUE));
resultLabel.setOnMouseClicked(event -> IncompatibleSchemaAlert.show(compatibility, getWindow()));
IncompatibleSchemaAlert.show(compatibility, getWindow());
}
} catch (Exception e) {
ErrorAlert.show(e, getWindow());
ErrorAlert.show("Exception when requesting compatibility check", "Could not check compatibility", e.getClass().getName(), e, getWindow(), true);
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/main/java/at/esque/kafka/alerts/IncompatibleSchemaAlert.java
@@ -0,0 +1,41 @@
package at.esque.kafka.alerts;

import at.esque.kafka.Main;
import at.esque.kafka.controls.FilterableListView;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Window;

import java.util.List;

public class IncompatibleSchemaAlert {
public static void show(List<String> messages, Window owner) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Schema Incompatible");
alert.setHeaderText("Incompatibility Information");
alert.setResizable(true);
Main.applyIcon(alert);
Main.applyStylesheet(alert.getDialogPane().getScene());
FilterableListView<String> messageView = new FilterableListView<>();
messageView.setAddButtonVisible(false);
messageView.setRefreshButtonVisible(false);
messageView.setItems(messages);

BorderPane borderPane = new BorderPane();
borderPane.setCenter(messageView);
borderPane.setTop(new Label("Messages"));
borderPane.setMaxWidth(Double.MAX_VALUE);
borderPane.setMaxHeight(Double.MAX_VALUE);
borderPane.setPrefSize(800, 600);


alert.getDialogPane().setContent(borderPane);

if (owner != null) {
alert.initOwner(owner);
}

alert.show();
}
}

0 comments on commit 3585b2a

Please sign in to comment.