FOSSology  4.4.0
Open Source License Compliance by Open Source Software
DecisionImporterAgent.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
4  SPDX-FileCopyrightText: © 2022 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
14 namespace Fossology\DecisionImporter;
15 
21 define("DECISIONIMPORTER_AGENT_NAME", "decisionimporter");
22 
23 use Exception;
25 
26 include_once(__DIR__ . "/version.php");
27 require_once "DecisionImporterIdFetcher.php";
28 require_once "FoDecisionData.php";
29 require_once "DecisionImporterDataCreator.php";
30 
36 {
41  public static $UPDATE_COUNT = 1000;
42 
43  const REPORT_KEY = "report";
44  const LONG_OPT_KEYS = ["userselect"];
45 
50  private $report;
51 
56  private $setUserId;
57 
62  private $reportData;
63 
69 
75 
79  function __construct()
80  {
81  parent::__construct(DECISIONIMPORTER_AGENT_NAME, AGENT_VERSION, AGENT_REV);
82 
83  $this->agentSpecifLongOptions[] = self::REPORT_KEY . ':';
84  foreach (self::LONG_OPT_KEYS as $opt) {
85  $this->agentSpecifLongOptions[] = $opt . ":";
86  }
87 
88  $dbManager = $this->container->get("db.manager");
89  $pfileDao = $this->container->get("dao.pfile");
90  $licenseDao = $this->container->get("dao.license");
91  $agentDao = $this->container->get("dao.agent");
92  $copyrightDao = $this->container->get("dao.copyright");
93  $uploadDao = $this->container->get("dao.upload");
94  $clearingDao = $this->container->get("dao.clearing");
95 
96  $this->decisionImporterUtils = new DecisionImporterIdFetcher($dbManager, $pfileDao, $licenseDao);
97  $this->decisionImporterDataCreator = new DecisionImporterDataCreator($dbManager, $agentDao, $copyrightDao,
98  $licenseDao, $uploadDao, $clearingDao);
99  }
100 
106  function processUploadId($uploadId)
107  {
110  global $SysConf;
111  $fileBase = $SysConf['FOSSOLOGY']['path'] . "/DecisionImport/";
112  $this->processArgs();
113  $this->report = $fileBase . $this->report;
114  if (!file_exists($this->report) ||
115  !is_readable($this->report)) {
116  echo "No report to process\n";
117  echo "Maybe the permissions on " . htmlspecialchars($fileBase) . " are not sufficient\n";
118  return false;
119  }
120 
121  $this->reportData = FoDecisionData::createFromFile($this->report);
122 
123  $this->heartbeat(0);
124 
125  $this->decisionImporterUtils->setUploadId($uploadId);
126  $this->decisionImporterUtils->setGroupId($groupId);
127  $this->decisionImporterUtils->setUserId($userId);
128 
129  $this->decisionImporterUtils->getOrCreateIds($this->reportData, $this);
130 
131  $this->decisionImporterDataCreator->setUserId($this->setUserId);
132  $this->decisionImporterDataCreator->setGroupId($groupId);
133  $this->decisionImporterDataCreator->setUploadId($uploadId);
134 
135  $this->decisionImporterDataCreator->createClearingDecisions($this->reportData, $this);
136  $this->decisionImporterDataCreator->createMonkBulkData($this->reportData, $this);
137  $this->decisionImporterDataCreator->createCopyrightData($this->reportData, $this, "copyright", $this->jobId);
138  $this->decisionImporterDataCreator->createCopyrightData($this->reportData, $this, "ecc", $this->jobId);
139  $this->decisionImporterDataCreator->createCopyrightData($this->reportData, $this, "ipra", $this->jobId);
140  $this->decisionImporterDataCreator->createReportData($this->reportData);
141  $this->decisionImporterDataCreator->createMainLicenses($this->reportData, $uploadId, $groupId);
142  $this->heartbeat(0);
143 
144  return true;
145  }
146 
150  private function processArgs(): void
151  {
152  $args = explode(" --", $this->args[self::REPORT_KEY]);
153  $this->report = $args[0];
154  $args = array_slice($args, 1);
155  foreach ($args as $arg) {
156  list($key, $value) = explode("=", $arg);
157  if ($key == self::LONG_OPT_KEYS[0]) {
158  $this->setUserId = intval($value);
159  }
160  }
161  }
162 }
Import decisions generated by Decision Exporter from JSON files.
const LONG_OPT_KEYS
Other CLI args required by agents.
processUploadId($uploadId)
Given an upload ID, process the items in it.
Structure of an Agent with all required parameters.
Definition: Agent.php:41
heartbeat($newProcessed)
Send hear beat to the scheduler.
Definition: Agent.php:203
int jobId
The id of the job.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308