Versions tasks

Creating a version from a document type

Example displaying the different ways to create versions from a document type.

public void document_createVersion( IDocumentManagementModule module, IContext context, IResourceDefinition resourceDefinition ) throws Exception 
{ 
        // creating a version by using the default setting 
        IVersion version = module.CreateVersionByResourceDefinition( context, resourceDefinition, "reference", "title" ); 
        // creating a version by using the default setting and specifying the location in the folders 
        IFolder folder = module.getRootFolder().GetFolder( "Folder SDK" ); 
        IVersion folderVersion = module.CreateVersionIntoFolder( context, resourceDefinition, "reference", "title", folder ); 
        // creating a version by using the default setting and specifying the location in the data 
        ISimpleDataForm form = module.GetSimpleDataFormByName( module.getRootDataForm(), "Form SDK" ); 
        IDataUnit dataUnit = module.CreateDataUnit( form ); 
        IVersion dataVersion = module.CreateVersionIntoDataUnit( context, resourceDefinition, "reference", "title", dataUnit ); 
        // creating a version by specifying the locations in the folders and the data 
        folder = module.getRootFolder().GetFolder( "Folder SDK" ); 
        form = module.GetSimpleDataFormByName( module.getRootDataForm(), "Form SDK" ); 
        dataUnit = module.CreateDataUnit( (ISimpleDataForm)form ); 
        IVersion folderAndDataVersion = module.CreateVersion( context, resourceDefinition, "reference", "title", folder, dataUnit );
        // position of the version number version.setVersion( "1.0" ); 
        // how about the version creation version.setComment( "Creation of a version via la SDK VDoc" ); 
        IResource resource = version.getResource(); 
        // boolean-type value resource.SetValueAsBool( "Boolean", true ); 
        // date-type value resource.SetValueAsDate( "DateTime", new Date() ); 
        resource.SetValueAsDate( "SmallDateTime", new Date() ); 
        // single list-type value resource.SetValueAsString( "Single selector", "A1" ); 
        // A1, being part of the list resource.SetValueAsString( "Simple list", "AZERTY" ); 
        // AZERTY, being part of the list 
        // multiple list-type value
         IOptionCollection arr = module.CreateCollection(); 
         arr.Add( "BB" ); 
         arr.Add( "CC" ); 
        // BB and CC, both belonging to the list 
        resource.SetValueAsCollection( "Multiple list", arr ); 
        arr = module.CreateCollection(); 
        arr.Add( "B1" ); 
        arr.Add( "B2" ); 
        arr.Add( "B3" ); 
        // B1, B2 and B3,the three belonging to the list 
        resource.SetValueAsCollection( "Multiple selector", arr ); 
        resource.Save(); 
}

Creating a version from a document template

Example of creating a version from a document template

public void document_createVersion( IDocumentManagementModule module, IContext context, IAttachmentTemplate template ) throws Exception 
{ 
        // recovering a folder 
        IFolder folder = module.getRootFolder().GetFolder( "Folder SDK" ); 
        // recovering data 
        ISimpleDataForm form = module.GetSimpleDataFormByName( module.getRootDataForm(), "Form SDK" ); 
        IDataUnit dataUnit = module.GetDataUnitByDataForm( form, new Object[]{"123"} ); 
        // creating a version by using a document template 
        IVersion version = module.CreateVersionByAttachmentTemplate( context, template, "reference", "title", folder, dataUnit ); 
        // recovering the resource associated to the version 
        IResource resource = version.getResource(); 
        // saving the resource. resource.Save(); 
}

Creating a version from a file

Example of creating a version by adding a file. The example presents the class IAttachment.

public void document_createVersion( IDocumentManagementModule module, IContext context ) throws Exception 
{ 
        // creating a version IVersion version = null; 
        // module.CreateVersion...; 
        // recovering the resource associated to the version 
        IResource resource = version.getResource();
        // saving the resource. resource.Save(); 
        // adding the attachment 
        IAttachment attachement = module.AddAttachment(version, "C:\\sdk\\any.doc"); 
}

Changing Version Step

Example of Step Change The example presents the classes ITaskInstance et IAction.

static void document_changeState( IDocumentManagementModule module, IContext context, IVersion version ) throws Exception 
{ 
        // recovering an active task on the version 
        ITaskInstance taskInstance = module.GetOneTaskInstance( context, version ); 
        // recovering the assigned "validate" action 
        IAction action = taskInstance.gettask().GetAction( module.getVALIDATE_ACTION() ); 
        //changing Version Step taskInstance.End( action, "Commentaire de changement d'étape" ); 
}

Creating a new version

Example of creating a new version.

public void document_createNewVersion( IDocumentManagementModule module, IContext context, IVersion version ) throws Exception 
{ 
        IVersion newVersion = module.CreateNewVersion( context, version, version.getReference(), version.getTitle(), "how to the new version." ); 
        IResource resource = newVersion.getResource(); resource.Save(); 
        LOGGER.info( "version:" + resource.getId().getAsString() + ", reference:" 
        + newVersion.getReference() + ", title:" + newVersion.getTitle() + ", version:" 
        + newVersion.getVersion() + ", comment:" + newVersion.getComment() ); 
}