new: New module type: Cortex

- similar to Enrichment modules except for not having the options to run hover
pull/2161/head
iglocska 2017-05-03 13:13:36 +02:00
parent ebd69bf59d
commit 9ccdc579a6
5 changed files with 70 additions and 15 deletions

View File

@ -764,6 +764,11 @@ class EventsController extends AppController {
$modules = $this->Module->getEnabledModules();
$this->set('modules', $modules);
}
if (Configure::read('Plugin.Cortex_services_enable')) {
$this->loadModel('Module');
$cortex_modules = $this->Module->getEnabledModules(false, 'Cortex');
$this->set('cortex_modules', $cortex_modules);
}
$this->set('deleted', (isset($this->params['named']['deleted']) && $this->params['named']['deleted']) ? true : false);
$this->set('typeGroups', array_keys($this->Event->Attribute->typeGroupings));
$this->set('attributeFilter', isset($this->params['named']['attributeFilter']) ? $this->params['named']['attributeFilter'] : 'all');
@ -883,6 +888,11 @@ class EventsController extends AppController {
$modules = $this->Module->getEnabledModules();
$this->set('modules', $modules);
}
if (Configure::read('Plugin.Cortex_services_enable')) {
$this->loadModel('Module');
$cortex_modules = $this->Module->getEnabledModules(false, 'Cortex');
$this->set('cortex_modules', $cortex_modules);
}
$this->set('contributors', $contributors);
$this->set('typeGroups', array_keys($this->Event->Attribute->typeGroupings));
$this->loadModel('Sighting');
@ -3870,14 +3880,14 @@ class EventsController extends AppController {
}
// expects an attribute ID and the module to be used
public function queryEnrichment($attribute_id, $module = false) {
if (!Configure::read('Plugin.Enrichment_services_enable')) throw new MethodNotAllowedException('Enrichment services are not enabled.');
public function queryEnrichment($attribute_id, $module = false, $type = 'Enrichment') {
if (!Configure::read('Plugin.' . $type . '_services_enable')) throw new MethodNotAllowedException($type . ' services are not enabled.');
$attribute = $this->Event->Attribute->fetchAttributes($this->Auth->user(), array('conditions' => array('Attribute.id' => $attribute_id)));
if (empty($attribute)) throw new MethodNotAllowedException('Attribute not found or you are not authorised to see it.');
if ($this->request->is('ajax')) {
$this->loadModel('Module');
$enabledModules = $this->Module->getEnabledModules();
if (!is_array($enabledModules) || empty($enabledModules)) throw new MethodNotAllowedException('No valid enrichment options found for this attribute.');
$enabledModules = $this->Module->getEnabledModules(false, $type);
if (!is_array($enabledModules) || empty($enabledModules)) throw new MethodNotAllowedException('No valid ' . $type . ' options found for this attribute.');
$modules = array();
foreach ($enabledModules['modules'] as $module) {
if (in_array($attribute[0]['Attribute']['type'], $module['mispattributes']['input'])) {
@ -3889,13 +3899,13 @@ class EventsController extends AppController {
} else {
$this->loadModel('Module');
$enabledModules = $this->Module->getEnabledModules();
if (!is_array($enabledModules) || empty($enabledModules)) throw new MethodNotAllowedException('No valid enrichment options found for this attribute.');
if (!is_array($enabledModules) || empty($enabledModules)) throw new MethodNotAllowedException('No valid ' . $type . ' options found for this attribute.');
$options = array();
foreach ($enabledModules['modules'] as $temp) {
if ($temp['name'] == $module) {
if (isset($temp['meta']['config'])) {
foreach ($temp['meta']['config'] as $conf) {
$options[$conf] = Configure::read('Plugin.Enrichment_' . $module . '_' . $conf);
$options[$conf] = Configure::read('Plugin.' . $type . '_' . $module . '_' . $conf);
}
}
}
@ -3907,7 +3917,7 @@ class EventsController extends AppController {
if (!empty($options)) $data['config'] = $options;
$data = json_encode($data);
$result = $this->Module->queryModuleServer('/query', $data);
if (!$result) throw new MethodNotAllowedException('Enrichment service not reachable.');
if (!$result) throw new MethodNotAllowedException($type . ' service not reachable.');
if (isset($result['error'])) $this->Session->setFlash($result['error']);
if (!is_array($result)) throw new Exception($result);
$resultArray = $this->Event->handleModuleResult($result, $attribute[0]['Attribute']['event_id']);

View File

@ -658,7 +658,7 @@ class ServersController extends AppController {
public function serverSettingsReloadSetting($setting, $id) {
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
$pathToSetting = explode('.', $setting);
if (strpos($setting, 'Plugin.Enrichment') !== false || strpos($setting, 'Plugin.Import') !== false || strpos($setting, 'Plugin.Export') !== false) {
if (strpos($setting, 'Plugin.Enrichment') !== false || strpos($setting, 'Plugin.Import') !== false || strpos($setting, 'Plugin.Export') !== false || strpos($setting, 'Plugin.Cortex') !== false) {
$settingObject = $this->Server->getCurrentServerSettings();
}
else $settingObject = $this->Server->serverSettings;
@ -811,7 +811,7 @@ class ServersController extends AppController {
// if Proxy is set up in the settings, try to connect to a test URL
$proxyStatus = $this->Server->proxyDiagnostics($diagnostic_errors);
$moduleTypes = array('Enrichment', 'Import', 'Export');
$moduleTypes = array('Enrichment', 'Import', 'Export', 'Cortex');
foreach ($moduleTypes as $type) {
$moduleStatus[$type] = $this->Server->moduleDiagnostics($diagnostic_errors, $type);
}
@ -925,7 +925,7 @@ class ServersController extends AppController {
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
if (!isset($setting) || !isset($id)) throw new MethodNotAllowedException();
$this->set('id', $id);
if (strpos($setting, 'Plugin.Enrichment') !== false || strpos($setting, 'Plugin.Import') !== false || strpos($setting, 'Plugin.Export') !== false) {
if (strpos($setting, 'Plugin.Enrichment') !== false || strpos($setting, 'Plugin.Import') !== false || strpos($setting, 'Plugin.Export') !== false || strpos($setting, 'Plugin.Cortex') !== false) {
$serverSettings = $this->Server->getCurrentServerSettings();
}
else $serverSettings = $this->Server->serverSettings;

View File

@ -8,14 +8,16 @@ class Module extends AppModel {
private $__validTypes = array(
'Enrichment' => array('hover', 'expansion'),
'Import' => array('import'),
'Export' => array('export')
'Export' => array('export'),
'Cortex' => array('cortex')
);
private $__typeToFamily = array(
'Import' => 'Import',
'Export' => 'Export',
'hover' => 'Enrichment',
'expansion' => 'Enrichment'
'expansion' => 'Enrichment',
'Cortex' => 'Cortex'
);
public $configTypes = array(
@ -96,7 +98,7 @@ class Module extends AppModel {
else if (isset($temp['meta']['module-type']) && in_array('export', $temp['meta']['module-type'])) $modules['Export'] = $temp['name'];
else {
foreach ($temp['mispattributes']['input'] as $input) {
if (!isset($temp['meta']['module-type']) || in_array('expansion', $temp['meta']['module-type'])) $modules['types'][$input][] = $temp['name'];
if (!isset($temp['meta']['module-type']) || (in_array('expansion', $temp['meta']['module-type']) || in_array('cortex', $temp['meta']['module-type']))) $modules['types'][$input][] = $temp['name'];
if (isset($temp['meta']['module-type']) && in_array('hover', $temp['meta']['module-type'])) $modules['hover_type'][$input][] = $temp['name'];
}
}

View File

@ -1319,6 +1319,38 @@ class Server extends AppModel {
'test' => 'testForPortNumber',
'type' => 'numeric'
),
'Cortex_services_url' => array(
'level' => 1,
'description' => 'The url used to access Cortex. By default, it is accessible at http://cortex-url/api',
'value' => 'http://127.0.0.1/api',
'errorMessage' => '',
'test' => 'testForEmpty',
'type' => 'string'
),
'Cortex_services_port' => array(
'level' => 1,
'description' => 'The port used to access Cortex. By default, this is port 9000',
'value' => '9000',
'errorMessage' => '',
'test' => 'testForPortNumber',
'type' => 'numeric'
),
'Cortex_services_enable' => array(
'level' => 0,
'description' => 'Enable/disable the import services',
'value' => false,
'errorMessage' => '',
'test' => 'testBool',
'type' => 'boolean'
),
'Cortex_timeout' => array(
'level' => 1,
'description' => 'Set a timeout for the import services',
'value' => 120,
'errorMessage' => '',
'test' => 'testForEmpty',
'type' => 'numeric'
),
'CustomAuth_custom_password_reset' => array(
'level' => 2,
'description' => 'Provide your custom authentication users with an external URL to the authentication system to reset their passwords.',
@ -1952,7 +1984,7 @@ class Server extends AppModel {
public function getCurrentServerSettings() {
$this->Module = ClassRegistry::init('Module');
$serverSettings = $this->serverSettings;
$moduleTypes = array('Enrichment', 'Import', 'Export');
$moduleTypes = array('Enrichment', 'Import', 'Export', 'Cortex');
foreach ($moduleTypes as $moduleType) {
if (Configure::read('Plugin.' . $moduleType . '_services_enable')) {
$results = $this->Module->getModuleSettings($moduleType);
@ -2887,7 +2919,7 @@ class Server extends AppModel {
public function moduleDiagnostics(&$diagnostic_errors, $type = 'Enrichment') {
$this->Module = ClassRegistry::init('Module');
$types = array('Enrichment', 'Import', 'Export');
$types = array('Enrichment', 'Import', 'Export', 'Cortex');
$diagnostic_errors++;
if (Configure::read('Plugin.' . $type . '_services_enable')) {
$exception = false;

View File

@ -491,6 +491,11 @@
if (isset($modules) && isset($modules['types'][$object['type']])):
?>
<span class="icon-asterisk useCursorPointer" title="Query enrichment" role="button" tabindex="0" aria-label="Query enrichment" onClick="simplePopup('<?php echo $baseurl;?>/events/queryEnrichment/<?php echo h($object['id']);?>/ShadowAttribute');" title="Propose enrichment">&nbsp;</span>
<?php
endif;
if (isset($cortex_modules) && isset($cortex_modules['types'][$object['type']])):
?>
<span class="icon-eye-open useCursorPointer" title="Query Cortex" role="button" tabindex="0" aria-label="Query Cortex" onClick="simplePopup('<?php echo $baseurl;?>/events/queryEnrichment/<?php echo h($object['id']);?>/ShadowAttribute/Cortex');" title="Propose enrichment through Cortex"></span>
<?php
endif;
?>
@ -508,6 +513,12 @@
<span class="icon-asterisk useCursorPointer" onClick="simplePopup('<?php echo $baseurl;?>/events/queryEnrichment/<?php echo h($object['id']);?>/Attribute');" title="Add enrichment" role="button" tabindex="0" aria-label="Add enrichment">&nbsp;</span>
<?php
endif;
if (isset($cortex_modules) && isset($cortex_modules['types'][$object['type']])):
?>
<span class="icon-eye-open useCursorPointer" onClick="simplePopup('<?php echo $baseurl;?>/events/queryEnrichment/<?php echo h($object['id']);?>/Attribute/Cortex');" title="Add enrichment" role="button" tabindex="0" aria-label="Add enrichment via Cortex">C</span>
<?php
endif;
?>
<a href="<?php echo $baseurl;?>/attributes/edit/<?php echo $object['id']; ?>" title="Edit" class="icon-edit useCursorPointer"></a>
<span class="icon-trash useCursorPointer" title="Delete attribute" role="button" tabindex="0" aria-label="Delete attribute" onClick="deleteObject('attributes', 'delete', '<?php echo h($object['id']); ?>', '<?php echo h($event['Event']['id']); ?>');"></span>