Small fixes and cleanup

This commit is contained in:
Christopher Schnick 2022-12-02 18:46:46 +01:00
parent 768da75992
commit 0d65db95f9
4 changed files with 3 additions and 184 deletions

View file

@ -189,7 +189,7 @@ public class BeaconClient implements AutoCloseable {
}
public <T extends RequestMessage> void sendRequest(T req) throws ClientException, ConnectorException {
ObjectNode json = JacksonMapper.newMapper().valueToTree(req);
ObjectNode json = JacksonMapper.getDefault().valueToTree(req);
var prov = MessageExchanges.byRequest(req);
if (prov.isEmpty()) {
throw new ClientException("Unknown request class " + req.getClass());

View file

@ -1,175 +0,0 @@
package io.xpipe.core.source;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.xpipe.core.data.type.TupleType;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.OptionalInt;
/**
* A data source info instances contains all required
* essential information of a specific data source type.
*
* This information is usually determined only once on data
* source creation, as this process might be expensive.
*
* @see DataSourceType
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public abstract class DataSourceInfo {
public abstract DataSourceType getType();
/**
* Casts this instance to a table info.
*/
public Table asTable() {
if (!getType().equals(DataSourceType.TABLE)) {
throw new IllegalStateException("Not a table");
}
return (Table) this;
}
/**
* Casts this instance to a structure info.
*/
public Structure asStructure() {
if (!getType().equals(DataSourceType.STRUCTURE)) {
throw new IllegalStateException("Not a structure");
}
return (Structure) this;
}
/**
* Casts this instance to a text info.
*/
public Text asText() {
if (!getType().equals(DataSourceType.TEXT)) {
throw new IllegalStateException("Not a text");
}
return (Text) this;
}
/**
* Casts this instance to a raw info.
*/
public Raw asRaw() {
if (!getType().equals(DataSourceType.RAW)) {
throw new IllegalStateException("Not raw");
}
return (Raw) this;
}
/**
* Casts this instance to a collection info.
*/
public Collection asCollection() {
if (!getType().equals(DataSourceType.COLLECTION)) {
throw new IllegalStateException("Not a collection");
}
return (Collection) this;
}
@EqualsAndHashCode(callSuper = false)
@Value
@JsonTypeName("table")
public static class Table extends DataSourceInfo {
TupleType dataType;
int rowCount;
@JsonCreator
public Table(TupleType dataType, int rowCount) {
this.dataType = dataType;
this.rowCount = rowCount;
}
public OptionalInt getRowCountIfPresent() {
return getRowCount() != -1 ? OptionalInt.of(getRowCount()) : OptionalInt.empty();
}
@Override
public DataSourceType getType() {
return DataSourceType.TABLE;
}
}
@EqualsAndHashCode(callSuper = false)
@Value
@JsonTypeName("structure")
public static class Structure extends DataSourceInfo {
int entries;
@JsonCreator
public Structure(int entries) {
this.entries = entries;
}
@Override
public DataSourceType getType() {
return DataSourceType.STRUCTURE;
}
}
@EqualsAndHashCode(callSuper = false)
@Value
@JsonTypeName("collection")
public static class Collection extends DataSourceInfo {
int entries;
@JsonCreator
public Collection(int entries) {
this.entries = entries;
}
@Override
public DataSourceType getType() {
return DataSourceType.COLLECTION;
}
}
@EqualsAndHashCode(callSuper = false)
@Value
@JsonTypeName("text")
public static class Text extends DataSourceInfo {
int characters;
int lineCount;
@JsonCreator
public Text(int characters, int lineCount) {
this.characters = characters;
this.lineCount = lineCount;
}
@Override
public DataSourceType getType() {
return DataSourceType.TEXT;
}
}
@EqualsAndHashCode(callSuper = false)
@Value
@JsonTypeName("raw")
public static class Raw extends DataSourceInfo {
int byteCount;
@JsonCreator
public Raw(int byteCount) {
this.byteCount = byteCount;
}
@Override
public DataSourceType getType() {
return DataSourceType.RAW;
}
}
}

View file

@ -23,7 +23,6 @@ import io.xpipe.core.dialog.HeaderElement;
import io.xpipe.core.impl.*;
import io.xpipe.core.process.ShellTypes;
import io.xpipe.core.source.DataSource;
import io.xpipe.core.source.DataSourceInfo;
import io.xpipe.core.source.DataSourceReference;
import java.io.IOException;
@ -48,11 +47,6 @@ public class CoreJacksonModule extends SimpleModule {
new NamedType(ShellTypes.Cmd.class),
new NamedType(ShellTypes.PowerShell.class),
new NamedType(ShellTypes.Sh.class),
new NamedType(DataSourceInfo.Table.class),
new NamedType(DataSourceInfo.Structure.class),
new NamedType(DataSourceInfo.Text.class),
new NamedType(DataSourceInfo.Collection.class),
new NamedType(DataSourceInfo.Raw.class),
new NamedType(BaseQueryElement.class),
new NamedType(ChoiceElement.class),
new NamedType(BusyElement.class),

View file

@ -48,9 +48,9 @@ public class XPipeInstallation {
public static String getDataBasePath(ShellProcessControl p) throws Exception {
if (p.getOsType().equals(OsType.WINDOWS)) {
var base = p.executeSimpleCommand(p.getShellType().getPrintVariableCommand("userprofile"));
return FileNames.join(base, "X-Pipe");
return FileNames.join(base, ".xpipe");
} else {
return FileNames.join("~", "xpipe");
return FileNames.join("~", ".xpipe");
}
}