Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DWI's isRealmEnabled to be config file based #1102

Merged
merged 3 commits into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion classes/OpenXdmod/DataWarehouseInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OpenXdmod;

use CCR\DB;
use Configuration\XdmodConfiguration;
use Exception;
use CCR\DB\iDatabase;
use ETL\Configuration\EtlConfiguration;
Expand Down Expand Up @@ -77,6 +78,13 @@ class DataWarehouseInitializer
*/
protected $append;

/**
* A String[] of the realms currently considered `enabled`.
*
* @var array
*/
protected $enabledRealms = null;

/**
* @param iDatabase $hpcdbDb The HPcDB database.
* @param iDatabase $warehouseDb The MoD warehouse database.
Expand Down Expand Up @@ -444,6 +452,40 @@ public function aggregate(
*/
public function isRealmEnabled($realm)
{
return in_array($realm, Realms::getEnabledRealms());
return in_array($realm, $this->getEnabledRealms());
}

/**
* Retrieve an array of the realms that are `enabled` for this XDMoD installation. `enabled` is defined as there
* being a resource present of a type that supports ( i.e. has a record in its `realms` property ) said realm.
* .
* @return array
*/
public function getEnabledRealms()
{
if ($this->enabledRealms !== null) {
return $this->enabledRealms;
}

$resources = XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR);
$resourceTypes = XdmodConfiguration::assocArrayFactory('resource_types.json', CONFIG_DIR)['resource_types'];

$currentResourceTypes = array();
foreach($resources as $resource) {
if (isset($resource['resource_type'])) {
$currentResourceTypes[] = $resource['resource_type'];
}
}
$currentResourceTypes = array_unique($currentResourceTypes);

$realms = array();
foreach($currentResourceTypes as $currentResourceType) {
if (isset($resourceTypes[$currentResourceType])) {
$realms = array_merge($realms, $resourceTypes[$currentResourceType]['realms']);
}
}
$this->enabledRealms = array_unique($realms);

return $this->enabledRealms;
}
}