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
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# ############################################
# metafactory.properties

# Relative path to the (project)folder that will contain the MetaFactored output
output.path=../metafactory-workshop-backend

# Base package name of the Java code
base.package=com.metafactory.workshop

# Structure of the Java directories
java.main.directory=src/main/java
java.test.directory=src/test/java
webapp.main.directory=src/main/webapp

# Frontend properties
frontend.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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?xml version="1.0" encoding="UTF-8"?>
<personal-iom-project xmlns="http://www.firstbase.nl/xsd/personaliom/project"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/project
                                          http://www.firstbase.nl/xsd/personaliom/project.xsd"
                      allowDeprecated="false">

    <!-- MetaFactory project xml -->

    <!-- Location of the Metafactory core files and folders -->
    <model>src/model/model.xml</model>
    <pattern>src/patterns/codeinstruction.xml</pattern>
    <snippetsFolder>src/snippets</snippetsFolder>

    <!-- Location of the metafactored output code and files -->
    <output>
        <path type="java">${project.property.output.path}</path>
        <path type="xml">${project.property.output.path}</path>
        <path type="file">${project.property.output.path}</path>
    </output>

    <!-- Define various BuildSets to be able to metafactor smaller subsets -->
    <buildSets>
        <buildSet name="Runtime_Model &amp; Pattern functions">
            <package name="org.metafactory.model.runtime" />
            <package name="org.metafactory.model.runtime.domain" />
            <package name="org.metafactory.model.runtime.menu" />
            <file name="pattern_functions.ftl" />
        </buildSet>
     </buildSets>

    <!-- Overrides of JavaTypes in Maps -->
    <!-- Make use Java8 versions of ye olde java.util.Date/Time -->
    <maps>
        <map name="javaTypes">
            <entry key="DateTime" value="java.time.ZonedDateTime"/>
            <entry key="Date" value="java.time.LocalDate"/>
            <entry key="time" value="java.time.LocalTime"/>
            <entry key="blob" value="byte[]"/>
        </map>
        <map name="tsTypes">
            <entry key="Boolean" value="boolean"/>
            <entry key="boolean" value="boolean"/>
            <entry key="yes_no" value="boolean"/>
            <entry key="Byte" value="number"/>
            <entry key="byte" value="number"/>
            <entry key="Float" value="number"/>
            <entry key="float" value="number"/>
            <entry key="Short" value="number"/>
            <entry key="short" value="number"/>
            <entry key="Double" value="number"/>
            <entry key="double" value="number"/>
            <entry key="Integer" value="number"/>
            <entry key="integer" value="number"/>
            <entry key="Long" value="number"/>
            <entry key="long" value="number"/>
            <entry key="big_decimal" value="number"/>
            <entry key="String" value="string"/>
            <entry key="char" value="string"/>
            <entry key="character" value="string"/>
            <entry key="text" value="string"/>
            <entry key="void" value="void"/>
            <entry key="Date" value="string"/>
            <entry key="DateTime" value="Date"/>
        </map>
    </maps>

    <!-- Location of the properties. Use those as ${project.property.bla}. See in the output-tag above. -->
    <propertyFiles>
        <propertyFile filepath="metafactory.properties" />
        <propertyFile filepath="local.properties" />
    </propertyFiles>

    <configuration>
      <usePrettierHtmlFormatter>true</usePrettierHtmlFormatter>
      <alwaysRunEclipseJavaScriptFormatter>false</alwaysRunEclipseJavaScriptFormatter>
      <alwaysRunEclipseJavaFormatter>true</alwaysRunEclipseJavaFormatter>
      <sortMetaData>false</sortMetaData>
    </configuration>

    <!-- Some defaults for the business logic style -->
    <businessStyle>
        <addAuthorToDefaultJavaDocForClass>false</addAuthorToDefaultJavaDocForClass>
        <addAuthorToDefaultJavaDocForInterface>false</addAuthorToDefaultJavaDocForInterface>
        <createDefaultJavaDocForClass>true</createDefaultJavaDocForClass>
        <createDefaultJavaDocForInterface>true</createDefaultJavaDocForInterface>
    </businessStyle>

</personal-iom-project>
  • Create a subdirectory named src/patterns and in it a coding instructions files named codeinstruction.xml that contains your application code instructions

Listing 2.4 src/patterns/codeinstruction.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="UTF-8"?>
<code_instruction
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="https://metafactory.io/xsd/v1/codeinstruction"
        xsi:schemaLocation="https://metafactory.io/xsd/v1/codeinstruction https://metafactory.io/xsd/v1/codeinstruction.xsd
                            https://metafactory.io/xsd/v1/java-codeinstruction https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
        xmlns:typescript="https://metafactory.io/xsd/v1/typescript-codeinstruction"
        xmlns:java="https://metafactory.io/xsd/v1/java-codeinstruction"
>
  <properties>
    <base>com.metafactory.workshop</base>
    <java.main.directory>src/main/java</java.main.directory>
    <java.generated.directory>src/main/generated</java.generated.directory>
    <conf.main.directory>src/main/resources</conf.main.directory>
    <java.test.directory>src/test/java</java.test.directory>
    <conf.test.directory>src/test/resources</conf.test.directory>
    <!-- Frontend properties -->
    <jhipster.style>4</jhipster.style>
    <jhipster6104_angular1000_frontend.output.path>./metafactory-workshop-frontend</jhipster6104_angular1000_frontend.output.path>
    <app.class.name>MetaFactoryWorkshopApplication</app.class.name>
    <angular.use.angular8.viewchild>true</angular.use.angular8.viewchild>
    <angular.app.name>Workshop</angular.app.name>
    <angular.app.title>MetaFactory Workshop</angular.app.title>
    <webapp.app.directory>/app</webapp.app.directory>
    <webapp.main.directory>${project.property.webapp.main.directory}</webapp.main.directory>
    <angular.library.output.path>./metafactory-workshop-frontend</angular.library.output.path>
    <angular.webapp.main.directory>src/main/webapp</angular.webapp.main.directory>
    <angular.webapp.root>src/main/webapp/app</angular.webapp.root>
    <webapp.components.selector>shc</webapp.components.selector>
    <app.showNotifications>true</app.showNotifications>
    <!-- Backend properties -->
    <jhipster6104_angular1000_backend.output.path>./metafactory-workshop-backend</jhipster6104_angular1000_backend.output.path>

  </properties>

  <!-- Load Freemarker template files -->
  <freemarker>
    <freemarker_library namespace="naming">/library/naming.ftl</freemarker_library>
    <freemarker_library namespace="util">/jhipster/util/util.ftl</freemarker_library>
    <freemarker_library namespace="state_util">/jhipster/util/state-utils.ftl</freemarker_library>
    <freemarker_library namespace="model_util">/library/model_utils.ftl</freemarker_library>
    <freemarker_library namespace="tl">/library/layout/tableLayout.ftl</freemarker_library>
    <freemarker_library namespace="metadata">/library/metadata.ftl</freemarker_library>
  </freemarker>

  <external_libraries>
    <external_library name="libMF">
      <path>./</path>
      <patterns_folder>src/patterns</patterns_folder>
      <snippets_folder>src/snippets</snippets_folder>
      <function_library>src/patterns/package/pattern-functions.xml</function_library>
    </external_library>
  </external_libraries>

  <features>

  </features>

  <!--#############################################################################################################-->
  <!--############################################### Java patterns ###############################################-->
  <!--#############################################################################################################-->

  <!-- The new MetaFactory Runtime Model => A pojo representation of your model.xml which can be used from your snippets-->
  <java:external_java_package id="libMF/package/model/runtime/model-root.xml" />
  <java:external_java_package id="libMF/package/model/runtime/model-pojo.xml" />

  <!-- your patterns here -->

</code_instruction>

Create a subdirectory src/model with a model file named model.xml with the following content:

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

Now:

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

  • Click on the Play button to run MetaFactory.

Once finished, MetaFactory 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