FOSSology  4.7.1
Open Source License Compliance by Open Source Software
ReuseReportProcessor.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Rohit Pandey <rohit.pandey4900@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
17 
23 {
25  private $dbManager;
27  private $uploadDao;
29  private $detectLicensesFolder;
31  private $clearingDao;
33  private $licenseProjector;
34 
35  function __construct()
36  {
37  $this->dbManager = $GLOBALS['container']->get('db.manager');
38  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
39  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
40  $this->detectLicensesFolder = $GLOBALS['container']->get('businessrules.detectlicensesfolder');
41  }
42 
49  public function getReuseSummary($uploadId)
50  {
51  $declearedLicenses = array_merge(
52  $this->detectLicensesFolder->getDeclearedLicenses($uploadId),
53  $this->detectLicensesFolder->getLicenseFileDeclaredLicenses($uploadId)
54  );
55  $groupId = Auth::getGroupId();
56  $uploadtreeTablename = GetUploadtreeTableName($uploadId);
57  $uploadTreeId = $this->uploadDao->getUploadParent($uploadId);
58  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadtreeTablename);
59  $clearedLicenses = $this->clearingDao->getClearedLicenses($itemTreeBounds, $groupId);
60  $this->licenseProjector = new LicenseMap($this->dbManager,$groupId,LicenseMap::CONCLUSION,true);
61  $concludedLicenses = [];
63  if (!empty($clearedLicenses)) {
64  foreach ($clearedLicenses as $licenseRef) {
65  $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(),$licenseRef->getShortName());
66  $concludedLicenses[] = $projectedName;
67  }
68  }
69 
70  $vars = [];
71  $vars["declearedLicense"] = implode(", ", $declearedLicenses);
72  $vars["clearedLicense"] = implode(", ", $concludedLicenses);
73 
74  if (empty($declearedLicenses)) {
75  $vars["usedLicense"] = "";
76  $vars["unusedLicense"] = "";
77  $vars["missingLicense"] = implode(", ", $concludedLicenses);
78  return $vars;
79  }
80 
81  $vars["usedLicense"] = implode(", ", array_intersect($declearedLicenses, $concludedLicenses));
82  $vars["unusedLicense"] = implode(", ", array_diff($declearedLicenses, $concludedLicenses));
83  $vars["missingLicense"] = implode(", ", array_diff($concludedLicenses, $declearedLicenses));
84  return $vars;
85  }
86 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getGroupId()
Get the current user's group id.
Definition: Auth.php:80
Detects licenses declard inside LICENSES directory.
Wrapper class for license map.
Definition: LicenseMap.php:19
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
Definition: libfossagent.c:414
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Contains business rules for FOSSology.