mirror of https://github.com/MISP/MISP
chg: [ClusterRelationsGraphTool] Refacto and simplified code
parent
1c4b3b97e9
commit
d348221792
|
@ -4830,13 +4830,12 @@ class EventsController extends AppController
|
|||
}
|
||||
}
|
||||
}
|
||||
$rootNodeIds = $clusterIds;
|
||||
$this->loadModel('GalaxyCluster');
|
||||
$clusters = $this->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => array('GalaxyCluster.id' => $clusterIds)), $full=true);
|
||||
App::uses('ClusterRelationsGraphTool', 'Tools');
|
||||
$grapher = new ClusterRelationsGraphTool();
|
||||
$grapher->construct($this->Auth->user(), $this->GalaxyCluster);
|
||||
$relations = $grapher->getNetwork($clusters, $rootNodeIds=$rootNodeIds, $keepNotLinkedClusters=true, $includeReferencingRelation=true);
|
||||
$relations = $grapher->getNetwork($clusters, $keepNotLinkedClusters=true, $includeReferencingRelation=true);
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($relations, $this->response->type());
|
||||
}
|
||||
|
|
|
@ -575,11 +575,10 @@ class GalaxiesController extends AppController
|
|||
'recursive' => -1,
|
||||
'conditions' => array('Galaxy.id' => $galaxyId)
|
||||
));
|
||||
$rootNodeIds = Hash::combine($clusters, '{n}.GalaxyCluster.id', '{n}.GalaxyCluster.id');
|
||||
App::uses('ClusterRelationsGraphTool', 'Tools');
|
||||
$grapher = new ClusterRelationsGraphTool();
|
||||
$grapher->construct($this->Auth->user(), $this->Galaxy->GalaxyCluster);
|
||||
$relations = $grapher->getNetwork($clusters, $rootNodeIds=$rootNodeIds);
|
||||
$relations = $grapher->getNetwork($clusters);
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($relations, $this->response->type());
|
||||
}
|
||||
|
|
|
@ -12,15 +12,23 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
public function getNetwork($clusters, $rootNodeIds=array(), $keepNotLinkedClusters=false, $includeReferencingRelation=false)
|
||||
/**
|
||||
* getNetwork Returns the network for the provided clusters
|
||||
*
|
||||
* @param mixed $clusters
|
||||
* @param bool $keepNotLinkedClusters If true, includes nodes not linked to others
|
||||
* @param bool $includeReferencingRelation If true, fetch and includes nodes referencing the $clusters passed
|
||||
* @return array The constructed network with nodes and links as keys
|
||||
*/
|
||||
public function getNetwork(array $clusters, $keepNotLinkedClusters=false, $includeReferencingRelation=false)
|
||||
{
|
||||
$rootNodeIds = Hash::extract($clusters, '{n}.GalaxyCluster.id');
|
||||
$nodes = array();
|
||||
$links = array();
|
||||
foreach ($clusters as $cluster) {
|
||||
$this->lookup[$cluster['GalaxyCluster']['uuid']] = $cluster;
|
||||
}
|
||||
foreach ($clusters as $cluster) {
|
||||
$cluster = $this->attachOwnerInsideCluster($cluster);
|
||||
if (!empty($cluster['GalaxyCluster']['GalaxyClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyCluster']['GalaxyClusterRelation'] as $relation) {
|
||||
$referencedClusterUuid = $relation['referenced_galaxy_cluster_uuid'];
|
||||
|
@ -30,14 +38,12 @@
|
|||
'contain' => array('Org', 'Orgc', 'SharingGroup'),
|
||||
));
|
||||
if (!empty($referencedCluster)) {
|
||||
$referencedCluster[0] = $this->attachOwnerInsideCluster($referencedCluster[0]);
|
||||
$this->lookup[$referencedClusterUuid] = $referencedCluster[0];
|
||||
} else {
|
||||
$this->lookup[$referencedClusterUuid] = array();
|
||||
}
|
||||
}
|
||||
$referencedCluster = $this->lookup[$referencedClusterUuid];
|
||||
$referencedCluster = $this->attachOwnerInsideCluster($referencedCluster);
|
||||
if (!empty($referencedCluster)) {
|
||||
$nodes[$referencedClusterUuid] = $referencedCluster['GalaxyCluster'];
|
||||
$nodes[$referencedClusterUuid]['group'] = $referencedCluster['GalaxyCluster']['type'];
|
||||
|
@ -68,7 +74,8 @@
|
|||
$referencingRelations = $this->GalaxyCluster->GalaxyClusterRelation->fetchRelations($this->user, array(
|
||||
'conditions' => array(
|
||||
'referenced_galaxy_cluster_uuid' => $cluster['GalaxyCluster']['uuid']
|
||||
)
|
||||
),
|
||||
'contain' => array('Org', 'Orgc', 'SharingGroup'),
|
||||
));
|
||||
if (!empty($referencingRelations)) {
|
||||
foreach ($referencingRelations as $relation) {
|
||||
|
@ -82,7 +89,6 @@
|
|||
}
|
||||
$referencingCluster = $this->lookup[$referencingClusterUuid];
|
||||
if (!empty($referencingCluster)) {
|
||||
$referencingCluster = $this->attachOwnerInsideCluster($referencingCluster);
|
||||
$nodes[$referencingClusterUuid] = $referencingCluster['GalaxyCluster'];
|
||||
$nodes[$referencingClusterUuid]['group'] = $referencingCluster['GalaxyCluster']['type'];
|
||||
$links[] = array(
|
||||
|
@ -98,28 +104,4 @@
|
|||
}
|
||||
return array('nodes' => array_values($nodes), 'links' => $links);
|
||||
}
|
||||
|
||||
private function attachOwnerInsideCluster($cluster)
|
||||
{
|
||||
if (!empty($cluster['GalaxyCluster']['Org']) && !isset($cluster['GalaxyCluster']['Org'])) {
|
||||
$cluster['GalaxyCluster']['Org'] = array(
|
||||
'id' => $cluster['Org']['id'],
|
||||
'name' => $cluster['Org']['name'],
|
||||
);
|
||||
}
|
||||
if (!empty($cluster['GalaxyCluster']['Orgc']) && !isset($cluster['GalaxyCluster']['Orgc'])) {
|
||||
$cluster['GalaxyCluster']['Orgc'] = array(
|
||||
'id' => $cluster['Orgc']['id'],
|
||||
'name' => $cluster['Orgc']['name'],
|
||||
);
|
||||
}
|
||||
if (!empty($cluster['GalaxyCluster']['SharingGroup']) && !isset($cluster['GalaxyCluster']['SharingGroup'])) {
|
||||
$cluster['GalaxyCluster']['SharingGroup'] = array(
|
||||
'id' => $cluster['SharingGroup']['id'],
|
||||
'name' => $cluster['SharingGroup']['name'],
|
||||
'description' => $cluster['SharingGroup']['description'],
|
||||
);
|
||||
}
|
||||
return $cluster;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue