Proceeding to project API

Edward M. Kagan 5 years ago
parent 7ae7d38b11
commit 84fb87ce56

@ -0,0 +1,24 @@
package link.pagan.traqtor._api;
import link.pagan.traqtor._api.result.CommandExecResult;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public abstract class BinaryCommand<T extends Commanded, R extends Commanded> extends UnaryCommand<T> {
protected R arg2;
public CommandExecResult subexec(BinaryCommand<T, R> subcommand) {
subcommand.setResultHolder(result);
subcommand.setArg(arg);
subcommand.setArg2(arg2);
return subcommand.exec();
}
public void setArg2(R arg2) {
this.arg2 = arg2;
}
}

@ -4,6 +4,6 @@ package link.pagan.traqtor._api;
* *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ */
abstract class Commanded<SELF extends Commanded<SELF>> { public interface Commanded {
} }

@ -1,40 +1,31 @@
package link.pagan.traqtor._api; //package link.pagan.traqtor._api;
//
import link.pagan.traqtor._api.result.CommandExecResult; //import link.pagan.traqtor._api.result.CommandExecResult;
import link.pagan.traqtor._api.result.CommandExecResultStatus; //import link.pagan.traqtor._api.result.CommandExecResultStatus;
//
/** ///**
* // *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} // * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ // */
public abstract class Executor<T extends Executor<T>> extends Commanded<T> { //public abstract class Executor<T extends Executor<T>> extends Commanded<T> {
//
private static boolean paranoindLoggin = false; //
private static boolean mute = true; //
// @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") // public CommandExecResult execute(Command<T> command) {
public CommandExecResult execute(Command<T> command) { // CommandExecResult result = new CommandExecResult();
CommandExecResult result = new CommandExecResult(); // command.setResultHolder(result);
command.setResultHolder(result); // command.exec((T) this);
command.exec((T) this); // if (!mute) {
if (!mute) { // if (paranoindLoggin) {
if (paranoindLoggin) { // result.print();
result.print(); // } else {
} else { // if (result.getStatus() != CommandExecResultStatus.DONE) {
if (result.getStatus() != CommandExecResultStatus.DONE) { // result.print();
result.print(); // }
} // }
} // }
} // return result;
return result; // }
} //
//}
public static void enableParanoindLoggin() {
enableLog();
paranoindLoggin = true;
}
public static void enableLog() {
mute = false;
}
}

@ -8,11 +8,30 @@ import link.pagan.traqtor._api.result.message.CommandExecMessageStatus;
* *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ */
public abstract class Command<T> { public abstract class UnaryCommand<T extends Commanded> {
private static boolean paranoindLoggin = false;
private static boolean mute = true;
public static void enableParanoindLoggin() {
enableLog();
paranoindLoggin = true;
}
public static void enableLog() {
mute = false;
}
protected CommandExecResult result; protected CommandExecResult result;
protected T arg;
public abstract CommandExecResult exec();
public abstract CommandExecResult exec(T object); public CommandExecResult subexec(UnaryCommand<T> subcommand) {
subcommand.setResultHolder(result);
subcommand.setArg(arg);
return subcommand.exec();
}
protected CommandExecResult fail(String message) { protected CommandExecResult fail(String message) {
result.add(new CommandExecMessage(CommandExecMessageStatus.FAIL, message)); result.add(new CommandExecMessage(CommandExecMessageStatus.FAIL, message));
@ -42,4 +61,17 @@ public abstract class Command<T> {
public void setResultHolder(CommandExecResult result) { public void setResultHolder(CommandExecResult result) {
this.result = result; this.result = result;
} }
public void setArg(T arg) {
this.arg = arg;
}
public static boolean paranoidLoggingEnabled() {
return paranoindLoggin;
}
public static boolean mute() {
return mute;
}
} }

@ -20,7 +20,7 @@ public class CommandExecResult {
} }
public boolean OK () { public boolean OK () {
return this.getStatus() == CommandExecResultStatus.DONE; return this.getStatus() != CommandExecResultStatus.FAIL;
} }
public CommandExecResultStatus getStatus() { public CommandExecResultStatus getStatus() {

@ -0,0 +1,303 @@
package link.pagan.traqtor.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import link.pagan.traqtor._api.UnaryCommand;
import link.pagan.traqtor._api.result.CommandExecResult;
import link.pagan.traqtor._api.result.message.CommandExecMessage;
import link.pagan.traqtor._api.result.message.CommandExecMessageStatus;
import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.api.project.universe.UniverseProject;
import link.pagan.traqtor.api.workspace.Workspace;
import link.pagan.traqtor.schema.data.DataTypeSchema;
import link.pagan.traqtor.util.Name;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class API {
private static boolean workspaceExists (CommandExecResult result, Traqtor traqtor) {
if (traqtor.workspace() == null) {
result.add(new CommandExecMessage(CommandExecMessageStatus.FAIL, "No workspace initialized"));
return false;
}
return true;
}
public static class CreateWorkspace extends UnaryCommand<Traqtor> {
private final Name name;
private final String path;
public CreateWorkspace() {
this(Workspace.DEFAULT_WORKSPACE_NAME);
}
public CreateWorkspace(Name name) {
this(name, null);
}
public CreateWorkspace(Name name, String path) {
this.name = name;
this.path = path;
}
@Override
public CommandExecResult exec() {
if (arg.workspace() != null) {
return fail("There is an open workspace - please close this first, before creating new one");
}
arg.workspace(new Workspace());
arg.workspace().name(name);
subexec(new API.WorkspaceLoadDataTypeSchema(Name.of("traqtor", "basic")));
if (!result.OK()) {
arg.workspace(null);
return result;
}
if (path != null) {
subexec(new SaveAsWorkspace(path));
if (!result.OK()) {
arg.workspace(null);
return result;
}
}
return done();
}
}
public static class SaveAsWorkspace extends UnaryCommand<Traqtor> {
private final String workspacePath;
public SaveAsWorkspace(String workspacePath) {
this.workspacePath = workspacePath;
}
@Override
public CommandExecResult exec() {
File workspaceDir = new File(workspacePath);
if (!workspaceDir.exists()) {
if (!workspaceDir.mkdir()) {
return fail("Failed to create workspace root directory at " + workspacePath);
} else {
info("Workspace root directory created at " + workspacePath);
}
} else {
if (workspaceDir.listFiles().length > 0) {
return fail("Root directory is not empty, failed to assing " + workspacePath + " as root for workspace");
}
}
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
try {
if (!workspaceFile.createNewFile()) {
return fail("Failed to create " + Workspace.JSON_FILENAME + ".json in workspace root directory");
}
} catch (IOException ex) {
return fail("IO erorr while creating " + Workspace.JSON_FILENAME + ".json in workspace root directory");
}
}
String hold = arg.workspace().root();
arg.workspace().root(workspacePath);
subexec(new SaveWorkspace());
if (!result.OK()) {
arg.workspace().root(hold);
return result;
}
return done();
}
}
public static class SaveWorkspace extends UnaryCommand<Traqtor> {
@Override
public CommandExecResult exec() {
String workspacePath = arg.workspace().root();
if (arg.workspace().root() == null) {
return fail("Workspace was not saved before - use \"save as\" command for the first save");
}
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
return fail("Failed to save, " + Workspace.JSON_FILENAME + ".json does not exist, workspace corrupted?");
}
if (!workspaceFile.canWrite()) {
return fail("Can not write " + Workspace.JSON_FILENAME + ".json - permission denied");
}
try {
arg.workspace().mapper().writeValue(workspaceFile, arg.workspace());
} catch (IOException ex) {
System.err.println(ex);
return fail("Failed to write " + Workspace.JSON_FILENAME + ".json");
}
//TODO add project save
// for (Project project : arg.workspace().projects()) {
// subexec(new )
// }
arg.workspace().dirty(false);
return done();
}
}
public static class LoadWorkspace extends UnaryCommand<Traqtor> {
private final String workspacePath;
public LoadWorkspace(String workspacePath) {
this.workspacePath = workspacePath;
}
@Override
public CommandExecResult exec() {
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
return fail("No " + Workspace.JSON_FILENAME + ".json file found in selected directory, missed?");
}
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(Workspace.class, new Workspace.WorkspaceDeserializer());
mapper.registerModule(module);
Workspace workspace = null;
try {
workspace = mapper.readValue(workspaceFile, Workspace.class);
} catch (IOException ex) {
System.err.println(ex);
return fail("Failed to read " + workspaceFile.getAbsolutePath());
}
workspace.root(workspacePath);
HashMap<Name, DataTypeSchema> schemas = workspace.dataTypeSchemas();
for (Name name : schemas.keySet()) {
if (schemas.get(name) == null) {
DataTypeSchema loaded = arg.dataTypeSchemas.get(name);
if (loaded == null) {
warn("Shema with name " + name.asDotted() + " was not found in system. Preload or give up");
} else {
schemas.put(name, loaded);
info("Shema " + name.asDotted() + " was found and loaded into workspace on load");
}
}
}
arg.workspace(workspace);
return done();
}
}
public static class WorkspaceLoadDataTypeSchema extends UnaryCommand<Traqtor> {
private final Name name;
public WorkspaceLoadDataTypeSchema(Name name) {
this.name = name;
}
@Override
public CommandExecResult exec() {
if (!workspaceExists(result, arg)) {
return result;
}
DataTypeSchema schema = arg.dataTypeSchemas.get(this.name);
if (schema == null) {
return fail("Unable to load data type schema by name " + name.asDotted());
}
arg.workspace().dataTypeSchemas().put(schema.getName(), schema);
return done();
}
}
public static class WorkspaceCreateUniverseProject extends UnaryCommand<Traqtor> {
private final Name name;
private final Name schema;
public WorkspaceCreateUniverseProject(Name name, Name schema) {
this.name = name;
this.schema = schema;
}
@Override
public CommandExecResult exec() {
if (!workspaceExists(result, arg)) {
return result;
}
Workspace workspace = arg.workspace();
DataTypeSchema dataTypeSchema = workspace.dataTypeSchemas().get(schema);
if (dataTypeSchema == null) {
return fail("Data type schema with name " + schema.asDotted() + " was not found");
}
if (workspace.projects().containsKey(this.name)) {
return fail("Project with name " + this.name + " already exists");
}
Project project = new UniverseProject(name, dataTypeSchema);
workspace.projects().put(project.name(), project);
workspace.dirty(true);
CommandExecResult saveResult = arg.execute(new API.SaveWorkspace());
if (!saveResult.OK()) {
return fail("Failed to save workspace, after project addition");
}
return done();
}
}
public static class ProjectSave extends UnaryCommand<Traqtor> {
private final Name name;
private final Name schema;
public ProjectSave(Name name, Name schema) {
this.name = name;
this.schema = schema;
}
@Override
public CommandExecResult exec() {
if (!workspaceExists(result, arg)) {
return result;
}
Workspace workspace = arg.workspace();
DataTypeSchema dataTypeSchema = workspace.dataTypeSchemas().get(schema);
if (dataTypeSchema == null) {
return fail("Data type schema with name " + schema.asDotted() + " was not found");
}
if (workspace.projects().containsKey(this.name)) {
return fail("Project with name " + this.name + " already exists");
}
Project project = new UniverseProject(name, dataTypeSchema);
workspace.projects().put(project.name(), project);
workspace.dirty(true);
CommandExecResult saveResult = arg.execute(new API.SaveWorkspace());
if (!saveResult.OK()) {
return fail("Failed to save workspace, after project addition");
}
return done();
}
}
}

@ -1,14 +1,11 @@
package link.pagan.traqtor.api; package link.pagan.traqtor.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import link.pagan.traqtor._api.Command; import link.pagan.traqtor._api.UnaryCommand;
import link.pagan.traqtor._api.Executor; import link.pagan.traqtor._api.Commanded;
import link.pagan.traqtor._api.result.CommandExecResult; import link.pagan.traqtor._api.result.CommandExecResult;
import link.pagan.traqtor._api.result.CommandExecResultStatus;
import link.pagan.traqtor.api.workspace.Workspace; import link.pagan.traqtor.api.workspace.Workspace;
import link.pagan.traqtor.schema.basic.data.DataTypeSchemaReferenceImplementation; import link.pagan.traqtor.schema.basic.data.DataTypeSchemaReferenceImplementation;
import link.pagan.traqtor.schema.data.DataTypeSchema; import link.pagan.traqtor.schema.data.DataTypeSchema;
@ -18,7 +15,7 @@ import link.pagan.traqtor.util.Name;
* *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ */
public class Traqtor extends Executor<Traqtor> { public class Traqtor implements Commanded {
private Workspace workspace; private Workspace workspace;
@ -30,7 +27,7 @@ public class Traqtor extends Executor<Traqtor> {
return traqtor; return traqtor;
} }
private void registerDataTypeSchema (DataTypeSchema schema){ private void registerDataTypeSchema(DataTypeSchema schema) {
this.dataTypeSchemas.put(schema.getName(), schema); this.dataTypeSchemas.put(schema.getName(), schema);
} }
@ -42,171 +39,25 @@ public class Traqtor extends Executor<Traqtor> {
return workspace; return workspace;
} }
public static class CreateWorkspace extends Command<Traqtor> { public void workspace(Workspace workspace) {
this.workspace = workspace;
private final Name name;
private final String path;
public CreateWorkspace() {
this(Workspace.DEFAULT_WORKSPACE_NAME);
}
public CreateWorkspace(Name name) {
this(name, null);
}
public CreateWorkspace(Name name, String path) {
this.name = name;
this.path = path;
}
@Override
public CommandExecResult exec(Traqtor traqtor) {
if (traqtor.workspace != null) {
return fail("There is an open workspace - please close this first, before creating new one");
} }
traqtor.workspace = new Workspace();
traqtor.workspace.name(name);
DataTypeSchemaReferenceImplementation dataTypeSchemaReferenceImplementation = new DataTypeSchemaReferenceImplementation();
traqtor.workspace.schemas().put(dataTypeSchemaReferenceImplementation.getName(), dataTypeSchemaReferenceImplementation);
if (path != null) {
SaveAsWorkspace saveAsWorkspace = new SaveAsWorkspace(path);
saveAsWorkspace.setResultHolder(result);
saveAsWorkspace.exec(traqtor);
if (!result.OK()) {
traqtor.workspace = null;
return result;
}
}
return done();
}
}
public static class SaveAsWorkspace extends Command<Traqtor> {
private final String workspacePath; public CommandExecResult execute(UnaryCommand<Traqtor> command) {
CommandExecResult result = new CommandExecResult();
public SaveAsWorkspace(String workspacePath) { command.setResultHolder(result);
this.workspacePath = workspacePath; command.setArg(this);
} command.exec();
if (!UnaryCommand.mute()) {
@Override if (UnaryCommand.paranoidLoggingEnabled()) {
public CommandExecResult exec(Traqtor traqtor) { result.print();
File workspaceDir = new File(workspacePath);
if (!workspaceDir.exists()) {
if (!workspaceDir.mkdir()) {
return fail("Failed to create workspace root directory at " + workspacePath);
} else { } else {
info("Workspace root directory created at " + workspacePath); if (result.getStatus() != CommandExecResultStatus.DONE) {
} result.print();
} else {
if (workspaceDir.listFiles().length > 0) {
return fail("Root directory is not empty, failed to assing " + workspacePath + " as root for workspace");
}
}
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
try {
if (!workspaceFile.createNewFile()) {
return fail("Failed to create " + Workspace.JSON_FILENAME + ".json in workspace root directory");
} }
} catch (IOException ex) {
return fail("IO erorr while creating " + Workspace.JSON_FILENAME + ".json in workspace root directory");
} }
} }
String hold = traqtor.workspace.root();
traqtor.workspace.root(workspacePath);
SaveWorkspace saveWorkspace = new SaveWorkspace();
saveWorkspace.setResultHolder(result);
saveWorkspace.exec(traqtor);
if (!result.OK()) {
traqtor.workspace.root(hold);
return result; return result;
} }
return done();
}
}
public static class SaveWorkspace extends Command<Traqtor> {
@Override
public CommandExecResult exec(Traqtor traqtor) {
String workspacePath = traqtor.workspace.root();
if (traqtor.workspace.root() == null) {
return fail("Workspace was not saved before - use \"save as\" command for the first save");
}
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
return fail("Failed to save, " + Workspace.JSON_FILENAME + ".json does not exist, workspace corrupted?");
}
if (!workspaceFile.canWrite()) {
return fail("Can not write " + Workspace.JSON_FILENAME + ".json - permission denied");
}
try {
traqtor.workspace.mapper().writeValue(workspaceFile, traqtor.workspace);
} catch (IOException ex) {
System.err.println(ex);
return fail("Failed to write " + Workspace.JSON_FILENAME + ".json");
}
traqtor.workspace.dirty(false);
return done();
}
}
public static class LoadWorkspace extends Command<Traqtor> {
private final String workspacePath;
public LoadWorkspace(String workspacePath) {
this.workspacePath = workspacePath;
}
@Override
public CommandExecResult exec(Traqtor traqtor) {
File workspaceFile = new File(workspacePath, Workspace.JSON_FILENAME + ".json");
if (!workspaceFile.exists()) {
return fail("No " + Workspace.JSON_FILENAME + ".json file found in selected directory, missed?");
}
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(Workspace.class, new Workspace.WorkspaceDeserializer());
mapper.registerModule(module);
Workspace workspace = null;
try {
workspace = mapper.readValue(workspaceFile, Workspace.class);
} catch (IOException ex) {
System.err.println(ex);
return fail("Failed to read " + workspaceFile.getAbsolutePath());
}
workspace.root(workspacePath);
HashMap<Name, DataTypeSchema> schemas = workspace.schemas();
for (Name name : schemas.keySet()) {
if (schemas.get(name) == null) {
DataTypeSchema loaded = traqtor.dataTypeSchemas.get(name);
if (loaded == null){
warn("Shema with name " + name.asDotted() + " was not found in system. Preload or give up");
} else {
schemas.put(name, loaded);
info("Shema " + name.asDotted() + " was found and loaded into workspace on load");
}
}
}
traqtor.workspace = workspace;
return done();
}
}
} }

@ -1,9 +1,42 @@
package link.pagan.traqtor.api.project; package link.pagan.traqtor.api.project;
import link.pagan.traqtor._api.Commanded;
import link.pagan.traqtor.util.Name;
/** /**
* *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ */
public abstract class Project { public abstract class Project implements Commanded {
private final ProjectType type;
private Name name;
private boolean dirty;
public Project(ProjectType type, Name name) {
this.type = type;
this.name = name;
this.dirty = true;
}
public ProjectType type() {
return type;
}
public Name name() {
return name;
}
public void name(Name name) {
this.name = name;
}
public boolean dirty() {
return dirty;
}
public void dirty(boolean dirty) {
this.dirty = dirty;
}
} }

@ -0,0 +1,74 @@
package link.pagan.traqtor.api.project;
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;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public enum ProjectType {
UNIVERSE("universe"),
DATABASE("database"),
FRONTEND("frontend"),
BACKEND("backend");
String jsonValue;
private ProjectType(String jsonValue) {
this.jsonValue = jsonValue;
}
public static final class ProjectTypeSerializer extends StdSerializer<ProjectType> {
private static final long serialVersionUID = 1L;
public ProjectTypeSerializer() {
this(null);
}
public ProjectTypeSerializer(Class<ProjectType> t) {
super(t);
}
@Override
public void serialize(ProjectType value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.jsonValue);
}
}
public static final class ProjectTypeDeserializer extends StdDeserializer<ProjectType> {
private static final long serialVersionUID = 1L;
public ProjectTypeDeserializer() {
this(null);
}
public ProjectTypeDeserializer(Class<ProjectType> t) {
super(t);
}
@Override
public ProjectType deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode stringType = parser.getCodec().readTree(parser);
String type = stringType.asText();
for (ProjectType pt : values()) {
if (pt.jsonValue.equals(type)) {
return pt;
}
}
return null;
}
}
}

@ -1,14 +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.api.project;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class UniverseProject extends Project {
}

@ -0,0 +1,22 @@
/*
* 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.backend;
import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.api.project.ProjectType;
import link.pagan.traqtor.util.Name;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class BackendProject extends Project {
public BackendProject(Name name) {
super(ProjectType.BACKEND, name);
}
}

@ -0,0 +1,22 @@
/*
* 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.database;
import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.api.project.ProjectType;
import link.pagan.traqtor.util.Name;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class DatabaseProject extends Project {
public DatabaseProject(Name name) {
super(ProjectType.DATABASE, name);
}
}

@ -0,0 +1,22 @@
/*
* 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.frontend;
import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.api.project.ProjectType;
import link.pagan.traqtor.util.Name;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class FrontendProject extends Project {
public FrontendProject(Name name) {
super(ProjectType.FRONTEND, name);
}
}

@ -0,0 +1,22 @@
package link.pagan.traqtor.api.project.universe;
import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.api.project.ProjectType;
import link.pagan.traqtor.schema.data.DataTypeSchema;
import link.pagan.traqtor.util.Name;
/**
*
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/
public class UniverseProject extends Project {
DataTypeSchema dataTypeSchema;
public UniverseProject(Name name, DataTypeSchema dataTypeSchema) {
super(ProjectType.UNIVERSE, name);
this.dataTypeSchema = dataTypeSchema;
}
}

@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import link.pagan.traqtor._api.Executor; import link.pagan.traqtor._api.Commanded;
import link.pagan.traqtor.api.project.Project; import link.pagan.traqtor.api.project.Project;
import link.pagan.traqtor.generator.blueprint.universe.AtomBlueprint; import link.pagan.traqtor.generator.blueprint.universe.AtomBlueprint;
import link.pagan.traqtor.generator.blueprint.universe.LinkBlueprint; import link.pagan.traqtor.generator.blueprint.universe.LinkBlueprint;
@ -28,7 +28,7 @@ import link.pagan.traqtor.util.Name;
* *
* @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >}
*/ */
public class Workspace extends Executor<Workspace> { public class Workspace implements Commanded {
public static final String JSON_FILENAME = "workspace"; public static final String JSON_FILENAME = "workspace";
public static final Name DEFAULT_WORKSPACE_NAME = Name.of("workspace"); public static final Name DEFAULT_WORKSPACE_NAME = Name.of("workspace");
@ -40,7 +40,6 @@ public class Workspace extends Executor<Workspace> {
private String root; private String root;
private Name name; private Name name;
private HashMap<Name, DataTypeSchema> schemas; private HashMap<Name, DataTypeSchema> schemas;
private HashMap<Name, Project> projects; private HashMap<Name, Project> projects;
@ -91,7 +90,7 @@ public class Workspace extends Executor<Workspace> {
this.dirty = dirty; this.dirty = dirty;
} }
public HashMap<Name, DataTypeSchema> schemas() { public HashMap<Name, DataTypeSchema> dataTypeSchemas() {
return schemas; return schemas;
} }

@ -28,13 +28,13 @@ public class TraqtorTest {
@DisplayName("New workspace creation") @DisplayName("New workspace creation")
void newWorkspaceSave() { void newWorkspaceSave() {
Traqtor traqtor = Traqtor.init(); Traqtor traqtor = Traqtor.init();
result = traqtor.execute(new Traqtor.CreateWorkspace()); result = traqtor.execute(new API.CreateWorkspace());
assertEquals(DONE, result.getStatus()); assertEquals(DONE, result.getStatus());
assertEquals(traqtor.workspace().dirty(), true); assertEquals(traqtor.workspace().dirty(), true);
result = traqtor.execute(new Traqtor.SaveWorkspace()); result = traqtor.execute(new API.SaveWorkspace());
assertEquals(FAIL, result.getStatus()); assertEquals(FAIL, result.getStatus());
assertEquals(traqtor.workspace().dirty(), true); assertEquals(traqtor.workspace().dirty(), true);
result = traqtor.execute(new Traqtor.SaveAsWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_ROOT)); result = traqtor.execute(new API.SaveAsWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_ROOT));
assertEquals(DONE, result.getStatus()); assertEquals(DONE, result.getStatus());
assertEquals(traqtor.workspace().dirty(), false); assertEquals(traqtor.workspace().dirty(), false);
} }
@ -43,18 +43,17 @@ public class TraqtorTest {
@DisplayName("Workspace load") @DisplayName("Workspace load")
void newSaveLoad() { void newSaveLoad() {
Traqtor traqtor = Traqtor.init(); Traqtor traqtor = Traqtor.init();
result = traqtor.execute(new Traqtor.CreateWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_NAME, TraqtorApiTestUtils.TEST_WORKSPACE_ROOT)); result = traqtor.execute(new API.CreateWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_NAME, TraqtorApiTestUtils.TEST_WORKSPACE_ROOT));
assertEquals(DONE, result.getStatus()); assertEquals(DONE, result.getStatus());
assertEquals(traqtor.workspace().dirty(), false); assertEquals(traqtor.workspace().dirty(), false);
traqtor = Traqtor.init(); traqtor = Traqtor.init();
result = traqtor.execute(new Traqtor.LoadWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_ROOT)); result = traqtor.execute(new API.LoadWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_ROOT));
assertEquals(DONE, result.getStatus()); assertEquals(DONE, result.getStatus());
assertEquals(traqtor.workspace().dirty(), false); assertEquals(traqtor.workspace().dirty(), false);
assertEquals(traqtor.workspace().schemas().size(), 1); assertEquals(traqtor.workspace().dataTypeSchemas().size(), 1);
result = traqtor.execute(new Traqtor.SaveWorkspace()); result = traqtor.execute(new API.SaveWorkspace());
assertEquals(DONE, result.getStatus()); assertEquals(DONE, result.getStatus());
assertEquals(traqtor.workspace().dirty(), false); assertEquals(traqtor.workspace().dirty(), false);
} }
} }

@ -1,55 +1,35 @@
package link.pagan.traqtor.api.workspace; package link.pagan.traqtor.api.workspace;
//package link.pagan.traqtor.api.workbench; import java.io.IOException;
// import link.pagan.traqtor._api.TraqtorApiTestUtils;
//import link.pagan.traqtor.api.workbench.command.WorkbenchCommandSaveAs; import link.pagan.traqtor._api.result.CommandExecResult;
//import link.pagan.traqtor.api.workbench.command.WorkbenchCommandSave; import static link.pagan.traqtor._api.result.CommandExecResultStatus.DONE;
//import java.io.IOException; import link.pagan.traqtor.api.API;
//import link.pagan.traqtor._api.PrimedTest; import link.pagan.traqtor.api.Traqtor;
//import link.pagan.traqtor._api.Executor; import link.pagan.traqtor.util.Name;
//import link.pagan.traqtor._api.result.CommandExecResult; import static org.junit.jupiter.api.Assertions.assertEquals;
//import static link.pagan.traqtor._api.result.CommandExecResultStatus.DONE; import org.junit.jupiter.api.BeforeEach;
//import static link.pagan.traqtor._api.result.CommandExecResultStatus.FAIL; import org.junit.jupiter.api.DisplayName;
//import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.BeforeEach; public class WorkspaceTest {
//import org.junit.jupiter.api.Test;
// CommandExecResult result;
///**
// * @BeforeEach
// * @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} public void cleanTestDir() throws IOException {
// */ TraqtorApiTestUtils.killTestRoot();
//public class WorkbenchTest { // Executor.enableParanoindLoggin();
// }
// @BeforeAll
// public static void setup() throws IOException { @Test
// Executor.enableParanoindLoggin(); @DisplayName("Create project")
// } void newSaveLoad() {
// Traqtor traqtor = Traqtor.init();
// @BeforeEach result = traqtor.execute(new API.CreateWorkspace(TraqtorApiTestUtils.TEST_WORKSPACE_NAME, TraqtorApiTestUtils.TEST_WORKSPACE_ROOT));
// public void clean() throws IOException { assertEquals(DONE, result.getStatus());
// killTestRoot(); assertEquals(traqtor.workspace().dirty(), false);
// } traqtor.execute(new API.WorkspaceCreateUniverseProject(Name.of("universe"), Name.of("traqtor", "basic")));
// }
//// @Test
//// void initSave() { }
//// CommandExecResult result = Workbench.init().exec(new WorkbenchCommandSave());
//// assertEquals(FAIL, result.getStatus());
//// }
////
//// @Test
//// void initSaveAs() {
//// CommandExecResult result = Workbench.init().exec(new WorkbenchCommandSaveAs(TEST_ROOT));
//// assertEquals(DONE, result.getStatus());
//// }
////
//// @Test
//// void initSaveAsSave() {
//// Workbench workbench = Workbench.init();
//// CommandExecResult result = workbench.exec(new WorkbenchCommandSaveAs(TEST_ROOT));
//// assertEquals(DONE, result.getStatus());
//// result = workbench.exec(new WorkbenchCommandSave());
//// assertEquals(DONE, result.getStatus());
//// }
//
//}

@ -3,6 +3,7 @@ package link.pagan.traqtor.generator;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import link.pagan.traqtor._api.result.CommandExecResult; import link.pagan.traqtor._api.result.CommandExecResult;
import static link.pagan.traqtor._api.result.CommandExecResultStatus.DONE; import static link.pagan.traqtor._api.result.CommandExecResultStatus.DONE;
import link.pagan.traqtor.api.API;
import link.pagan.traqtor.api.Traqtor; import link.pagan.traqtor.api.Traqtor;
import link.pagan.traqtor.generator.blueprint.universe.LinkType; 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.LinkBlueprintBuilder;
@ -78,7 +79,7 @@ public class UniverseBlueprintTest {
Traqtor traqtor = Traqtor.init(); Traqtor traqtor = Traqtor.init();
CommandExecResult result = traqtor.execute(new Traqtor.CreateWorkspace()); CommandExecResult result = traqtor.execute(new API.CreateWorkspace());
assertEquals(result.getStatus(), DONE); assertEquals(result.getStatus(), DONE);
assertEquals(traqtor.workspace().dirty(), true); assertEquals(traqtor.workspace().dirty(), true);
String serialized = traqtor.workspace().mapper().writeValueAsString(build); String serialized = traqtor.workspace().mapper().writeValueAsString(build);

Loading…
Cancel
Save