How to Create Project Templates

This feature allows the customization of 'OpenLegacy New Project Wizard' templates to tailor new projects to meet client needs.

Step-by-Step Guide

Create Custom Project Template

  1. Open IDE
  2. Select File → New → OpenLegacy Project Template



  3. The OpenLegacy Project Template Wizard opens:



  4. There are several project template types available for customization:



  5. Select the required Project template type. If the selected template type is related to a specific SDK project (RPC/Screens), an additional Back-end selection becomes available.
  6. Select the templates you want to customize (the Templates Selection section contains templates according to the project template type and back-end selection)




  7. Set the project template name and click Finish
  8. You can add external files to the template, to be used when creating a custom project. See details below
  9. You can now see the new template project just created in the IDE.



    The auto-generated  template-set.yml that is added to the template project contains the project's back-end and front-end types.

    Templates defined under the project-creation-exclude and the component-creation-exclude sections are excluded during project or component creation.
    Template exclusion means that if template test-spring.factories.ftl is defined under project-creation-exclude, the Java file which should be auto-generated from that particular template at the project generation stage, will not be generated.
    If the template RpcEntityTest.java.ftl is defined under the component-creation-exclude section, the Java file which should be auto-generated from the specified template at the entity generation stage, will not be generated.

    To add the Exclusion section, add the template file relative path to the list, for example:

    backend: AS400_RPC
    frontend: JAVA
    project-creation-exclude:
      - spring-boot/test-spring.factories.ftl
    component-creation-exclude: 
      - RpcEntityTest.java.ftl

    The name of the folder in which the template is located can be obtained from the templates structure represented in the OpenLegacy Project Template Wizard:


    Note: you can define as many templates to be excluded as needed.

  10. You can now customize the templates according to your needs.

Add External Files

You can use external files in custom OpenLegacy projects by adding them to the Project Template.

Edit the following properties in the template-set.yml file to add files:

  • add-files - List<AddFileConfig> => representing the new files to add. AddFileConfig model containing relevant configuration to manage this new file.
    • from - can either be an actual file (e.g. Random.java, application-random.yml) or a Freemarker template (*.ftl) relative to template set location. 
    • to -  folder/file location relative to project path (e.g. src/main/java/com/openlegacy/pkg or src/main/java/com/openlegacy/pkg/SpecificClass.java) if it is a specific file, replace the file name on change.

If the file is a Freemarker template (suffix .ftl), to property cannot be a folder. The following models support generation from the provided template:

TemplateSetSdkAddFileModel

  • projectName - String
  • orchestratedKey - String
  • basePackage - String
  • backend - org.openlegacy.core.designtime.BackendSolution (enum)


TemplateSetApiAddFileModel

  • projectName - String
  • basePackage - String
  • frontendSolution -  org.openlegacy.core.designtime.FrontendSolution (enum)
  • contractProject - Boolean
  • microserviceProject - Boolean
Set Descriptor (format)
project:
  add-files:
    -
      from: add-files/NewFile.java:
      to: src/main/java/com/example/models
    -
      from: add-files/application-new.yml
      to: src/main/resources
    -
      from: add-files/NewFile2.java
      to: src/main/java/com/example/models/NewName.java
    -
      from: add-files/random.java.ftl
      to: src/main/java/com/example/models/NewName.java
    ...

Use Custom Project Template

  1. Generate OpenLegacy SDK Project via File → New → OpenLegacy SDK Project
  2. The OpenLegacy SDK Project Wizard opens:



  3. Set the project name and check the Use custom project template check box.
  4. At this stage you have two options: 
    1. "Select from workspace" allows you to use the template set you created previously
    2. "Select template ZIP" allow you to use an archived template set you can obtain from someone else. Refer to the How to archive the custom template guide at the bottom of this document.
       
    The Backend combo box becomes disabled and shows the back-end as was defined during template creation (saved as backend configuration parameter in template-set.yml file)
  5. Complete the SDK project creation
  6. The project is created according to the customizations done previously. In addition, the "templates" folder which contains the component-creation customized templates is created in the project tree.

Important:

  1. After a project is created from the custom template, any changes made in the template project affect new projects only
  2. SImilarly, any changes made in the template project for component-creation templates affect on new components only
  3. After a project has been created, if further customization of the project's components is needed, we can customize them within the project using the project's templates: {project-name}/templates/freemarker/component-creation

After you have created a project from the custom template, do NOT use the Custom Code Template option in your customized project, as this will integrate default templates that will override your customized templates

How to Archive the Custom Template

  1. Right click on the template project and select Export
  2. Select General → Archive File and click Next
  3. Configure the export as defined in screenshot 



    1. Uncheck .project resource
    2. Select "Create only selected directories" option
    3. Set the archive file path in "To archive file"
  4. Click Finish