8 Administration of HOPEX from APIs
The objective of administration applications is to manage workspaces, environments, users, etc. HOPEX administration can be carried out from the application itself or from the outside.
8.1 Introduction
8.1.1 Starting administration
To start an administration application in VBScript, you must use a MegaApplication type variable. You can access such a variable by using the standard CreateObject function:
Dim oMegaApplication
Set oMegaApplication = CreateObject ("Mega.Application")
When the variable has been created, you can access all the properties accessible from the MegaApplication class and its associated objects (environment, repository, etc.).
Before each execution of components using Administration API (CreateObject (“Mega.Application”)), you must reference Mega.Application. To do so, use the HOPEX-regserver.ps1 powershell script available at the root folder of the HAS instance:
<Path to HAS>\HOPEX Application Server\<Instance port>
C;\MEGA\HOPEX Application Server\5000
>.\HOPEX-regserver.ps1
8.1.2 Connecting to an open session
To connect to an open session to analyze or modify the current repository:
use a MegaCurrentEnv type variable, or
use the standard function CreateObject ("MegaRepository.CurrentEnv").
From such a variable you can access the repository root (MegaRoot) and therefore all the contained objects.
Example: access to the current repository. This example displays the number of repository procedures:
Dim oMegaCurrentEnv
Set oMegaCurrentEnv = CreateObject (“MegaRepository.CurrentEnv”)
Dim oMegaRoot as MegaRoot
Set oMegaRoot = oMegaCurrentEnv.GetRoot
MsgBox oMegaRoot.Getcollection ("Procedure").Count
Connection to an already open HOPEX session or manual opening
The MegaCurrentEnv object enables you to determine whether a HOPEX session is open or not by means of the IsSessionOpen function.
If the HOPEX session is not open, the GetRoot function now proposes an interactive connection dialog box enabling the user to open a session.
Intrusion protection
To protect the repository against malicious intrusion, HOPEX displays an acceptance message when calling the GetRoot function. This behavior can be cancelled in the case of a call originated by HOPEX. To do this, see the reference guide, SetOpenToken function.
8.2 Repository Administration Tasks
You can carry out certain HOPEX administration tasks using APIs.
You can execute these tasks by means of VB scripts written and stored in external .vbs files.
HOPEX must be closed during execution of VB scripts carrying out administration tasks. The data regarding environments, workspaces, users and repositories cannot be read when a HOPEX session is open.
8.2.1 Getting the environment IdAbs
To get the environment IdAbs, enter the following code in a .vbs file:
Set oMegaApp = CreateObject ("Mega.Application")
Set oEnvironment = oMegaApp.Environments.Item("EnvironmentFolder")
MsgBox "Idabs de l'environnement: " & oEnvironment.GetProp("EnvHexaIdAbs")
Replace "EnvironmentFolder" in bold by the environment path.
Code description:
Set oMegaApp = CreateObject ("Mega.Application")
Creates an instance of the class MegaApplication and assigns it to the "oMegaApp" Variable. This class defines the data corresponding to a HOPEX site.
Set oEnvironment = oMegaApp.Environments.Item("EnvironmentFolder")
From the environments defined for the application oMegaApp, the environment located in the "EnvironmentFolder" folder is retrieved and assigned to the "oEnvironment" Variable.
You must specify the path in the form in which the environment was referenced (if a UNC path was used, you must use the UNC path).
MsgBox "IdAbs of the environment: " & oEnvironment.GetProp("EnvHexaIdAbs")
The environment IdAbs is retrieved.
8.2.2 Connecting to an open repository
To connect to an open repository, enter the following code in a .vbs file:
Set oMegaApp = CreateObject ("Mega.Application")
Set oEnvironment = oMegaApp.Environments.Item("EnvironmentFolder")
oEnvironment.CurrentAdministrator = "Administrator"
oEnvironment.CurrentPassword = "AdministratorPassword"
Set oDataBase = oEnvironment.Databases.Item("RepositoryName")
Replace the words in bold by the environment path, administrator name, administrator password, repository name and repository logical backup file name respectively.
Code description:
Set oMegaApp = CreateObject ("Mega.Application")
Creates an instance of the class MegaApplication and assigns it to the "oMegaApp" Variable. This class defines the data corresponding to a HOPEX site.
Set oEnvironment = oMegaApp.Environments.Item("EnvironmentFolder")
From the environments defined for the application oMegaApp, the environment located in the "EnvironmentFolder" folder is retrieved and assigned to the "oEnvironment" Variable.
You must specify the path in the form in which the environment was referenced (if a UNC path was used, you must use the UNC path).
oEnvironment.CurrentAdministrator = "Administrator"
The administrator name is entered.
oEnvironment.CurrentPassword = "AdministratorPassword"
The administrator password is entered.
Set oDataBase = oEnvironment.Databases.Item("RepositoryName")
From the repositories of the selected environment, the "RepositoryName" repository is retrieved and assigned to the "oDataBase" variable.
8.2.3 Repository logical backup
Having written code for connection to the repository oDataBase, enter the following code in a .vbs file:
oDataBase.LogicalSave "LogicalBackupFileName")
WScript.Echo "Processing completed"
Code description:
oDataBase.LogicalSave "LogicalBackupFileName")
Applies the "LogicalSave" function (which carries out repository logical backup) to the selected repository, specifying the complete name of the backup file.
WScript.Echo "Processing completed"
When logical backup is completed, a window appears and displays "Processing completed".
8.2.4 Compiling the environment
To compile the environment use the Compilation macro:
oRoot.CallFunction("~91tmJFSUQL6I[Compilation]", MetaModel, TechnicalData, Permission, DeleteOldCompilationResults, SaveCurrentCompilationResults)
Dim oRoot
Dim MetaModel,TechnicalData,Permission,DeleteOldCompilationResults,SaveCurrentCompilationResults
MetaModel=1
TechnicalData=1
Permission=1
DeleteOldCompilationResults = 1
SaveCurrentCompilationResults = 1
sResult = oRoot.CallFunction("~91tmJFSUQL6I[Compilation]", MetaModel, TechnicalData, Permission, DeleteOldCompilationResults, SaveCurrentCompilationResults)
sResult is a json that gives a status after compilation:
{
"compilationrequired":1,
"metamodelcompiled":1,
"technicaldatacompiled":1,
"permissionscompiled":1,
"messages":[]
}
8.2.5 Getting the environment compilation states
The IsCompiled function can be used to get information regarding the Metamodel and Technical Data compilations, but this function does not take into account more compilation states like permissions.
To get more information regarding the current environment compilation state, use
CurrentEnvironment.GetCompilationStates
This function enables to get the compilation states of MetaData, TechnicalData, MetaPicture, MetaTreeNode, DiagramTypeZoom, DiagramType, Query, and Permission.
It returns a bit string (0 to 8) corresponding to each of the states
&H0001 for "MetaData"
&H0002 for "TechnicalData”
&H0004 for "Workflow"
&H0008 for "MetaPicture"
&H0010 for "MetaTreeNode"
&H0020 for "DiagramTypeZoom"
&H0040 for "DiagramType"
&H0080 for "Query"
&H0100 for "Permission"
Example: to get the permission compilation state of the current environment, enter the following code in a .vbs file:
Dim uStates
uStates = oRoot.CurrentEnvironment.GetCompilationStates
if uStates and &H0100 then
print "Permissions are compiled"
else
print "Permissions are not compiled"
end if
8.2.6 Reinitializing a repository backup logfile
Having written code for connection to the repository oDataBase, enter the following code in a .vbs file:
Set oDataBaseLog = oDataBase.Log
oDataBaseLog.Reset
WScript.Echo "Processing completed"
Code description:
Set oDataBaseLog = oDataBase.Log
The selected repository logfile is retrieved and assigned to the variable "oDataBaseLog".
oDataBaseLog.Reset
The "Reset" function, which reinitializes this logfile, is applied to the repository logfile.
WScript.Echo "Processing completed"
When backup is completed, a window appears and displays "Processing completed".
8.2.7 Deleting a repository
Having written code for connection to the repository oDataBase, enter the following code in a .vbs file:
oDataBase.Destroy
WScript.Echo "Processing completed"
Code description:
oDataBase.Destroy
The "Destroy" function that deletes the repository is applied to the selected repository.
WScript.Echo "Processing completed"
When deletion of the repository is completed, a window appears and displays "Processing completed".
8.2.8 Deleting a workspace
Having written code for connection to the repository oDataBase, enter the following code in a .vbs file:
oTransaction.Abort
WScript.Echo "Processing completed"
Code description:
oTransaction.Abort
The "Abort" function that deletes the workspace is applied to the workspace.
WScript.Echo "Processing completed"
When deletion of the workspace is completed, a window appears and displays "Processing completed".
8.2.9 Disabling repository log
A session parameter enables to disable repository log when running HOPEX API processing.
To prevent repository log deactivation for updates independent from the current thread, you can only deactivate the repository log using the update privilege.
The repository log deactivation is managed by an option, a new script parameter of EnterPrivilege:
MegaRoot.EnterPrivilege "DESCRIPTION","DisableLog=1"
8.2.10 Deactivating/Reactivating repository log
For performance optimization, you can deactivate/reactivate the repository log (also undo, locks, CRUD test) in a macro.
8.2.11 Flushing the ERQL cache
Query results are cached. This avoid repeating calculation of the same query results, so that frequently used queries are executed faster.
For test purpose, if you need to flush this ERQL cache, use the following function:
CurrentEnvironment.RefreshQueryResult
8.2.12 Initializing and synchronizing a Reporting Datamart
From HOPEX Administration application (Administration.exe) you can schedule a synchronization on all the repositories for all their Reporting Datamarts.
Using APIs, you can launch and particularly schedule actions on a specific repository, for a specific Reporting Datamart, and without connecting to the Administration application.
Use:
DataInitialize to initialize the Reporting Datamart data with the HOPEX repository content according to the user/profile permissions and the object type selected at Reporting Datamart creation.
StructureInitialize to initialize the structure with the HOPEX repository metamodel. All the tables and columns are created even if there is no data to feed them. The table remains empty, so that the Reporting Datamart structure is always consistent. This ensures the user that any of his queries run properly on the Reporting Datamart.
IncrementalUpdate to launch an incremental synchronization to update the Reporting Datamart with all the dispatches performed after the last synchronization.
ComputedAttributesSync to launch a calculated MetaAttribute synchronization to scan all the objects and links of the HOPEX repository that can have calculated MetaAttribute values and put their values in the Reporting Datamart.
Do not launch or schedule a calculated MetaAttribute synchronization if you do not use the values of calculated MetaAttributes from the Reporting Datamart.
DiagramsSync to launch a diagram synchronization to scan all the HOPEX repository diagrams and update the Reporting Datamart with their drawing representation in the SVG format.
Do not launch or schedule a diagram synchronization if yo u do not use diagrams.
|
VB Script
|
For example, to initialize the “datamart1” Reporting Datamart data with the “EA” HOPEX repository content:
set oEnv = CurrentEnvironment.Site.Environments.Item(CurrentEnvironment.Path)
set oDbEA = oEnv.Databases.Item("EA")
set oDbEADatamarts = oDbEA.Datamarts
set oDm1 = oDbEADatamarts.Item("datamart1")
oDm1.DataInitialize()
Code description:
set oEnv = CurrentEnvironment.Site.Environments.Item(CurrentEnvironment.Path)
set oDbEA = oEnv.Databases.Item("EA")
Specifies the HOPEX repository from which the Reporting Datamart is created: EA.
set oDm1 = oDbEADatamarts.Item("datamart1")
“datamart1” is the name of the Reporting Datamart to be updated.
oDm1.DataInitialize()
“datamart1” data is initialized with the “EA” HOPEX repository.
|
8.2.13 Getting repository information
To get information regarding the repository use the MegaRoot.GetBaseInfo(“<information>”) function.
If the MegaRoot is on the System Repository, to get the information on SystemDB, add:
Set MegaSystemRoot = MegaRoot.GetSystemRoot
MegaSystemRoot.GetBaseInfo(“<information>”)
Use:
MegaRoot.GetBaseInfo(“<information>”) to get the information in string format.
MegaRoot.GetBaseInfo("<information>","Internal") to get the information in internal format. This can be particularly useful for dates.
MegaRoot.GetBaseInfo(“#n”) to get all the information
where <information> can be:
TRANSTATE
STARTSTATE
STARTDATE
TRANSTATE_ORIGIN
IDABS
LANGUAGE_IDABS
LANGUAGE_NAME
PATHNAME
PATHNAME_WORK
PATHNAME_USER
DB_ALLOCATEDSIZE
DB_ALLOCATEDUSEDSIZE
MGE_REJECT_FILELONGNAME
MGR_REJECT_FILELONGNAME
MGL_REJECT_FILELONGNAME
BDATABASESYSTEM
BSYSTEM
DMP_FILELONGNAME
TRANSACTION_IDABS
CONNECTION_IDABS
TRAN_NAME
TRAN_LOGACTIVITY
TRAN_CRD_FILELONGNAME
TRAN_PATHNAME
TRAN_TYPE
TRAN_OPENMODE
TRAN_MGL_FILELONGNAME
TRAN_MGE_FILELONGNAME
TRAN_MGR_FILELONGNAME
TRAN_EXT_FILELONGNAME
TRAN_CMP_FILELONGNAME
TRAN_DEL_FILELONGNAME
XMG_REJECT_FILELONGNAME
TRAN_DATE_CREATION
TRAN_DATE_VALIDATION
TRAN_DATE_CONNEXION
TRAN_SIZE
PROFILE_SZ
TRAN_VERSION
DEFAULT_AUTHORIZATION
DEFAULT_VISIBILITY
BASELINE
ADVANCEDOBJECTTRACKING
DB_AREATYPE
DB_CONTENT_UPDATE_COUNT
For example, to get the absolute identifier (IdAbs) of a workspace (transaction):
MegaRoot.GetBaseInfo("TRANSACTION_IDABS")
8.3 Executing tasks offline
Certain time-consuming processing operations can be batch-executed using administration commands and MEGA APIs.
8.3.1 Reorganizing repositories
The script given as an example below enables reorganization of all repositories of the first environment of a site. It saves active workspaces in logfiles and executes logical backup of repositories. This script is an administration script: HOPEX must therefore be closed before running the script. Workspaces are recreated and their logfiles reinjected.
Explicit Option
Dim TabTrans(256,2), sDbSave, sDbRej, STransSave, sTransRej, sAdministratorName, sPassword
Dim oMegaApp, oDataBase, oEnvironment, oTransaction, i, j, oShell, sSystem
i=0
' TODO: replace the two values with an available HOPEX user and its optional password.
sAdministratorName = "a user name"
sPassword = "your password"
Set oMegaApp = CreateObject ("Mega.Application") Set oEnvironment = oMegaApp.Environments.Item(1)
oEnvironment.CurrentAdministrator = sAdministratorName if sPassword <> "" then oEnvironment.CurrentPassword = sPassword
' Stores each workspace in a logfile.
'There must be no active workspace
For each oTransaction in oEnvironment.Transactions
If Right(oTransaction.Name,8)= "(System)" Then
Else
i=i+1
TabTrans(i,1) = oTransaction.User name
TabTrans(i,2) = oTransaction.Database.name
STransSave = oEnvironment.path & "\Mega_usr\Trans" & oTransaction.Name & ".mgl"
oTransaction.Database.Log.Export STransSave
oTransaction.abort
End If
Next
' Performs the logical save of each repository except the system repository.
For each oDatabase in oEnvironment.Databases
If oDatabase.Name="SystemDb" Then
Else
sDbSave = oEnvironment.path & "\Mega_usr\DB" & oDataBase.Name & ".mgr"
sDbRej = oEnvironment.path & "\Mega_usr\DB" & oDataBase.Name & "Rej.mgr"
oDataBase.LogicalSave sDbSave,"meta=off,technical=off,data=On,FileOpen=Rewrite"
oDataBase.Reset
odataBase.Import sDbSave, sDbRej
End If
Next
' Creates new workspace replacing the previous ones.
For j= 1 to i
oEnvironment.Transactions.create TabTrans(j,2), TabTrans(j,1)
Next
' Imports the saved logs in the corresponding workspaces.
For each oTransaction in oEnvironment.Transactions
sTransSave = oEnvironment.path & "\Mega_usr\Trans" & oTransaction.Name & ".mgl"
sTransRej = oEnvironment.path & "\Mega_usr\Trans" & oTransaction.Name & "Rej.mgl"
If Right(oTransaction.Name,8)= "(System)" Then
Else
oTransaction.Database.import sTransSave,sTransRej
End If
Next
Set oTransaction = Nothing
Set oDataBase = Nothing
Set oEnvironment = Nothing
Set oMegaApp = Nothing
MsgBox "Environment closed"
8.3.2 Generating documents
To create a document using a VB script:
Apply the NewDocument method to a MegaObject.
This method takes as a parameter the document template from which you create the document.
The NewDocument method returns the created document.
Example:
Set oRoot = object.GetRoot
Set objDoc = oRoot.GetCollection("~pj)grmQ9pG90[Business Process]").Item("~2F6SN4tSpyh0[Purchasing]").NewDocument("Business Process documentation")
Creates a document on the "Purchasing" business process from the "Business Process Description" document template and assigns it to the variable "objDoc".
To update document links:
Apply to the document the RefreshDocument method without a parameter.
Example:
Set RefreshStatus = objDoc.RefreshDocument()
This method returns an object with value:
• 1 when document update is in progress
• 0 if document update is completed.
Two document update operations cannot be started simultaneously.
To detach a document from HOPEX:
Apply to the document the DetachDocument method. This takes as parameter the complete file name (example: C:\My documents\Document.doc).
Example:
objDoc.DetachDocument("C:\My documents\Document.doc")
This method detaches the current document, cuts document links and creates a file independent of HOPEX.
8.3.3 Generating Web sites
To generate a Web site:
Apply to the Web site the GenerateWebSite() function. Example:
Set oRoot = object.GetRoot
Set oWebSiteList = oRoot.GetCollection("Web Site")
For each oWebSite in oWebSiteList
oWebSite.GenerateWebSite()
Next
In this example, Web sites existing in HOPEX are retrieved and we apply to each one the GenerateWebSite() function.
VB scripts also enable generation of the CHM file corresponding to a Web site. Apply to the Web site the GenerateCHM() function.
Example:
Set oRoot = object.GetRoot
Set oWebSiteList = oRoot.GetCollection("Web Site")
For each oWebSite in oWebSiteList
oWebSite.GenerateCHM()
Next
In this example, Web sites existing in HOPEX are retrieved and you apply to each one the GenerateCHM() function.