Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.
HTML
                    <div id="main-content" class="wiki-content group">
                    <h1 id="MecanismodeAtribuiçãoCustomizado-Índice">Contents</h1><p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1412695703823 {padding: 0px;}
div.rbtoc1412695703823 ul {list-style: none;margin-left: 0px;}
div.rbtoc1412695703823 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1412695703823'>
<ul class='toc-indentation'>
<li><span class='TOCOutline'>1</span> <a href='#MecanismodeAtribuiçãoCustomizado-Objetivo'>Objective</a></li>
<li><span class='TOCOutline'>2</span> <a href='#MecanismodeAtribuiçãoCustomizado-Pré-requisitos'>Requirements</a></li>
<li><span class='TOCOutline'>3</span> <a href='#MecanismodeAtribuiçãoCustomizado-ConstruindoumMecanismoPersonalizado'>Building a Custom Mechanism</a></li>
<li><span class='TOCOutline'>4</span> <a href='#MecanismodeAtribuiçãoCustomizado-RetornandoumaListagemdeUsuários'>Returning a User List</a></li>
<li><span class='TOCOutline'>5</span> <a href='#MecanismodeAtribuiçãoCustomizado-UtilizandoDatasets'>Using Datasets</a></li>
<li><span class='TOCOutline'>6</span> <a href='#MecanismodeAtribuiçãoCustomizado-UtilizandoServiços/Webservices'>Using Services / Webservices</a></li>
</ul>
</div></p><h1 id="MecanismodeAtribuiçãoCustomizado-Objetivo">Objective</h1><p>The purpose of this guide is to provide instructions on how to build a <em>script</em> with the purpose of solving a assignee for a workflow process task and/or process manager.</p><h1 id="MecanismodeAtribuiçãoCustomizado-Pré-requisitos">Requirements<strong><br /></strong></h1><ul><li>Knowledge of JavaScript language;</li><li>Knowledge on the construction of Workflow Fluig process flows;</li><li>Knowledge on using Fluig Datasets;</li><li>Understanding of Web, Webservice, SOAP e XML services;</li><li>Familiarity with the development tool, TOTVS Developer Studio or Eclipse;</li><li>Installation of Fluig Studio.</li></ul><h1 id="MecanismodeAtribuiçãoCustomizado-ConstruindoumMecanismoPersonalizado">Building a Custom Mechanism</h1><p>In some situations, a more complex and specific logic is required regarding the definition of who will be responsible for the execution of the activity in the workflow process request. That is the purpose of the "Custom Attribution Mechanism".</p><p>To start building this mechanism, one should, from an existing project, click on the folder <em>mechanisms</em> and access the menu&#160;<em>File > New > Other... </em>(accessible through the shortcut<em>CTRL+N,</em>&#160;or by clicking the folder with the right mouse button, then following the drop-down menu), expand the <em>Fluig</em>&#160;group (folder),&#160;select&#160;<em>Custom Fluig Mechanism</em>&#160;and click on <em>Next. </em>In the following screen, enter the <em>Code</em>&#160;(mandatory and cannot be changed at a later time) in the respective field and its <em>Description </em>(optional), and, lastly, click <em>Finish</em>.</p><p>&#160;</p>    <div class="aui-message hint shadowed information-macro">
                    <p class="title">Note</p>
                            <span class="aui-icon icon-hint">Icon</span>
                <div class="message-content">
                            <p>The code for the mechanism must follow the default specification, according to the <a href="http://tdn.totvs.com/download/attachments/185741417/142935815.docx?version=1&modificationDate=1426513779000&api=v2">Fluig Forms</a> document.</p>
                    </div>
    </div>
<p>&#160;</p><p>Therefore, this basic function will be created, and must be implemented:<span>&#160;</span></p><p><span> <br /></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: javascript; gutter: false" style="font-size:12px;">function resolve(process,colleague){
	var&#160;userList = null;
	return&#160;userList;
}</pre>
</div></div><p>&#160;</p><p>The function above <strong>does not</strong> <strong>return any user</strong>. Its execution will not enable the selection of a user, and therefore the function must be complemented.</p><p>The function <strong>should </strong>return an <strong><em>ArrayList </em></strong>with the <strong>registration </strong>of users. The registration is not necessarily the same as the user login. The registration corresponds to existing value in the field with the same name as the registration for this user and the column <em>colleaguePK.colleagueId</em>, of the Dataset <em>colleague</em>.</p><p>&#160;</p>    <div class="aui-message warning shadowed information-macro">
                    <p class="title">Warning</p>
                            <span class="aui-icon icon-warning">Icon</span>
                <div class="message-content">
                            <p>If a syntax error or error in executing the mechanism occurs, it will be aborted and therefore will not return anyone responsible for the next task/process activity. It is important that the entire implementation go through error handling and execution protection. A good practice is to use <em>try catch</em> clauses.</p>
                    </div>
    </div>
<p>&#160;</p><p>&#160;</p>    <div class="aui-message hint shadowed information-macro">
                    <p class="title">Note</p>
                            <span class="aui-icon icon-hint">Icon</span>
                <div class="message-content">
                            <p>No error message can be issued to the user during its execution, as these mechanisms may be invoked without interaction with the user, such as calls to <em>ECMWorkflowEngineService</em>, through external integrations.</p>
                    </div>
    </div>
<p>&#160;</p><h1 id="MecanismodeAtribuiçãoCustomizado-RetornandoumaListagemdeUsuários">Returning a User List</h1><p>An example of return for a fixed user list is shown below:</p><p>&#160;</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: javascript; gutter: false" style="font-size:12px;">function resolve(process,colleague){
	var userList = new java.util.ArrayList();
	userList.add('matricula_1');
	userList.add('matricula_2');
	userList.add('matricula_3');
	return userList;
}</pre>
</div></div><p>&#160;</p><h1 id="MecanismodeAtribuiçãoCustomizado-UtilizandoDatasets">Using Datasets</h1><p>It is possible to query a Platform <em>Dataset </em> (internal, forms or customized), in order to draw up the final result of users that may be listed for selection of the execution of the next activity. This procedure must be performed according to the example below:</p><p><span><br /></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: javascript; gutter: false" style="font-size:12px;">function resolve(process,colleague){
	var userList = new java.util.ArrayList();
	//-- QUERY TO A DATASET, OF FLUIG USERS GROUP
	var dtsGroup = DatasetFactory.getDataset('group',null,null,null);
	for(var g = 0; g &lt; dtsGroup.values.length; g++){
		userList.add( 'Pool:Group:'+dtsGroup.getValue(g.toString(),"groupPK.groupId") );
	}
	
	//-- QUERY TO A DATASET, OF FLUIG USERS ROLE
	var dtsRole = DatasetFactory.getDataset('workflowRole',null,null,null);
	for each(papel in dtsRole.values){
		userList.add( 'Pool:Role:'+papel["workflowRolePK.roleId"] );
	}
	
	return userList;
}</pre>
</div></div><p>&#160;</p><p>In the example above, in order for the <strong>Group(s)</strong> to be listed, it is necessary to include the prefix <strong><em>"Pool: Group:"</em></strong> concatenated to the code for this Group. With this, when the group is selected, the activity is attributed to the Group and someone from the group should assume it. The same is true for the <strong>Workflow Role(s)</strong>, however the prefix will be <strong><em>"Pool:Role:"</em></strong>, followed by the Role code.</p><p>&#160;</p><h1 id="MecanismodeAtribuiçãoCustomizado-UtilizandoServiços/Webservices">Using Services / Webservices</h1><p>The construction of a mechanism also enables the use of a <strong>Fluig Integration Service</strong>, which may consume a <strong>SOAP</strong> or <strong>Progress</strong> <strong>webservice&#160;</strong>to retrieve the assignees, according to a business rule provided by the ERP, for example. This method may follow the model below:</p><p>&#160;</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: javascript; gutter: false" style="font-size:12px;">function resolve(process,colleague){
	var userList = new java.util.ArrayList();
	//-- CALL TO A FLUIG INTEGRATION SERVICE, WITH A SPECIFIED WEBSERVICE
	var biblioteca = ServiceManager.getService('ECMColleagueService').getBean();
	var endpoint = biblioteca.instantiate('com.totvs.technology.ecm.foundation.ws.ECMColleagueServiceServiceLocator');
	var webservice = endpoint.getColleagueServicePort();
	var usuariosDtoArray = webservice.getSummaryColleagues(1);
	for each(usuario in usuariosDtoArray.getItem()){
		userList.add( usuario.getColleagueId().toString() );
	}
	
	return userList;
}</pre>
</div></div><p>&#160;</p><p>Where the&#160;"process" and&#160;"colleague" parameters refer, respectively, to the objects&#160;<span style="color: rgb(38,38,38);">WorkflowProcess process and Colleague colleague.</span></p><p>&#160;</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="2" style="text-align: center;" class="confluenceTh"><span style="color: rgb(0,51,102);">WorkflowProcess</span></th></tr><tr><th style="text-align: center;" class="confluenceTh">Parameter</th><th style="text-align: center;" class="confluenceTh">Type</th></tr><tr><td class="confluenceTd"><span style="color: rgb(38,38,38);">companyId</span></td><td class="confluenceTd">long</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">processInstanceId</span></td><td colspan="1" class="confluenceTd">int</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">processId</span></td><td colspan="1" class="confluenceTd">String</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">version</span></td><td colspan="1" class="confluenceTd">Integer</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">requesterId</span></td><td colspan="1" class="confluenceTd">String</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">active</span></td><td colspan="1" class="confluenceTd">Boolean</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">attachmentSeqId&#160;</span></td><td colspan="1" class="confluenceTd">Integer</td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">sourceProcess&#160;</span></td><td colspan="1" class="confluenceTd"><span>Integer</span></td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">sourceThreadSequence&#160;</span></td><td colspan="1" class="confluenceTd"><span>Integer</span></td></tr><tr><td colspan="1" class="confluenceTd"><span style="color: rgb(38,38,38);">uuid</span></td><td colspan="1" class="confluenceTd">String</td></tr></tbody></table></div><p>&#160;</p><p>&#160;</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="2" style="text-align: center;" class="confluenceTh"><span style="color: rgb(0,51,102);">Colleague</span></th></tr><tr><th style="text-align: center;" class="confluenceTh">Parameter</th><th style="text-align: center;" class="confluenceTh">Type</th></tr><tr><td class="confluenceTd"><p>colleaguePK&#160;</p><ul style="list-style-type: square;"><li><span><span>long companyId</span></span></li><li><span>private String colleagueId</span></li></ul></td><td class="confluenceTd">ColleaguePK&#160;</td></tr><tr><td colspan="1" class="confluenceTd">userTenantId</td><td colspan="1" class="confluenceTd">long&#160;</td></tr><tr><td colspan="1" class="confluenceTd">colleagueName</td><td colspan="1" class="confluenceTd"><span>String</span></td></tr><tr><td colspan="1" class="confluenceTd">mail</td><td colspan="1" class="confluenceTd"><span>String</span></td></tr><tr><td colspan="1" class="confluenceTd">login</td><td colspan="1" class="confluenceTd"><span>String</span></td></tr><tr><td colspan="1" class="confluenceTd">passwd</td><td colspan="1" class="confluenceTd"><span>String</span></td></tr><tr><td colspan="1" class="confluenceTd">active</td><td colspan="1" class="confluenceTd">Boolean&#160;</td></tr><tr><td colspan="1" class="confluenceTd">adminUser</td><td colspan="1" class="confluenceTd">Boolean&#160;</td></tr><tr><td colspan="1" class="confluenceTd">groupId</td><td colspan="1" class="confluenceTd">String</td></tr></tbody></table></div><p>&#160;</p><p>The example above used the webservice <em><strong>ECMColleagueService, </strong></em>from the very platform, and the <strong>Service </strong>was created with <strong>API Axis</strong>, standard in TOTVS ECM 3.0.</p><p>&#160;</p>
                    </div>