From the IWorkflow object, documents can be created. Please note that the third argument of the method createWorkflowInstance is null. This indicates that the system determines the document reference depending on the format specified in the web designer. However it is possible to force the reference to a precise value. In this case the third argument must be specified.
public void document_create( IContext context, IWorkflowModule workflowModule, IWorkflow workflow ) throws WorkflowModuleException { try { // starting a transaction workflowModule.beginTransaction( this ); // creation of the document IWorkflowInstance newInstance = workflowModule.createWorkflowInstance( context, workflow, null ); // positioning some values newInstance.setValue( "fldDocumentVersion", "5.0" ); newInstance.setValue( "fldDocumentType", "Type simple" ); newInstance.setValue( "fldNature", "Interne" ); newInstance.setValue( "fldWritingRequired", "Non" ); newInstance.setValue( "fldReadingRequired", "Non" ); newInstance.setValue( "fldVerificationRequired", "Non" ); newInstance.setValue( "fldApprovingRequired", "Non" ); newInstance.setValue( "sys_Title", "Documentation SDK" ); newInstance.setValue( "fldDocumentDescription", "Les possibilités d'intégration" ); newInstance.setValue( "fldKeywords", "vdoc process sdk education" ); // backing-up modifications newInstance.save(); // validating the transaction workflowModule.commitTransaction( this ); } catch( Exception e ) { // if an error has occurred, canceling the previous processing workflowModule.rollbackTransaction( this ); getNavigator().processErrors( e ); } }
The following example shows how to customize the reference before it is registered in database.
public void document_createWithCustomReference( IContext context, IWorkflowModule workflowModule, IWorkflow workflow, IResourceDefinition definition ) throws WorkflowModuleException { try { // starting a transaction workflowModule.beginTransaction( this ); // 1st using form: retrieving the calculated reference for a // resource definition String defaultReference = workflowModule.generateReference( definition ); // 2nd using form: retrieving the calculated reference for a // resource definition and a wanted format String myReference = workflowModule.generateReference( definition, "[MYTAG]-[site]-[company]-[jj]-[mm]-[aaaa]-[aa]-[dd]-[yyyy]-[yy]-[chrono]" ); myReference = StringUtils.replaceAll( myReference, "[MYTAG]", "REF" ); // creation of the document IWorkflowInstance newWorkflowInstance = workflowModule.createWorkflowInstance( context, workflow, myReference ); // positioning some values // ... // backing-up modifications newWorkflowInstance.save(); // validating the transaction workflowModule.commitTransaction( this ); } catch( Exception e ) { // if an error has occurred, canceling the previous processing workflowModule.rollbackTransaction( this ); getNavigator().processErrors( e ); } finally { workflowModule.unInitialize(); } }
The following example shows how to recover the next chrono digit of the formatted reference
public void document_getNextChrono( IWorkflowModule workflowModule, IResourceDefinition definition ) throws WorkflowModuleException { // recovering the next chrono of the calculated reference int nextChrono = workflowModule.generateChrono( definition ); }
The following example shows how to add an event in the document history.
public void document_addEventHistory( IContext context, IWorkflowModule workflowModule, IWorkflowInstance workflowInstance ) throws WorkflowModuleException { IUser qui = workflowModule.getUser( getNavigator().getLoggedOnUser() ); IUser pourQui = qui; workflowInstance.getHistory().addEvent( "Action", "Etat", qui, pourQui, "Description", "En tant que" ); }
The following example shows how to add the right to read to a document.
public void document_addRights( IWorkflowModule workflowModule, IWorkflowInstance workflowInstance ) throws WorkflowModuleException { IUser user = workflowModule.getUser( getNavigator().getLoggedOnUser() ); ISecurityController securityController = workflowModule.getSecurityController( workflowInstance ); securityController.addPermission( user, Rights.Treatment.TreatmentLevel.READ_CONTENT ); }
The following example shows how to fill-in a single user selector. This example applies to every directory selectors (IUser, IGroup, ILocalization, IOrganization),as well as the publication module folder or file selector (IFile, IFolder).
public void document_setSelectorValue( IWorkflowModule workflowModule, IWorkflowInstance workflowInstance ) throws WorkflowModuleException { // positioning the value from a single user selector IUser user = workflowModule.getUserByLogin( "user1" ); workflowModule.setExternalUser( workflowInstance, "fldSingleUserSelector", user ); }
The following example shows how to fill-in a multiple user selector. This example applies to every directory selectors (IUser, IGroup, ILocalization, IOrganization),as well as the publication module folder or file selector (IFile, IFolder).
public void document_setSelectorValues( IWorkflowModule workflowModule, IWorkflowInstance workflowInstance ) throws WorkflowModuleException { // creation of a users list ArrayList arrUsers = new ArrayList(); arrUsers.add( workflowModule.getUserByLogin( "user1" ) ); arrUsers.add( workflowModule.getUserByLogin( "user2" ) ); // positioning the value of a multiple users selector workflowModule.setExternalElements( workflowInstance, "fldMultipleUserSelector", arrUsers ); }
For an advanced using, VDoc provides a SQL request system that lets directly recover API SDK elements.
Every object implementing the interface ISearchSupport may be directly retrieved via a SQL request.
[com.axemble.vdoc.sdk.supports.ISearchSupport] [IAction] [ICatalog] [IResource] [ILinkedResource] [IWorkflowInstance] [IResourceDefinition] [IRole] [ITask] [ITaskInstance] [IUser] [IOperator] [IWorkflow] [IWorkflowContainer]
Example1: recovering every application documents
public void document_useSearch( IContext context, IWorkflowModule workflowModule ) { try { IJdbcReference jdbcReference = workflowModule.getJdbcReference( context, "vdocDatabase" ); ISearchController searchController = workflowModule.getSearchController( jdbcReference ); Collection docs = searchController.findElements( IWorkflowInstance.class, "select id from vdp_treatments", null ); for ( Iterator iter = worflowInstances.iterator() ; iter.hasNext() ; ) { IWorkflowInstance workflowInstance = (IWorkflowInstance)iter.next(); } } catch( Exception e ) { getNavigator().processErrors( e ); } }
Example2: recovering the user whose login is "froggy"
Object[] arrParams = new Object[1]; arrParams[0] = "froggy"; Collection users = searchController.findElements( IUser.class, "select id from vdp_users where login = ?", arrParams ); for ( Iterator iterUser = users.iterator() ; iterUser.hasNext() ; ) { IUser user = (IUser)iterUser.next(); }
To recover the dynamic table elements, you just have to use the method getLinkedResources(). This one returns a list of objects ILinkedResource.
public void document_browseTableLines( IWorkflowInstance workflowInstance ) { Collection linkedResources = workflowInstance.getLinkedResources( "propertyName" ); for ( Iterator iter = linkedResources.iterator() ; iter.hasNext() ; ) { ILinkedResource linkedResource = (ILinkedResource)iter.next(); String textValue = (String)linkedResource.getValue( "textColumn_1" ); Float numberValue = (Float)linkedResource.getValue( "numberColumn_2" ); } }
The method createLinkedResource() simplifies the way to create table rows. You just have to indicate on each field (property system name) you want to create a row.
public void document_createTableLines( IWorkflowInstance workflowInstance ) { // creating a row ILinkedResource linkedResource = workflowInstance.createLinkedResource( "propertyName" ); String textValue = "some text"; Float numberValue = new Float( 7 ); // positioning some values linkedResource.setValue( "textColumn_1", textValue ); linkedResource.setValue( "numberColumn_2", numberValue ); // adding the row to the table workflowInstance.addLinkedResource( linkedResource ); }
In this example, three methods are displayed to add files in the attachments field.
public void document_createAttachment( IWorkflowModule module, IWorkflowInstance instance ) throws WorkflowModuleException { // creating an attachment object from a file on the server IAttachment idisk = module.addAttachment( instance, "propertyName", "xxx", "c:/xxx.xls" ); // creating an attachment object from a java.io.InputStream InputStream inputStream = null; IAttachment istream = module.addAttachment( instance, "propertyName", "document_name", inputStream ); // creating an attachment object from a java.io.File object File file = new File( "c:/tmp/document_name.xls" ); IAttachment ifile = module.addAttachment( instance, "propertyName", file ); }
The method getAttachments() of the workflow module enables to recover every files of an attachment field. It is then possible,via the IAttachment interface, to recover, for each file every information and content.
public void document_getAttachments( IWorkflowModule module, IWorkflowInstance instance ) throws WorkflowModuleException, FileNotFoundException { Collection attachments = module.getAttachments( instance, "propertyName" ); for ( Iterator iter = attachments.iterator() ; iter.hasNext() ; ) { IAttachment attachment = (IAttachment)iter.next(); // retrieving the name attachment.getName(); // retrieving the size attachment.getSize(); // retrieving the content in a OutputStream attachment.getContent( new FileOutputStream( new File( "c:/tmp/xxx.yyy" ) ) ); // retrieving the content in a file attachment.getContent( new File( "c:/tmp/xxx.yyy" ) ); } }
In this example, several elements are displayed:
public void document_changeStage( IWorkflowModule module, IWorkflowInstance instance ) throws WorkflowModuleException { IContext localContext = module.getContextByLogin( "froggy" ); ITaskInstance taskInstance = instance.getCurrentTaskInstance( localContext ); if ( taskInstance != null ) { IAction action = taskInstance.getTask().getAction( "actionName" ); if ( action != null ) { module.end( localContext, taskInstance, action, "decription" ); } } }
In this example are shown two methods for converting documents from and into XML.
public void document_transform( IWorkflowModule module, IWorkflowInstance instance ) throws WorkflowModuleException, IOException { // retrieving a transformation object ITransformer transformer = module.getTransformer(); // converting a workflow instance into a XML file FileOutputStream xmlOutput = new FileOutputStream( new File( "D:/tmp/sdk/XXX.xml" ) ); transformer.resourceToXML( instance, xmlOutput ); // converting a XML file into a workflow instance InputStream inputStream = new FileInputStream( new File( "D:/tmp/sdk/XXX.xml" ) ); transformer.xmlToResource( inputStream ); }