Splitting is a must in case of different source code layers - helps to keep track. Fixed base data types layous. Generics are evil in this case.
parent
f5f99ef8ac
commit
501aca9f33
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>TraQtor</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>traqtor-env</module>
|
||||||
|
<module>traqtor-json</module>
|
||||||
|
<module>traqtor-model</module>
|
||||||
|
<module>traqtor-schema</module>
|
||||||
|
<module>traqtor-tests</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<source>11</source>
|
||||||
|
<target>11</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -1,79 +0,0 @@
|
|||||||
//package link.pagan.traqtor.mapping;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//import java.util.List;
|
|
||||||
//import link.pagan.traqtor.outdated.schema.basic.data.mapping.MappingSchemaImpl;
|
|
||||||
//import link.pagan.traqtor.project.universe.schema.DataType;
|
|
||||||
//import link.pagan.traqtor.util.Name;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// *
|
|
||||||
// * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
// */
|
|
||||||
//public class DataTypeSchemaReferenceImplementation implements DataTypeSchema {
|
|
||||||
//
|
|
||||||
// private static final Name name = Name.of("traqtor", "basic");
|
|
||||||
//
|
|
||||||
// // ARRAY(""),
|
|
||||||
// // LIST(""),
|
|
||||||
// // SET(""),
|
|
||||||
//// // MAP(""),
|
|
||||||
//// public static final DataType BOOLEAN = new DataType("boolean");
|
|
||||||
//// public static final DataType BYTE = new DataType("byte");
|
|
||||||
//// public static final DataType SHORT = new DataType("short");
|
|
||||||
//// public static final DataType INTEGER = new DataType("int");
|
|
||||||
//// public static final DataType LONG = new DataType("long");
|
|
||||||
//// public static final DataType FLOAT = new DataType("float");
|
|
||||||
//// public static final DataType DOUBLE = new DataType("double");
|
|
||||||
//// public static final DataType STRING = new DataType("string");
|
|
||||||
//// public static final DataType DATE = new DataType("date");
|
|
||||||
//// public static final DataType TIME = new DataType("time");
|
|
||||||
//// public static final DataType TIMESTAMP = new DataType("timestamp");
|
|
||||||
//// public static final DataType ID = new DataType("id");
|
|
||||||
//// public static final DataType UUID = new DataType("uuid");
|
|
||||||
////
|
|
||||||
//// private static final List<DataType> dataTypes = List.of(BOOLEAN, BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, STRING,
|
|
||||||
//// DATE, TIME, TIMESTAMP, ID, UUID);
|
|
||||||
//
|
|
||||||
//// private static final List<MappingSchema> mappingSchemas = List.of(new MappingSchemaImpl());
|
|
||||||
//
|
|
||||||
//// @Override
|
|
||||||
//// public List<DataType> getDataTypes() {
|
|
||||||
//// return dataTypes;
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// @Override
|
|
||||||
//// public Name getName() {
|
|
||||||
//// return name;
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// @Override
|
|
||||||
//// public List<MappingSchema> getMappingSchema() {
|
|
||||||
//// return mappingSchemas;
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
//// @Override
|
|
||||||
//// public Map<String, DataType> register() {
|
|
||||||
//// return new HashMap<String, DataType>(){
|
|
||||||
//// private static final long serialVersionUID = 1L;
|
|
||||||
//// {
|
|
||||||
//// put(BOOLEAN.getName(), BOOLEAN);
|
|
||||||
//// put(BYTE.getName(), BYTE);
|
|
||||||
//// put(SHORT.getName(), SHORT);
|
|
||||||
//// put(INTEGER.getName(), INTEGER);
|
|
||||||
//// put(LONG.getName(), LONG);
|
|
||||||
//// put(FLOAT.getName(), FLOAT);
|
|
||||||
//// put(DOUBLE.getName(), DOUBLE);
|
|
||||||
//// put(STRING.getName(), STRING);
|
|
||||||
//// put(BOOLEAN.getName(), BOOLEAN);
|
|
||||||
//// put(DATE.getName(), DATE);
|
|
||||||
//// put(TIME.getName(), TIME);
|
|
||||||
//// put(TIMESTAMP.getName(), TIMESTAMP);
|
|
||||||
//// put(ID.getName(), ID);
|
|
||||||
//// put(UUID.getName(), UUID);
|
|
||||||
//// }};
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package link.pagan.traqtor.mapping;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class Mapping {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final HashMap<MappingEntry, String> mapping;
|
|
||||||
|
|
||||||
protected Mapping (String name, HashMap<MappingEntry, String> mapping) {
|
|
||||||
this.mapping = mapping;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName () { return name; }
|
|
||||||
|
|
||||||
public HashMap<MappingEntry, String> getMapping () { return mapping; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package link.pagan.traqtor.mapping;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class MappingEntry {
|
|
||||||
|
|
||||||
private final DataType dataType;
|
|
||||||
|
|
||||||
private final boolean nullable;
|
|
||||||
|
|
||||||
private final boolean keyable;
|
|
||||||
|
|
||||||
public MappingEntry (DataType dataType, boolean nullable, boolean keyable) {
|
|
||||||
this.dataType = dataType;
|
|
||||||
this.nullable = nullable;
|
|
||||||
this.keyable = keyable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataType getDataType () { return dataType; }
|
|
||||||
|
|
||||||
public boolean isNullable () { return nullable; }
|
|
||||||
|
|
||||||
public boolean isKeyable () { return keyable; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package link.pagan.traqtor.mapping;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public interface MappingSchema {
|
|
||||||
|
|
||||||
public List<MappingEntry> getMappings ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
// package link.pagan.traqtor.mapping;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// import java.util.List;
|
|
||||||
// import link.pagan.traqtor.util.Name;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/// **
|
|
||||||
// *
|
|
||||||
// * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
// */
|
|
||||||
// public class MappingSchemaImpl implements MappingSchema {
|
|
||||||
//
|
|
||||||
// private static final Name name = Name.of("traqtor", "basic", "default");
|
|
||||||
////
|
|
||||||
//// public static final MappingEntry NULLABLE_BOOLEAN = new MappingEntry(DataTypeSchemaReferenceImplementation.BOOLEAN
|
|
||||||
// , true , false );
|
|
||||||
//// public static final MappingEntry BOOLEAN = new MappingEntry(DataTypeSchemaReferenceImplementation.BOOLEAN , false ,
|
|
||||||
// true );
|
|
||||||
//// public static final MappingEntry NULLABLE_BYTE = new MappingEntry(DataTypeSchemaReferenceImplementation.BYTE , true
|
|
||||||
// , false );
|
|
||||||
//// public static final MappingEntry BYTE = new MappingEntry(DataTypeSchemaReferenceImplementation.BYTE , false , true
|
|
||||||
// );
|
|
||||||
//// public static final MappingEntry NULLABLE_SHORT = new MappingEntry(DataTypeSchemaReferenceImplementation.SHORT ,
|
|
||||||
// true , false );
|
|
||||||
//// public static final MappingEntry SHORT = new MappingEntry(DataTypeSchemaReferenceImplementation.SHORT , false ,
|
|
||||||
// true );
|
|
||||||
//// public static final MappingEntry NULLABLE_INTEGER = new MappingEntry(DataTypeSchemaReferenceImplementation.INTEGER
|
|
||||||
// , true , false );
|
|
||||||
//// public static final MappingEntry INTEGER = new MappingEntry(DataTypeSchemaReferenceImplementation.INTEGER , false ,
|
|
||||||
// true );
|
|
||||||
//// public static final MappingEntry NULLABLE_LONG = new MappingEntry(DataTypeSchemaReferenceImplementation.LONG , true
|
|
||||||
// , false );
|
|
||||||
//// public static final MappingEntry LONG = new MappingEntry(DataTypeSchemaReferenceImplementation.LONG , false , true
|
|
||||||
// );
|
|
||||||
//// public static final MappingEntry NULLABLE_FLOAT = new MappingEntry(DataTypeSchemaReferenceImplementation.FLOAT ,
|
|
||||||
// true , false );
|
|
||||||
//// public static final MappingEntry FLOAT = new MappingEntry(DataTypeSchemaReferenceImplementation.FLOAT , false ,
|
|
||||||
// false );
|
|
||||||
//// public static final MappingEntry NULLABLE_DOUBLE = new MappingEntry(DataTypeSchemaReferenceImplementation.DOUBLE ,
|
|
||||||
// true , false );
|
|
||||||
//// public static final MappingEntry DOUBLE = new MappingEntry(DataTypeSchemaReferenceImplementation.DOUBLE , false ,
|
|
||||||
// false );
|
|
||||||
//// public static final MappingEntry STRING = new MappingEntry(DataTypeSchemaReferenceImplementation.STRING , true ,
|
|
||||||
// false );
|
|
||||||
//// public static final MappingEntry DATE = new MappingEntry(DataTypeSchemaReferenceImplementation.DATE , true , false
|
|
||||||
// );
|
|
||||||
//// public static final MappingEntry TIME = new MappingEntry(DataTypeSchemaReferenceImplementation.TIME , true , false
|
|
||||||
// );
|
|
||||||
//// public static final MappingEntry TIMESTAMP = new MappingEntry(DataTypeSchemaReferenceImplementation.TIMESTAMP ,
|
|
||||||
// true , false );
|
|
||||||
//// public static final MappingEntry ID = new MappingEntry(DataTypeSchemaReferenceImplementation.ID , true , true );
|
|
||||||
//// public static final MappingEntry UUID = new MappingEntry(DataTypeSchemaReferenceImplementation.UUID , true , true
|
|
||||||
// );
|
|
||||||
////
|
|
||||||
//// private static final List<MappingEntry> mappings = List.of(NULLABLE_BOOLEAN, BOOLEAN,
|
|
||||||
//// NULLABLE_BYTE, BYTE,
|
|
||||||
//// NULLABLE_SHORT, SHORT,
|
|
||||||
//// NULLABLE_INTEGER, INTEGER,
|
|
||||||
//// NULLABLE_LONG, LONG,
|
|
||||||
//// NULLABLE_FLOAT, FLOAT,
|
|
||||||
//// NULLABLE_DOUBLE, DOUBLE,
|
|
||||||
//// STRING,
|
|
||||||
//// DATE, TIME, TIMESTAMP,
|
|
||||||
//// ID, UUID);
|
|
||||||
////
|
|
||||||
//// @Override
|
|
||||||
//// public List<MappingEntry> getMappings() {
|
|
||||||
//// return mappings;
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// @Override
|
|
||||||
//// public Name getName() {
|
|
||||||
//// return name;
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package link.pagan.traqtor.mapping.backend;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import link.pagan.traqtor.mapping.Mapping;
|
|
||||||
import link.pagan.traqtor.mapping.MappingEntry;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class BackendMapping extends Mapping {
|
|
||||||
|
|
||||||
public BackendMapping (String name, HashMap<MappingEntry, String> mapping) {
|
|
||||||
super(name, mapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package link.pagan.traqtor.mapping.frontend;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import link.pagan.traqtor.mapping.Mapping;
|
|
||||||
import link.pagan.traqtor.mapping.MappingEntry;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class FrontendMapping extends Mapping {
|
|
||||||
|
|
||||||
public FrontendMapping (String name, HashMap<MappingEntry, String> mapping) {
|
|
||||||
super(name, mapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,259 +0,0 @@
|
|||||||
package link.pagan.traqtor.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import link.pagan.traqtor.util.io.Filed;
|
|
||||||
import link.pagan.traqtor.util.io.Directoried;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.util.op.OperationObjectResult;
|
|
||||||
import link.pagan.traqtor.util.op.OperationResult;
|
|
||||||
import link.pagan.traqtor.model.project.Project;
|
|
||||||
import link.pagan.traqtor.model.project.database.DatabaseProject;
|
|
||||||
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
@JsonDeserialize(using = WorkspaceDeserializer.class)
|
|
||||||
@JsonSerialize(using = WorkspaceSerializer.class)
|
|
||||||
public class Workspace implements Filed, Directoried {
|
|
||||||
|
|
||||||
private ObjectMapper json;
|
|
||||||
|
|
||||||
private File root;
|
|
||||||
|
|
||||||
private Name name;
|
|
||||||
|
|
||||||
private boolean dirty;
|
|
||||||
|
|
||||||
private boolean pretty;
|
|
||||||
|
|
||||||
private final List<Project> projects;
|
|
||||||
|
|
||||||
public Workspace () {
|
|
||||||
this.root = null;
|
|
||||||
this.dirty = true;
|
|
||||||
this.pretty = true;
|
|
||||||
this.json = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
|
||||||
this.projects = new ArrayList<Project>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniverseProject universe () {
|
|
||||||
UniverseProject project = new UniverseProject(this);
|
|
||||||
this.projects.add(project);
|
|
||||||
this.dirty = true;
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseProject database () {
|
|
||||||
DatabaseProject project = new DatabaseProject(this);
|
|
||||||
this.projects.add(project);
|
|
||||||
this.dirty = true;
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Workspace name (Name name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Project> projects () {
|
|
||||||
return projects;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Workspace projects (Project... projects) {
|
|
||||||
this.projects.addAll(Arrays.asList(projects));
|
|
||||||
this.dirty = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File dir () {
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File file () {
|
|
||||||
return file(Workspace.this.dir());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File file (File dir) {
|
|
||||||
return new File(dir, ".tw");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Workspace dir (File root) {
|
|
||||||
this.root = root;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dirty (boolean dirty) {
|
|
||||||
this.dirty = dirty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean dirty () {
|
|
||||||
return dirty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean pretty () {
|
|
||||||
return pretty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pretty (boolean pretty) {
|
|
||||||
|
|
||||||
if (pretty) {
|
|
||||||
this.json.enable(SerializationFeature.INDENT_OUTPUT);
|
|
||||||
} else {
|
|
||||||
this.json.disable(SerializationFeature.INDENT_OUTPUT);
|
|
||||||
}
|
|
||||||
this.pretty = pretty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectMapper json () {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OperationResult saveAs (File parentDir) {
|
|
||||||
return saveAs(this, parentDir, new OperationResult());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult saveAs (Workspace workspace, File parent, OperationResult result) {
|
|
||||||
|
|
||||||
if (parent == null) {
|
|
||||||
return result
|
|
||||||
.info("Target directory must be set, are you OK?")
|
|
||||||
.fail("Failed to save workspace, no new root directory was passed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parent.exists()) {
|
|
||||||
return result
|
|
||||||
.info("Directory " + parent.getAbsolutePath() + " does not exist, deleted/moved/unmounted?")
|
|
||||||
.fail("Failed to save workspace, due non existent parent direcory for new workspace");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (workspace.name() == null) {
|
|
||||||
return result
|
|
||||||
.info("Workspace does not contain name - how did you even achieve that?")
|
|
||||||
.fail("Failed to save workspace, due unknown name of it, huh...");
|
|
||||||
}
|
|
||||||
|
|
||||||
File root = new File(parent, workspace.name().asTiled());
|
|
||||||
|
|
||||||
if (!root.exists()) {
|
|
||||||
result.info("Creating new root direcory at " + root.getAbsolutePath());
|
|
||||||
|
|
||||||
if (!root.mkdirs()) {
|
|
||||||
return result
|
|
||||||
.info("Unable to create directory " + root.getAbsolutePath() + " - permission problem?")
|
|
||||||
.fail("Failed to save workspace, can not create new root directory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.listFiles().length > 0) {
|
|
||||||
return result
|
|
||||||
.info("Directory " + root.getAbsolutePath() + " is not empty, not safe to save?")
|
|
||||||
.fail("Failed to save workspace, due to polluted new root direcory");
|
|
||||||
}
|
|
||||||
File oldRoot = workspace.dir();
|
|
||||||
boolean oldDirty = workspace.dirty();
|
|
||||||
|
|
||||||
workspace.dir(root);
|
|
||||||
workspace.dirty(true);
|
|
||||||
result.info("Setting workspace root to " + root.getAbsolutePath());
|
|
||||||
save(workspace, result.startSubresult());
|
|
||||||
|
|
||||||
if (!result.ok()) {
|
|
||||||
result.info("Reverting workspace root to " + oldRoot.getAbsolutePath());
|
|
||||||
workspace.dir(oldRoot);
|
|
||||||
workspace.dirty(oldDirty);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OperationResult save () {
|
|
||||||
return save(this, new OperationResult());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult save (Workspace workspace, OperationResult result) {
|
|
||||||
|
|
||||||
if (!workspace.dirty()) { return result.warn("Workspace is not dirty - no need to save"); }
|
|
||||||
|
|
||||||
result.info("Saving workspace " + workspace.name().asTiled() + " ...");
|
|
||||||
|
|
||||||
if (workspace.dir() == null) {
|
|
||||||
return result
|
|
||||||
.info("Workspace root is not set - is this a new workspace?")
|
|
||||||
.fail("Failed to save workspace, due to unknown root directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!workspace.dir().exists()) {
|
|
||||||
return result
|
|
||||||
.info("Directory " + workspace.dir().getAbsolutePath() +
|
|
||||||
" does not exist, deleted/moved/unmounted?")
|
|
||||||
.fail("Failed to save workspace, due non existent root direcory");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!workspace.dir().canRead()) {
|
|
||||||
return result
|
|
||||||
.info("Unable to read " + workspace.dir().getAbsolutePath() + " - permission problem?")
|
|
||||||
.fail("Failed to save workspace, due unreadable root direcory");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!workspace.dir().canWrite()) {
|
|
||||||
return result
|
|
||||||
.info("Unable to write " + workspace.dir().getAbsolutePath() + " - permission problem?")
|
|
||||||
.fail("Failed to save workspace, due write restriction on root direcory");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Project project : workspace.projects()) { project.save(result.startSubresult()); }
|
|
||||||
|
|
||||||
writeJson(workspace, result.startSubresult());
|
|
||||||
|
|
||||||
if (result.ok()) { workspace.dirty(false); }
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult writeJson (Workspace workspace, OperationResult result) {
|
|
||||||
File file = workspace.file();
|
|
||||||
result.info("Writing workspace descriptor file to " + file.getAbsolutePath() + " ...");
|
|
||||||
|
|
||||||
try {
|
|
||||||
workspace.json().writeValue(file, workspace);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return result.fail("Failed to write file " + file.getAbsolutePath() + " - IO exception")
|
|
||||||
.fail(ex);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static OperationObjectResult<Workspace> load (File dir) {
|
|
||||||
OperationObjectResult<Workspace> result = new OperationObjectResult<Workspace>();
|
|
||||||
readJson(dir, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationObjectResult<Workspace> readJson (File dir, OperationObjectResult<Workspace> result) {
|
|
||||||
File file = file(dir);
|
|
||||||
result.info("Reading workspace from " + dir.getAbsolutePath() + " ...");
|
|
||||||
|
|
||||||
try {
|
|
||||||
result.info("Reading json from " + file.getAbsolutePath() + " ...");
|
|
||||||
result.object(new ObjectMapper().readValue(file, Workspace.class));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return result.fail("Failed to read file " + file.getAbsolutePath() + " - IO exception").fail(ex);
|
|
||||||
}
|
|
||||||
result.object().dir(file);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.util.io.Directoried;
|
|
||||||
import link.pagan.traqtor.util.io.Filed;
|
|
||||||
import link.pagan.traqtor.model.Workspace;
|
|
||||||
import link.pagan.traqtor.util.op.OperationResult;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public abstract class Project implements Filed, Directoried {
|
|
||||||
|
|
||||||
protected final Workspace workspace;
|
|
||||||
|
|
||||||
protected Name name;
|
|
||||||
|
|
||||||
protected boolean dirty;
|
|
||||||
|
|
||||||
public Project (Workspace workspace) {
|
|
||||||
this.workspace = workspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
|
|
||||||
if (name == null) { return Name.NO_NAME; }
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project name (String... parts) {
|
|
||||||
|
|
||||||
return name(Name.of(parts));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project name (Name name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract OperationResult save (OperationResult result);
|
|
||||||
|
|
||||||
public Workspace workspace () {
|
|
||||||
return workspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.database.mapping;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import link.pagan.traqtor.mapping.Mapping;
|
|
||||||
import link.pagan.traqtor.mapping.MappingEntry;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class DatabaseMapping extends Mapping {
|
|
||||||
|
|
||||||
public DatabaseMapping (String name, HashMap<MappingEntry, String> mapping) {
|
|
||||||
super(name, mapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.database.mapping.impl;
|
|
||||||
|
|
||||||
/// *
|
|
||||||
// * To change this license header, choose License Headers in Project Properties.
|
|
||||||
// * To change this template file, choose Tools | Templates
|
|
||||||
// * and open the template in the editor.
|
|
||||||
// */
|
|
||||||
// package link.pagan.traqtor.project.database.mapping.impl;
|
|
||||||
//
|
|
||||||
// import link.pagan.traqtor.project.database.mapping.DatabaseAdapter;
|
|
||||||
// import link.pagan.traqtor.util.Name;
|
|
||||||
//
|
|
||||||
/// ** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
// public class PostgresDatabaseAdapter extends DatabaseAdapter {
|
|
||||||
//
|
|
||||||
// private static final Name NAME = Name.of("traqtor", "basic", "db", "postgres");
|
|
||||||
//
|
|
||||||
// public PostgresDatabaseAdapter () {
|
|
||||||
// super(NAME);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // @Override
|
|
||||||
// // public Map<String, DatabaseAdapter> register() {
|
|
||||||
// // return new HashMap<String, DatabaseAdapter>(){
|
|
||||||
// // private static final long serialVersionUID = 1L;
|
|
||||||
// // {
|
|
||||||
// // put(NAME, new PostgresDatabaseAdapter());
|
|
||||||
// // }};
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Name getName () { return NAME; }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.database.mapping.impl;
|
|
||||||
|
|
||||||
// package link.pagan.traqtor.project.database.mapping.impl;
|
|
||||||
//
|
|
||||||
// import java.util.HashMap;
|
|
||||||
// import link.pagan.traqtor.mapping.MappingEntry;
|
|
||||||
// import link.pagan.traqtor.project.database.mapping.DatabaseMapping;
|
|
||||||
//
|
|
||||||
/// ** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
// public class PostgresDatabaseMapping extends DatabaseMapping {
|
|
||||||
//
|
|
||||||
// public PostgresDatabaseMapping () {
|
|
||||||
// super("PostgreSQL", new HashMap<MappingEntry, String>() {
|
|
||||||
//
|
|
||||||
// private static final long serialVersionUID = 1L;
|
|
||||||
// {
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_BOOLEAN, "boolean");
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_BYTE, "smallint");
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_SHORT, "smallint");
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_INTEGER, "integer");
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_LONG, "bigint");
|
|
||||||
//
|
|
||||||
// put(MappingSchemaImpl.BOOLEAN, "boolean");
|
|
||||||
// put(MappingSchemaImpl.BYTE, "smallint");
|
|
||||||
// put(MappingSchemaImpl.SHORT, "smallint");
|
|
||||||
// put(MappingSchemaImpl.INTEGER, "integer");
|
|
||||||
// put(MappingSchemaImpl.LONG, "bigint");
|
|
||||||
//
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_DOUBLE, "double precision");
|
|
||||||
// put(MappingSchemaImpl.NULLABLE_FLOAT, "real");
|
|
||||||
//
|
|
||||||
// put(MappingSchemaImpl.DOUBLE, "double precision");
|
|
||||||
// put(MappingSchemaImpl.FLOAT, "real");
|
|
||||||
//
|
|
||||||
// put(MappingSchemaImpl.ID, "bigserial");
|
|
||||||
// put(MappingSchemaImpl.UUID, "uuid");
|
|
||||||
//
|
|
||||||
// put(MappingSchemaImpl.STRING, "String");
|
|
||||||
// put(MappingSchemaImpl.DATE, "date");
|
|
||||||
// put(MappingSchemaImpl.TIME, "time");
|
|
||||||
// put(MappingSchemaImpl.TIMESTAMP, "timestamp");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
@ -1,140 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import link.pagan.traqtor.model.Workspace;
|
|
||||||
import link.pagan.traqtor.util.op.OperationResult;
|
|
||||||
import link.pagan.traqtor.model.project.Project;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Atom;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.link.Link;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Element;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Isotope;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
// @JsonDeserialize(using = UniverseDeserializer.class)
|
|
||||||
@JsonSerialize(using = UniverseSerializer.class)
|
|
||||||
public class UniverseProject extends Project {
|
|
||||||
|
|
||||||
private final Set<DatatypeSchema> schemas;
|
|
||||||
|
|
||||||
private final Set<Element> elements;
|
|
||||||
|
|
||||||
private final Set<Link> links;
|
|
||||||
|
|
||||||
public UniverseProject (Workspace workspace) {
|
|
||||||
super(workspace);
|
|
||||||
this.schemas = new TreeSet<DatatypeSchema>( (DatatypeSchema a, DatatypeSchema b) -> a.name()
|
|
||||||
.compareTo(b.name()));
|
|
||||||
this.elements = new TreeSet<Element>( (Element a, Element b) -> a.name().compareTo(b.name()));
|
|
||||||
this.links = new TreeSet<Link>( (Link a,
|
|
||||||
Link b) -> (a.from().name().asDotted() + "_" + a.fromName().asDotted())
|
|
||||||
.compareTo((b.from()
|
|
||||||
.name()
|
|
||||||
.asDotted() +
|
|
||||||
"_" +
|
|
||||||
b.fromName()
|
|
||||||
.asDotted())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UniverseProject name (String... parts) {
|
|
||||||
return name(Name.of(parts));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UniverseProject name (Name name) {
|
|
||||||
super.name(name);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatatypeSchema[] schemas () {
|
|
||||||
return this.schemas.toArray(new DatatypeSchema[this.schemas.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniverseProject schemas (DatatypeSchema... schemas) {
|
|
||||||
this.schemas.addAll(Arrays.asList(schemas));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element[] elements () {
|
|
||||||
return this.elements.toArray(new Element[this.elements.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniverseProject elements (Element... element) {
|
|
||||||
this.elements.addAll(Arrays.asList(element));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Link[] links () {
|
|
||||||
return this.links.toArray(new Link[this.links.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniverseProject links (Link... links) {
|
|
||||||
this.links.addAll(Arrays.asList(links));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OperationResult save (OperationResult result) {
|
|
||||||
return save(this, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult save (UniverseProject project, OperationResult result) {
|
|
||||||
|
|
||||||
if (!project.dir().exists()) {
|
|
||||||
result.warn("Project directory " + project.dir().getAbsolutePath() + " does not exist");
|
|
||||||
result.info("Creating project directory at " + project.dir().getAbsolutePath() + " ...");
|
|
||||||
|
|
||||||
if (!project.dir().mkdirs()) {
|
|
||||||
return result.fail("Failed to created project directory at " + project.dir().getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Element element : project.elements()) { element.save(result.startSubresult()); }
|
|
||||||
|
|
||||||
writeJson(project, result.startSubresult());
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult writeJson (UniverseProject project, OperationResult result) {
|
|
||||||
File file = project.file();
|
|
||||||
result.info("Writing project descriptor file to " + file.getAbsolutePath() + " ...");
|
|
||||||
|
|
||||||
try {
|
|
||||||
project.workspace().json().writeValue(file, project);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
result.fail("Failed to write file " + file.getAbsolutePath() + " - IO exception");
|
|
||||||
result.fail(ex);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File file () {
|
|
||||||
return new File(this.dir(), ".tup");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File dir () {
|
|
||||||
return new File(workspace.dir(), this.name.asTiled() + "-universe");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Atom atom () {
|
|
||||||
Atom res = new Atom(this);
|
|
||||||
this.elements.add(res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Isotope isotope (Element base) {
|
|
||||||
Isotope res = new Isotope(this, base);
|
|
||||||
this.elements.add(res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,104 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.element;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.util.io.Filed;
|
|
||||||
import link.pagan.traqtor.util.op.OperationResult;
|
|
||||||
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
// @JsonDeserialize(using = LinkDeserializer.class)
|
|
||||||
@JsonSerialize(using = ElementSerializer.class)
|
|
||||||
public abstract class Element implements Filed {
|
|
||||||
|
|
||||||
protected final UniverseProject project;
|
|
||||||
|
|
||||||
private static final Comparator<Particle<? extends DataType>> PARTICLE_SORT_COMPARATOR = new Comparator<Particle<? extends DataType>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare (Particle<? extends DataType> a, Particle<? extends DataType> b) {
|
|
||||||
return a.name().asDotted().compareTo(b.name().asDotted());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private Name name;
|
|
||||||
|
|
||||||
private final Set<Particle<? extends DataType>> particles;
|
|
||||||
|
|
||||||
public Element (UniverseProject project) {
|
|
||||||
this.project = project;
|
|
||||||
this.particles = new TreeSet<Particle<? extends DataType>>(PARTICLE_SORT_COMPARATOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
|
|
||||||
if (name == null) { return Name.NO_NAME; }
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element name (String... parts) {
|
|
||||||
return name(Name.of(parts));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element name (Name name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Particle<? extends DataType>> particles () {
|
|
||||||
return particles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public final Element particles (Particle<? extends DataType>... particles) {
|
|
||||||
return particles(Arrays.asList(particles));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element particles (List<Particle<? extends DataType>> particles) {
|
|
||||||
this.particles.addAll(particles);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OperationResult save (OperationResult result) {
|
|
||||||
return save(this, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult save (Element element, OperationResult result) {
|
|
||||||
|
|
||||||
if (element.getClass().equals(Atom.class) || element.getClass().equals(Isotope.class)) {
|
|
||||||
writeJson(element, result.startSubresult());
|
|
||||||
} else {
|
|
||||||
return result.fail("Unknown element type - not supported class " + element.getClass().getName());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OperationResult writeJson (Element element, OperationResult result) {
|
|
||||||
File file = element.file();
|
|
||||||
result.info("Writing element to " + file.getAbsolutePath() + " ...");
|
|
||||||
|
|
||||||
try {
|
|
||||||
element.project().workspace().json().writeValue(file, element);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
result.fail("Failed to write file " + file.getAbsolutePath() + " - IO exception");
|
|
||||||
result.fail(ex);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniverseProject project () {
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.element;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.ConstraintInfo;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
// @JsonDeserialize(using = LinkDeserializer.class)
|
|
||||||
@JsonSerialize(using = PaticleInfoSerializer.class)
|
|
||||||
public class Particle <T extends DataType> extends PaticleInfo {
|
|
||||||
|
|
||||||
private final Set<ConstraintInfo> constraints;
|
|
||||||
|
|
||||||
public Particle (DataType type) {
|
|
||||||
super(type);
|
|
||||||
this.constraints = new TreeSet<ConstraintInfo>( (ConstraintInfo a,
|
|
||||||
ConstraintInfo b) -> a.name()
|
|
||||||
.asDotted()
|
|
||||||
.compareTo(b.name()
|
|
||||||
.asDotted()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public final Particle<T> constraints (Constraint<? super T>... args) {
|
|
||||||
return constraints(Arrays.asList(args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Particle<T> constraints (List<Constraint<? super T>> args) {
|
|
||||||
this.constraints.addAll(args);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Particle<T> name (String... parts) {
|
|
||||||
return name(Name.of(parts));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Particle<T> name (Name name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Particle<T> description (String description) {
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Particle<T> optional (boolean optional) {
|
|
||||||
this.optional = optional;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<ConstraintInfo> constraints () {
|
|
||||||
return this.constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.element;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.ConstraintInfo;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class PaticleInfo {
|
|
||||||
|
|
||||||
protected final DataType type;
|
|
||||||
|
|
||||||
protected Name name;
|
|
||||||
|
|
||||||
protected String description;
|
|
||||||
|
|
||||||
protected boolean optional;
|
|
||||||
|
|
||||||
public PaticleInfo (DataType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
|
|
||||||
if (name == null) { return Name.NO_NAME; }
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String description () {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataType type () {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Set<ConstraintInfo> constraints ();
|
|
||||||
|
|
||||||
public boolean optional () {
|
|
||||||
return this.optional;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.link;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public enum LinkType {
|
|
||||||
|
|
||||||
ONE_TO_ONE("1->1"),
|
|
||||||
ONE_TO_MANY("1->N"),
|
|
||||||
MANY_TO_MANY("N->N");
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
|
|
||||||
private LinkType (String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String code () {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
* @param <T> type to which this constraint is applicable */
|
|
||||||
|
|
||||||
// @JsonDeserialize(using = LinkDeserializer.class)
|
|
||||||
@JsonSerialize(using = ConstraintInfoSerializer.class)
|
|
||||||
public abstract class Constraint <T extends DataType> extends ConstraintInfo {
|
|
||||||
|
|
||||||
protected Name name;
|
|
||||||
|
|
||||||
protected Object value;
|
|
||||||
|
|
||||||
public Constraint (Name name, Object value) {
|
|
||||||
this.name = name;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Name name () {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object value () {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class ConstraintInfo {
|
|
||||||
|
|
||||||
public abstract Name name ();
|
|
||||||
|
|
||||||
public abstract Object value ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
class ConstraintInfoSerializer extends StdSerializer<ConstraintInfo> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ConstraintInfoSerializer () {
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConstraintInfoSerializer (Class<ConstraintInfo> t) {
|
|
||||||
super(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serialize (ConstraintInfo value, JsonGenerator gen, SerializerProvider provider)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
gen.writeStartObject();
|
|
||||||
gen.writeObjectField("name", value.name());
|
|
||||||
gen.writeObjectField("value", value.value());
|
|
||||||
gen.writeEndObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public abstract class DataType {
|
|
||||||
|
|
||||||
protected final Name name;
|
|
||||||
|
|
||||||
protected final List<Constraint<? extends DataType>> constraints;
|
|
||||||
|
|
||||||
public DataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
this.name = name;
|
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Constraint<? extends DataType>> constraints () {
|
|
||||||
return this.constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Particle<? extends DataType> particle ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class DatatypeSchema {
|
|
||||||
|
|
||||||
private Name name;
|
|
||||||
|
|
||||||
public DatatypeSchema (Name name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Name name () {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.literal.StringDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public class LiteralDataTypeSchema extends DatatypeSchema {
|
|
||||||
|
|
||||||
private final static Name NAME = Name.of("default", "schema", "literal");
|
|
||||||
|
|
||||||
private static final LiteralDataTypeSchema instance = new LiteralDataTypeSchema();
|
|
||||||
|
|
||||||
public final StringDataType STRING = StringDataType.instance();
|
|
||||||
|
|
||||||
public static LiteralDataTypeSchema instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiteralDataTypeSchema () {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LogicDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.logic.BooleanDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public class LogicDatatypeSchema extends DatatypeSchema {
|
|
||||||
|
|
||||||
private final static Name NAME = Name.of("default", "schema", "logic");
|
|
||||||
|
|
||||||
private static final LogicDatatypeSchema instance = new LogicDatatypeSchema();
|
|
||||||
|
|
||||||
public final LogicDataType BOOLEAN = BooleanDataType.instance();
|
|
||||||
|
|
||||||
public static LogicDatatypeSchema instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogicDatatypeSchema () {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.ByteDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.IntDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.LongDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.ShortDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.DoubleDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.FloatDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public class NumericDatatypeSchema extends DatatypeSchema {
|
|
||||||
|
|
||||||
private final static Name NAME = Name.of("default", "schema", "numeric");
|
|
||||||
|
|
||||||
private static final NumericDatatypeSchema instance = new NumericDatatypeSchema();
|
|
||||||
|
|
||||||
public final ByteDataType BYTE = ByteDataType.instance();
|
|
||||||
|
|
||||||
public final ShortDataType SHORT = ShortDataType.instance();
|
|
||||||
|
|
||||||
public final IntDataType INTEGER = IntDataType.instance();
|
|
||||||
|
|
||||||
public final LongDataType LONG = LongDataType.instance();
|
|
||||||
|
|
||||||
public final FloatDataType FLOAT = FloatDataType.instance();
|
|
||||||
|
|
||||||
public final DoubleDataType DOUBLE = DoubleDataType.instance();
|
|
||||||
|
|
||||||
public static NumericDatatypeSchema instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NumericDatatypeSchema () {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.TemporalDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.temporal.DateDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.temporal.TimeDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.temporal.TimestampDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
public class TemporalDatatypeSchema extends DatatypeSchema {
|
|
||||||
|
|
||||||
private final static Name NAME = Name.of("default", "schema", "temporal");
|
|
||||||
|
|
||||||
private static final TemporalDatatypeSchema instance = new TemporalDatatypeSchema();
|
|
||||||
|
|
||||||
public final TemporalDataType DATE = DateDataType.instance();
|
|
||||||
|
|
||||||
public final TemporalDataType TIME = TimeDataType.instance();
|
|
||||||
|
|
||||||
public final TemporalDataType TIMESTAMP = TimestampDataType.instance();
|
|
||||||
|
|
||||||
public static TemporalDatatypeSchema instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemporalDatatypeSchema () {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class LiteralDataType extends DataType {
|
|
||||||
|
|
||||||
public LiteralDataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends LiteralDataType> particle ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class LogicDataType extends DataType {
|
|
||||||
|
|
||||||
public LogicDataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends LogicDataType> particle ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class NumericDataType extends DataType {
|
|
||||||
|
|
||||||
public NumericDataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends NumericDataType> particle ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class TemporalDataType extends DataType {
|
|
||||||
|
|
||||||
public TemporalDataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends TemporalDataType> particle ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.literal;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LiteralDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints.LiteralMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints.LiteralMinConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints.LiteralRegExpConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class StringDataType extends LiteralDataType {
|
|
||||||
|
|
||||||
private static final StringDataType instance = new StringDataType();
|
|
||||||
|
|
||||||
public static StringDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private StringDataType () {
|
|
||||||
super(Name.of("string"), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<StringDataType> particle () {
|
|
||||||
return new Particle<StringDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiteralMinConstraint min (long min) {
|
|
||||||
return new LiteralMinConstraint(min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiteralMaxConstraint max (long max) {
|
|
||||||
return new LiteralMaxConstraint(max);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiteralRegExpConstraint regExp (String regExp) {
|
|
||||||
return new LiteralRegExpConstraint(regExp);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LiteralDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class LiteralMaxConstraint extends Constraint<LiteralDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("literal", "max");
|
|
||||||
|
|
||||||
public LiteralMaxConstraint (Long max) {
|
|
||||||
super(NAME, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LiteralDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class LiteralMinConstraint extends Constraint<LiteralDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("literal", "min");
|
|
||||||
|
|
||||||
public LiteralMinConstraint (Long min) {
|
|
||||||
super(NAME, min);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.literal.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LiteralDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class LiteralRegExpConstraint extends Constraint<LiteralDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("literal", "regular", "expression");
|
|
||||||
|
|
||||||
public LiteralRegExpConstraint (String regExp) {
|
|
||||||
super(NAME, regExp);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.logic;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.LogicDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class BooleanDataType extends LogicDataType {
|
|
||||||
|
|
||||||
private static final BooleanDataType instance = new BooleanDataType();
|
|
||||||
|
|
||||||
public static BooleanDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BooleanDataType () {
|
|
||||||
super(Name.of("boolean"), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<BooleanDataType> particle () {
|
|
||||||
return new Particle<BooleanDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.NumericDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
*/
|
|
||||||
public abstract class IntegerDataType extends NumericDataType {
|
|
||||||
|
|
||||||
public IntegerDataType(Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends IntegerDataType> particle();
|
|
||||||
|
|
||||||
public IntegerMinConstraint min(long min) {
|
|
||||||
return new IntegerMinConstraint(min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntegerMaxConstraint max(long max) {
|
|
||||||
return new IntegerMaxConstraint(max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.NumericDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public abstract class RationalDataType extends NumericDataType {
|
|
||||||
|
|
||||||
public RationalDataType (Name name, List<Constraint<? extends DataType>> constraints) {
|
|
||||||
super(name, constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract Particle<? extends RationalDataType> particle ();
|
|
||||||
|
|
||||||
public RationalMinConstraint min (double min) {
|
|
||||||
return new RationalMinConstraint(min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RationalMaxConstraint max (double max) {
|
|
||||||
return new RationalMaxConstraint(max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class ByteDataType extends IntegerDataType {
|
|
||||||
|
|
||||||
private static final ByteDataType instance = new ByteDataType();
|
|
||||||
|
|
||||||
public static ByteDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ByteDataType () {
|
|
||||||
super(Name.of("byte"),
|
|
||||||
new ArrayList<>()
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new IntegerMaxConstraint(Long.valueOf(Byte.MAX_VALUE)));
|
|
||||||
add(new IntegerMinConstraint(Long.valueOf(Byte.MIN_VALUE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<ByteDataType> particle () {
|
|
||||||
return new Particle<ByteDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class IntDataType extends IntegerDataType {
|
|
||||||
|
|
||||||
private static final IntDataType instance = new IntDataType();
|
|
||||||
|
|
||||||
public static IntDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IntDataType () {
|
|
||||||
super(Name.of("int"), new ArrayList<>() {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new IntegerMaxConstraint(Long.valueOf(Integer.MAX_VALUE)));
|
|
||||||
add(new IntegerMinConstraint(Long.valueOf(Integer.MIN_VALUE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<IntDataType> particle () {
|
|
||||||
return new Particle<IntDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class LongDataType extends IntegerDataType {
|
|
||||||
|
|
||||||
private static final LongDataType instance = new LongDataType();
|
|
||||||
|
|
||||||
public static LongDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LongDataType () {
|
|
||||||
super(Name.of("long"), new ArrayList<>() {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new IntegerMaxConstraint(Long.MAX_VALUE));
|
|
||||||
add(new IntegerMinConstraint(Long.MIN_VALUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<LongDataType> particle () {
|
|
||||||
return new Particle<LongDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints.IntegerMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class ShortDataType extends IntegerDataType {
|
|
||||||
|
|
||||||
private static final ShortDataType instance = new ShortDataType();
|
|
||||||
|
|
||||||
public static ShortDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ShortDataType () {
|
|
||||||
super(Name.of("short"), new ArrayList<>() {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new IntegerMaxConstraint(Long.valueOf(Short.MAX_VALUE)));
|
|
||||||
add(new IntegerMinConstraint(Long.valueOf(Short.MIN_VALUE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<ShortDataType> particle () {
|
|
||||||
return new Particle<ShortDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class IntegerMaxConstraint extends Constraint<IntegerDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("integer", "max");
|
|
||||||
|
|
||||||
public IntegerMaxConstraint (Long max) {
|
|
||||||
super(NAME, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.IntegerDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class IntegerMinConstraint extends Constraint<IntegerDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("integer", "min");
|
|
||||||
|
|
||||||
public IntegerMinConstraint (Long min) {
|
|
||||||
super(NAME, min);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.RationalDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class DoubleDataType extends RationalDataType {
|
|
||||||
|
|
||||||
private static final DoubleDataType instance = new DoubleDataType();
|
|
||||||
|
|
||||||
public static DoubleDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DoubleDataType () {
|
|
||||||
super(
|
|
||||||
Name.of("double"),
|
|
||||||
new ArrayList<>()
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new RationalMaxConstraint(Double.MAX_VALUE));
|
|
||||||
add(new RationalMinConstraint(Double.MIN_VALUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<DoubleDataType> particle () {
|
|
||||||
return new Particle<DoubleDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.RationalDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMaxConstraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints.RationalMinConstraint;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class FloatDataType extends RationalDataType {
|
|
||||||
|
|
||||||
private static final FloatDataType instance = new FloatDataType();
|
|
||||||
|
|
||||||
public static FloatDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FloatDataType () {
|
|
||||||
super(Name.of("float"), new ArrayList<>() {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
add(new RationalMaxConstraint(Double.valueOf(Float.MAX_VALUE)));
|
|
||||||
add(new RationalMinConstraint(Double.valueOf(Float.MIN_VALUE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<FloatDataType> particle () {
|
|
||||||
return new Particle<FloatDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.RationalDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class RationalMaxConstraint extends Constraint<RationalDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("rational", "max");
|
|
||||||
|
|
||||||
public RationalMaxConstraint (Double max) {
|
|
||||||
super(NAME, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.constraints;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.Constraint;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.RationalDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class RationalMinConstraint extends Constraint<RationalDataType> {
|
|
||||||
|
|
||||||
private static final Name NAME = Name.of("rational", "min");
|
|
||||||
|
|
||||||
public RationalMinConstraint (Double min) {
|
|
||||||
super(NAME, min);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.temporal;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.TemporalDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class DateDataType extends TemporalDataType {
|
|
||||||
|
|
||||||
private static final DateDataType instance = new DateDataType();
|
|
||||||
|
|
||||||
public static DateDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateDataType () {
|
|
||||||
super(Name.of("date"), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<DateDataType> particle () {
|
|
||||||
return new Particle<DateDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.temporal;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.TemporalDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class TimeDataType extends TemporalDataType {
|
|
||||||
|
|
||||||
private static final TimeDataType instance = new TimeDataType();
|
|
||||||
|
|
||||||
public static TimeDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimeDataType () {
|
|
||||||
super(Name.of("time"), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<TimeDataType> particle () {
|
|
||||||
return new Particle<TimeDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.schema.impl.data.temporal;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.TemporalDataType;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class TimestampDataType extends TemporalDataType {
|
|
||||||
|
|
||||||
private static final TimestampDataType instance = new TimestampDataType();
|
|
||||||
|
|
||||||
public static TimestampDataType instance () {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimestampDataType () {
|
|
||||||
super(Name.of("timestamp"), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Particle<TimestampDataType> particle () {
|
|
||||||
return new Particle<TimestampDataType>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
package link.pagan.traqtor.util;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
@JsonDeserialize(using = NameDeserializer.class)
|
|
||||||
@JsonSerialize(using = NameSerializer.class)
|
|
||||||
public class Name implements Comparable<Name> {
|
|
||||||
|
|
||||||
public static final Name NO_NAME = Name.of("no", "name");
|
|
||||||
|
|
||||||
String[] parts;
|
|
||||||
|
|
||||||
Name (String... parts) {
|
|
||||||
this.parts = parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Name of (String... parts) {
|
|
||||||
return new Name(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asTiled () {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < this.parts.length; i++) {
|
|
||||||
sb.append(parts[i]);
|
|
||||||
|
|
||||||
if (i != this.parts.length - 1) { sb.append('-'); }
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asDotted () {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < this.parts.length; i++) {
|
|
||||||
sb.append(parts[i]);
|
|
||||||
|
|
||||||
if (i != this.parts.length - 1) { sb.append('.'); }
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo (Name t) {
|
|
||||||
return this.asDotted().compareTo(t.asDotted());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode () {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + Arrays.hashCode(parts);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals (Object obj) {
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (obj == null) return false;
|
|
||||||
if (getClass() != obj.getClass()) return false;
|
|
||||||
Name other = (Name) obj;
|
|
||||||
if (!Arrays.equals(parts, other.parts)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package link.pagan.traqtor.util.io;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public interface Directoried {
|
|
||||||
|
|
||||||
public File dir ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
package link.pagan.traqtor.test.model;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.Workspace;
|
|
||||||
import link.pagan.traqtor.test.TestUtils;
|
|
||||||
import link.pagan.traqtor.util.op.OperationObjectResult;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class WorkspaceTest {
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void cleanTestDir () {
|
|
||||||
TestUtils.rebuildTestRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void killCore () {
|
|
||||||
TestUtils.deleteTestRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Workspace save")
|
|
||||||
void workspaceSave () {
|
|
||||||
Workspace workspace = new Workspace().name(Name.of("traqtor", "demo", "workspace"));
|
|
||||||
Assertions.assertTrue(!workspace.save().ok());
|
|
||||||
TestUtils.deleteTestRoot();
|
|
||||||
Assertions.assertTrue(!workspace.dir(TestUtils.testRoot()).save().ok());
|
|
||||||
TestUtils.rebuildTestRoot();
|
|
||||||
Assertions.assertTrue(workspace.saveAs(TestUtils.testRoot()).ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Workspace save/load")
|
|
||||||
void saveLoad () {
|
|
||||||
Workspace workspace = new Workspace().name(Name.of("traqtor", "demo", "workspace"));
|
|
||||||
Assertions.assertTrue(workspace.saveAs(TestUtils.testRoot()).ok());
|
|
||||||
OperationObjectResult<Workspace> loadResult = Workspace.load(workspace.dir());
|
|
||||||
Assertions.assertTrue(loadResult.ok());
|
|
||||||
Assertions.assertEquals(workspace.name(), loadResult.object().name());
|
|
||||||
Assertions.assertEquals(workspace.pretty(), loadResult.object().pretty());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,181 +0,0 @@
|
|||||||
package link.pagan.traqtor.test.model.project.universe;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.Workspace;
|
|
||||||
import link.pagan.traqtor.model.project.universe.Universe;
|
|
||||||
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Element;
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Particle;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.DatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.LiteralDataTypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.LogicDatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.NumericDatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.TemporalDatatypeSchema;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.literal.StringDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.integer.IntDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.DoubleDataType;
|
|
||||||
import link.pagan.traqtor.model.project.universe.schema.impl.data.numeric.real.FloatDataType;
|
|
||||||
import link.pagan.traqtor.test.TestUtils;
|
|
||||||
import link.pagan.traqtor.util.Name;
|
|
||||||
import link.pagan.traqtor.util.RegExpHelper;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
|
||||||
public class UniverseProjectTest {
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void cleanTestDir () {
|
|
||||||
TestUtils.rebuildTestRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void killCore () {
|
|
||||||
TestUtils.deleteTestRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Universe Project save")
|
|
||||||
void projectSaveAs () {
|
|
||||||
DatatypeSchema LITERAL = LiteralDataTypeSchema.instance();
|
|
||||||
DatatypeSchema LOGIC = LogicDatatypeSchema.instance();
|
|
||||||
DatatypeSchema NUMERIC = NumericDatatypeSchema.instance();
|
|
||||||
DatatypeSchema TEMPORAL = TemporalDatatypeSchema.instance();
|
|
||||||
|
|
||||||
StringDataType STRING = LiteralDataTypeSchema.instance().STRING;
|
|
||||||
// LogicDataType BOOLEAN = LOGIC.BOOLEAN;
|
|
||||||
// IntegerDataType BYTE = NUMERIC.BYTE;
|
|
||||||
// IntegerDataType SHORT = NUMERIC.SHORT;
|
|
||||||
IntDataType INTEGER = NumericDatatypeSchema.instance().INTEGER;
|
|
||||||
// IntegerDataType LONG = NUMERIC.LONG;
|
|
||||||
FloatDataType FLOAT = NumericDatatypeSchema.instance().FLOAT;
|
|
||||||
DoubleDataType DOUBLE = NumericDatatypeSchema.instance().DOUBLE;
|
|
||||||
// TemporalDataType DATE = TEMPORAL.DATE;
|
|
||||||
// TemporalDataType TIME = TEMPORAL.TIME;
|
|
||||||
// TemporalDataType TIMESTAMP = TEMPORAL.TIMESTAMP;
|
|
||||||
|
|
||||||
Workspace workspace = new Workspace().name(Name.of("traqtor", "demo", "workspace"));
|
|
||||||
|
|
||||||
UniverseProject base = workspace.universe().name("base").schemas(LITERAL, LOGIC, NUMERIC, TEMPORAL);
|
|
||||||
|
|
||||||
Particle<StringDataType> email = STRING.particle()
|
|
||||||
.name("email")
|
|
||||||
.description("email as main identifier for an account")
|
|
||||||
.constraints(STRING.min(4), STRING.max(512), STRING.regExp(RegExpHelper.EMAIL));
|
|
||||||
Particle<StringDataType> phone = STRING.particle()
|
|
||||||
.name("phone")
|
|
||||||
.description("alternative identifier for an account")
|
|
||||||
.optional(true)
|
|
||||||
.constraints(STRING.min(10), STRING.max(32), STRING.regExp(RegExpHelper.PHONE));
|
|
||||||
Particle<StringDataType> password = STRING.particle()
|
|
||||||
.name("phone")
|
|
||||||
.description("account password")
|
|
||||||
.constraints(STRING.min(8), STRING.max(32));
|
|
||||||
|
|
||||||
Element account = base.atom()
|
|
||||||
.name("account")
|
|
||||||
.particles(email, phone, password);
|
|
||||||
|
|
||||||
Particle<StringDataType> lastName = STRING.particle()
|
|
||||||
.name("last", "name")
|
|
||||||
.description("last name of user")
|
|
||||||
.constraints(STRING.max(64), STRING.min(1));
|
|
||||||
|
|
||||||
Particle<StringDataType> firstName = STRING.particle()
|
|
||||||
.name("first", "name")
|
|
||||||
.description("first name of user")
|
|
||||||
.optional(true)
|
|
||||||
.constraints(STRING.max(64), STRING.min(1));
|
|
||||||
|
|
||||||
Particle<IntDataType> age = INTEGER.particle()
|
|
||||||
.name("age")
|
|
||||||
.description("age of user owning an account")
|
|
||||||
.constraints(INTEGER.min(18), INTEGER.max(65));
|
|
||||||
|
|
||||||
Element accountDetails = base.atom()
|
|
||||||
.name("account", "details")
|
|
||||||
.particles(lastName, firstName, age);
|
|
||||||
|
|
||||||
Particle<DoubleDataType> length = DOUBLE.particle()
|
|
||||||
.name("length")
|
|
||||||
.description("penis length")
|
|
||||||
.constraints(DOUBLE.min(0), DOUBLE.max(40));
|
|
||||||
|
|
||||||
Element male = base.isotope(account)
|
|
||||||
.name("male")
|
|
||||||
.particles(length);
|
|
||||||
|
|
||||||
Particle<FloatDataType> depth = FLOAT.particle()
|
|
||||||
.name("depth")
|
|
||||||
.description("vagina depth")
|
|
||||||
.constraints(DOUBLE.min(0), DOUBLE.max(40));
|
|
||||||
|
|
||||||
base.isotope(account)
|
|
||||||
.name("female")
|
|
||||||
.particles(depth);
|
|
||||||
|
|
||||||
Particle<StringDataType> positionName = STRING.particle()
|
|
||||||
.name("title")
|
|
||||||
.description("position name")
|
|
||||||
.constraints(STRING.max(255), STRING.min(3));
|
|
||||||
|
|
||||||
Element position = base.atom()
|
|
||||||
.name("position")
|
|
||||||
.particles(positionName);
|
|
||||||
|
|
||||||
Particle<StringDataType> idNumber = STRING.particle()
|
|
||||||
.name("number")
|
|
||||||
.description("military id number")
|
|
||||||
.constraints(STRING.max(11), STRING.min(11));
|
|
||||||
|
|
||||||
Element militaryId = base.atom()
|
|
||||||
.name("military", "id")
|
|
||||||
.particles(idNumber);
|
|
||||||
|
|
||||||
Element profile = base.atom()
|
|
||||||
.name(("profile"));
|
|
||||||
|
|
||||||
base.links(Universe.linkOneToOne()
|
|
||||||
.from(account)
|
|
||||||
.fromName("details")
|
|
||||||
.to(accountDetails)
|
|
||||||
.toName("account")
|
|
||||||
.mandatory(), Universe.linkOneToMany()
|
|
||||||
.from(account)
|
|
||||||
.fromName("profiles")
|
|
||||||
.to(profile)
|
|
||||||
.toName("account")
|
|
||||||
.more(0), Universe.linkManyToMany()
|
|
||||||
.from(profile)
|
|
||||||
.fromName("positions")
|
|
||||||
.to(position)
|
|
||||||
.toName("profiles"), Universe.linkOneToOne()
|
|
||||||
.from(male)
|
|
||||||
.fromName("military", "id")
|
|
||||||
.to(militaryId)
|
|
||||||
.toName("account"));
|
|
||||||
|
|
||||||
UniverseProject data = workspace.universe()
|
|
||||||
.name("data")
|
|
||||||
.schemas(LITERAL);
|
|
||||||
|
|
||||||
Particle<StringDataType> organizationName = STRING.particle()
|
|
||||||
.name("name")
|
|
||||||
.description("full name of an organization")
|
|
||||||
.constraints(STRING.max(255), STRING.min(3));
|
|
||||||
Element organization = data.atom();
|
|
||||||
organization.name("organization");
|
|
||||||
organization.particles(organizationName);
|
|
||||||
|
|
||||||
Assertions.assertTrue(workspace.saveAs(TestUtils.testRoot()).ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Universe Project load")
|
|
||||||
void projectLoad () {
|
|
||||||
Workspace.load(TestUtils.testRoot());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor-env</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>TraQtor - Environment </name>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.7.1</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>traqtor-json</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>traqtor-schema</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,217 @@
|
|||||||
|
package link.pagan.traqtor.env;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import link.pagan.traqtor.env.actions.OperationObjectResult;
|
||||||
|
import link.pagan.traqtor.env.actions.OperationResult;
|
||||||
|
import link.pagan.traqtor.model.Workspace;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.DataTypeSchema;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.impl.DefaultSchema;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public class Environment {
|
||||||
|
|
||||||
|
private final Map<Name, DataTypeSchema> datatypeSchemas;
|
||||||
|
|
||||||
|
private Environment () {
|
||||||
|
this.datatypeSchemas = new HashMap<Name, DataTypeSchema>();
|
||||||
|
this.addDatatypeSchema(DefaultSchema.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addDatatypeSchema (DataTypeSchema schema) {
|
||||||
|
this.datatypeSchemas.put(schema.name(), schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataTypeSchema schemaByName (Name name) {
|
||||||
|
return datatypeSchemas.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Environment init () {
|
||||||
|
return new Environment();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Workspace workspace () {
|
||||||
|
return new Workspace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public OperationResult saveAs (File parentDir) {
|
||||||
|
// return saveAs(this, parentDir, new OperationResult());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private static OperationResult saveAs (Workspace workspace, File parent, OperationResult result) {
|
||||||
|
//
|
||||||
|
// if (parent == null) {
|
||||||
|
// return result
|
||||||
|
// .info("Target directory must be set, are you OK?")
|
||||||
|
// .fail("Failed to save workspace, no new root directory was passed");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!parent.exists()) {
|
||||||
|
// return result
|
||||||
|
// .info("Directory " + parent.getAbsolutePath() + " does not exist, deleted/moved/unmounted?")
|
||||||
|
// .fail("Failed to save workspace, due non existent parent direcory for new workspace");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (workspace.name() == null) {
|
||||||
|
// return result
|
||||||
|
// .info("Workspace does not contain name - how did you even achieve that?")
|
||||||
|
// .fail("Failed to save workspace, due unknown name of it, huh...");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// File root = new File(parent, workspace.name().asTiled());
|
||||||
|
//
|
||||||
|
// if (!root.exists()) {
|
||||||
|
// result.info("Creating new root direcory at " + root.getAbsolutePath());
|
||||||
|
//
|
||||||
|
// if (!root.mkdirs()) {
|
||||||
|
// return result
|
||||||
|
// .info("Unable to create directory " + root.getAbsolutePath() + " - permission problem?")
|
||||||
|
// .fail("Failed to save workspace, can not create new root directory");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (root.listFiles().length > 0) {
|
||||||
|
// return result
|
||||||
|
// .info("Directory " + root.getAbsolutePath() + " is not empty, not safe to save?")
|
||||||
|
// .fail("Failed to save workspace, due to polluted new root direcory");
|
||||||
|
// }
|
||||||
|
// File oldRoot = workspace.dir();
|
||||||
|
// boolean oldDirty = workspace.dirty();
|
||||||
|
//
|
||||||
|
// workspace.dir(root);
|
||||||
|
// workspace.dirty(true);
|
||||||
|
// result.info("Setting workspace root to " + root.getAbsolutePath());
|
||||||
|
// save(workspace, result.startSubresult());
|
||||||
|
//
|
||||||
|
// if (!result.ok()) {
|
||||||
|
// result.info("Reverting workspace root to " + oldRoot.getAbsolutePath());
|
||||||
|
// workspace.dir(oldRoot);
|
||||||
|
// workspace.dirty(oldDirty);
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public OperationResult save () {
|
||||||
|
// return save(this, new OperationResult());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationResult save (Workspace workspace, OperationResult result) {
|
||||||
|
//
|
||||||
|
// if (!workspace.dirty()) { return result.warn("Workspace is not dirty - no need to save"); }
|
||||||
|
//
|
||||||
|
// result.info("Saving workspace " + workspace.name().asTiled() + " ...");
|
||||||
|
//
|
||||||
|
// if (workspace.dir() == null) {
|
||||||
|
// return result
|
||||||
|
// .info("Workspace root is not set - is this a new workspace?")
|
||||||
|
// .fail("Failed to save workspace, due to unknown root directory");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!workspace.dir().exists()) {
|
||||||
|
// return result
|
||||||
|
// .info("Directory " + workspace.dir().getAbsolutePath() +
|
||||||
|
// " does not exist, deleted/moved/unmounted?")
|
||||||
|
// .fail("Failed to save workspace, due non existent root direcory");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!workspace.dir().canRead()) {
|
||||||
|
// return result
|
||||||
|
// .info("Unable to read " + workspace.dir().getAbsolutePath() + " - permission problem?")
|
||||||
|
// .fail("Failed to save workspace, due unreadable root direcory");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!workspace.dir().canWrite()) {
|
||||||
|
// return result
|
||||||
|
// .info("Unable to write " + workspace.dir().getAbsolutePath() + " - permission problem?")
|
||||||
|
// .fail("Failed to save workspace, due write restriction on root direcory");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (Project project : workspace.projects()) { project.save(result.startSubresult()); }
|
||||||
|
//
|
||||||
|
// writeJson(workspace, result.startSubresult());
|
||||||
|
//
|
||||||
|
// if (result.ok()) { workspace.dirty(false); }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationResult writeJson (Workspace workspace, OperationResult result) {
|
||||||
|
// File file = workspace.file();
|
||||||
|
// result.info("Writing workspace descriptor file to " + file.getAbsolutePath() + " ...");
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// workspace.json().writeValue(file, workspace);
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// return result.fail("Failed to write file " + file.getAbsolutePath() + " - IO exception")
|
||||||
|
// .fail(ex);
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public static OperationObjectResult<Workspace> load (File dir) {
|
||||||
|
// OperationObjectResult<Workspace> result = new OperationObjectResult<Workspace>();
|
||||||
|
// readJson(dir, result);
|
||||||
|
//
|
||||||
|
// for (File projectsDir : dir.listFiles()) {
|
||||||
|
//
|
||||||
|
// if (projectsDir.isDirectory()) {
|
||||||
|
//
|
||||||
|
// ProjectType guessedProjectType = Project.guessProjectType(projectsDir);
|
||||||
|
//
|
||||||
|
// if (guessedProjectType != null) {
|
||||||
|
//
|
||||||
|
// switch (guessedProjectType) {
|
||||||
|
// case UNIVERSE: {
|
||||||
|
// UniverseProject.load(projectsDir);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case DATABASE: {
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case BACKEND: {
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case FRONTEND: {
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationObjectResult<Workspace> readJson (File dir, OperationObjectResult<Workspace> result) {
|
||||||
|
// File file = file(dir);
|
||||||
|
// result.info("Reading workspace from " + dir.getAbsolutePath() + " ...");
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// result.info("Reading json from " + file.getAbsolutePath() + " ...");
|
||||||
|
// result.object(new ObjectMapper().readValue(file, Workspace.class));
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// return result.fail("Failed to read file " + file.getAbsolutePath() + " - IO exception").fail(ex);
|
||||||
|
// }
|
||||||
|
// result.object().dir(file);
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public OperationObjectResult<Workspace> workspaceLoad(File dir) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult workspaceSaveAs(Workspace workspace, File dir) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult workspaceSave(Workspace workspace) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package link.pagan.traqtor.util.op;
|
package link.pagan.traqtor.env.actions;
|
||||||
|
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package link.pagan.traqtor.util.op;
|
package link.pagan.traqtor.env.actions;
|
||||||
|
|
||||||
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
public class OperationObjectResult <T> extends OperationResult {
|
public class OperationObjectResult <T> extends OperationResult {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package link.pagan.traqtor.util.op;
|
package link.pagan.traqtor.env.actions;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor-json</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>TraQtor - Json </name>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.7.1</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.12.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>traqtor-model</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>link.pagan</groupId>
|
||||||
|
<artifactId>traqtor-model</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>TraQtor - Model </name>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.7.1</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
package link.pagan.traqtor.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.Project;
|
||||||
|
import link.pagan.traqtor.model.project.database.DatabaseProject;
|
||||||
|
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
import link.pagan.traqtor.util.io.Directoried;
|
||||||
|
import link.pagan.traqtor.util.io.Filed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class Workspace implements Filed, Directoried {
|
||||||
|
|
||||||
|
// private ObjectMapper json;
|
||||||
|
|
||||||
|
private File root;
|
||||||
|
|
||||||
|
private Name name;
|
||||||
|
|
||||||
|
private boolean dirty;
|
||||||
|
|
||||||
|
private boolean pretty;
|
||||||
|
|
||||||
|
private final List<Project> projects;
|
||||||
|
|
||||||
|
public Workspace() {
|
||||||
|
this.root = null;
|
||||||
|
this.dirty = true;
|
||||||
|
this.pretty = true;
|
||||||
|
// this.json = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
this.projects = new ArrayList<Project>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseProject universe() {
|
||||||
|
UniverseProject project = new UniverseProject(this);
|
||||||
|
this.projects.add(project);
|
||||||
|
this.dirty = true;
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseProject database() {
|
||||||
|
DatabaseProject project = new DatabaseProject(this);
|
||||||
|
this.projects.add(project);
|
||||||
|
this.dirty = true;
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Workspace name(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Project> projects() {
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Workspace projects(Project... projects) {
|
||||||
|
this.projects.addAll(Arrays.asList(projects));
|
||||||
|
this.dirty = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File dir() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File file() {
|
||||||
|
return file(Workspace.this.dir());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File file(File dir) {
|
||||||
|
return new File(dir, ".tw");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Workspace dir(File root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dirty(boolean dirty) {
|
||||||
|
this.dirty = dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean dirty() {
|
||||||
|
return dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean pretty() {
|
||||||
|
return pretty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pretty(boolean pretty) {
|
||||||
|
this.pretty = pretty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package link.pagan.traqtor.model.project;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.util.io.Directoried;
|
||||||
|
import link.pagan.traqtor.util.io.Filed;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.Workspace;
|
||||||
|
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public abstract class Project implements Filed, Directoried {
|
||||||
|
|
||||||
|
public enum ProjectType {
|
||||||
|
|
||||||
|
UNIVERSE, DATABASE, FRONTEND, BACKEND;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Workspace workspace;
|
||||||
|
|
||||||
|
protected Name name;
|
||||||
|
|
||||||
|
protected boolean dirty;
|
||||||
|
|
||||||
|
public Project(Workspace workspace) {
|
||||||
|
this.workspace = workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
|
||||||
|
if (name == null) {
|
||||||
|
return Name.NO_NAME;
|
||||||
|
}
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project name(String... parts) {
|
||||||
|
|
||||||
|
return name(Name.of(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project name(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public abstract OperationResult save (OperationResult result);
|
||||||
|
|
||||||
|
public abstract ProjectType type();
|
||||||
|
|
||||||
|
public Workspace workspace() {
|
||||||
|
return workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProjectType guessProjectType(File projectsDir) {
|
||||||
|
|
||||||
|
for (File file : projectsDir.listFiles()) {
|
||||||
|
|
||||||
|
if (file.isFile()) {
|
||||||
|
|
||||||
|
if (file.getName().endsWith(UniverseProject.EXTENSION)) {
|
||||||
|
return ProjectType.UNIVERSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
//package link.pagan.traqtor.model.project.database.mapping;
|
||||||
|
//
|
||||||
|
//import java.util.HashMap;
|
||||||
|
////import link.pagan.traqtor.mapping.Mapping;
|
||||||
|
////import link.pagan.traqtor.mapping.MappingEntry;
|
||||||
|
//
|
||||||
|
///** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
|
//public class DatabaseMapping extends Mapping {
|
||||||
|
//
|
||||||
|
// public DatabaseMapping (String name, HashMap<MappingEntry, String> mapping) {
|
||||||
|
// super(name, mapping);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
@ -0,0 +1,155 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import link.pagan.traqtor.model.Workspace;
|
||||||
|
import link.pagan.traqtor.model.project.Project;
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Atom;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.DataTypeSchema;
|
||||||
|
import link.pagan.traqtor.model.project.universe.link.Link;
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Element;
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Isotope;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public class UniverseProject extends Project {
|
||||||
|
|
||||||
|
public static final String EXTENSION = ".tup";
|
||||||
|
|
||||||
|
private final Set<DataTypeSchema> schemas;
|
||||||
|
|
||||||
|
private final Set<Element> elements;
|
||||||
|
|
||||||
|
private final Set<Link> links;
|
||||||
|
|
||||||
|
public UniverseProject(Workspace workspace) {
|
||||||
|
super(workspace);
|
||||||
|
this.schemas = new TreeSet<DataTypeSchema>(
|
||||||
|
(DataTypeSchema a, DataTypeSchema b) -> a.name().compareTo(b.name()));
|
||||||
|
this.elements = new TreeSet<Element>((Element a, Element b) -> a.name().compareTo(b.name()));
|
||||||
|
this.links = new TreeSet<Link>((Link a, Link b) -> (a.from().name().asDotted() + "_" + a.fromName().asDotted())
|
||||||
|
.compareTo((b.from().name().asDotted() + "_" + b.fromName().asDotted())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UniverseProject name(String... parts) {
|
||||||
|
return name(Name.of(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UniverseProject name(Name name) {
|
||||||
|
super.name(name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataTypeSchema[] schemas() {
|
||||||
|
return this.schemas.toArray(new DataTypeSchema[this.schemas.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseProject schemas(DataTypeSchema... schemas) {
|
||||||
|
this.schemas.addAll(Arrays.asList(schemas));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element[] elements() {
|
||||||
|
return this.elements.toArray(new Element[this.elements.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseProject elements(Element... element) {
|
||||||
|
this.elements.addAll(Arrays.asList(element));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Link[] links() {
|
||||||
|
return this.links.toArray(new Link[this.links.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseProject links(Link... links) {
|
||||||
|
this.links.addAll(Arrays.asList(links));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public OperationResult save (OperationResult result) {
|
||||||
|
// return save(this, result);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationResult save (UniverseProject project, OperationResult
|
||||||
|
// result) {
|
||||||
|
//
|
||||||
|
// if (!project.dir().exists()) {
|
||||||
|
// result.warn("Project directory " + project.dir().getAbsolutePath() + " does
|
||||||
|
// not exist");
|
||||||
|
// result.info("Creating project directory at " +
|
||||||
|
// project.dir().getAbsolutePath() + " ...");
|
||||||
|
//
|
||||||
|
// if (!project.dir().mkdirs()) {
|
||||||
|
// return result.fail("Failed to created project directory at " +
|
||||||
|
// project.dir().getAbsolutePath());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (Element element : project.elements()) {
|
||||||
|
// element.save(result.startSubresult()); }
|
||||||
|
//
|
||||||
|
// writeJson(project, result.startSubresult());
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationResult writeJson (UniverseProject project,
|
||||||
|
// OperationResult result) {
|
||||||
|
// File file = project.file();
|
||||||
|
// result.info("Writing project descriptor file to " + file.getAbsolutePath() +
|
||||||
|
// " ...");
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// project.workspace().json().writeValue(file, project);
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// result.fail("Failed to write file " + file.getAbsolutePath() + " - IO
|
||||||
|
// exception");
|
||||||
|
// result.fail(ex);
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File file() {
|
||||||
|
return new File(this.dir(), EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File dir() {
|
||||||
|
return new File(workspace.dir(), this.name.asTiled() + "-universe");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Atom atom() {
|
||||||
|
Atom res = new Atom(this);
|
||||||
|
this.elements.add(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Isotope isotope(Element base) {
|
||||||
|
Isotope res = new Isotope(this, base);
|
||||||
|
this.elements.add(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// public static UniverseProject load (File projectsDir) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProjectType type() {
|
||||||
|
return ProjectType.UNIVERSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataTypeSchema schema(Name name) {
|
||||||
|
|
||||||
|
for (DataTypeSchema schema : this.schemas) {
|
||||||
|
if (schema.name().equals(name))
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.element;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.util.io.Filed;
|
||||||
|
import link.pagan.traqtor.model.project.universe.UniverseProject;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public abstract class Element implements Filed {
|
||||||
|
|
||||||
|
protected final UniverseProject project;
|
||||||
|
|
||||||
|
private static final Comparator<Particle> PARTICLE_SORT_COMPARATOR = (Particle a, Particle b) -> a.name().asDotted().compareTo(b.name().asDotted());
|
||||||
|
|
||||||
|
private Name name;
|
||||||
|
|
||||||
|
private final Set<Particle> particles;
|
||||||
|
|
||||||
|
public Element (UniverseProject project) {
|
||||||
|
this.project = project;
|
||||||
|
this.particles = new TreeSet<Particle>(PARTICLE_SORT_COMPARATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name () {
|
||||||
|
|
||||||
|
if (name == null) { return Name.NO_NAME; }
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element name (String... parts) {
|
||||||
|
return name(Name.of(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element name (Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Particle> particles () {
|
||||||
|
return particles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public final Element particles (Particle... particles) {
|
||||||
|
return particles(Arrays.asList(particles));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element particles (List<Particle> particles) {
|
||||||
|
this.particles.addAll(particles);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public OperationResult save (OperationResult result) {
|
||||||
|
// return save(this, result);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private static OperationResult save (Element element, OperationResult result) {
|
||||||
|
//
|
||||||
|
// if (element.getClass().equals(Atom.class) || element.getClass().equals(Isotope.class)) {
|
||||||
|
// writeJson(element, result.startSubresult());
|
||||||
|
// } else {
|
||||||
|
// return result.fail("Unknown element type - not supported class " + element.getClass().getName());
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private static OperationResult writeJson (Element element, OperationResult result) {
|
||||||
|
// File file = element.file();
|
||||||
|
// result.info("Writing element to " + file.getAbsolutePath() + " ...");
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// element.project().workspace().json().writeValue(file, element);
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// result.fail("Failed to write file " + file.getAbsolutePath() + " - IO exception");
|
||||||
|
// result.fail(ex);
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public UniverseProject project () {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,98 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.element;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.DataType;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.Constraint;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public class Particle {
|
||||||
|
|
||||||
|
private Name name;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private final DataType type;
|
||||||
|
|
||||||
|
private final List<ParticleConstraint> constraints;
|
||||||
|
|
||||||
|
public Particle(DataType type) {
|
||||||
|
this.type = type;
|
||||||
|
this.constraints = new ArrayList<ParticleConstraint>();
|
||||||
|
this.constraints.addAll(this.type.typeConstraints());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle name(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle description(String description) {
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
|
||||||
|
if (name == null) {
|
||||||
|
return Name.NO_NAME;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String description() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataType type() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ParticleConstraint> constraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name) {
|
||||||
|
Constraint constraint = this.type.constraint(name);
|
||||||
|
constraint.apply(this);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, long value) {
|
||||||
|
Constraint constraint = this.type.constraint(name);
|
||||||
|
constraint.apply(this, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, int value) {
|
||||||
|
return constraint(name, (long)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, short value) {
|
||||||
|
return constraint(name, (long)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, byte value) {
|
||||||
|
return constraint(name, (long)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, double value) {
|
||||||
|
Constraint constraint = this.type.constraint(name);
|
||||||
|
constraint.apply(this, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, float value) {
|
||||||
|
return constraint(name, (double)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle constraint (Name name, String value) {
|
||||||
|
Constraint constraint = this.type.constraint(name);
|
||||||
|
constraint.apply(this, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,14 +1,28 @@
|
|||||||
package link.pagan.traqtor.model.project.universe.link;
|
package link.pagan.traqtor.model.project.universe.link;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
import link.pagan.traqtor.model.project.universe.element.Element;
|
import link.pagan.traqtor.model.project.universe.element.Element;
|
||||||
import link.pagan.traqtor.util.Name;
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
// @JsonDeserialize(using = LinkDeserializer.class)
|
|
||||||
@JsonSerialize(using = LinkSerializer.class)
|
|
||||||
public abstract class Link {
|
public abstract class Link {
|
||||||
|
|
||||||
|
public enum LinkType {
|
||||||
|
|
||||||
|
ONE_TO_ONE("1->1"),
|
||||||
|
ONE_TO_MANY("1->N"),
|
||||||
|
MANY_TO_MANY("N->N");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private LinkType (String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String code () {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Element from;
|
private Element from;
|
||||||
|
|
||||||
private Element to;
|
private Element to;
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.Constraint;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.impl.NotNull;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
public abstract class DataType {
|
||||||
|
|
||||||
|
private final DataType parent;
|
||||||
|
private final Name name;
|
||||||
|
private final boolean instancable;
|
||||||
|
protected final Constraint[] constraintTypes;
|
||||||
|
|
||||||
|
protected DataType(DataType parent, Name name, boolean instancable) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.name = name;
|
||||||
|
this.instancable = instancable;
|
||||||
|
this.constraintTypes = new Constraint[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DataType(DataType parent, Name name, boolean instancable, Constraint[] typeConstraints) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.name = name;
|
||||||
|
this.instancable = instancable;
|
||||||
|
this.constraintTypes = typeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final DataType getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Name name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isInstancable() {
|
||||||
|
return instancable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint constraint(Name name) {
|
||||||
|
for (Constraint c : this.availableConstraints()) {
|
||||||
|
if (c.name().equals(name)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<Constraint> availableConstraints() {
|
||||||
|
if (this.parent != null) {
|
||||||
|
List<Constraint> res = new ArrayList<Constraint>();
|
||||||
|
res.addAll(Arrays.asList(this.constraintTypes));
|
||||||
|
|
||||||
|
this.parent.availableConstraints().stream().filter(c -> (!res.contains(c))).forEach(c -> {
|
||||||
|
res.add(c);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
return Arrays.asList(this.constraintTypes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected final List<ParticleConstraint> noConstraint = new ArrayList<ParticleConstraint>();
|
||||||
|
|
||||||
|
public List<ParticleConstraint> typeConstraints() {
|
||||||
|
return noConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle instance() {
|
||||||
|
if (this.instancable) {
|
||||||
|
return new Particle(this);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unable to instantiate non-instansable type particle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final static DataType ROOT = new DataType(null, Name.of("root"), false,
|
||||||
|
new Constraint[] { NotNull.CONSTRAINT }) {
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class DataTypeSchema {
|
||||||
|
|
||||||
|
private final Set<DataType> types;
|
||||||
|
|
||||||
|
public DataTypeSchema(DataType[] shemaTypes) {
|
||||||
|
this.types = new TreeSet<DataType>(
|
||||||
|
(DataType a, DataType b) -> a.name().asDotted().compareTo(b.name().asDotted()));
|
||||||
|
for (DataType type : shemaTypes) {
|
||||||
|
this.types.add(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Name name();
|
||||||
|
|
||||||
|
public DataType type(Name name) {
|
||||||
|
|
||||||
|
for (DataType type : this.types) {
|
||||||
|
if (type.name().equals(name)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema.constraint;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class Constraint {
|
||||||
|
|
||||||
|
final Name name;
|
||||||
|
|
||||||
|
public Constraint(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Particle apply(Particle particle);
|
||||||
|
|
||||||
|
public abstract Particle apply(Particle particle, Long value);
|
||||||
|
|
||||||
|
public abstract Particle apply(Particle particle, String value);
|
||||||
|
|
||||||
|
public abstract Particle apply(Particle particle, Double value);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema.constraint;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleFactConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class FactConstraint extends Constraint {
|
||||||
|
|
||||||
|
public FactConstraint(Name name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle) {
|
||||||
|
particle.constraints().add(new ParticleFactConstraint(this));
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Double value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Long value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, String value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema.constraint;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleIntegerConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class IntegerConstraint extends Constraint {
|
||||||
|
|
||||||
|
public IntegerConstraint(Name name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleIntegerConstraint forParticle(long value) {
|
||||||
|
return new ParticleIntegerConstraint(this, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Double value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Long value) {
|
||||||
|
particle.constraints().add(forParticle(value));
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, String value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema.constraint;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleLiteralConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class LiteralConstraint extends Constraint {
|
||||||
|
|
||||||
|
public LiteralConstraint(Name name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Double value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Long value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, String value) {
|
||||||
|
particle.constraints().add(new ParticleLiteralConstraint(this, value));
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package link.pagan.traqtor.model.project.universe.schema.constraint;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.model.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.model.project.universe.schema.constraint.particle.ParticleRationalConstraint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public abstract class RationalConstraint extends Constraint {
|
||||||
|
|
||||||
|
public RationalConstraint(Name name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleRationalConstraint forParticle(double value) {
|
||||||
|
return new ParticleRationalConstraint(this, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, String value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Double value) {
|
||||||
|
particle.constraints().add(forParticle(value));
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle apply(Particle particle, Long value) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue