CML to JDL file using JHipster is not working and the file that is generated using the templates are incomplete
below the details of the code
The CML file that I used for this JDL generation is here
GenericContentGenerator genericContentGenerator = new GenericContentGenerator();
genericContentGenerator.setFreemarkerTemplateFile(getTemplateFile(projectType)); genericContentGenerator.setTargetFileName(inputFileName + ".jdl");
contextMapper.callGenerator(cmlResource, genericContentGenerator);
logger.info("JDL Files Successfully created");
the Freemarker template that i used for this below
<#--
This template generates a JHipster JDL file.
Please consult our online tutorial https://contextmapper.org/docs/jhipster-microservice-generation/ to learn how to use it.
-->
<#--
variables to collect entity names and references:
-->
<#assign allEntityNames = [] />
<#assign oneToManyRefs = [] />
<#assign oneToOneRefs = [] />
<#--
counter to give microservices different ports
-->
<#assign portCounter = 8083 />
<#--
loop to collect entity data per Bounded Context (BC) and create application plus microservice for each BC
-->
<#list filterStructuralBoundedContexts(boundedContexts) as bc>
<#assign entities = [] />
<#assign entityNames = [] />
<#list bc.aggregates as agg>
<#assign entities = entities + agg.domainObjects?filter(dob -> instanceOf(dob, Entity) || instanceOf(dob, ValueObject))>
</#list>
<#assign entityNames = entities?map(e -> e.name)>
<#assign allEntityNames = allEntityNames + entityNames>
<#if entities?has_content>
/* Bounded Context ${bc.name} */<#lt>
<#list entities as entity>
entity ${entity.name} {
<#list entity.attributes as attribute>
${attribute.name} ${mapAttributeType(attribute.type)}
</#list>
}
<#list entity.references as reference>
<#if reference.domainObjectType?has_content && (instanceOf(reference.domainObjectType, Entity) || instanceOf(reference.domainObjectType, ValueObject)) && entityNames?seq_contains(reference.domainObjectType.name)>
<#if reference.collectionType?has_content && reference.collectionType.name() != "NONE">
<#assign oneToManyRefs = oneToManyRefs + [ entity.name + "{" + reference.name + "} to " + reference.domainObjectType.name ]>
<#else>
<#assign oneToOneRefs = oneToOneRefs + [ entity.name + "{"+ reference.name + "} to " + reference.domainObjectType.name ]>
</#if>
</#if>
</#list>
</#list>
microservice ${entityNames?join(", ")} with ${bc.name}<#lt>
</#if>
<#assign portCounter++ />
application {
config {
baseName ${bc.name}
packageName ${bc.name?lower_case}
applicationType microservice
serverPort ${portCounter?int?c}
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
<#if entityNames?has_content>
entities ${entityNames?join(", ")}
</#if>
}
</#list>
<#--
here we print the collected references as relationships:
-->
/* relationships */
<#if oneToManyRefs?has_content>
relationship OneToMany {<#lt>
<#list oneToManyRefs as reference>
${reference}
</#list>
}<#lt>
</#if>
<#if oneToOneRefs?has_content>
relationship OneToOne {<#lt>
<#list oneToOneRefs as reference>
${reference}
</#list>
}<#lt>
</#if>
<#--
create a microservice gateway (user interface)
-->
/* microservice gateway app */
application {
config {
baseName gateway
packageName gateway
applicationType gateway
serverPort 8080
}
<#if allEntityNames?has_content>
entities ${allEntityNames?join(", ")}
</#if>
}
<#--
additional configurations for the JHipster generator:
-->
/* additional options */
dto * with mapstruct
service * with serviceImpl
<#-- Data type mapping: -->
<#function mapAttributeType inputType>
<#if inputType == "String">
<#return "String">
<#elseif inputType == "int" || inputType == "Integer">
<#return "Integer">
<#elseif inputType == "long" || inputType == "Long">
<#return "Long">
<#elseif inputType == "boolean" || inputType == "Boolean">
<#return "Boolean">
<#elseif inputType == "Date" || inputType == "DateTime" || inputType == "Timestamp">
<#return "LocalDate">
<#elseif inputType == "BigDecimal" || inputType == "BigInteger">
<#return "BigDecimal">
<#elseif inputType == "double" || inputType == "Double">
<#return "Double">
<#elseif inputType == "float" || inputType == "Float">
<#return "Float">
<#elseif inputType == "Key">
<#return "UUID">
<#elseif inputType == "Blob" || inputType =="Object[]">
<#return "Blob">
<#elseif inputType == "Clob">
<#return "TextBlob">
<#else>
<#return "Blob">
</#if>
</#function>
now when I generate the JDL file , the jdl file is getting created but seems to be incomplete O/P of the jdl file that is created is below
/* Bounded Context CustomerManagementContext */
entity Customer {
firstname String
lastname String
}
entity Address {
street String
postalCode Integer
city String
}
entity SocialInsuranceNumber {
sin String
}
microservice Customer, Address, SocialInsuranceNumber with CustomerManagementContext
application {
config {
baseName CustomerManagementContext
packageName customermanagementcontext
applicationType microservice
serverPort 8084
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities Customer, Address, SocialInsuranceNumber
}
/* Bounded Context CustomerSelfServiceContext */
entity CustomerAddressChange {
}
entity UserAccount {
username String
}
microservice CustomerAddressChange, UserAccount with CustomerSelfServiceContext
application {
config {
baseName CustomerSelfServiceContext
packageName customerselfservicecontext
applicationType microservice
serverPort 8085
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities CustomerAddressChange, UserAccount
}
/* Bounded Context PrintingContext */
entity PrintingJob {
printingId Integer
}
entity Document {
source Blob
template String
}
entity Template {
templateId Integer
templateName String
}
microservice PrintingJob, Document, Template with PrintingContext
application {
config {
baseName PrintingContext
packageName printingcontext
applicationType microservice
serverPort 8086
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities PrintingJob, Document, Template
}
/* Bounded Context PolicyManagementContext */
entity Offer {
offerId Integer
price BigDecimal
}
entity Contract {
}
entity ContractId {
contractId Integer
}
entity Policy {
policyNr Integer
price BigDecimal
}
microservice Offer, Contract, ContractId, Policy with PolicyManagementContext
application {
config {
baseName PolicyManagementContext
packageName policymanagementcontext
applicationType microservice
serverPort 8087
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities Offer, Contract, ContractId, Policy
}
/* Bounded Context RiskManagementContext */
entity CustomerRiskFactor {
totalRiskFactor Integer
}
entity Risk {
likelihood Integer
risk String
}
microservice CustomerRiskFactor, Risk with RiskManagementContext
application {
config {
baseName RiskManagementContext
packageName riskmanagementcontext
applicationType microservice
serverPort 8088
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities CustomerRiskFactor, Risk
}
/* Bounded Context DebtCollection */
entity Debt {
debtNr Integer
creationDate LocalDate
paymentDate LocalDate
paymentDeadline LocalDate
price BigDecimal
status Blob
}
entity Dunning {
dunningNr Integer
dunningDate LocalDate
paymentDeadline LocalDate
}
microservice Debt, Dunning with DebtCollection
application {
config {
baseName DebtCollection
packageName debtcollection
applicationType microservice
serverPort 8089
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities Debt, Dunning
}
/* Bounded Context NewBoundedContext1 */
entity Product {
productName String
}
entity ProductId {
productId Integer
}
microservice Product, ProductId with NewBoundedContext1
application {
config {
baseName NewBoundedContext1
packageName newboundedcontext1
applicationType microservice
serverPort 8090
enableSwaggerCodegen true
clientFramework react
prodDatabaseType postgresql
}
entities Product, ProductId
}
/* relationships */
relationship OneToMany {
Customer{addresses} to Address
CustomerRiskFactor{risks} to Risk
Debt{dunnigs} to Dunning
}
relationship OneToOne {
Customer{sin} to SocialInsuranceNumber
CustomerAddressChange{issuer} to UserAccount
PrintingJob{document} to Document
PrintingJob{template} to Template
Contract{identifier} to ContractId
Policy{contract} to Contract
Dunning{debt} to Debt
Product{identifier} to ProductId
}
/* microservice gateway app */
application {
config {
baseName gateway
packageName gateway
applicationType gateway
serverPort 8080
}
entities Customer, Address, SocialInsuranceNumber, CustomerAddressChange, UserAccount, PrintingJob, Document, Template, Offer, Contract, ContractId, Policy, CustomerRiskFactor, Risk, Debt, Dunning, Product, ProductId
}
/* additional options */
dto * with mapstruct
service * with serviceImpl
**g{debt} to Debt
Product{identifier} to ProductId
}
/* microservice gateway app */
application {
config {
baseName gateway
packageName gateway
applicationType gateway
serverPort 8080
}
entities Customer, Address, SocialInsuranceNumber, CustomerAddressChange, UserAccount, Pr**
In the above o/p, the fonts that are marked in bold are wrongly generated as an extra. Not sure why the Maven tags refered for this work is listed below
<!-- CML TO JDL Dependencies -->
<dependency>
<groupId>org.contextmapper</groupId>
<artifactId>context-mapper-dsl</artifactId>
<!-- we hv to validate the vulnerability-->
<version>6.3.0</version>
</dependency>
<!--<dependency>
<groupId>org.contextmapper</groupId>
<artifactId>context-map-generator</artifactId>
<version>1.2.1</version>
</dependency>-->
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.26.0</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.plantuml/plantuml -->
<dependency>
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>1.2022.8</version>
</dependency>
Need Help