Browse Source

Wrap diagnostic result in object to prepare it for possible fix action

Armin Schrenk 4 years ago
parent
commit
66e3625a0b

+ 6 - 7
main/ui/src/main/java/org/cryptomator/ui/health/CheckDetailController.java

@@ -2,7 +2,6 @@ package org.cryptomator.ui.health;
 
 import com.tobiasdiez.easybind.EasyBind;
 import com.tobiasdiez.easybind.optional.OptionalBinding;
-import org.cryptomator.cryptofs.health.api.DiagnosticResult;
 import org.cryptomator.ui.common.FxController;
 
 import javax.inject.Inject;
@@ -19,15 +18,15 @@ import javafx.scene.control.TableView;
 
 public class CheckDetailController implements FxController {
 
-	private final Binding<ObservableList<DiagnosticResult>> results;
+	private final Binding<ObservableList<DiagnosticResultAction>> results;
 	private final OptionalBinding<Worker.State> taskState;
 	private final Binding<String> taskName;
 	private final Binding<String> taskDescription;
 	private final BooleanBinding producingResults;
 
-	public TableView<DiagnosticResult> resultsTableView;
-	public TableColumn<DiagnosticResult, String> resultDescriptionColumn;
-	public TableColumn<DiagnosticResult, String> resultSeverityColumn;
+	public TableView<DiagnosticResultAction> resultsTableView;
+	public TableColumn<DiagnosticResultAction, String> resultDescriptionColumn;
+	public TableColumn<DiagnosticResultAction, String> resultSeverityColumn;
 
 	@Inject
 	public CheckDetailController(ObjectProperty<HealthCheckTask> selectedTask) {
@@ -48,8 +47,8 @@ public class CheckDetailController implements FxController {
 	@FXML
 	public void initialize() {
 		resultsTableView.itemsProperty().bind(results);
-		resultDescriptionColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().toString()));
-		resultSeverityColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().getServerity().name()));
+		resultDescriptionColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().getDescription()));
+		resultSeverityColumn.setCellValueFactory(cellFeatures -> new SimpleStringProperty(cellFeatures.getValue().getSeverity().name()));
 	}
 	/* Getter/Setter */
 

+ 47 - 0
main/ui/src/main/java/org/cryptomator/ui/health/DiagnosticResultAction.java

@@ -0,0 +1,47 @@
+package org.cryptomator.ui.health;
+
+import org.cryptomator.cryptofs.VaultConfig;
+import org.cryptomator.cryptofs.health.api.DiagnosticResult;
+import org.cryptomator.cryptolib.api.Masterkey;
+
+import javafx.scene.control.Alert;
+import java.nio.file.Path;
+import java.security.SecureRandom;
+
+class DiagnosticResultAction implements Runnable {
+
+	private final DiagnosticResult result;
+	private final Path vaultPath;
+	private final VaultConfig vaultConfig;
+	private final Masterkey masterkey;
+	private final SecureRandom csprng;
+
+	DiagnosticResultAction(DiagnosticResult result, Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng) {
+		this.result = result;
+		this.vaultPath = vaultPath;
+		this.vaultConfig = vaultConfig;
+		this.masterkey = masterkey;
+		this.csprng = csprng;
+	}
+
+	public void run() {
+		try (var masterkeyClone = masterkey.clone(); //
+			 var cryptor = vaultConfig.getCipherCombo().getCryptorProvider(csprng).withKey(masterkeyClone)) {
+			result.fix(vaultPath, vaultConfig, masterkeyClone, cryptor);
+		} catch (Exception e) {
+			e.printStackTrace();
+			Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage());
+			alert.showAndWait();
+			//TODO: real error/not supported handling
+		}
+	}
+
+	public DiagnosticResult.Severity getSeverity() {
+		return result.getServerity(); //TODO: fix spelling with updated cryptofs release
+	}
+
+	public String getDescription() {
+		return result.toString();
+	}
+
+}

+ 3 - 3
main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckTask.java

@@ -25,7 +25,7 @@ class HealthCheckTask extends Task<Void> {
 	private final Masterkey masterkey;
 	private final SecureRandom csprng;
 	private final HealthCheck check;
-	private final ObservableList<DiagnosticResult> results;
+	private final ObservableList<DiagnosticResultAction> results;
 
 	public HealthCheckTask(Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng, HealthCheck check) {
 		this.vaultPath = Objects.requireNonNull(vaultPath);
@@ -58,7 +58,7 @@ class HealthCheckTask extends Task<Void> {
 						throw new RuntimeException(e);
 					}
 				}
-				Platform.runLater(() -> results.add(result));
+				Platform.runLater(() -> results.add(new DiagnosticResultAction(result,vaultPath,vaultConfig, masterkey,csprng))); //FIXME: there can be a lotta results, each with a reference to the master key -> differentiate with severity!
 			});
 		}
 		return null;
@@ -76,7 +76,7 @@ class HealthCheckTask extends Task<Void> {
 
 	/* Getter */
 
-	public ObservableList<DiagnosticResult> results() {
+	public ObservableList<DiagnosticResultAction> results() {
 		return results;
 	}
 

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/health/ReportWriter.java

@@ -67,7 +67,7 @@ public class ReportWriter {
 					case SUCCEEDED -> {
 						writer.write("STATUS: SUCCESS\nRESULTS:\n");
 						for (var result : task.results()) {
-							writer.write(REPORT_CHECK_RESULT.formatted(result.getServerity(), result));
+							writer.write(REPORT_CHECK_RESULT.formatted(result.getSeverity(), result));
 						}
 					}
 					case CANCELLED -> writer.write("STATUS: CANCELED\n");