This shows you the differences between two versions of the page.

Link to this comparison view

tutorial:customize_scenario [2020/04/16 10:56] (current)
Line 1: Line 1:
 +<WRAP adihi>
 +This step is optional. If you used examples given by Adichatz (pagila/​PosgreSQL or sakila/​MySQL),​ an customization file if automatically proposed to you when creating project. ​
 +</​WRAP> ​
 +====== Customization of the generation processes issues ======
 +<wrap adicode>​Scenario Tree</​wrap>​ describes how to drive automatic generation processes.\\
 +Indeed, a scenario transforms an input (XML files, Pojos) into a GENERATED XML file which describes the body of a part (Editor, Query, Detail UI...).\\
 +The default generation process which is driven by <wrap adicode>​Scenario Tree</​wrap>​ provided by **Scenario.xml** file (see [[tutorial:​scenario|Scenario architecture]]),​ may contain defects.
 +For instance, in our case, we want to make 3 improvements:​
 +  - For **Film** entity, Hibernate generates a **Pojo** which maps the **year** property to a date. The property must be changed to an **int** which can have a value between 1900 and 2155.
 +  - For **Film** entity, property **specialFeatures** is a string corresponding to a set of values. [[controllers:​multichoicecontroller|MultiChoice]] control to display value is more appropriate.
 +  - All POJOs that contain a **lastUpdate** property must extend a **ASuperLastUpdate** class that initializes the property value to the current date when creating or modifying entity.
 +Making changes to <wrap adicode>​Scenario Tree</​wrap>​ file means update the generation processes. The belowing example shows differents possiblities:​
 +  * New scenarios, generators, path elements, parameters can be specified or added to the Scenario Tree before launching or relaunching generation processes.
 +  * Pojo rewriter for injecting changes in Pojos (e.g. <wrap adicode>​org.adichatz.scenario.generation.SuperPojoRewriter</​wrap>​ is a java class for rewrite Pojo in order to add a super class).
 +  * Specific features as new item value, validators or listeners can be added to the scenario tree.  ​
 +====== Store scheduled changes inside an XML file ======
 +These changes can be manually made by the developper inside the **Scenario.xml** file.
 +A other way is to assemble changes inside a new <wrap adicode>​Scenario tree</​wrap>​ stored in a specific <wrap adicode>​xml file</​wrap>,​ inject these changes inside the current **Scenario.xml** file and launch needed generation processes.\\
 +In the example below, previously described needed change are incorparated.
 +<sxh xml; highlight: [4,​10,​11,​16,​17,​18,​19,​20,​21,​25,​26,​30,​33,​34,​35,​36,​37,​38,​39,​42,​45,​48,​49,​50,​51];​ first-line: 1; title: excerpt from '​pagilaMappingOverride.xml'​ file.>
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<​scenarioTree xmlns:​xsi="​http://​www.w3.org/​2001/​XMLSchema-instance"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.9.1/​generator/​scenarioTree.xsd">​
 +    <​pathElements>​
 +        <​pathElement type="​PROJECT"​ location="​myscenario"/>​
 +    </​pathElements>​
 + <​params>​
 +    <param id="​devl.default.integer.pattern"​ value="#####"/>​
 +    </​params>​
 +    <​generators>​
 +        <​generator treeClassName="​org.adichatz.generator.wrapper.TableWrapper"​ generatorClassName="​org.mycompany.myscenario.generator.MyTableGenerator"/>​
 +        <​generator treeClassName="#​CONTROLGENERATOR()"​ generatorClassName="​org.mycompany.myscenario.generator.MyControlGenerator"/>​
 +    </​generators>​
 +    <​generationScenario scenarioClassName="​org.adichatz.scenario.impl.PluginEntityScenario">​
 +    <​modelPart>​
 +    <​pojoRewriters>​
 +     <​pojoRewriter rewriterClassName="​org.adichatz.scenario.generation.SuperPojoRewriter"​ propertyRegex="​lastUpdate">​
 +     <​params>​
 +     <​param id="​superClassURI"​ value="​bundleclass://​./#​PACKAGENAME().model.ASuperLastUpdate"/>​
 +     <​param id="​sourceURI"​ value="​platform:/​plugin/​org.adichatz.template/​template/​src/​ASuperLastUpdate.java"/>​
 +     </​params>​
 +     </​pojoRewriter>​
 + </​pojoRewriters>​
 +    </​modelPart>​
 + <​propertyField id="​lastUpdate">​
 +        <​controlField xsi:​type="​dateTextType"​ enabled="​false"​ style="​SWT.BORDER | SWT.TIME"/>​
 +        <​columnField xsi:​type="​tableColumnType"​ property="​lastUpdate"​ sorted="​true"​ style="​SWT.CENTER"/>​
 + </​propertyField>​
 +        <​pluginEntity entityURI="​adi://​./​./​FilmMM">​
 +        <​messages>​
 +        <​message key="​invalid.year.value"​ value="​Invalid year '​{0}'​! Value must be between 1900 and 2155"/>​
 +        </​messages>​
 +            <​propertyField id="​releaseYear"​ pojoType="​short">​
 +         <​controlField xsi:​type="​formattedTextType"​ editPattern="####"​ format="​Integer">​
 +         <​validators>​
 +            ​ <​validator key="​invalidYear"​ errorMessage="#​MSG(film,​ invalid.year.value,​ #​FV())">​
 +            ​ <​errorWhen>​return #FV() &lt; 1900 ||  #FV() &gt; 2155;</​errorWhen>​
 +            ​ </​validator>​
 +         </​validators>​
 +         </​controlField>​
 +            </​propertyField>​
 +            <​propertyField id="​specialFeatures">​
 +         <​controlField xsi:​type="​multiChoiceType"​ multiChoiceType="​String"​ values="​Trailers,​Commentaries,​Deleted Scenes,​Behind the Scenes"​ popupToolbar="​true"/>​
 +            </​propertyField>​
 +        </​pluginEntity>​
 +        <​generationUnit scenarioClassName="​org.adichatz.scenario.impl.GroupListNavigatorScenario"​ adiResourceURI="​adi://​groupNavigator/​GroupNavigatorContent"​ type="​NAVIGATOR"/>​
 +    </​generationScenario>​
 +    <​customPostAction injectInsideScenarioFile="​true"​ generatePojo="​true"​ generateEJB="​true"​ generatePersistenceXml="​true"​ deployEJB="​true">​
 +        <​customGenerationUnit type="​ENTITY"​ propertyRegex="​lastUpdate"/>​
 +        <​customGenerationUnit type="​DETAIL"​ propertyRegex="​lastUpdate"/>​
 +        <​customGenerationUnit type="​TABLE"​ entityRegex="​Film"/>​
 +        <​customGenerationUnit type="​MESSAGE_BUNDLE"​ entityRegex="​Film"/>​
 +    </​customPostAction>​
 +<WRAP indic><​wrap adititle>​Remarks</​wrap>:​\\
 +|< 100% 10em - >|
 +^  <​html><​small></​html>​Line 4<​html></​small></​html>:​|@#​eff5fb:​A new project containing resources (classes) is added to the path for generation processes.|
 +^  <​html><​small></​html>​Lines 10-11<​html></​small></​html>:​|@#​eff5fb:​2 new **Generators** are used instead of standard generators.|
 +^  <​html><​small></​html>​Lines 16-21<​html></​small></​html>:​|@#​eff5fb:​2 new <wrap adicode>​pojo rewriters</​wrap>​ are executed after **Pojos** are generated.|
 +^  <​html><​small></​html>​Lines 25-26<​html></​small></​html>:​|@#​eff5fb:​The **controller** for <wrap adicode>​lastUpdate</​wrap>​ property will be a <wrap adicode>​DateTextController</​wrap>​ for any entity of the project.|  ​
 +^  <​html><​small></​html>​Line 30<​html></​small></​html>:​|@#​eff5fb:​An item is added to the message bundle file linked to the <wrap adicode>​Film</​wrap>​ entity (<wrap adicode>​filmGENERATED.properties</​wrap>​ file).|
 +^  <​html><​small></​html>​Lines 33-39<​html></​small></​html>:​|@#​eff5fb:​Assumes that the value of the <wrap adicode>​releaseYear</​wrap>​ property must be between 1900 and 2155 (Client side).|
 +^  <​html><​small></​html>​Line 42 <​html></​small></​html>:​|@#​eff5fb:​The value of the <wrap adicode>​specialFeatures</​wrap>​ property is an array of predetermined values and uses a [[controllers:​multichoicecontroller|MultiChoiceController]] controller.|
 +^  <​html><​small></​html>​Line 45<​html></​small></​html>:​|@#​eff5fb:​A new navigator will be generated which provide List/​Detail ​ query editor.|
 +^  <​html><​small></​html>​Line 48<​html></​small></​html>:​|@#​eff5fb:​Regenerate <wrap adicode>​Entity MetaModel</​wrap>​ (e.g. ActorMM) for all entity having a <wrap adicode>​lastUpdate</​wrap>​ property.|
 +^  <​html><​small></​html>​Line 49<​html></​small></​html>:​|@#​eff5fb:​Regenerate <wrap adicode>​Detail Include</​wrap>​ (e.g. ActorDI) for all entity having a <wrap adicode>​lastUpdate</​wrap>​ property.|
 +^  <​html><​small></​html>​Line 50<​html></​small></​html>:​|@#​eff5fb:​Regenerate <wrap adicode>​Table Include</​wrap>​ (e.g. FilmTI) for <wrap adicode>​Film</​wrap>​ entity.|
 +^  <​html><​small></​html>​Line 51<​html></​small></​html>:​|@#​eff5fb:​Regenerate <wrap adicode>​Message Bundle</​wrap>​ (e.g. film.properties) for <wrap adicode>​Film</​wrap>​ entity.|
 +</​WRAP>​\\ \\ 
 +====== Specify a customization file for a data source ======
 +<columns 100% l 400px>
 +{{:​tutorial:​customization_file_datasource.png?​400 |}}
 +<​newcolumn left>
 +When defining a datasource, a Customization file can be specified linked to this data source.
 +Each time this data source is chosen, the customization file is suggested to bring changes to the scenario tree before launching the generation process.
 +\\ \\
 +Datasource window is open by clicking on the **Data source** hyperlink field of the page **Model** of the **Scenario Tree** editor. ​
 +\\ \\
 +====== Inject scheduled changes inside Scenario.xml file ======
 +<columns 100% l 400px>
 +{{:​tutorial:​choose_customized_scenario_tree.png?​400 |}}
 +<​newcolumn left>
 +\\ \\ \\
 +  - Open file <wrap adicode>​$projectDirectory/​resources/​xml/​Scenario.xml</​wrap>​ with Adichatz editor, choose <wrap adicode>​Customizations</​wrap>​ page.
 +  - Select a <wrap adicode>​Customization File</​wrap>​. For example, open file <wrap adicode>​[eclipse_dir]/​plugins/​org.adichatz.template/​template/​connectors/​pagilaNewOverride.xml</​wrap>​
 +<columns 100% l 400px>
 +{{:​tutorial:​launch_customization.png?​400 |}}
 +<​newcolumn left>
 +\\ \\ \\
 +  * Open file <wrap adicode>​$projectDirectory/​resources/​xml/​Scenario.xml</​wrap>​ with Adichatz editor, choose <wrap adicode>​Customizations</​wrap>​ page.
 +  * Select <wrap adicode>​Merge customizations</​wrap> ​ {{img_generate_scenario.png|Merge customizations to scenario}} at top right of the page.
 +  * Choose the right options and launch the generation process.
 +<WRAP adihi>
 +This customized <wrap adicode>​Scenario Tree</​wrap>​ will be merged to the standard <wrap adicode>​Scenario Tree</​wrap>​ in order to inject the aboved described features in the project.
 +So, Developpers can build and share powerfull aspects to easily enrich the generation processes.
 +</​WRAP> ​
 +<wrap adititle>​Initial and final **Scenario.xml** can be respectively seen [[http://​www.adichatz.org/​document/​Scenario.xml|here]] and [[http://​www.adichatz.org/​document/​Scenario_Customized.xml|here]].</​wrap>:​\\