Moving towar workspace mechanics impl
parent
f02b304cd7
commit
7ae7d38b11
@ -1,36 +1,9 @@
|
|||||||
package link.pagan.traqtor.api.project;
|
package link.pagan.traqtor.api.project;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import link.pagan.traqtor.generator.blueprint.database.DatabaseBlueprint;
|
|
||||||
import link.pagan.traqtor.schema.basic.EndpointSchemaImpl;
|
|
||||||
import link.pagan.traqtor.schema.basic.data.DataTypeSchemaImpl;
|
|
||||||
import link.pagan.traqtor.schema.data.DataTypeSchema;
|
|
||||||
import link.pagan.traqtor.schema.logic.EndpointSchema;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
*/
|
*/
|
||||||
public class Project {
|
public abstract class Project {
|
||||||
|
|
||||||
private EndpointSchema endpointSchema;
|
|
||||||
private DataTypeSchema dataTypeSchema;
|
|
||||||
|
|
||||||
private List<DatabaseBlueprint> dataBases;
|
|
||||||
|
|
||||||
static Project init() {
|
|
||||||
return new Project(new EndpointSchemaImpl(), new DataTypeSchemaImpl());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project(EndpointSchema endpointSchema, DataTypeSchema dataTypeSchema) {
|
|
||||||
this.endpointSchema = endpointSchema;
|
|
||||||
this.dataTypeSchema = dataTypeSchema;
|
|
||||||
this.dataBases = new ArrayList<DatabaseBlueprint>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void addDataBaseBlueprint(DatabaseBlueprint dataBaseBlueprint) {
|
|
||||||
this.dataBases.add(dataBaseBlueprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class UniverseProject extends Project {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,35 +0,0 @@
|
|||||||
package link.pagan.traqtor.api.workspace.command;
|
|
||||||
|
|
||||||
//package link.pagan.traqtor.api.workbench.command;
|
|
||||||
//
|
|
||||||
//import java.io.File;
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import link.pagan.traqtor._api.Command;
|
|
||||||
//import link.pagan.traqtor._api.result.CommandExecResult;
|
|
||||||
//import link.pagan.traqtor.api.workbench.Workbench;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// *
|
|
||||||
// * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
// */
|
|
||||||
//public class WorkbenchCommandSave extends Command<Workbench> {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public CommandExecResult exec(Workbench workbench) {
|
|
||||||
// if (workbench.getRoot() == null) {
|
|
||||||
// return fail("Workspace was not saved before - use \"save as\" command for the first save");
|
|
||||||
// }
|
|
||||||
// File demoDir = new File(workbench.getRoot());
|
|
||||||
// File workbenchFile = new File(demoDir, Workbench.JSON_FILENAME + ".json");
|
|
||||||
// if (!workbenchFile.exists()) {
|
|
||||||
// return fail("Workspace lock file (" + (workbenchFile.getAbsolutePath()) + ") does not exit ");
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// workbench.getMapper().writeValue(workbenchFile, workbench);
|
|
||||||
// } catch (IOException ex) {
|
|
||||||
// return fail("Failed to write" + Workbench.JSON_FILENAME + ".json");
|
|
||||||
// }
|
|
||||||
// return done();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package link.pagan.traqtor.api.workspace.command;
|
|
||||||
|
|
||||||
//package link.pagan.traqtor.api.workbench.command;
|
|
||||||
//
|
|
||||||
//import java.io.File;
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import link.pagan.traqtor._api.Command;
|
|
||||||
//import link.pagan.traqtor._api.result.CommandExecResult;
|
|
||||||
//import link.pagan.traqtor.api.workbench.Workbench;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// *
|
|
||||||
// * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
// */
|
|
||||||
//public class WorkbenchCommandSaveAs extends Command<Workbench> {
|
|
||||||
//
|
|
||||||
// String path;
|
|
||||||
//
|
|
||||||
// public WorkbenchCommandSaveAs(String path) {
|
|
||||||
// this.path = path;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public CommandExecResult exec(Workbench workbench) {
|
|
||||||
// File demoDir = new File(path);
|
|
||||||
// if (!demoDir.exists()) {
|
|
||||||
// if (!demoDir.mkdir()) {
|
|
||||||
// return fail("Failed to create workbench root directory at " + path);
|
|
||||||
// } else {
|
|
||||||
// info("Create workbench root directory at " + path);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (demoDir.listFiles().length > 0) {
|
|
||||||
// return fail("Root directory is not empty, failed to assing " + path + " as root for workspace");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// File workbenchFile = new File(demoDir, Workbench.JSON_FILENAME + ".json");
|
|
||||||
// try {
|
|
||||||
// workbench.getMapper().writeValue(workbenchFile, workbench);
|
|
||||||
// } catch (IOException ex) {
|
|
||||||
// return fail("Failed to write " + Workbench.JSON_FILENAME + ".json");
|
|
||||||
// }
|
|
||||||
// workbench.setRoot(path);
|
|
||||||
// return done();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package link.pagan.traqtor.generator;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import link.pagan.traqtor._api.result.CommandExecResult;
|
||||||
|
import static link.pagan.traqtor._api.result.CommandExecResultStatus.DONE;
|
||||||
|
import link.pagan.traqtor.api.Traqtor;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.LinkType;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.build.LinkBlueprintBuilder;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.build.AtomBlueprintBuilder;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.build.ParticleBlueprintBuilder;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.build.UniverseBlueprintBuilder;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.UniverseBlueprint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
import link.pagan.traqtor.schema.basic.data.DataTypeSchemaReferenceImplementation;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class UniverseBlueprintTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void programmaticBuild() throws JsonProcessingException {
|
||||||
|
UniverseBlueprintBuilder builder = new UniverseBlueprintBuilder(new DataTypeSchemaReferenceImplementation());
|
||||||
|
builder
|
||||||
|
.addAtom(new AtomBlueprintBuilder()
|
||||||
|
.name(Name.of("account"))
|
||||||
|
.description("Base user atom")
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("nickname"))
|
||||||
|
.description("User nickname, just in case")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("email"))
|
||||||
|
.description("Main auth facility for user")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("phone"))
|
||||||
|
.description("Alternative user authentification facility")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("password"))
|
||||||
|
.description("User password")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addAtom(new AtomBlueprintBuilder()
|
||||||
|
.name(Name.of("account", "details"))
|
||||||
|
.description("User info atom")
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("first", "name"))
|
||||||
|
.description("First name of a user")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("last", "name"))
|
||||||
|
.description("Last name of a user")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
.addParticle(new ParticleBlueprintBuilder()
|
||||||
|
.name(Name.of("middle", "names"))
|
||||||
|
.description("Middle names of a user")
|
||||||
|
.type("string")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addLink(new LinkBlueprintBuilder()
|
||||||
|
.from(Name.of("account"))
|
||||||
|
.to(Name.of("account", "details"))
|
||||||
|
.type(LinkType.ONE_TO_ONE)
|
||||||
|
);
|
||||||
|
|
||||||
|
UniverseBlueprint build = builder.build();
|
||||||
|
|
||||||
|
|
||||||
|
Traqtor traqtor = Traqtor.init();
|
||||||
|
CommandExecResult result = traqtor.execute(new Traqtor.CreateWorkspace());
|
||||||
|
assertEquals(result.getStatus(), DONE);
|
||||||
|
assertEquals(traqtor.workspace().dirty(), true);
|
||||||
|
String serialized = traqtor.workspace().mapper().writeValueAsString(build);
|
||||||
|
System.out.println(serialized);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package link.pagan.traqtor.generator.blueprint;
|
package link.pagan.traqtor.generator;
|
||||||
|
|
||||||
import link.pagan.traqtor.generator.blueprint.database.builder.ColumnBlueprintBuilder;
|
import link.pagan.traqtor.generator.blueprint.database.builder.ColumnBlueprintBuilder;
|
||||||
import link.pagan.traqtor.generator.blueprint.database.builder.DatabaseBlueprintBuilder;
|
import link.pagan.traqtor.generator.blueprint.database.builder.DatabaseBlueprintBuilder;
|
||||||
@ -1,25 +1,20 @@
|
|||||||
/*
|
|
||||||
* 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.generator.blueprint;
|
package link.pagan.traqtor.generator.blueprint;
|
||||||
|
|
||||||
import link.pagan.traqtor.generator.blueprint.util.Name;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
*/
|
*/
|
||||||
public class ProjectBlueprint {
|
public abstract class ProjectBlueprint {
|
||||||
|
|
||||||
String name;
|
|
||||||
Name rootPackage;
|
|
||||||
String description;
|
|
||||||
|
|
||||||
|
|
||||||
public void assemble() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// String name;
|
||||||
|
// Name rootPackage;
|
||||||
|
// String description;
|
||||||
|
|
||||||
|
//
|
||||||
|
// public void assemble() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class AtomBlueprint {
|
||||||
|
|
||||||
|
Name name;
|
||||||
|
String description;
|
||||||
|
List<ParticleBlueprint> particles;
|
||||||
|
|
||||||
|
public AtomBlueprint(Name name, String description, List<ParticleBlueprint> particles) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.particles = particles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class AtomBlueprintSerializer extends StdSerializer<AtomBlueprint> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public AtomBlueprintSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprintSerializer(Class<AtomBlueprint> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(AtomBlueprint value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
gen.writeStartObject();
|
||||||
|
gen.writeObjectField("name", value.name);
|
||||||
|
gen.writeStringField("description", value.description);
|
||||||
|
gen.writeArrayFieldStart("particles");
|
||||||
|
for (ParticleBlueprint ab : value.particles) {
|
||||||
|
gen.writeObject(ab);
|
||||||
|
}
|
||||||
|
gen.writeEndArray();
|
||||||
|
gen.writeEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class LinkBlueprint {
|
||||||
|
|
||||||
|
AtomBlueprint from;
|
||||||
|
AtomBlueprint to;
|
||||||
|
LinkType type;
|
||||||
|
|
||||||
|
public LinkBlueprint(AtomBlueprint from, AtomBlueprint to, LinkType type) {
|
||||||
|
this.from = from;
|
||||||
|
this.to = to;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprint from() {
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprint to() {
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class LinkBlueprintSerializer extends StdSerializer<LinkBlueprint> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public LinkBlueprintSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkBlueprintSerializer(Class<LinkBlueprint> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(LinkBlueprint value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
gen.writeStartObject();
|
||||||
|
gen.writeObjectField("name", value.from.name);
|
||||||
|
gen.writeObjectField("to", value.to.name);
|
||||||
|
gen.writeObjectField("type", value.type);
|
||||||
|
gen.writeEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public enum LinkType {
|
||||||
|
MANY_TO_MANY,
|
||||||
|
ONE_TO_MANY,
|
||||||
|
ONE_TO_ONE;
|
||||||
|
|
||||||
|
public static final class LinkTypeSerializer extends StdSerializer<LinkType> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public LinkTypeSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkTypeSerializer(Class<LinkType> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(LinkType value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
if (value.equals(MANY_TO_MANY)) {
|
||||||
|
gen.writeString("MANY_TO_MANY");
|
||||||
|
} else if (value.equals(ONE_TO_MANY)) {
|
||||||
|
gen.writeString("ONE_TO_MANY");
|
||||||
|
} else {
|
||||||
|
gen.writeString("ONE_TO_ONE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
import link.pagan.traqtor.schema.data.DataType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class ParticleBlueprint {
|
||||||
|
|
||||||
|
Name name;
|
||||||
|
String description;
|
||||||
|
DataType type;
|
||||||
|
|
||||||
|
public ParticleBlueprint(Name name, String description, DataType type) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ParticleBlueprintSerializer extends StdSerializer<ParticleBlueprint> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ParticleBlueprintSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBlueprintSerializer(Class<ParticleBlueprint> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ParticleBlueprint value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
gen.writeStartObject();
|
||||||
|
gen.writeObjectField("name", value.name);
|
||||||
|
gen.writeStringField("description", value.description);
|
||||||
|
gen.writeStringField("type", value.type.getName());
|
||||||
|
gen.writeEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.ProjectBlueprint;
|
||||||
|
import link.pagan.traqtor.schema.data.DataTypeSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class UniverseBlueprint extends ProjectBlueprint {
|
||||||
|
|
||||||
|
List<AtomBlueprint> atoms;
|
||||||
|
List<LinkBlueprint> links;
|
||||||
|
DataTypeSchema dataTypeSchema;
|
||||||
|
|
||||||
|
public UniverseBlueprint(List<AtomBlueprint> atoms, List<LinkBlueprint> links, DataTypeSchema dataTypeSchema) {
|
||||||
|
this.atoms = atoms;
|
||||||
|
this.links = links;
|
||||||
|
this.dataTypeSchema = dataTypeSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class UniverseBlueprintSerializer extends StdSerializer<UniverseBlueprint> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public UniverseBlueprintSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseBlueprintSerializer(Class<UniverseBlueprint> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(UniverseBlueprint value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
gen.writeStartObject();
|
||||||
|
gen.writeObjectField("schema", value.dataTypeSchema.getName());
|
||||||
|
gen.writeArrayFieldStart("atoms");
|
||||||
|
for (AtomBlueprint ab : value.atoms) {
|
||||||
|
gen.writeObject(ab);
|
||||||
|
}
|
||||||
|
gen.writeEndArray();
|
||||||
|
gen.writeArrayFieldStart("links");
|
||||||
|
for (LinkBlueprint lb : value.links) {
|
||||||
|
gen.writeObject(lb);
|
||||||
|
}
|
||||||
|
gen.writeEndArray();
|
||||||
|
gen.writeEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe.build;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.AtomBlueprint;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.ParticleBlueprint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class AtomBlueprintBuilder {
|
||||||
|
|
||||||
|
Name name;
|
||||||
|
String description;
|
||||||
|
List<ParticleBlueprintBuilder> particleBuilders;
|
||||||
|
|
||||||
|
public AtomBlueprintBuilder() {
|
||||||
|
this.particleBuilders = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprint build(UniverseBlueprintBuilder builder) {
|
||||||
|
List<ParticleBlueprint> particles = new ArrayList<>();
|
||||||
|
for (ParticleBlueprintBuilder pb : particleBuilders) {
|
||||||
|
particles.add(pb.build(builder));
|
||||||
|
}
|
||||||
|
particles.sort(new Comparator<ParticleBlueprint>() {
|
||||||
|
@Override
|
||||||
|
public int compare(ParticleBlueprint a, ParticleBlueprint b) {
|
||||||
|
return a.name().asDotted().compareTo(b.name().asDotted());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new AtomBlueprint(name, description, particles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Name name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprintBuilder name(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprintBuilder description(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomBlueprintBuilder addParticle(ParticleBlueprintBuilder particle) {
|
||||||
|
this.particleBuilders.add(particle);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe.build;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.AtomBlueprint;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.LinkBlueprint;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.LinkType;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class LinkBlueprintBuilder {
|
||||||
|
|
||||||
|
Name from;
|
||||||
|
Name to;
|
||||||
|
LinkType type;
|
||||||
|
|
||||||
|
public LinkBlueprint build(UniverseBlueprintBuilder builder, ArrayList<AtomBlueprint> atoms) {
|
||||||
|
AtomBlueprint fromAtom = getAtom(from, atoms);
|
||||||
|
if (fromAtom == null) {
|
||||||
|
throw new RuntimeException("Link from atom can not be null");
|
||||||
|
}
|
||||||
|
AtomBlueprint toAtom = getAtom(to, atoms);
|
||||||
|
if (toAtom == null) {
|
||||||
|
throw new RuntimeException("Link to atom can not be null");
|
||||||
|
}
|
||||||
|
return new LinkBlueprint(fromAtom, toAtom, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkBlueprintBuilder from(Name from) {
|
||||||
|
this.from = from;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkBlueprintBuilder to(Name to) {
|
||||||
|
this.to = to;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkBlueprintBuilder type(LinkType type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AtomBlueprint getAtom(Name name, ArrayList<AtomBlueprint> atoms) {
|
||||||
|
for (AtomBlueprint ab : atoms) {
|
||||||
|
if (ab.name().equals(name)) {
|
||||||
|
return ab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe.build;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.ParticleBlueprint;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
import link.pagan.traqtor.schema.data.DataType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class ParticleBlueprintBuilder {
|
||||||
|
|
||||||
|
Name name;
|
||||||
|
String description;
|
||||||
|
String type;
|
||||||
|
|
||||||
|
public ParticleBlueprint build(UniverseBlueprintBuilder builder) {
|
||||||
|
DataType dataType = builder.getType(type);
|
||||||
|
if (dataType == null) {
|
||||||
|
throw new RuntimeException("Particle type was not found on build");
|
||||||
|
}
|
||||||
|
return new ParticleBlueprint(name, description, dataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBlueprintBuilder name(Name name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBlueprintBuilder description(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBlueprintBuilder type(String type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package link.pagan.traqtor.generator.blueprint.universe.build;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.UniverseBlueprint;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.AtomBlueprint;
|
||||||
|
import link.pagan.traqtor.generator.blueprint.universe.LinkBlueprint;
|
||||||
|
import link.pagan.traqtor.schema.data.DataType;
|
||||||
|
import link.pagan.traqtor.schema.data.DataTypeSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class UniverseBlueprintBuilder {
|
||||||
|
|
||||||
|
List<AtomBlueprintBuilder> atomBuilders;
|
||||||
|
List<LinkBlueprintBuilder> linkBuilder;
|
||||||
|
DataTypeSchema dataTypeSchema;
|
||||||
|
|
||||||
|
public UniverseBlueprintBuilder(DataTypeSchema dataTypeSchema) {
|
||||||
|
this.atomBuilders = new ArrayList<>();
|
||||||
|
this.linkBuilder = new ArrayList<>();
|
||||||
|
this.dataTypeSchema = dataTypeSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseBlueprintBuilder addAtom(AtomBlueprintBuilder atom) {
|
||||||
|
this.atomBuilders.add(atom);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseBlueprintBuilder addLink(LinkBlueprintBuilder link) {
|
||||||
|
this.linkBuilder.add(link);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniverseBlueprint build() {
|
||||||
|
ArrayList<AtomBlueprint> atoms = new ArrayList<>();
|
||||||
|
for (AtomBlueprintBuilder ab : atomBuilders) {
|
||||||
|
atoms.add(ab.build(this));
|
||||||
|
}
|
||||||
|
atoms.sort(new Comparator<AtomBlueprint>() {
|
||||||
|
@Override
|
||||||
|
public int compare(AtomBlueprint a, AtomBlueprint b) {
|
||||||
|
return a.name().asDotted().compareTo(b.name().asDotted());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ArrayList<LinkBlueprint> links = new ArrayList<>();
|
||||||
|
for (LinkBlueprintBuilder lb : linkBuilder) {
|
||||||
|
links.add(lb.build(this, atoms));
|
||||||
|
}
|
||||||
|
links.sort(new Comparator<LinkBlueprint>() {
|
||||||
|
@Override
|
||||||
|
public int compare(LinkBlueprint a, LinkBlueprint b) {
|
||||||
|
return (a.from().name().asDotted() + "->" + a.to().name().asDotted()).compareTo(
|
||||||
|
(b.from().name().asDotted() + "->" + b.to().name().asDotted()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new UniverseBlueprint(atoms, links, dataTypeSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataType getType(String type) {
|
||||||
|
for (DataType dt : this.dataTypeSchema.getDataTypes()) {
|
||||||
|
if (dt.getName().equals(type)) {
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.generator.blueprint.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
|
||||||
*/
|
|
||||||
public class Name {
|
|
||||||
|
|
||||||
String [] parts;
|
|
||||||
|
|
||||||
public Name(String[] parts) {
|
|
||||||
this.parts = parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Name of (String... parts) {
|
|
||||||
if (parts == null) {
|
|
||||||
throw new NullPointerException("name can not be null");
|
|
||||||
}
|
|
||||||
if (parts.length < 1) {
|
|
||||||
throw new IllegalArgumentException("name can not be empty");
|
|
||||||
}
|
|
||||||
return new Name(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
package link.pagan.traqtor.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
|
*/
|
||||||
|
public class Name {
|
||||||
|
|
||||||
|
public static final Comparator<Name> COMPARATOR = new Comparator<Name>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Name a, Name b) {
|
||||||
|
return a.asDotted().compareTo(b.asDotted());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
String[] parts;
|
||||||
|
|
||||||
|
public Name(String[] parts) {
|
||||||
|
this.parts = parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Name of(String... parts) {
|
||||||
|
if (parts == null) {
|
||||||
|
throw new NullPointerException("name can not be null");
|
||||||
|
}
|
||||||
|
if (parts.length < 1) {
|
||||||
|
throw new IllegalArgumentException("name can not be empty");
|
||||||
|
}
|
||||||
|
return new Name(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Name name = (Name) o;
|
||||||
|
if (name.parts == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (name.parts.length != this.parts.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < this.parts.length; i++) {
|
||||||
|
if (!this.parts[i].equals(name.parts[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 43 * hash + Arrays.deepHashCode(this.parts);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class NameSerializer extends StdSerializer<Name> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NameSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameSerializer(Class<Name> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(Name value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
|
gen.writeArray(value.parts, 0, value.parts.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class NameDeserializer extends StdDeserializer<Name> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NameDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameDeserializer(Class<Name> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Name deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
|
JsonNode partArray = parser.getCodec().readTree(parser);
|
||||||
|
String[] parts = new String[partArray.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (final JsonNode part : partArray) {
|
||||||
|
parts[i] = part.asText();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Name(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,13 +1,11 @@
|
|||||||
package link.pagan.traqtor.util;
|
package link.pagan.traqtor.util;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
|
||||||
*/
|
*/
|
||||||
public interface Registrable<T> {
|
public interface Registrable<T> {
|
||||||
|
|
||||||
public Map<String, T> register();
|
// public Map<String, T> register();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue