Convert business model into micro service specification
Note: For further informaions about MSstack https://msstack.grydtech.com
- Clone repository to your local machine (assume you already installed git if not please install)
git clone https://github.com/msstack/model-converter.git
mvn clean install
- go to target folder
- run
java -jar modelconverter-1.0.jar "b2m" "sample.json" "output.json"
- Mode: "b2m" - convert to micro service model, "m2b" - convert to business model
- Input file (eg: sample.json): Load input file and convert it
- Output file (eg: output.json): Result will save in here
- Add snapshot version to maven pom file
- Follow these instruction when adding dependency
File file = new File(Sample.class.getResource("/sample.json").toURI());
ModelReader modelReader = new DefaultModelReader();
ModelConverter modelConverter = new DefaultModelConverter();
BusinessModel businessModel = modelReader.readBusinessModel(file);
List<MicroServiceModel> microServiceModels = modelConverter.convertToMicroServiceModel(businessModel);
{
"schemaVersion": "0.0.3",
"entities": [
{
"name": "item",
"fields": [
{
"name": "item_code",
"type": "string",
"constraints": ["NOT_NULL"]
},
{
"name": "name",
"type": "string",
"constraints": ["NOT_NULL"]
}
]
},
{
"name": "order",
"fields": [
{
"name": "order_id",
"type": "string",
"constraints": ["NOT_NULL"]
},
{
"name": "items",
"type": "list<{ref:entities#item}>",
"constraints": ["NOT_NULL"]
}
]
}
],
"events": [
{
"name": "order_created",
"entity": "{ref:entities#order}",
"fields": [
{
"name": "order_id",
"type": "string"
},
{
"name": "customer_id",
"type": "string"
}
]
},
{
"name": "order_validated",
"entity": "{ref:entities#order}",
"fields": [
{
"name": "order_id",
"type": "string"
},
{
"name": "status",
"type": "string"
}
]
},
{
"name": "order_accepted",
"entity": "{ref:entities#order}",
"fields": [
{
"name": "order_id",
"type": "string"
}
]
},
{
"name": "order_rejected",
"entity": "{ref:entities#order}",
"fields": [
{
"name": "order_id",
"type": "string"
}
]
}
],
"requests": [
{
"name": "create_order",
"fields": [
{
"name": "customer_id",
"type": "string"
}
]
}
],
"responses": [
{
"name": "order_accepted",
"fields": [
{
"name": "order_id",
"type": "string"
}
]
},
{
"name": "order_rejected",
"fields": [
{
"name": "order_id",
"type": "string"
},
{
"name": "message",
"type": "string"
}
]
}
],
"contracts": [
{
"name": "create_order",
"description": "creates an order in pending state",
"entity": "{ref:entities#order}",
"type": "COMMAND",
"consumes": "{ref:requests#create_order}",
"produces": {
"on_success": ["{ref:events#order_created}"],
"on_failure": []
}
},
{
"name": "validate_order",
"description": "chech if the order is valid",
"entity": "{ref:entities#order}",
"type": "EVENT",
"consumes": "{ref:events#order_created}",
"produces": {
"on_success": ["{ref:events#order_validated}"],
"on_failure": [],
}
},
{
"name": "finalize_order",
"description": "complete creation of order",
"entity": "{ref:entities#order}",
"type": "EVENT",
"consumes": "{ref:events#order_validated}",
"produces": {
"on_success": ["{ref:events#order_accepted}", "{ref:responses#order_accepted}"],
"on_failure": ["{ref:events#order_rejected}", "{ref:responses#order_rejected}"],
}
}
]
}