mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-08-12 20:40:59 +00:00
Add more exchanges + move some files
This commit is contained in:
@@ -50,6 +50,10 @@ public class TupleType extends DataType {
|
||||
return new TupleType(Collections.nCopies(types.size(), null), types);
|
||||
}
|
||||
|
||||
public boolean hasAllNames() {
|
||||
return names.stream().allMatch(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "tuple";
|
||||
|
||||
@@ -1,49 +1,29 @@
|
||||
package io.xpipe.core.source;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Singular;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
@Jacksonized
|
||||
public class DataSourceConfig {
|
||||
String description;
|
||||
|
||||
private String description;
|
||||
private List<Option<?>> options;
|
||||
@Singular
|
||||
List<Option> options;
|
||||
|
||||
public DataSourceConfig(String description, List<Option<?>> options) {
|
||||
this.description = description;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public List<Option<?>> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public abstract static class Option<T> {
|
||||
|
||||
private final String name;
|
||||
protected T value;
|
||||
|
||||
public Option(String name) {
|
||||
this.name = name;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public Option(String name, T value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected abstract String enterValue(String val);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
@Value
|
||||
@Builder
|
||||
@Jacksonized
|
||||
@AllArgsConstructor
|
||||
public static class Option {
|
||||
String name;
|
||||
String key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.xpipe.core.source;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
@Jacksonized
|
||||
@AllArgsConstructor
|
||||
public class DataSourceConfigInstance {
|
||||
|
||||
String provider;
|
||||
DataSourceConfig config;
|
||||
Map<String, String> currentValues;
|
||||
}
|
||||
@@ -22,8 +22,11 @@ import lombok.Getter;
|
||||
public class DataSourceId {
|
||||
|
||||
public static final char SEPARATOR = ':';
|
||||
public static final DataSourceId ANONYMOUS = new DataSourceId(null, null);
|
||||
|
||||
private final String collectionName;
|
||||
private final String entryName;
|
||||
|
||||
@JsonCreator
|
||||
private DataSourceId(String collectionName, String entryName) {
|
||||
this.collectionName = collectionName;
|
||||
@@ -38,6 +41,10 @@ public class DataSourceId {
|
||||
* @throws IllegalArgumentException if any name is not valid
|
||||
*/
|
||||
public static DataSourceId create(String collectionName, String entryName) {
|
||||
if (collectionName == null && entryName == null) {
|
||||
return ANONYMOUS;
|
||||
}
|
||||
|
||||
if (collectionName != null && collectionName.trim().length() == 0) {
|
||||
throw new IllegalArgumentException("Trimmed collection name is empty");
|
||||
}
|
||||
@@ -70,6 +77,10 @@ public class DataSourceId {
|
||||
throw new IllegalArgumentException("String is null");
|
||||
}
|
||||
|
||||
if (s.equals(String.valueOf(SEPARATOR))) {
|
||||
return ANONYMOUS;
|
||||
}
|
||||
|
||||
var split = s.split(String.valueOf(SEPARATOR));
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("Data source id must contain exactly one " + SEPARATOR);
|
||||
@@ -87,6 +98,6 @@ public class DataSourceId {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (collectionName != null ? collectionName : "") + SEPARATOR + entryName;
|
||||
return (collectionName != null ? collectionName.toLowerCase() : "") + SEPARATOR + (entryName != null ? entryName.toLowerCase() : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,9 @@ public class InputStreamDataStore implements StreamDataStore {
|
||||
public OutputStream openOutput() throws Exception {
|
||||
throw new UnsupportedOperationException("No output available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.xpipe.core.store;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -13,6 +14,7 @@ import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonTypeName("local")
|
||||
@EqualsAndHashCode
|
||||
public class LocalFileDataStore implements StreamDataStore {
|
||||
|
||||
private final Path file;
|
||||
@@ -50,4 +52,9 @@ public class LocalFileDataStore implements StreamDataStore {
|
||||
public OutputStream openOutput() throws Exception {
|
||||
return Files.newOutputStream(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return Files.exists(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ public class RemoteFileDataStore implements StreamDataStore {
|
||||
public OutputStream openOutput() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A data store that can be accessed using InputStreams and/or OutputStreams.
|
||||
@@ -9,6 +16,21 @@ import java.io.OutputStream;
|
||||
*/
|
||||
public interface StreamDataStore extends DataStore {
|
||||
|
||||
static Optional<StreamDataStore> fromString(@NonNull String s) {
|
||||
try {
|
||||
var path = Path.of(s);
|
||||
return Optional.of(new LocalFileDataStore(path));
|
||||
} catch (InvalidPathException ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
var path = new URL(s);
|
||||
} catch (MalformedURLException ignored) {
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an input stream. This input stream does not necessarily have to be a new instance.
|
||||
*/
|
||||
@@ -18,4 +40,6 @@ public interface StreamDataStore extends DataStore {
|
||||
* Opens an output stream. This output stream does not necessarily have to be a new instance.
|
||||
*/
|
||||
OutputStream openOutput() throws Exception;
|
||||
|
||||
boolean exists();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import io.xpipe.core.data.type.ArrayType;
|
||||
@@ -35,6 +36,8 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
|
||||
addSerializer(Path.class, new LocalPathSerializer());
|
||||
addDeserializer(Path.class, new LocalPathDeserializer());
|
||||
|
||||
context.setMixInAnnotations(Throwable.class, ExceptionTypeMixIn.class);
|
||||
}
|
||||
|
||||
public static class CharsetSerializer extends JsonSerializer<Charset> {
|
||||
@@ -70,4 +73,10 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
return Path.of(p.getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@JsonSerialize(as = Throwable.class)
|
||||
public abstract static class ExceptionTypeMixIn {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user