protected function loadFromDirectory(AbstractMetaModel $metamodel, array $filters = NULL, $path, $namespace, $level = 0) {
        $filecount = 0;

        $handle = opendir($path);
        if ($handle !== FALSE) {
            $indent = str_pad('', $level * 4);
            while (($filename = readdir($handle)) !== FALSE) {
                if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) {
                    if ($filename[0] != '.') {
                        $folder = DIRECTORY_SEPARATOR . $filename;

                        $nestedNameSpace = isset($namespace) ? NameSpaceHelper::addNameSpace($namespace, $filename) : $filename;

                        LogHelper::log_debug(t("{$indent}Scanning '@folderName' ...", array('@folderName' => $folder)));
                        $filecount += $this->loadFromDirectory($metamodel, $filters, $path . $folder, $nestedNameSpace, $level + 1);
                    }
                }
                elseif ($this->fileNameEndsWithJson($filename)) {
                    LogHelper::log_debug(t("{$indent}Processing '@filename' ...", array('@filename' => $filename)));

                    $this->loadFromFile($metamodel, $filters, $namespace, $path . DIRECTORY_SEPARATOR, $filename);
                    $filecount++;
                }
            }

            closedir($handle);
        }

        return $filecount;
    }
    public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Loading Environment Meta Model from settings.php ...'));

        $datasourceCount = 0;

        $configurationDataSources = Environment::getInstance()->getConfigurationSection('Data Sources');
        if (isset($configurationDataSources)) {
            foreach ($configurationDataSources as $namespace => $sourceDataSources) {
                foreach ($sourceDataSources as $datasourceName => $sourceDataSource) {
                    $datasourceName = NameSpaceHelper::resolveNameSpace($namespace, $datasourceName);

                    $datasource = new DataSourceMetaData();
                    $datasource->name = $datasourceName;
                    $datasource->initializeFrom($sourceDataSource);
                    // it is possible that configuration contains 'readonly' property. We need to honor it
                    // ... and only when it is not set we mark the data source as read only
                    if (!isset($datasource->readonly)) {
                        $datasource->readonly = TRUE;
                    }

                    $environment_metamodel->registerDataSource($datasource);

                    $datasourceCount++;
                }
            }
        }

        LogHelper::log_info(t('Processed @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
    public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Generating Environment Meta Model for Drupal database connections ...'));

        global $databases;

        $datasourceCount = 0;
        foreach ($databases as $namespace => $connections) {
            foreach ($connections as $datasourceNameOnly => $connection) {
                $datasource = new DataSourceMetaData();
                $datasource->name = NameSpaceHelper::addNameSpace($namespace, $datasourceNameOnly);
                $datasource->markAsPrivate();
                $datasource->readonly = FALSE;
                // setting required properties
                $this->setDataSourceProperty($datasource, $connection, 'type', 'driver');
                // setting other provided properties
                $this->setDataSourceExtensionProperties($datasource, $connection);

                // registering the data source
                $environment_metamodel->registerDataSource($datasource);
                $datasourceCount++;
            }
        }

        // Default database connection is shared because we store common utilities and dimensions there
        $defaultDataSource = $environment_metamodel->getDataSource(self::$DATASOURCE_NAME__DEFAULT);
        $defaultDataSource->shared = TRUE;

        LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
 public static function checkAlias($alias) {
     $v = $alias;
     do {
         list($v, $name) = NameSpaceHelper::splitAlias($v);
         StringDataTypeHandler::checkValueAsWord($name);
     }
     while ($v != NULL);
 }
    protected function assembleCacheEntryName($name) {
        $cacheEntryName = $name;
        if (isset($this->prefix)) {
            $cacheEntryName = isset($name) ? NameSpaceHelper::addNameSpace($this->prefix, $name) : $this->prefix;
        }

        return $cacheEntryName;
    }
    protected function getRequestId() {
        $requestId = &drupal_static(__CLASS__ . '::requestId');
        if (!isset($requestId)) {
            $sequenceName = NameSpaceHelper::addNameSpace(get_class($this), 'requestId');
            $requestId = Sequence::getNextSequenceValue($sequenceName);
        }

        return $requestId;
    }
Ejemplo n.º 7
0
 public function findDataSourceByNamespacelessName($datasourceNamespacelessName)
 {
     $datasources = NULL;
     foreach ($this->datasources as $datasourceName => $datasource) {
         list($namespace, $datasourceNameOnly) = NameSpaceHelper::splitAlias($datasourceName);
         if ($datasourceNameOnly == $datasourceNamespacelessName) {
             $datasources[$datasourceName] = $datasource;
         }
     }
     return $datasources;
 }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $environment_metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Generating Environment Meta Model for APC cache ...'));
     $datasourceCount = 0;
     $datasource = new DataSourceMetaData();
     $datasource->name = NameSpaceHelper::addNameSpace(APCHandler::$CACHE__TYPE, DefaultCacheFactory::$DATASOURCE_NAME__DEFAULT);
     $datasource->type = APCHandler::$CACHE__TYPE;
     $environment_metamodel->registerDataSource($datasource);
     $datasourceCount++;
     LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
     return self::LOAD_STATE__SUCCESSFUL;
 }
    public function __construct($prefix, DataSourceMetaData $datasource = NULL) {
        LogHelper::log_notice(t('[@cacheType] Initializing PHP extension ...', array('@cacheType' => $this->getCacheType())));

        // taking into account possible datasource's nested name space
        $adjustedPrefix = isset($datasource->nestedNameSpace)
            ? (isset($prefix) ? NameSpaceHelper::addNameSpace($datasource->nestedNameSpace, $prefix) : $datasource->nestedNameSpace)
            : $prefix;
        parent::__construct($adjustedPrefix);

        if ($this->initialize($prefix, $datasource) !== FALSE) {
            $this->checkAccessibility(FALSE);
        }
    }
Ejemplo n.º 10
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";
}
Ejemplo n.º 11
0
 public function __construct($prefix, DataSourceMetaData $datasource)
 {
     LogHelper::log_notice(t('[@cacheType] Initializing PHP extension ...', array('@cacheType' => $this->getCacheType())));
     // taking into account possible datasource's nested name space
     $adjustedPrefix = isset($datasource->nestedNameSpace) ? NameSpaceHelper::addNameSpace($prefix, $datasource->nestedNameSpace) : $prefix;
     parent::__construct($adjustedPrefix);
     // the optional datasource can have its own expiration schedule
     if (isset($datasource->entryExpiration)) {
         $this->entryExpiration = $datasource->entryExpiration;
     }
     if ($this->initialize($prefix, $datasource) !== FALSE) {
         $this->checkAccessibility(FALSE);
     }
 }
    public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Generating Environment Meta Model for APC cache ...'));

        $datasourceCount = 0;

        $datasource = new DataSourceMetaData();
        $datasource->name = NameSpaceHelper::addNameSpace(APCHandler::CACHE__TYPE, 'default');
        $datasource->type = APCHandler::CACHE__TYPE;
        $datasource->category = CacheFactory::$DATASOURCE__CATEGORY;
        $datasource->markAsPrivate();

        $environment_metamodel->registerDataSource($datasource);
        $datasourceCount++;

        LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
    public function flush() {
        if (!isset($this->recordsHolder)) {
            return;
        }

        $datasetName = NameSpaceHelper::addNameSpace(DATASOURCE_NAME__HEALTH_MONITORING, 'hm_trails');

        // generating and assigning primary key
        $identifiers = Sequence::getNextSequenceValues($datasetName, count($this->recordsHolder->records));
        foreach ($this->recordsHolder->records as $index => $recordInstance) {
            $recordInstance->setColumnValue(0, $identifiers[$index]);
        }

        // storing data in the database
        $dataManipulationController = data_controller_dml_get_instance();
        $dataManipulationController->insertDatasetRecordBatch($datasetName, $this->recordsHolder);

        $this->recordsHolder = NULL;
    }
    protected static function generateFromReference($reference) {
        if (!isset($reference)) {
            return NULL;
        }

        $parts = ReferencePathHelper::splitReference($reference);

        $databaseColumnName = NULL;
        for ($i = 0, $count = count($parts); $i < $count; $i += 2) {
            $resource = $parts[$i];
            $name = $parts[$i + 1];

            $columnNameSegment = $name;
            if (isset($resource)) {
                list($namespace, $resourceName) = NameSpaceHelper::splitAlias($resource);

                $columnNameSegment .= '_';
                if (isset($namespace)) {
                    $columnNameSegment .= $namespace . '_';
                }
                $columnNameSegment .= $resourceName;
            }

            if (isset($databaseColumnName)) {
                $databaseColumnName .= '_';
            }
            $databaseColumnName .= $columnNameSegment;
        }

        // replacing non-word characters with '_'
        $databaseColumnName = preg_replace('#\W+#', '_', $databaseColumnName);
        // removing several subsequent instances of '_'
        $databaseColumnName = preg_replace('#_{2,}#', '_', $databaseColumnName);
        // fixing possibility for leading digits
        if ((strlen($databaseColumnName) > 0) && is_numeric(substr($databaseColumnName, 0, 1))) {
            $databaseColumnName = 'fix_' . $databaseColumnName;
        }

        $databaseColumnName = strtolower($databaseColumnName);

        return $databaseColumnName;
    }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $environment_metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Loading Environment Meta Model from settings.php ...'));
     $datasourceCount = 0;
     $configurationDataSources = Environment::getInstance()->getConfigurationSection('Data Sources');
     if (isset($configurationDataSources)) {
         foreach ($configurationDataSources as $namespace => $sourceDataSources) {
             foreach ($sourceDataSources as $datasourceName => $sourceDataSource) {
                 $datasourceName = NameSpaceHelper::resolveNameSpace($namespace, $datasourceName);
                 $datasource = new DataSourceMetaData();
                 $datasource->name = $datasourceName;
                 $datasource->system = TRUE;
                 $datasource->readonly = TRUE;
                 $datasource->initializeFrom($sourceDataSource);
                 $environment_metamodel->registerDataSource($datasource);
                 $datasourceCount++;
             }
         }
     }
     LogHelper::log_info(t('Processed @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
     return self::LOAD_STATE__SUCCESSFUL;
 }
    protected function getDatasetHandler(DataControllerCallContext $callcontext, $datasetName) {
        $metamodel = data_controller_get_metamodel();

        $dataset = $metamodel->getDataset($datasetName);

        $namespace = NameSpaceHelper::getNameSpace($dataset->datasourceName);
        $classname = $dataset->source;

        $foundScriptName = NULL;

        // TODO load the configuration only once when instance of the class is initialized
        // reuse the cached data here to look for PHP script
        $metamodelConfigurations = module_invoke_all('dp_metamodel');
        foreach ($metamodelConfigurations as $metamodelConfiguration) {
            $path = $metamodelConfiguration['path'];

            $scriptName = "$path/metamodel/metamodel/$namespace/php/" . $classname . '.php';
            if (file_exists($scriptName)) {
                if (isset($foundScriptName)) {
                    throw new IllegalStateException(t(
                    	"Found several PHP scripts to support '@className' dataset: [@previousScriptName, @scriptName]",
                        array('@className' => $classname, '@previousScriptName' => $foundScriptName, '@scriptName' => $scriptName)));
                }

                $foundScriptName = $scriptName;
            }
        }

        if (isset($foundScriptName)) {
            require_once($foundScriptName);
        }
        else {
            throw new IllegalStateException(t("Could not find PHP script to support '@datasetName' dataset", array('@datasetName' => $dataset->publicName)));
        }

        return new $classname;
    }
    protected function generateDatasets(SystemTableMetaModelLoaderCallContext $callcontext, DataSourceMetaData $datasource) {
        $columnsProperties = $this->loadColumnsProperties($callcontext, $datasource);
        if (isset($columnsProperties)) {
            foreach ($columnsProperties as $columnProperties) {
                $tableOwner = $this->adjustOwnerName($columnProperties[self::CN_TABLE_OWNER]);

                $originalTableName = $columnProperties[self::CN_TABLE_NAME];
                $tableName = $this->adjustTableName($originalTableName);
                if (!$this->isTableSupported($callcontext, $tableName)) {
                    continue;
                }

                $tableAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $tableName));

                // checking if we can process the column name
                $originalColumnName = $columnProperties[self::CN_COLUMN_NAME];
                $columnName = $this->adjustColumnName($originalColumnName);
                $generatedColumnName = $this->nameGenerator->generate($columnName);
                // this column cannot be supported by the system
                if ($columnName != $generatedColumnName) {
                    LogHelper::log_warn(t(
                        "Unsupported column name from '@tableName' table: @columnName",
                        array('@tableName' => $originalTableName, '@columnName' => $originalColumnName)));
                    continue;
                }

                // preparing new dataset
                if (!isset($callcontext->datasets[$tableAccessKey])) {
                    $source =  TableReferenceHelper::assembleTableReference($tableOwner, $tableName);

                    $dataset = new DatasetMetaData();
                    $dataset->name = NameSpaceHelper::addNameSpace($datasource->name, $this->nameGenerator->generate($tableName));
                    $dataset->publicName = $this->generateTablePublicName($originalTableName);
                    $dataset->datasourceName = $datasource->name;
                    $dataset->source = $source;
                    $dataset->markAsPrivate();

                    $callcontext->datasets[$tableAccessKey] = $dataset;
                }
                $dataset = $callcontext->datasets[$tableAccessKey];

                // adding new column to the dataset
                $column = $dataset->initiateColumn();
                $column->name = $columnName;
                $column->publicName = $this->generateColumnPublicName($originalColumnName);
                $column->persistence = ColumnMetaData::PERSISTENCE__STORAGE_CREATED;
                $column->columnIndex = $columnProperties[self::CN_COLUMN_INDEX];
                $column->type->databaseType = $columnProperties[self::CN_COLUMN_TYPE];
                if (isset($columnProperties[self::CN_COLUMN_TYPE_LENGTH])) {
                    $column->type->length = $columnProperties[self::CN_COLUMN_TYPE_LENGTH];
                }
                if (isset($columnProperties[self::CN_COLUMN_TYPE_PRECISION])) {
                    $column->type->precision = $columnProperties[self::CN_COLUMN_TYPE_PRECISION];
                }
                if (isset($columnProperties[self::CN_COLUMN_TYPE_SCALE])) {
                    $column->type->scale = $columnProperties[self::CN_COLUMN_TYPE_SCALE];
                }
                $this->generateColumnApplicationType($callcontext, $datasource, $column);

                // adjusting column properties
                if (!isset($column->type->applicationType)) {
                    $column->visible = FALSE;
                    LogHelper::log_warn(t(
                        "Data type is not supported for '@columnName' column from '@tableName' table: @databaseDataType",
                        array(
                            '@tableName' => $originalTableName,
                            '@columnName' => $originalColumnName,
                            '@databaseDataType' => $column->type->databaseType)));
                }
                $this->adjustColumnVisibility($callcontext, $column);

                $dataset->registerColumnInstance($column);
            }
        }

        LogHelper::log_info(t(
            'Processed system meta data about @tableCount table(s) and @columnCount column(s)',
            array('@tableCount' => count($callcontext->datasets), '@columnCount' => count($columnsProperties))));
    }
    public function queryCube(DataControllerCallContext $callcontext, CubeQueryRequest $request, ResultFormatter $resultFormatter) {
        $records = NULL;

        $environment_metamodel = data_controller_get_environment_metamodel();
        $metamodel = data_controller_get_metamodel();

        $cubeName = $request->getCubeName();
        $cube = $metamodel->getCube($cubeName);

        $cubeDatasetName = $cube->sourceDatasetName;
        $cubeDataset = $metamodel->getDataset($cubeDatasetName);
        $datasource = $environment_metamodel->getDataSource($cubeDataset->datasourceName);

        $designDocumentName = NameSpaceHelper::removeNameSpace($cubeName);
        $viewName = NameSpaceHelper::removeNameSpace($cubeName);
        $url = '/' . $cubeDataset->source->database . "/_design/$designDocumentName/_view/$viewName";

        $dimensionCount = $cube->getDimensionCount();

        $queryKeys = NULL;
        // TODO list of dimensions could be empty
        foreach ($cube->dimensions as $dimension) {
            $queryDimension = $request->findDimensionQuery($dimension->name);

            if (isset($queryDimension)) {
                $queryKeys[] = $queryDimension->values;
            }
            else {
                $queryKeys[] = NULL;
            }
        }

        // TODO develop more comprehensive validation or mapping
        if ($cube->getMeasureCount() != 1) {
            throw new UnsupportedOperationException(t('Only one measure is supported'));
        }
        $cubeMeasurePropertyName = NULL;
        foreach ($cube->measures as $measureName => $measure) {
            $cubeMeasurePropertyName = $measureName;
        }

        // preparing set of keys to access data
        $requestKeys = NULL;
        $this->prepareCubeRequestKeys($requestKeys, $queryKeys, 0, NULL);

        // preparing server requests
        if (isset($requestKeys)) {
            foreach ($requestKeys as $requestKey) {
                $parameterKey = '';
                foreach ($requestKey as $dimensionKey) {
                    $parameterKey .= self::prepareSingleValue($dimensionKey);
                }
                $parameterKey = '[' . substr($parameterKey, 0, strlen($parameterKey) - 1) . ']';

                $serverRequest = NULL;
                $serverRequest->url = $url . "?key=$parameterKey";

                // executing the server request
                $serverResponse = $this->communicateWithServer($datasource, $serverRequest);
                $this->checkDocumentExistence($serverResponse, TRUE);

                if (isset($serverResponse->rows[0])) {
                    $record = NULL;
                    // adding dimension-related properties
                    for ($i = 0; $i < $dimensionCount; $i++) {
                        // we should have data for a dimension to report related property
                        if (!isset($requestKey[$i])) {
                            continue;
                        }

                        $dimension = $cube->dimensions[$i];
                        $dimensionKey = $requestKey[$i];

                        // FIXME there is no support for targetKey any more
                        $record[$dimension->targetKey] = $dimensionKey;
                    }
                    // adding measure value
                    $record[$cubeMeasurePropertyName] = $serverResponse->rows[0]->value;

                    $records[] = $record;
                }
            }
        }

        return $records;
    }
    protected function populateDatasets() {
        $metamodel = data_controller_get_metamodel();

        $namespaceParts = explode(NameSpaceHelper::NAME_SPACE_SEPARATOR, DATASOURCE_NAME__TEST);
        $path = realpath(drupal_get_path('module', 'gd_test'))
            . DIRECTORY_SEPARATOR . '_db'
            . DIRECTORY_SEPARATOR . 'data'
            . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $namespaceParts);

        $handle = opendir($path);
        if ($handle !== FALSE) {
            while (($name = readdir($handle)) !== FALSE) {
                if ($name[0] == '.') {
                    continue;
                }

                $fullname = $path . DIRECTORY_SEPARATOR . $name;

                if (!is_dir($fullname)) {
                    continue;
                }

                $datasetName = NameSpaceHelper::addNameSpace(DATASOURCE_NAME__TEST, $name);
                $dataset = $metamodel->findDataset($datasetName);
                if (!isset($dataset)) {
                    continue;
                }

                $folderName = $fullname;
                $this->populateDataset($dataset, $folderName);
            }
            closedir($handle);
        }
    }
Ejemplo n.º 20
0
 public function getLocalCacheHandler($prefix)
 {
     $handlerKey = NameSpaceHelper::addNameSpace($prefix, InMemoryCacheHandler::$CACHE__TYPE);
     if (isset($this->handlerInstances[$handlerKey])) {
         $handler = $this->handlerInstances[$handlerKey];
     } else {
         $handler = $this->initializeLocalCache($prefix);
         $this->handlerInstances[$handlerKey] = $handler;
     }
     return $handler;
 }
Ejemplo n.º 21
0
 protected function assembleCacheEntryName($name)
 {
     return isset($this->prefix) ? NameSpaceHelper::addNameSpace($this->prefix, $name) : $name;
 }
 public static function getDatasetName($contentTypeName)
 {
     // FIXME cache it somewhere
     list($namespace) = NameSpaceHelper::splitAlias(AbstractDrupalDataSourceQueryProxy::$DATASOURCE_NAME__DEFAULT);
     return NameSpaceHelper::addNameSpace($namespace, self::$DATASET__PREFIX . $contentTypeName);
 }
    public function registerCube(CubeMetaData $cube) {
        $this->checkAssemblingStarted();

        if (!isset($cube->name)) {
            LogHelper::log_debug($cube);
            throw new IllegalArgumentException(t('Cube name has not been defined'));
        }

        $cubeName = $cube->name;
        NameSpaceHelper::checkAlias($cubeName);

        $existingCube = $this->findCube($cubeName, TRUE);
        if (isset($existingCube)) {
            if ($cube->isTemporary()) {
                $this->unregisterCube($cubeName);
            }
            else {
                LogHelper::log_debug($existingCube);
                LogHelper::log_debug($cube);
                throw new IllegalArgumentException(t(
                    'Cube with name %cubeName has already been defined',
                    array('%cubeName' => $cube->publicName)));
            }
        }

        if (!$cube->isTemporary()) {
            // we support only one cube per dataset
            $cube2 = $this->findCubeByDatasetName($cube->factsDatasetName);
            if (isset($cube2)) {
                LogHelper::log_debug($cube2);
                LogHelper::log_debug($cube);
                throw new IllegalArgumentException(t(
                    'Found several cubes for %datasetName dataset: [%cubeName1, %cubeName2]',
                    array('%datasetName' => $cube->factsDatasetName, '%cubeName1' => $cube->publicName, '%cubeName2' => $cube2->publicName)));
            }
        }

        // fixing cube properties
        if (isset($cube->dimensions)) {
            foreach ($cube->dimensions as $dimension) {
                if (!isset($dimension->attributeColumnName)) {
                    $dimension->attributeColumnName = $dimension->name;
                }
            }
        }

        $this->cubes[$cubeName] = $cube;
    }
    public static function checkReference($reference, $checkResource = TRUE, $checkName = TRUE) {
        if (!isset($reference)) {
            return;
        }

        $parts = self::splitReference($reference);
        for ($i = 0, $count = count($parts); $i < $count; $i += 2) {
            if ($checkResource) {
                $resource = $parts[$i];
                if (isset($resource)) {
                    NameSpaceHelper::checkAlias($resource);
                }
            }

            if ($checkName) {
                $name = $parts[$i + 1];
                StringDataTypeHandler::checkValueAsWord($name);
            }
        }
    }
Ejemplo n.º 25
0
 protected function mergeWithCube(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceCubeName, $sourceCube)
 {
     $cubeName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCubeName);
     // cube/sourceDataset/Name
     if (!isset($sourceCube->sourceDatasetName)) {
         throw new IllegalStateException(t("'@cubeName' cube definition does not contain a reference to source dataset", array('@cubeName' => isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName)));
     }
     $sourceCube->sourceDatasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCube->sourceDatasetName);
     // fix dimensions
     if (isset($sourceCube->dimensions)) {
         foreach ($sourceCube->dimensions as $dimension) {
             if (isset($dimension->levels)) {
                 foreach ($dimension->levels as $level) {
                     // cube/dimension/level/dataset/name
                     if (!isset($level->datasetName)) {
                         continue;
                     }
                     $level->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $level->datasetName);
                 }
             }
         }
     }
     // cube/region/dataset/name
     if (isset($sourceCube->regions)) {
         foreach ($sourceCube->regions as $regionName => $region) {
             if (!isset($region->datasetName)) {
                 throw new IllegalStateException(t("'@regionName' region of '@cubeName' cube does not contain a reference to dataset", array('@cubeName' => isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName, '@regionName' => $regionName)));
             }
             $region->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $region->datasetName);
         }
     }
     $cube = new CubeMetaData();
     $cube->name = $cubeName;
     $cube->initializeFrom($sourceCube);
     $metamodel->registerCube($cube);
     return $cube;
 }
    public function getLocalCacheHandler($prefix) {
        $handlerKey = isset($prefix) ? $prefix : (get_class($this) . '.local');
        $handlerKey = NameSpaceHelper::addNameSpace($handlerKey, InMemoryCacheHandler::CACHE__TYPE);

        if (isset($this->handlers[$handlerKey])) {
            $handler = $this->handlers[$handlerKey];
        }
        else {
            $handler = $this->initializeLocalCache($prefix);
            $this->handlers[$handlerKey] = $handler;
        }

        return $handler;
    }
Ejemplo n.º 27
0
 public function registerCube(CubeMetaData $cube)
 {
     $this->checkAssemblingStarted();
     if (!isset($cube->name)) {
         LogHelper::log_error($cube);
         throw new IllegalArgumentException(t('Cube name has not been defined'));
     }
     $cubeName = $cube->name;
     NameSpaceHelper::checkAlias($cubeName);
     if (isset($this->cubes[$cubeName])) {
         if ($cube->temporary) {
             unset($this->cubes[$cubeName]);
         } else {
             throw new IllegalArgumentException(t('Cube with name @cubeName has already been defined', array('@cubeName' => $cube->publicName)));
         }
     }
     if (!$cube->temporary) {
         // we support only one cube per dataset
         $cube2 = $this->findCubeByDatasetName($cube->sourceDatasetName);
         if (isset($cube2)) {
             throw new IllegalArgumentException(t("Found several cubes for '@datasetName' dataset: ['@cubeName1', '@cubeName2']", array('@datasetName' => $cube->sourceDatasetName, '@cubeName1' => $cube->publicName, '@cubeName2' => $cube2->publicName)));
         }
     }
     $this->cubes[$cubeName] = $cube;
 }
    protected function processConfig ( &$config ) {
        $metamodel = data_controller_get_metamodel();

        if ( !empty($config->model->datasets) ) {
            foreach ( $config->model->datasets as $key => $datasetName ) {
                $dataset = $metamodel->getDataset($datasetName);
                if (isset($dataset->uuid)) {
                    $config->model->datasets[$key] = $dataset->uuid;
                } else {
                    $config->model->datasets[$key] = NameSpaceHelper::removeNameSpace($dataset->name);
                }
            }
        }

        // update columns
        if ( !empty($config->model->columns) ) {
            foreach ( $config->model->columns as $key => $value ) {
                $config->model->columns[$key] = DatasetExportHelper::getExportColumnName($value,$metamodel);
            }
        }

        // update column configs
        if ( !empty($config->columnConfigs) ) {
            foreach ( $config->columnConfigs as $key => $value ) {
                $config->columnConfigs[$key]->columnId = DatasetExportHelper::getExportColumnName($value->columnId,$metamodel);
            }
        }

        // update column orders
        if ( !empty($config->model->columnOrder) ) {
            foreach ( $config->model->columnOrder as $key => $value ) {
                $config->model->columnOrder[$key] = DatasetExportHelper::getExportColumnName($value,$metamodel);
            }
        }

        // update column sorts
        if ( !empty($config->model->orderBy) ) {
            foreach ( $config->model->orderBy as $key => $value ) {
                $config->model->orderBy[$key]->column = DatasetExportHelper::getExportColumnName($value->column,$metamodel);
            }
        }

        // update visual series
        if ( !empty($config->visual->series) ) {
            $newSeries = array();
            foreach ( $config->visual->series as $key => $value ) {
                $newSeries[DatasetExportHelper::getExportColumnName($key,$metamodel)] = $value;
            }
            $config->visual->series = $newSeries;
        }

        // update traffic column
        if ( !empty($config->visual->trafficColumn) ) {
            $config->visual->trafficColumn = DatasetExportHelper::getExportColumnName($config->visual->trafficColumn,$metamodel);
        }

        // update color column
        if ( !empty($config->visual->useColumnDataForColor) ) {
            $config->visual->useColumnDataForColor = DatasetExportHelper::getExportColumnName($config->visual->useColumnDataForColor,$metamodel);
        }

        // update traffic columns
        if ( !empty($config->visual->traffic) ) {
            $newTraffic = array();
            foreach ( $config->visual->traffic as $key => $value ) {
                $value->trafficColumn = DatasetExportHelper::getExportColumnName($key,$metamodel);
                $newTraffic[DatasetExportHelper::getExportColumnName($key,$metamodel)] = $value;
            }
            $config->visual->traffic = $newTraffic;
        }

        // update filters
        if ( !empty($config->model->filters) ) {
            foreach ( $config->model->filters as $key => $value ) {
                $config->model->filters[$key]->column = DatasetExportHelper::getExportColumnName($value->column,$metamodel);
            }
        }
    }
    protected function mergeWithCube(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceCubeName, $sourceCube) {
        $cubeName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCubeName);

        // cube/sourceDataset/Name
        if (!isset($sourceCube->factsDatasetName)) {
            throw new IllegalStateException(t(
                '%cubeName cube definition does not contain a reference to facts dataset',
                array('%cubeName' => (isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName))));
        }
        $sourceCube->factsDatasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCube->factsDatasetName);

        // fix dimensions
        if (isset($sourceCube->dimensions)) {
            foreach ($sourceCube->dimensions as $dimension) {
                // cube/dimension/dataset/name
                if (!isset($dimension->datasetName)) {
                    continue;
                }
                $dimension->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $dimension->datasetName);
            }
        }

        $cube = new CubeMetaData();
        $cube->name = $cubeName;
        $cube->initializeFrom($sourceCube);

        $isCubeAcceptable = $this->isMetaDataAcceptable($cube, $filters);

        // TODO eliminate this check in the future. Use different approach
        if ($isCubeAcceptable) {
            $isCubeAcceptable = $metamodel->findDataset($cube->factsDatasetName) !== NULL;
        }

        if ($isCubeAcceptable) {
            $metamodel->registerCube($cube);
        }

        return $cube;
    }
 public function assembleResourceName($resourceType, $name) {
     return NameSpaceHelper::addNameSpace($resourceType, $name);
 }