Implemented Universe Project save routine.
parent
c1afb189a1
commit
48a0c2be81
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
|
public interface Directoried {
|
||||||
|
|
||||||
|
public File dir ();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package link.pagan.traqtor.deck;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import link.pagan.traqtor.Workspace;
|
||||||
|
import link.pagan.traqtor.WorkspaceSerializer;
|
||||||
|
import link.pagan.traqtor.project.universe.UniverseProject;
|
||||||
|
import link.pagan.traqtor.project.universe.UniverseProjectSerializer;
|
||||||
|
import link.pagan.traqtor.project.universe.element.Element;
|
||||||
|
import link.pagan.traqtor.project.universe.element.ElementSerializer;
|
||||||
|
import link.pagan.traqtor.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.project.universe.element.PaticleInfoSerializer;
|
||||||
|
import link.pagan.traqtor.project.universe.link.Link;
|
||||||
|
import link.pagan.traqtor.project.universe.link.LinkSerializer;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.Constraint;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.ConstraintInfoSerializer;
|
||||||
|
import link.pagan.traqtor.util.Name;
|
||||||
|
import link.pagan.traqtor.util.NameSerializer;
|
||||||
|
|
||||||
|
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
|
public abstract class SystemConfig {
|
||||||
|
|
||||||
|
public static final ObjectMapper JSON = new ObjectMapper()
|
||||||
|
.enable(SerializationFeature.INDENT_OUTPUT)
|
||||||
|
.registerModule(new SimpleModule()
|
||||||
|
.addSerializer(Name.class, new NameSerializer())
|
||||||
|
.addSerializer(UniverseProject.class, new UniverseProjectSerializer())
|
||||||
|
.addSerializer(Element.class, new ElementSerializer())
|
||||||
|
.addSerializer(Particle.class, new PaticleInfoSerializer())
|
||||||
|
.addSerializer(Constraint.class, new ConstraintInfoSerializer())
|
||||||
|
.addSerializer(Link.class, new LinkSerializer())
|
||||||
|
.addSerializer(Workspace.class, new WorkspaceSerializer()));
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.backend.mapping;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import link.pagan.traqtor.Workspace;
|
||||||
|
import link.pagan.traqtor.deck.op.OperationResult;
|
||||||
|
import link.pagan.traqtor.project.Project;
|
||||||
|
|
||||||
|
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
|
public class BackendProject extends Project {
|
||||||
|
|
||||||
|
public BackendProject (Workspace workspace) {
|
||||||
|
super(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperationResult save (OperationResult result) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose
|
||||||
|
// Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File file () {
|
||||||
|
return new File(this.dir(), "backend.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File dir () {
|
||||||
|
return new File(workspace.dir(), this.name.asTiled() + "-backend");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.frontend;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import link.pagan.traqtor.Workspace;
|
||||||
|
import link.pagan.traqtor.deck.op.OperationResult;
|
||||||
|
import link.pagan.traqtor.project.Project;
|
||||||
|
|
||||||
|
/** @author Edward M. Kagan {@literal <}kaganem{@literal @}2pm.tech{@literal >} */
|
||||||
|
public class FrontendProject extends Project {
|
||||||
|
|
||||||
|
public FrontendProject (Workspace workspace) {
|
||||||
|
super(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperationResult save (OperationResult result) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose
|
||||||
|
// Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File file () {
|
||||||
|
return new File(this.dir(), "frontend.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File dir () {
|
||||||
|
return new File(workspace.dir(), this.name.asTiled() + "-frontend");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package link.pagan.traqtor.test;
|
||||||
|
|
||||||
|
import link.pagan.traqtor.Workspace;
|
||||||
|
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("traqtor", "demo", "workspace");
|
||||||
|
Assertions.assertTrue(!workspace.save().ok());
|
||||||
|
TestUtils.deleteTestRoot();
|
||||||
|
Assertions.assertTrue(!workspace.root(TestUtils.testRoot()).save().ok());
|
||||||
|
TestUtils.rebuildTestRoot();
|
||||||
|
Assertions.assertTrue(workspace.saveAs(TestUtils.testRoot()).ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,175 @@
|
|||||||
|
package link.pagan.traqtor.test.project.universe;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import link.pagan.traqtor.Workspace;
|
||||||
|
import link.pagan.traqtor.project.universe.Universe;
|
||||||
|
import link.pagan.traqtor.project.universe.UniverseProject;
|
||||||
|
import link.pagan.traqtor.project.universe.element.Element;
|
||||||
|
import link.pagan.traqtor.project.universe.element.Particle;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.DatatypeSchema;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.LiteralDataTypeSchema;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.LogicDatatypeSchema;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.NumericDatatypeSchema;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.TemporalDatatypeSchema;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.data.literal.StringDataType;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.data.numeric.integer.IntDataType;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.data.numeric.real.DoubleDataType;
|
||||||
|
import link.pagan.traqtor.project.universe.schema.impl.data.numeric.real.FloatDataType;
|
||||||
|
import link.pagan.traqtor.test.TestUtils;
|
||||||
|
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 () throws JsonProcessingException {
|
||||||
|
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("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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue