2.1. T00 Setup Project

To set up a MetaFactory project you need to create the following 5 files:

  1. a global configuration file named metafactory.properties

  2. a local configuration file named local.properties

  3. a project file named metafactory.xml for all project configuration

  4. a coding instructions files named codeinstruction.xml that contains your application code instructions

  5. a model file named model.xml that holds all domain specific data and metadata.

2.1.1. Get the Metafactory environment up and running

If you have not done it yet, GoTo S Get and install MetaFactory environment.

You have now installed MetaFactory, configured your IDE and created a basic project.

2.1.2. Get started

Let’s now get started with the basic files of MetaFactory and your first lines of coding instructions.

Exclam M All files need to be created in the directory metafactory-workshop-metafactory or its subdirectories.

  • Create a global configuration file named metafactory.properties with the following content:

Listing 2.1 metafactory.properties
 1# ############################################
 2# metafactory.properties
 3
 4# Relative path to the (project)folder that will contain the MetaFactored output
 5output.path=../metafactory-workshop-backend
 6
 7# Base package name of the Java code
 8base.package=com.metafactory.workshop
 9
10# Structure of the Java directories
11java.main.directory=src/main/java
12java.test.directory=src/test/java
13webapp.main.directory=src/main/webapp
14
15# Frontend properties
16frontend.output.path=../metafactory-workshop-frontend
  • Create a local configuration file named local.properties with the following (empty) content:

Listing 2.2 local.properties
1
  • Create a project file named metafactory.xml with the following content:

Listing 2.3 metafactory.xml
 1<?xml version="1.0" encoding="UTF-8"?>
 2<personal-iom-project xmlns="http://www.firstbase.nl/xsd/personaliom/project"
 3                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4                      xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/project
 5                                          http://www.firstbase.nl/xsd/personaliom/project.xsd"
 6                      allowDeprecated="false">
 7
 8        <!-- MetaFactory project xml -->
 9
10        <!-- Location of the Metafactory core files and folders -->
11        <model>src/model/model.xml</model>
12        <pattern>src/patterns/codeinstruction.xml</pattern>
13        <snippetsFolder>src/snippets</snippetsFolder>
14
15        <!-- Location of the metafactored output code and files -->
16        <output>
17                <path type="java">${project.property.output.path}</path>
18                <path type="xml">${project.property.output.path}</path>
19                <path type="file">${project.property.output.path}</path>
20        </output>
21
22        <!-- Define various BuildSets to be able to metafactor smaller subsets -->
23        <buildSets>
24                <buildSet name="Runtime_Model &amp; Pattern functions">
25                        <package name="org.metafactory.model.runtime" />
26                        <package name="org.metafactory.model.runtime.domain" />
27                        <package name="org.metafactory.model.runtime.menu" />
28                        <file name="pattern_functions.ftl" />
29                </buildSet>
30         </buildSets>
31
32        <!-- Overrides of JavaTypes in Maps -->
33        <!-- Make use Java8 versions of ye olde java.util.Date/Time -->
34        <maps>
35                <map name="javaTypes">
36                        <entry key="DateTime" value="java.time.ZonedDateTime"/>
37                        <entry key="Date" value="java.time.LocalDate"/>
38                        <entry key="time" value="java.time.LocalTime"/>
39                        <entry key="blob" value="byte[]"/>
40                </map>
41                <map name="tsTypes">
42                        <entry key="Boolean" value="boolean"/>
43                        <entry key="boolean" value="boolean"/>
44                        <entry key="yes_no" value="boolean"/>
45                        <entry key="Byte" value="number"/>
46                        <entry key="byte" value="number"/>
47                        <entry key="Float" value="number"/>
48                        <entry key="float" value="number"/>
49                        <entry key="Short" value="number"/>
50                        <entry key="short" value="number"/>
51                        <entry key="Double" value="number"/>
52                        <entry key="double" value="number"/>
53                        <entry key="Integer" value="number"/>
54                        <entry key="integer" value="number"/>
55                        <entry key="Long" value="number"/>
56                        <entry key="long" value="number"/>
57                        <entry key="big_decimal" value="number"/>
58                        <entry key="String" value="string"/>
59                        <entry key="char" value="string"/>
60                        <entry key="character" value="string"/>
61                        <entry key="text" value="string"/>
62                        <entry key="void" value="void"/>
63                        <entry key="Date" value="string"/>
64                        <entry key="DateTime" value="Date"/>
65                </map>
66        </maps>
67
68        <!-- Location of the properties. Use those as ${project.property.bla}. See in the output-tag above. -->
69        <propertyFiles>
70                <propertyFile filepath="metafactory.properties" />
71                <propertyFile filepath="local.properties" />
72        </propertyFiles>
73
74        <configuration>
75          <usePrettierHtmlFormatter>true</usePrettierHtmlFormatter>
76          <alwaysRunEclipseJavaScriptFormatter>false</alwaysRunEclipseJavaScriptFormatter>
77          <alwaysRunEclipseJavaFormatter>true</alwaysRunEclipseJavaFormatter>
78          <sortMetaData>false</sortMetaData>
79        </configuration>
80
81        <!-- Some defaults for the business logic style -->
82        <businessStyle>
83                <addAuthorToDefaultJavaDocForClass>false</addAuthorToDefaultJavaDocForClass>
84                <addAuthorToDefaultJavaDocForInterface>false</addAuthorToDefaultJavaDocForInterface>
85                <createDefaultJavaDocForClass>true</createDefaultJavaDocForClass>
86                <createDefaultJavaDocForInterface>true</createDefaultJavaDocForInterface>
87        </businessStyle>
88
89</personal-iom-project>
  • Create a subdirectory named src/codeinstructions and in it a code instruction file named codeinstruction.xml that contains the code instructions for your application:

Listing 2.4 codeinstruction.xml
 1<?xml version="1.0" encoding="UTF-8"?>
 2<code_instruction
 3                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4                xmlns="https://metafactory.io/xsd/v1/codeinstruction"
 5                xsi:schemaLocation="https://metafactory.io/xsd/v1/codeinstruction https://metafactory.io/xsd/v1/codeinstruction.xsd
 6                                    https://metafactory.io/xsd/v1/java-codeinstruction https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
 7                xmlns:typescript="https://metafactory.io/xsd/v1/typescript-codeinstruction"
 8                xmlns:java="https://metafactory.io/xsd/v1/java-codeinstruction">
 9
10<properties>
11        <base>com.metafactory.workshop</base>
12        <java.main.directory>src/main/java</java.main.directory>
13        <java.generated.directory>src/main/generated</java.generated.directory>
14        <conf.main.directory>src/main/resources</conf.main.directory>
15        <java.test.directory>src/test/java</java.test.directory>
16        <conf.test.directory>src/test/resources</conf.test.directory>
17
18        <!-- Frontend properties -->
19        <jhipster.style>4</jhipster.style>
20        <jhipster6104_angular1000_frontend.output.path>./metafactory-workshop-frontend</jhipster6104_angular1000_frontend.output.path>
21        <app.class.name>MetaFactoryWorkshopApplication</app.class.name>
22        <angular.use.angular8.viewchild>true</angular.use.angular8.viewchild>
23        <angular.app.name>Workshop</angular.app.name>
24        <angular.app.title>MetaFactory Workshop</angular.app.title>
25        <webapp.app.directory>/app</webapp.app.directory>
26        <webapp.main.directory>${project.property.webapp.main.directory}</webapp.main.directory>
27        <angular.library.output.path>./metafactory-workshop-frontend</angular.library.output.path>
28        <angular.webapp.main.directory>src/main/webapp</angular.webapp.main.directory>
29        <angular.webapp.root>src/main/webapp/app</angular.webapp.root>
30        <webapp.components.selector>shc</webapp.components.selector>
31        <app.showNotifications>true</app.showNotifications>
32
33        <!-- Backend properties -->
34        <jhipster6104_angular1000_backend.output.path>./metafactory-workshop-backend</jhipster6104_angular1000_backend.output.path>
35</properties>
36
37<!-- Load Freemarker template files -->
38<freemarker>
39        <freemarker_library namespace="naming">/library/naming.ftl</freemarker_library>
40        <freemarker_library namespace="util">/jhipster/util/util.ftl</freemarker_library>
41        <freemarker_library namespace="state_util">/jhipster/util/state-utils.ftl</freemarker_library>
42        <freemarker_library namespace="model_util">/library/model_utils.ftl</freemarker_library>
43        <freemarker_library namespace="tl">/library/layout/tableLayout.ftl</freemarker_library>
44        <freemarker_library namespace="metadata">/library/metadata.ftl</freemarker_library>
45</freemarker>
46
47<external_libraries>
48        <external_library name="libMF">
49                <path>./</path>
50                <patterns_folder>src/patterns</patterns_folder>
51                <snippets_folder>src/snippets</snippets_folder>
52                <function_library>src/patterns/package/pattern-functions.xml</function_library>
53        </external_library>
54</external_libraries>
55
56<features>
57
58</features>
59
60  <!--#############################################################################################################-->
61  <!--########################################## Java code instructions ###########################################-->
62  <!--#############################################################################################################-->
63
64  <!-- The new MetaFactory Runtime Model => A pojo representation of your model.xml which can be used from your snippets-->
65  <java:external_java_package id="libMF/java_package/model/runtime/model-root.xml" />
66  <java:external_java_package id="libMF/java_package/model/runtime/model-pojo.xml" />
67
68  <!-- your code instructions here -->
69
70</code_instruction>
  • Create a subdirectory src/model with a model file named model.xml with the following content:

Listing 2.5 model.xml
 1<?xml version="1.0" encoding="UTF-8"?>
 2<model xmlns="https://metafactory.io/xsd/v1/model"
 3       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4       xsi:schemaLocation="https://metafactory.io/xsd/v1/model https://metafactory.io/xsd/v1/model.xsd">
 5
 6  <metadata>
 7        <angular.webapp>
 8           <main.directory>src/main/webapp</main.directory>
 9           <root>src/main/webapp/app</root>
10        </angular.webapp>
11        <application>
12           <backend.api.url>
13                <dev>http://workshop.local:8080</dev>
14                <prod>https://localhost:8080</prod>
15           </backend.api.url>
16           <frontend.host.dev>localhost</frontend.host.dev>
17        </application>
18        <backend.app.class.name>MetaFactoryworkshopApplication</backend.app.class.name>
19        <main.stylesheet.filename>global.scss</main.stylesheet.filename>
20  </metadata>
21  <package name="domain">
22        <metadata>
23          <base>com.metafactory.workshop</base>
24          <content.folder.name>content</content.folder.name>
25          <dto>
26                <demo.keyword>Demo</demo.keyword>
27                <rest.controller.package>com.metafactory.workshop.rest.dto</rest.controller.package>
28          </dto>
29          <jhipster>
30                <login.screen>modal</login.screen>
31                <style>6</style>
32          </jhipster>
33          <jhl.base>com.metafactory.workshop</jhl.base>
34          <main.stylesheet.filename>global.scss</main.stylesheet.filename>
35          <markup.version>material_v1</markup.version>
36          <maven.artifact>
37                <id>metafactory-workshop</id>
38                <name>MetaFactory workshop</name>
39                <version>1.0.0-SNAPSHOT</version>
40          </maven.artifact>
41          <model>
42                <implementation.package>com.metafactory.workshop.domain</implementation.package>
43                <runtime.package>org.metafactory.model.runtime.domain</runtime.package>
44          </model>
45          <project.support.intelligentfiltering>true</project.support.intelligentfiltering>
46          <repository.jpa>
47                <class.package>com.metafactory.workshop.repository.jpa.impl</class.package>
48                <dialect>
49                  <packagename>com.metafactory.workshop.repository.dialect</packagename>
50                  <version>82</version>
51                </dialect>
52          </repository.jpa>
53          <repository>
54                <jpa>
55                  <interface.package>com.metafactory.workshop.repository.jpa</interface.package>
56                </jpa>
57                <style>JPA2</style>
58                <util.package>com.metafactory.workshop.repository.util</util.package>
59          </repository>
60          <sequencename>hibernate_sequence</sequencename>
61          <theme>hoursangular</theme>
62        </metadata>
63        <object name="YourFirstObject">
64          <attribute name="firstAttribute" type="String"></attribute>
65        </object>
66  </package>
67</model>

Now:

  • Click on “Runtime_Model and Pattern functions” in the Code Composer Project window.

  • Click on the Play button to run MetaFactory.

Once finished, the Code Composer will have generated the Java class RuntimeModel.java and some other classes that will be used during generation with MetaFactory.

../_images/create-runtime-model-and-pattern-functions-screenshot.png