Example of creating a bundle from a bundle template Several cases are displayed in this example:
public void document_createBundle( IDocumentManagementModule module, IContext context, IBundleDefinition bundleDefinition ) throws Exception
{
// creating a bundle by using the bundle setting
IBundle bundle = module.CreateBundleByBundleDefinition( context, bundleDefinition, "reference", "title" );
// creating a bundle by using the bundle setting and specifying the location in the folders
IFolder folder = module.GetFolderByName( context, module.getRootFolder(), "Folder SDK" );
IBundle folderBundle = module.CreateBundleIntoFolder( context, bundleDefinition, "reference", "title", folder );
// creating a bundle by using the bundle setting and specifying the location in data
ISimpleDataForm form = module.GetSimpleDataFormByName( module.getRootDataForm(), "Form SDK" );
IDataUnit dataUnit = module.CreateDataUnit( form );
IBundle dataBundle = module.CreateBundleIntoDataUnit( context, bundleDefinition, "reference", "title", dataUnit );
// creating a bundle 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 );
IBundle folderAndDataBundle = module.CreateBundle( context, bundleDefinition, "reference", "title", folder, dataUnit );
// positioning the bundle version number
bundle.getVersion().setVersion( "1.0" );
// how about the bundle creation
bundle.getVersion().setComment( "Creation of a bundle via the SDK VDoc" );
IResource resource = bundle.getVersion().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( "List selector", "A1" );
// A1, being part of the list resource.SetValueAsString( "List simple", "AZERTY" );
// AZERTY, being part of the list
// multiple list-type value _OptionCollection arr = module.CreateCollection();
arr.Add( "BB" );
arr.Add( "CC" );
// BB and CC, both belonging to the list
resource.SetValueAsCollection( "List multiple", 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( "List selector multiple", arr );
resource.Save();
}Example of creating a new bundle.
public void document_createNewBundle( IDocumentManagementModule module, IContext context, IBundle bundle ) throws Exception
{
IBundle newBundle = module.CreateNewBundle( context, bundle, bundle.getVersion().getReference(), bundle.getVersion().getTitle(), "how for the new version." );
IVersion version = newBundle.getVersion();
IResource resource = version.getResource(); resource.Save();
LOGGER.info( "version:" + resource.getId().getAsString() + ", reference:" + version.getReference() + ", title:" + version.getTitle() + ", version:" + version.getVersion() + ", how:" + version.getComment() );
}Example of browsing the bundle content
public void document_getBundleContent( IDocumentManagementModule module, IContext context, IBundle bundle ) throws Exception
{
// recovering the bundle elements in the form of versions
_VersionCollection elements = bundle.getElements();
for ( int index = 0 ; index < elements.getCount() ;
index++ )
{
IVersion element = elements.getItem( index );
// checking the element type if ( element.getIsBundle() )
{
// recovering the bundle
IBundle childBundle = element.getBundle();
// recovering the bundle version
IVersion childVersion = childBundle.getVersion();
// recovering the resource associated to the version
IResource childResource = childVersion.getResource();
LOGGER.info( "bundle:" + childResource.getId().getAsString() + ", reference:" + element.getReference() + ", title:" + element.getTitle() + ", version:" + element.getVersion() + ", version:" + element.getComment() );
}
else
{
// recovering the resource associated to the element
IResource resource = element.getResource();
LOGGER.info( "version:" + resource.getId().getAsString() + ", reference:" + element.getReference() + ", title:" + element.getTitle() + ", version:" + element.getVersion() + ", version:" + element.getComment() );
}
}
}Retrieving all the bundles at the server root. The example presents the class _BundleCollection.
public void document_getBundles( IDocumentManagementModule module, IContext context ) throws Exception
{
// recovering every bundles
_BundleCollection bundles = module.GetBundles( context );
for ( int index = 0 ; index < bundles.getCount() ; index++ )
{
IBundle bundle = bundles.getItem( index );
// retrieving the associated version
IVersion version = bundle.getVersion();
// recovering the resource associated to the version
IResource resource = version.getResource();
LOGGER.info( "bundle:" + resource.getId().getAsString() + ", reference:" + version.getReference() + ", title:" + version.getTitle() + ", version:" + version.getVersion() + ", comment:" + version.getComment() );
}
}Retrieving all the bundles at the server root. The example presents the class _BundleCollection.
public void document_getChildBundles( IDocumentManagementModule module, IContext context, IBundle bundle ) throws Exception
{
// retrieving the sub-bundles
_BundleCollection bundles = module.GetChildBundles( context, bundle );
for ( int index = 0 ; index < bundles.getCount() ; index++ )
{
IBundle child = bundles.getItem( index );
// recovering the version associated to the sub-bundle
IVersion version = child.getVersion();
// recovering the resource associated to the version
IResource resource = version.getResource();
LOGGER.info( "bundle:" + resource.getId().getAsString() + ", reference:" + version.getReference() + ", title:" + version.getTitle() + ", version:" + version.getVersion() + ", comment:" + version.getComment() );
}
}