mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-17 09:43:37 +00:00
Rework hierarchy validation
This commit is contained in:
parent
5b25f34988
commit
39f32af927
7 changed files with 42 additions and 37 deletions
|
@ -280,6 +280,9 @@ public class StoreCreationComp extends DialogComp {
|
|||
return busy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void discard() {}
|
||||
|
||||
@Override
|
||||
protected void finish() {
|
||||
if (finished.get()) {
|
||||
|
@ -351,9 +354,6 @@ public class StoreCreationComp extends DialogComp {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void discard() {}
|
||||
|
||||
@Override
|
||||
public Comp<?> content() {
|
||||
return Comp.of(this::createLayout);
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.xpipe.app.util.ThreadHelper;
|
|||
import io.xpipe.core.store.DataStore;
|
||||
import io.xpipe.core.store.FixedChildStore;
|
||||
import io.xpipe.core.store.StorePath;
|
||||
import io.xpipe.core.store.ValidationContext;
|
||||
import io.xpipe.core.util.UuidHelper;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
@ -356,15 +357,22 @@ public abstract class DataStorage {
|
|||
return refreshChildren(e, false);
|
||||
}
|
||||
|
||||
public boolean refreshChildren(DataStoreEntry e, boolean throwOnFail) throws Exception {
|
||||
if (!(e.getStore() instanceof FixedHierarchyStore h)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ValidationContext<?>> boolean refreshChildren(DataStoreEntry e, boolean throwOnFail) throws Exception {
|
||||
if (!(e.getStore() instanceof FixedHierarchyStore<?> h)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
e.incrementBusyCounter();
|
||||
List<? extends DataStoreEntryRef<? extends FixedChildStore>> newChildren;
|
||||
T context = null;
|
||||
try {
|
||||
newChildren = h.listChildren(e).stream()
|
||||
context = (T) h.createContext();
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
newChildren = ((FixedHierarchyStore<T>)h).listChildren(context).stream()
|
||||
.filter(dataStoreEntryRef -> dataStoreEntryRef != null && dataStoreEntryRef.get() != null)
|
||||
.toList();
|
||||
} catch (Exception ex) {
|
||||
|
@ -375,6 +383,9 @@ public abstract class DataStorage {
|
|||
return false;
|
||||
}
|
||||
} finally {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
e.decrementBusyCounter();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.xpipe.app.ext.DataStoreProvider;
|
|||
import io.xpipe.app.ext.DataStoreProviders;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.resources.SystemIcons;
|
||||
import io.xpipe.app.util.FixedHierarchyStore;
|
||||
import io.xpipe.core.store.*;
|
||||
import io.xpipe.core.util.JacksonMapper;
|
||||
import lombok.*;
|
||||
|
@ -22,7 +21,6 @@ import java.nio.file.Path;
|
|||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Value
|
||||
|
@ -504,26 +502,7 @@ public class DataStoreEntry extends StorageElement {
|
|||
}
|
||||
|
||||
public void validateOrThrow() throws Throwable {
|
||||
var r = validateOrThrowAndClose(null);
|
||||
if (!r) {
|
||||
validateRefreshChildrenOrThrow();
|
||||
}
|
||||
}
|
||||
|
||||
public void validateRefreshChildrenOrThrow() throws Throwable {
|
||||
if (!(store instanceof FixedHierarchyStore h)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
store.checkComplete();
|
||||
incrementBusyCounter();
|
||||
childrenCache = h.listChildren(this).stream()
|
||||
.map(DataStoreEntryRef::get)
|
||||
.collect(Collectors.toSet());
|
||||
} finally {
|
||||
decrementBusyCounter();
|
||||
}
|
||||
validateOrThrowAndClose(null);
|
||||
}
|
||||
|
||||
public boolean validateOrThrowAndClose(ValidationContext<?> existingContext) throws Throwable {
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import io.xpipe.core.store.FixedChildStore;
|
||||
import io.xpipe.core.store.ValidatableStore;
|
||||
import io.xpipe.core.store.ValidationContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FixedHierarchyStore extends DataStore {
|
||||
public interface FixedHierarchyStore<T extends ValidationContext<?>> extends ValidatableStore<T>, DataStore {
|
||||
|
||||
default boolean removeLeftovers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<? extends DataStoreEntryRef<? extends FixedChildStore>> listChildren(DataStoreEntry self) throws Exception;
|
||||
@Override
|
||||
default T validate(T context) throws Exception {
|
||||
listChildren(context);
|
||||
return null;
|
||||
}
|
||||
|
||||
List<? extends DataStoreEntryRef<? extends FixedChildStore>> listChildren(T context) throws Exception;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,9 @@ public class TerminalLauncherManager {
|
|||
if (e == null) {
|
||||
throw new BeaconClientException("Unknown launch request " + request);
|
||||
}
|
||||
|
||||
if (e.isLaunched()) {
|
||||
submitAsync(e.getRequest(), e.getProcessControl(), e.getConfig(), e.getWorkingDirectory());
|
||||
}
|
||||
return waitForCompletion(e);
|
||||
}
|
||||
|
||||
|
@ -131,6 +133,7 @@ public class TerminalLauncherManager {
|
|||
throw new BeaconClientException("Invalid launch request state " + request);
|
||||
}
|
||||
|
||||
e.setLaunched(true);
|
||||
return ((ResultSuccess) e.getResult()).getTargetScript();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
|
||||
|
||||
.root:pretty:light .color-box.blue {
|
||||
-fx-background-color: linear-gradient(from 100% 0% to 0% 100%, rgb(130, 130, 250, 0.1) 40%, rgb(57, 57, 200, 0.1) 50%, rgb(137, 137, 250, 0.1) 100%);
|
||||
-fx-background-color: linear-gradient(from 100% 0% to 0% 100%, rgb(130, 130, 250, 0.08) 40%, rgb(57, 57, 200, 0.08) 50%, rgb(137, 137, 250, 0.08) 100%);
|
||||
-fx-border-color: rgba(80, 100, 150, 0.6);
|
||||
}
|
||||
|
||||
.root:performance:light .color-box.blue {
|
||||
-fx-background-color: rgb(130, 130, 250, 0.1);
|
||||
-fx-background-color: rgb(130, 130, 250, 0.08);
|
||||
-fx-border-color: rgba(80, 100, 150, 0.6);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.xpipe.ext.base.service;
|
||||
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.FixedHierarchyStore;
|
||||
import io.xpipe.app.util.Validators;
|
||||
|
@ -8,6 +7,7 @@ import io.xpipe.core.store.DataStore;
|
|||
import io.xpipe.core.store.FixedChildStore;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.core.store.ValidationContext;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
@Jacksonized
|
||||
@JsonTypeName("fixedServiceGroup")
|
||||
public class FixedServiceGroupStore extends AbstractServiceGroupStore<FixedServiceCreatorStore>
|
||||
implements DataStore, FixedHierarchyStore {
|
||||
implements DataStore, FixedHierarchyStore<ValidationContext<?>> {
|
||||
|
||||
@Override
|
||||
public void checkComplete() throws Throwable {
|
||||
|
@ -32,9 +32,14 @@ public class FixedServiceGroupStore extends AbstractServiceGroupStore<FixedServi
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<? extends DataStoreEntryRef<? extends FixedChildStore>> listChildren(DataStoreEntry self)
|
||||
public List<? extends DataStoreEntryRef<? extends FixedChildStore>> listChildren(ValidationContext<?> context)
|
||||
throws Exception {
|
||||
return (List<? extends DataStoreEntryRef<? extends FixedChildStore>>)
|
||||
getParent().getStore().createFixedServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationContext<?> createContext() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue