FOSSology  4.4.0
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 = $this->detectLicensesFolder->getDeclearedLicenses($uploadId);
52  $groupId = Auth::getGroupId();
53  $uploadtreeTablename = GetUploadtreeTableName($uploadId);
54  $uploadTreeId = $this->uploadDao->getUploadParent($uploadId);
55  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadtreeTablename);
56  $clearedLicenses = $this->clearingDao->getClearedLicenses($itemTreeBounds, $groupId);
57  $this->licenseProjector = new LicenseMap($this->dbManager,$groupId,LicenseMap::CONCLUSION,true);
58  $concludedLicenses = [];
60  if (!empty($clearedLicenses)) {
61  foreach ($clearedLicenses as $licenseRef) {
62  $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(),$licenseRef->getShortName());
63  $concludedLicenses[] = $projectedName;
64  }
65  }
66 
67  $vars = [];
68  $vars["declearedLicense"] = implode(", ", $declearedLicenses);
69  $vars["clearedLicense"] = implode(", ", $concludedLicenses);
70 
71  if (empty($declearedLicenses)) {
72  $vars["usedLicense"] = "";
73  $vars["unusedLicense"] = "";
74  $vars["missingLicense"] = implode(", ", $concludedLicenses);
75  return $vars;
76  }
77 
78  $vars["usedLicense"] = implode(", ", array_intersect($declearedLicenses, $concludedLicenses));
79  $vars["unusedLicense"] = implode(", ", array_diff($declearedLicenses, $concludedLicenses));
80  $vars["missingLicense"] = implode(", ", array_diff($concludedLicenses, $declearedLicenses));
81  return $vars;
82  }
83 }
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.