FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
DeciderAgentPlugin.php
1 <?php
2 /***********************************************************
3  * Copyright (C) 2014-2018, Siemens AG
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
21 
22 include_once(__DIR__ . "/../agent/version.php");
23 
29 {
30  const RULES_FLAG = "-r";
31 
32  function __construct()
33  {
34  $this->Name = "agent_decider";
35  $this->Title = _("Automatic Concluded License Decider, based on scanners Matches");
36  $this->AgentName = AGENT_DECIDER_NAME;
37 
38  parent::__construct();
39  }
40 
41 
47  public function renderContent(&$vars)
48  {
49  $renderer = $GLOBALS['container']->get('twig.environment');
50  $vars['isNinkaInstalled'] = false;
51  if ($ninkaUi=plugin_find('agent_ninka')) {
52  $vars['isNinkaInstalled'] = $ninkaUi->isNinkaInstalled();
53  }
54  return $renderer->loadTemplate('agent_decider.html.twig')->render($vars);
55  }
56 
62  public function renderFoot(&$vars)
63  {
64  return "";
65  }
66 
75  public function scheduleAgent($jobId, $uploadId, &$errorMsg, $request)
76  {
77  $dependencies = array();
78 
79  $rules = $request->get('deciderRules') ?: array();
80  $agents = $request->get('agents') ?: array();
81  if (in_array('agent_nomos', $agents)) {
82  $checkAgentNomos = true;
83  } else {
84  $checkAgentNomos = $request->get('Check_agent_nomos') ?: false;
85  }
86  $rulebits = 0;
87 
88  foreach ($rules as $rule) {
89  switch ($rule) {
90  case 'nomosInMonk':
91  $dependencies[] = 'agent_nomos';
92  $dependencies[] = 'agent_monk';
93  $rulebits |= 0x1;
94  break;
95  case 'nomosMonkNinka':
96  $dependencies[] = 'agent_nomos';
97  $dependencies[] = 'agent_monk';
98  $dependencies[] = 'agent_ninka';
99  $rulebits |= 0x2;
100  break;
101  case 'reuseBulk':
102  $dependencies[] = 'agent_nomos';
103  $dependencies[] = 'agent_monk';
104  $dependencies[] = 'agent_reuser';
105  $rulebits |= 0x4;
106  break;
107  case 'ojoNoContradiction':
108  if ($checkAgentNomos) {
109  $dependencies[] = 'agent_nomos';
110  }
111  $dependencies[] = 'agent_ojo';
112  $rulebits |= 0x10;
113  break;
114  case 'wipScannerUpdates':
115  $this->addScannerDependencies($dependencies, $request);
116  $rulebits |= 0x8;
117  }
118  }
119 
120  if (empty($rulebits)) {
121  return 0;
122  }
123 
124  $args = self::RULES_FLAG.$rulebits;
125  return parent::AgentAdd($jobId, $uploadId, $errorMsg, array_unique($dependencies), $args);
126  }
127 
133  protected function addScannerDependencies(&$dependencies, Request $request)
134  {
135  $agentList = $request->get('agents') ?: array();
136  foreach (array('agent_nomos', 'agent_monk', 'agent_ninka') as $agentName) {
137  if (in_array($agentName, $dependencies)) {
138  continue;
139  }
140  if ($request->get('Check_'.$agentName)) {
141  $dependencies[] = $agentName;
142  continue;
143  }
144  if (in_array($agentName, $agentList)) {
145  $dependencies[] = $agentName;
146  }
147  }
148  }
149 
154  public function preInstall()
155  {
156  menu_insert("ParmAgents::" . $this->Title, 0, $this->Name);
157  }
158 }
159 
160 register_plugin(new DeciderAgentPlugin());
addScannerDependencies(&$dependencies, Request $request)
Add dependencies on DeciderAgent.
UI plugin for DeciderAgent.
renderContent(&$vars)
Render HTML from template.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
renderFoot(&$vars)
Render footer HTML.
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item...
scheduleAgent($jobId, $uploadId, &$errorMsg, $request)
Schedule decider agent.