Example #1
0
function testDatasetUploader_registerDatasetStorage($dataset)
{
    $dataController = data_controller_get_instance();
    echo "<h2>Registering dataset</h2>\n";
    $nameSuffix = uniqid();
    $dataset->name = NameSpaceHelper::addNameSpace(DrupalDataSourceHandler::$NAME_SPACE__DEFAULT, $nameSuffix);
    $dataset->source = TABLE_PREFIX . $nameSuffix;
    $dataset->datasourceName = DrupalDataSourceHandler::$DATASOURCE__DEFAULT;
    $dataController->registerDatasetStorage(DrupalDataSourceHandler::$NAME_SPACE__DEFAULT, $dataset);
    $cube = StarSchemaCubeMetaData::initializeFromDataset(DrupalDataSourceHandler::$DATASOURCE__DEFAULT, $dataset);
    $dataController->registerCubeStorage(DrupalDataSourceHandler::$NAME_SPACE__DEFAULT, $cube);
    echo "{$dataset->name}\n";
}
    protected function generateCubes(SystemTableMetaModelLoaderCallContext $callcontext, AbstractMetaModel $metamodel) {
        $cubeCount = 0;

        $loaderName = $this->getName();

        foreach ($callcontext->logicalDatasets as $tableAccessKey => $logicalDataset) {
            $dataset = $callcontext->datasets[$tableAccessKey];

            $cubeName = $logicalDataset->name;
            $cube = new CubeMetaData();
            $cube->name = $cubeName;
            $cube->publicName = $logicalDataset->publicName;
            $cube->description = $logicalDataset->description;
            $cube->factsDatasetName = $dataset->name;
            $cube->factsDataset = $dataset;

            foreach ($logicalDataset->columns as $logicalColumn) {
                StarSchemaCubeMetaData::initializeDimensionFromColumn($metamodel, $cube, $logicalDataset, $logicalColumn->name);

                // FIXME fixing dimensions and pointing to physical datasets instead. Remove the following block once we remove support for logical datasets in cubes
                // FIXME remove support for $callcontext->logicalDatasetNameMappings property as well
                $dimension = $cube->findDimension($logicalColumn->name);
                if (isset($dimension) && isset($dimension->datasetName)) {
                    $dimensionLogicalDatasetName = $dimension->datasetName;
                    $dimensionTableAccessKey = $callcontext->logicalDatasetNameMappings[$dimensionLogicalDatasetName];
                    $dimensionDataset = $callcontext->datasets[$dimensionTableAccessKey];
                    $dimension->datasetName = $dimensionDataset->name;
                    $dimension->dataset = $dimensionDataset;
                }
            }

            foreach ($logicalDataset->columns as $logicalColumn) {
                StarSchemaCubeMetaData::initializeMeasuresFromColumn($cube, $logicalDataset, $logicalColumn->name);
            }

            StarSchemaCubeMetaData::registerCubeMeasures($cube);

            $cube->loaderName = $loaderName;
            $cube->markAsComplete();

            $metamodel->registerCube($cube);
            $cubeCount++;
        }

        LogHelper::log_info(t('Generated and registered @cubeCount cubes', array('@cubeCount' => $cubeCount)));
    }
    public function finalize(AbstractMetaModel $metamodel) {
        parent::finalize($metamodel);

        $loaderName = $this->getName();

        // initializing all cubes. We separated registration from initialization to support inter-cube references
        $loadedDatasets = NULL;
        foreach ($metamodel->datasets as $dataset) {
            // working only with datasets which are created by this loader
            if ($dataset->loaderName != $loaderName) {
                continue;
            }

            StarSchemaCubeMetaData::registerFromDataset($metamodel, $dataset);

            $loadedDatasets[$dataset->nid] = $dataset;
        }

        if (isset($loadedDatasets)) {
            $dataset_nids = array_keys($loadedDatasets);

            // loading measures
            $measureNodes = gd_measure_get_measures_4_dataset($dataset_nids, LOAD_ENTITY);
            // grouping measures in context of dataset
            $datasetsMeasureNodes = $this->groupNodesByDataset($measureNodes, 'field_measure_dataset');

            // creating cubes for all datasets
            foreach ($loadedDatasets as $dataset) {
                // preparing corresponding cube
                $cube = StarSchemaCubeMetaData::initializeFromDataset($metamodel, $dataset);
                // assigning a loader which created the cube
                $cube->factsDataset->loaderName = $loaderName;
                $cube->loaderName = $loaderName;
                // preparing additional measures
                $datasetMeasureNodes = isset($datasetsMeasureNodes[$dataset->nid]) ? $datasetsMeasureNodes[$dataset->nid] : NULL;
                if (isset($datasetMeasureNodes)) {
                    foreach ($datasetMeasureNodes as $measureNode) {
                        $measure = $cube->registerMeasure(get_node_field_value($measureNode, 'field_measure_sysname', 0, 'value', TRUE));
                        $measure->publicName = $measureNode->title;
                        $measure->description = get_node_field_value($measureNode, 'field_measure_desc');
                        $measure->function = get_node_field_value($measureNode, 'field_measure_function', 0, 'value', TRUE);
                    }
                }
            }
        }

        // processing references
        $referenceNodes = gd_reference_get_references(LOAD_ENTITY);
        $referencePointNodes = isset($referenceNodes) ? gd_reference_get_reference_points(LOAD_ENTITY) : NULL;
        if (isset($referencePointNodes)) {
            foreach ($referenceNodes as $referenceNode) {
                GD_DatasetMetaModelLoaderHelper::prepareReference($metamodel, $referenceNode, $referencePointNodes);
            }
        }
    }
    public function createColumnStorage(DataControllerCallContext $callcontext, DataSourceStructureHandler $datasourceStructureHandler, DatasetMetaData $dataset, $columnName, $stage) {
        switch ($stage) {
            case DatasetStorageObserver::STAGE__BEFORE:
                StarSchemaCubeMetaData::deinitializeByColumn($this->originalCube, $this->originalLogicalDataset, $columnName);
                break;
            case DatasetStorageObserver::STAGE__AFTER:
                $metamodel = data_controller_get_metamodel();

                $newLogicalColumn = $this->newLogicalDataset->getColumn($columnName);
                $newColumn = $dataset->getColumn($columnName);

                $originalLogicalColumn = $this->originalLogicalDataset->getColumn($columnName);

                // Note: storing logical data type for the column
                $originalLogicalColumn->initializeTypeFrom($newLogicalColumn->type, TRUE);
                $originalLogicalColumn->persistence = $newColumn->persistence;

                StarSchemaCubeMetaData::initializeFromColumn($metamodel, $this->originalCube, $this->originalLogicalDataset, $columnName);
                break;
        }

        parent::createColumnStorage($callcontext, $datasourceStructureHandler, $dataset, $columnName, $stage);
    }