Sample 03

In this sample, you will learn how to look up information from the ExpressDataManager system model.

Before reading this sample, you should run through Sample 01 and make sure you understand the basic operations of EDMsdk.

The complete package with resource files and source code is available from Getting Started with EDMsdk, but you may also download the source code of the sample below.

 

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_icon_C(30px)'.

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_xc_GettingStarted_Case_03'.

This sample use the system model ExpressDataManager. Like everything else in the EDMdatabase, the ExpressDataManager model is a population of an Express schema. The underlying express schema for the ExpressDataManager model is named express_data_manager and is an important part of this sample. You can look up the express_data_manager with the EDMsupervisor, or you can download it from the link below.

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_icon_exp(30px)'.

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_f_EXPRESS_DATA_MANAGER'.

In the following, we will walk you through all the statements and explain them. In the preparations for this sample, we connect as superuser, create a new EDMdatabase, compile the IFC4 express schema and populate it with two EDMmodels in the DataRepository.

Sample_03 Preparations
  if (rstat = edmiDefineServerContext("MyContext", 
                  "superuser", NULL, dbPwd, "LOCAL_CONTEXT", NULL, NULL, 
                  NULL, NULL, NULL, NULL, NULL, &myCtxtId)) goto err;

  if (rstat = edmiRemoteDeleteDatabase(myCtxtId, dbPath, dbName, dbPwd, NULL)) {
    if (rstat != edmiENOSUCHDATABASE) goto err;
    sdaiErrorQuery(); /* Reset the error buffer */
  }
  if (rstat = edmiRemoteCreateDatabase(myCtxtId, dbPath, dbName, dbPwd)) goto err;
  if (rstat = edmiRemoteOpenDatabase(myCtxtId, dbPath, dbName, dbPwd)) goto err;

  /* Open a local session if EDMstandaloneClient. In LOCAL_CONTEXT mode
   * the EDMuser, EDMgroup and password must be provided in a separate
   * connect statement and the session must be opened "manually" */
  if (myCommType == LOCAL_CONTEXT) {
    if (rstat = edmiConnect("superuser", NULL, dbPwd, &unavailMess)) goto err;
    if ((sessionId = sdaiOpenSession()) == 0) goto err;
  }

  /* Compile the IFC4 express schema and import two cubes */
  if (rstat = edmiRemoteDefineSchema(myCtxtId, EXPRESS_SCHEMA_TYPE, 
                  "./ifc4.exp", "./ifc4.dia", "IFC4", 0, &nWrn, &nErr, NULL)) goto err;

  if (rstat = edmiRemoteReadStepFile(myCtxtId, 
                  "DataRepository", "MyFirstCube", NULL, NULL, 
                  "./cube.ifc", "./cube.dia", "IFC4", NULL, 0, 
                  &nWrn, &nErr, &sdaiErr, NULL)) goto err;

  if (rstat = edmiRemoteReadStepFile(myCtxtId, 
                  "DataRepository", "MySecondCube", NULL, NULL, 
                  "./cube.ifc", "./cube.dia", "IFC4", NULL, 0, 
                  &nWrn, &nErr, &sdaiErr, NULL)) goto err;

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_icon_Important(30px)'.
If any of the statements shown above is unclear to you, then you should go back to Sample 01 and repeat the exercise.

The ExpressDataManager model is located in the SystemRepository. It defines an EDM_SCHEMA entity type that holds information about every express schema that has been compiled into the EDMdatabase, including nine system schemas.

Get the EDM_SCHEMA entity extent
if (rstat = edmiRemoteGetEntityExtentBN(myCtxtId, 
                "SystemRepository", "ExpressDataManager", "EDM_SCHEMA", 
                0, &schemaAggrId, &nSchema, &nSubType, NULL)) goto err;

The entity extent is an aggregate identifier ("handle") . To have a buffer of schema identifiers, we need to read them into a buffer in memory,

Read buffer of schema identifiers
if(rstat = edmiRemoteReadAggrElements(myCtxtId, schemaAggrId, 0, 0, 100, 
               &nSchema, &type, &pValueSet, &pSchemaIds, NULL)) goto err;

The number of elements in the pSchemaIds will be assigned nSchema variable. Time to loop over each schema identifier and look up the details.

The EDM_SCHEMA Entity
ENTITY edm_schema;
  name                    : _SIMPLEID;
  original_name          : _SIMPLEID;
  schema_id               : _INDEX;
  sdai_schema             : schema_definition;
  dictionary_model        : sdai_model;
  models                  : SET OF edm_model;
  schema_maps             : SET OF edm_schema_map;
  rule_schemata           : SET OF edm_rule_schema;
  query_schemata          : SET OF edm_query_schema;
  archived_models         : OPTIONAL SET OF edm_archived_model;
  xml_configuration       : SET OF edm_xml_configuration;
  description             : OPTIONAL STRING;
  source_stored           : BOOLEAN;
  source_file             : OPTIONAL express_source_file;
  line_number_offset      : OPTIONAL INTEGER;
  instantiable            : BOOLEAN;
  compilation_errors      : OPTIONAL SET OF STRING;
  compilation_warnings    : OPTIONAL SET OF STRING;
  compilation_sdai_errors : OPTIONAL SET OF STRING;
  compilation_options     : OPTIONAL INTEGER;
  flags                   : OPTIONAL INTEGER;
END_ENTITY;
Get the EDM_MODEL entity extent
  for (i=0; i<nSchema; i++) {
    SdaiString schemaName;
    SdaiAggr modelAggr;
    if(rstat = edmiRemoteGetAttrsBN(myCtxtId, *(pSchemaIds+i), 0, 2, NULL,
                   "NAME", sdaiSTRING, &schemaName,
                   "MODELS", sdaiAGGR, &modelAggr)) goto err;

    printf("\nSchema: %-30s", schemaName);

In addition to the name of the schema, we are interested in the aggregate of EDMmodels that are populations of the schema. In this sample, we will only print out the populations of the IFC schemas.

The definition of the EDM_MODEL entity is shown to the right.

Read buffer of EDMmodel identifiers
if (strstr(schemaName, "IFC")) {
  if (rstat = edmiRemoteReadAggrElements(myCtxtId, modelAggr, 0, 0, 100, 
                  &nModel, &type, &pValueSet, &pModelIds, NULL)) goto err;

  for (j=0; j<nModel; j++) {

    if (rstat = edmiRemoteGetAttrsBN(myCtxtId, *(pModelIds+j), 0, 6, NULL,
                    "NAME", sdaiSTRING, &modelName,
                    "CREATED", sdaiINTEGER, &created,
                    "REPOSITORY", sdaiINSTANCE, &repositoryId,
                    "INSTANCES", sdaiINTEGER, &nInstances,
                    "DATA_SIZE", sdaiINTEGER, &dataSize,
                    "OWNER", sdaiINSTANCE, &ownerId)) goto err;
The EDM_MODEL Entity
ENTITY edm_model;
  name                  : _SIMPLEID;
  model_id              : _INDEX;
  created               : _TIMESTAMP;
  owner                 : edm_user;
  group                 : edm_group;
  administrators        : SET OF USER_OR_GROUP;
  protection            : INTEGER;
  access_rights_for     : SET OF access_rights;
  repository            : edm_repository;
  schema                : edm_schema;
  schema_map            : OPTIONAL edm_schema_map;
  sdai_model            : sdai_model;
  packed                : BOOLEAN;
  string_encoding       : OPTIONAL STRING;
  dependent_of_models   : SET OF edm_model;
  depending_models      : SET OF edm_model;
  instances             : INTEGER;
  data_size             : INTEGER;
  last_time_updated     : _DATETIME;
  transaction_counter   : INTEGER;
  last_updating_user    : edm_user;
  step_id_model         : OPTIONAL sdai_model;
  step_data_model       : OPTIONAL sdai_model;
  description           : OPTIONAL STRING;
  versions              : OPTIONAL LIST OF edm_model_version;
  last_model_version_id : OPTIONAL INTEGER;
  flags                 : OPTIONAL INTEGER;
END_ENTITY;

Some of these are attributes are returned as plain values. For other, like the name of the owner and the repository, we need to follow the reference graphs even further.

Look up more EDMmodel info
if (rstat = edmiRemoteGetAttrsBN(myCtxtId, repositoryId, 0, 1, NULL, 
                "NAME", sdaiSTRING, &repositoryName)) goto err;

if (rstat = edmiRemoteGetAttrsBN(myCtxtId, ownerId, 0, 1, NULL, 
                "NAME", sdaiSTRING, &ownerName)) goto err;

if (rstat = edmiUnpackDate(created, &date, &dateString, 0)) goto err;

printf("\n        (%d)  Model '%s' in repository '%s' is a ", j+1, modelName, repositoryName, schemaName);
printf("\n             population of the schema '%s'. The model was created", schemaName);
printf("\n             by '%s' and contains %d instances. The model was", ownerName, nInstances);
printf("\n             created %s, and has a total size ", dateString);
printf("\n             of %d bytes\n", dataSize);
The EDM_USER entity
ENTITY edm_user;
  name                                  : _SIMPLEID;
  user_id                               : _INDEX;
  user_name                             : OPTIONAL STRING;
  created                               : _TIMESTAMP;
  last_time_connected                   : _DATETIME;
  groups                                : OPTIONAL SET OF edm_group;
  default_model_repositories_protection : INTEGER;
  default_dictionary_models_protection  : INTEGER;
  default_data_models_protection        : INTEGER;
  default_extra_schemata_protection     : INTEGER;
  default_archived_models_protection    : INTEGER;
  creating_repository_permission        : OPTIONAL BOOLEAN;
  creating_group_permission             : OPTIONAL BOOLEAN;
  owning_system_instances               : OPTIONAL SET OF entity_instance;
  password_defined                      : BOOLEAN;
  flags                                 : OPTIONAL INTEGER;
END_ENTITY;
Output from Sample 03
================================================================
Compilation result of
    EXPRESS Schema   : IFC4
    in source file   : ./ifc4.exp
================================================================

    0 WARNINGS detected.
    0 ERRORS detected.

Schema: SDAI_DICTIONARY_MODEL
Schema: SDAI_SESSION_MODEL
Schema: EXPRESS_DATA_MANAGER
Schema: HEADER_SECTION_SCHEMA
Schema: SDAI_ABSTRACT_DATA_TYPE_SCHEMA
Schema: EDM_VALIDATION_RESULT_SCHEMA
Schema: EDM_DUMMY_SCHEMA
Schema: EXPRESS_G
Schema: SYSTEM_QUERIES
Schema: IFC4
        (1)  Model 'MyFirstCube' in repository 'DataRepository' is a
             population of the schema 'IFC4'. The model was created
             by 'superuser' and contains 1926 instances. The model was
             created Mon Jul 31 10:12:31 2017, and has a total size
             of 110592 bytes

        (2)  Model 'MySecondCube' in repository 'DataRepository' is a
             population of the schema 'IFC4'. The model was created
             by 'superuser' and contains 1926 instances. The model was
             created Mon Jul 31 10:12:31 2017, and has a total size
             of 110592 bytes

   *****  DONE *****

Check also the other samples in Getting Started with EDMsdk