Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Each lifecycle configuration contains one or more state elements. More information on lifecycle configuration and the various elements in it, can be found in Configuring Lifecycles.

The client-side scripting support is available for lifecycle state transition event. This can be done by adding something similar to the following under the state datamodel element.

Code Block

<js><data name="transitionScripts">
                            <!--name - defines that this element contains the set of transition scripts. It is required to be
                            set to 'transitionScripts'-->
                            <js forEvent="">
                                <!--forEvent - defines the event that this script block will execute-->
                                <console promoteFunctionfunction="myFunction">">
                                    <!--function - defines the name of the function-->
                                    <script type="text/javascript">
                myFunction = function() {                     // executable<!--contains the script-->
                 }                   </script>
                                </console>
                                <server function="">
                                    <script type="text/javascript"></script>
                                </server>
                            </js>

 </data>

Here is an example on how to add an alert for for the state transition from Initialize to Designed make an redirection after a "Promote" is done in the default ServiceLifeCycle.

1. Edit the existing lifecycle by adding the configuration below.

Code Block

<aspect name="ServiceLifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.ChecklistLifeCycle">.DefaultLifeCycle">
    <configuration type="literal">
        <lifecycle>
            <scxml xmlns="http://www.w3.org/2005/07/scxml"
                   version="1.0"
                   initialstate="Development">
             <configuration type   <state id="literalDevelopment">
            <lifecycle>        <datamodel>
                        <data name="checkItems">
                            <state<item name="Initialize" location="/environment/init">Code Completed" forEvent="">
                                <!--<permissions>
                                    <permission roles=""/>
                                </permissions>
                                <validations>
                                    <validation forEvent="" class="">
                                  <checkitem>Requirements Gathered</checkitem>      <parameter name="" value=""/>
                                   <checkitem>Architecture Finalized</checkitem></validation>
                             <checkitem>High Level Design Completed</checkitem></validations>-->
                            </item>
      <js>                      <item name="WSDL, Schema <consoleCreated" promoteFunctionforEvent="myFunction">
                            </item>
           <script type="text/javascript                  <item name="QoS Created" forEvent="">
                            </item>
   myFunction = function() {                     </data>
                        alert("Promoted Resource to Designed State");<!--<data name="transitionValidation">
                            <validation forEvent="" class="">
                                }<parameter name="" value=""/>
                            </script>validation>
                        </console>data>
                        <data name="transitionPermission">
                            <permission  </js>forEvent="" roles=""/>
                        </state>data>-->
                       <state name="Designed" location="/environment/design"><data name="transitionScripts">
		                <js forEvent="Promote">
		                    <console function="doPromote">
		                        <script type="text/javascript">
		                              doPromote = function() {
		                                window.location = unescape("../listService/service.jsp?region=region3%26item=governance_list_services_menu");
		                                        }
		                        </script>
		                     </console>
		                  </js>                            
		       <checkitem>Code Completed</checkitem></data>                   
                  <checkitem>WSDL, Schema Created<</checkitem>datamodel>
                    <transition <checkitem>QoS Created</checkitem>event="Promote" target="Tested"/>                  
                </state>
                <state nameid="Created" location="/environment/developmentTested">
                    <datamodel>
                        <data name="checkItems">
                    <checkitem>Effective Inspection Completed</checkitem>        <item name="Effective Inspection Completed" forEvent="">
                          <checkitem>Test Cases Passed</checkitem></item>
                            <checkitem>Smoke<item name="Test Passed</checkitem> Cases Passed" forEvent="">
                            </state>item>
                            <state<item name="TestedSmoke Test Passed" locationforEvent="/environment/qa">
                    <checkitem>Service Configuration</checkitem>        </item>
                        </data>
                    </state>datamodel>
                    <state<transition nameevent="DeployedPromote" locationtarget="Production"/environment/prod">
                    <checkitem>Service Configuration</checkitem><transition event="Demote" target="Development"/>
                </state>
                <state nameid="Deprecated" location="/environment/support" />Production">  
                    <transition event="Demote" target="Tested"/>
                </state>                
            </lifecycle>scxml>
        </configuration>lifecycle>
    </configuration>
</aspect>

2. After saving this configuration (See Adding Lifecycles), add the ServiceLifeCycle to a Service (or any other resource/collection). See Managing Lifecycle.

...

You can add any valid executable JavaScript that is capable of performing some task that you require.

Excerpt
hiddentrue

Instructions on how to handle client-side scripting for lifecycles in the Governance Registry.

 

<data name="transitionScripts">
                            <!--name - defines that this element contains the set of transition scripts. It is required to be
                            set to 'transitionScripts'-->
                            <js forEvent="">
                                <!--forEvent - defines the event that this script block will execute-->
                                <console function="">
                                    <!--function - defines the name of the function-->
                                    <script type="text/javascript">
                                        <!--contains the script-->
                                    </script>
                                </console>
                                <server function="">
                                    <script type="text/javascript"></script>
                                </server>
                            </js>
                        </data>