Lifecycle Applications |
EBOM Part & Assembly Detailing |
Adding Business Rules to a CommandCustomizing a command with a pre- and post-process |
Use Case |
AbstractThis article shows how to extend a server command to perform some checks before executing this command and to perform some works after executing this same command. |
This use case is intended to show you how to implement a single interface to plug in rules before executing a command and after its execution.
A command has input parameters, is executed, and can have output parameters. A command is also designed
to call some additional code to check specific rules or execute specific actions depending on each customer.
This additional code is made available to the command by implementing the Prepare and Cleanup methods of
the CATIAVPMVDACommandExtension interface in an extension class of the command.
Before executing, the command will call the Prepare method. At this point, Prepare can have access to all
the input parameters of the command. If those parameters, or if other conditions are not satisfactory, Prepare
can return an error code to prevent the command from beeing executed.
If Prepare returns successfully, and the command is executed, it then calls the Cleanup method. At this point,
Cleanup can have access to all input and output parameters. But returning an error code here will have no effect
on the command execution, since this execution is completed.
[Top]
CAADkoCommandExtenstion is a use case of the CAAVPMDesktopObjects.edu framework that illustrates VPMDesktopObjects framework capabilities.
[Top]
CAADkoCommandExtension is a data extension of the CATIAVPMAddChild command. The way to extend other server commands is exactly the same, so we just extend one of them.
CATIAVPMAddChild is used to create a business object and attach it to a parent business object, for example when creating a Part Instance and attaching it to a Product Root Class.
Before the execution, we check that a Context object (of type ENOVIA_VPMContext) already exists, and that its identifier is composed of the name of the object to create to which the string " for context" is appended. If this context object does not exist, we send back an error code to prevent the command from creating the object.
[Top]
To launch CAADkoCommandExtension , you will need to set up the build time environment, then compile CAADkoCommandExtension along with its prerequisites, set up the run time environment, and then execute the use case [1].
[Top]
The CAADkoCommandExtension use case is made of a single file located in the CAADkoCommandExtension.m module of the CAAVPMDesktopObjects.edu framework:
Windows | InstallRootDirectory\CAAVPMDesktopObjects.edu\CAADkoCommandExtension.m\ |
Unix | InstallRootDirectory/CAAVPMDesktopObjects.edu/CAADkoCommandExtension.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are three logical steps in CAADkoCommandExtension:
[Top]
class ExportedByCAADkoCommandExtension CAADkoCommandExtension : public CATBaseUnknown { CATDeclareClass; public : /** Default Constructor. */ CAADkoCommandExtension(); /** Destructor. */ virtual ~CAADkoCommandExtension(); /** Called just before the execution of the command. * The execution of a command is made of three steps : preparation with parameters, * execution, cleanup and retrieval of the results. This method is called just before * the execution, so that every parameter is accessible and the execution of the command * can be cancelled if this method returns an error code. */ HRESULT Prepare(); /** Called just after the execution of the command. * This method is called just after the execution, so that further work can be done * on the results of the command. */ HRESULT Cleanup(); private : /** Copy constructor. */ CAADkoCommandExtension( const CAADkoCommandExtension & Extension ); }; |
The implementation file is the following (empty so far) :
/** Class to implement custom rules when using the AddChild command (example). * The purpose of this implementation is to code custom rules before and after executing a * server command. |
[Top]
CATIAVPMVDAAddChild_var spAddChild( this ); |
spAddChild->get_ChildData( pChildtype, pIdentifier, pName, pDescription, piChildReference ); |
// Construct and get an Exists Command, to search for objects. CATIAVPMVDACommandFactory_var spCommandFactory = GetCommandFactory(); CATIAVPMVDACommand * piCommand = NULL; CATUnicodeString ExistsString( "Exists" ); // Create the Exists command. RC = spCommandFactory->Create( ExistsString, piCommand ); |
// Retrieve the interface of this Exists command. CATIAVPMVDAExists * piExistsCommand = NULL; RC = piCommand->QueryInterface( IID_CATIAVPMVDAExists, (void **) & piExistsCommand ); |
// Constructs parameters for the command. CATUnicodeString ObjectType( "ENOVIA_VPMContext" ); // Execute the Exists Command. piExistsCommand->put_Type( ObjectType ); piExistsCommand->put_ID( ContextName ); piExistsCommand->Exec(); |
// Get the result object, if any. ENOVIABusinessObject * piObjectResult = NULL; piExistsCommand->get_BObject( piObjectResult ); if ( piObjectResult != NULL ) { // The Context object exists, the check is good. piObjectResult->Release(); piObjectResult = NULL; } else { // The Context object does not exists, we suppose then that it is // an error, send an error code to bypass the execution. RC = E_FAIL; } |
[Top]
CATIAVPMVDAAddChild_var spAddChild( this ); |
// Retrieves the created object. ENOVIABusinessObject * piCreatedObject = NULL; RC = spAddChild->get_ChildBObject( piCreatedObject ); |
// Construct and get a Copy Command. CATIAVPMVDACommandFactory_var spCommandFactory = GetCommandFactory(); CATIAVPMVDACommand * piCommand = NULL; CATUnicodeString CopyString( "Copy" ); // Create a Copy Command. RC = spCommandFactory->Create( CopyString, piCommand ); // Retrieves the interface of the Copy Command. CATIAVPMVDACopy * piCopyCommand = NULL; RC = piCommand->QueryInterface( IID_CATIAVPMVDACopy, (void **) & piCopyCommand ); |
// Execute the Copy Command. piCopyCommand->put_BObject( piCreatedObject ); piCopyCommand->Exec(); |
[Top]
CATVpmVDAAddChild CATIAVPMVDACommandExtension libCAADkoCommandExtension |
[Top]
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [May 2001] | Version: 2 [October 2003] | Document created |
[Top] |
Copyright © 2001, Dassault Systèmes. All rights reserved.