8 namespace Fossology\Lib\Report;
36 public function __construct()
39 $this->licenseDao = $container->get(
'dao.license');
40 $this->clearingDao = $container->get(
'dao.clearing');
41 $this->uploadDao = $container->get(
'dao.upload');
53 function getObligations($licenseStatements, $mainLicenseStatements, $uploadId, $groupId)
55 $whiteLists = array();
56 $licenseIds = $this->
contentOnly($licenseStatements) ?: array();
57 $mainLicenseIds = $this->
contentOnly($mainLicenseStatements);
59 if (!empty($mainLicenseIds)) {
60 $allLicenseIds = array_unique(array_merge($licenseIds, $mainLicenseIds));
62 $allLicenseIds = array_unique($licenseIds);
66 if (!empty($bulkAddIds)) {
67 $allLicenseIds = array_unique(array_merge($licenseIds, $bulkAddIds));
70 $obligationRef = $this->licenseDao->getLicenseObligations($allLicenseIds) ?: array();
71 $obligationCandidate = $this->licenseDao->getLicenseObligations($allLicenseIds,
true) ?: array();
72 $obligations = array_merge($obligationRef, $obligationCandidate);
73 $onlyLicenseIdsWithObligation = array_column($obligations,
'rf_fk');
74 $licenseWithObligations = array_unique(array_intersect($onlyLicenseIdsWithObligation, $allLicenseIds));
75 $licenseWithoutObligations = array_diff($allLicenseIds, $licenseWithObligations) ?: array();
76 foreach ($licenseWithoutObligations as $licenseWithoutObligation) {
77 $license = $this->licenseDao->getLicenseById($licenseWithoutObligation);
78 if (!empty($license)) {
79 $whiteLists[] = $license->getSpdxId();
83 return array($newobligations, $whiteLists);
94 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
95 $parentTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
96 $bulkHistory = $this->clearingDao->getBulkHistory($parentTreeBounds, $groupId,
false);
98 if (!empty($bulkHistory)) {
99 $licenseLists = array_column($bulkHistory,
'addedLicenses');
100 $allLicenses = array();
101 foreach ($licenseLists as $licenseList) {
102 $allLicenses = array_unique(array_merge($allLicenses, $licenseList));
104 foreach ($allLicenses as $allLicense) {
105 $license = $this->licenseDao->getLicenseByShortName($allLicense);
106 if (!empty($license)) {
107 $licenseId[] = $license->getId();
121 $groupedOb = array();
122 $row = $this->uploadDao->getReportInfo($uploadId);
123 $excludedObligations = (array) json_decode($row[
'ri_excluded_obligations'],
true);
124 foreach ($obligations as $obligation ) {
125 $obTopic = $obligation[
'ob_topic'];
126 $obText = $obligation[
'ob_text'];
128 $obligation[
'rf_spdx_id']);
130 if (!empty($excludedObligations) && array_key_exists($obTopic, $excludedObligations)) {
131 $obligationLicenseNames = $excludedObligations[$obTopic];
133 $obligationLicenseNames = array();
135 if (!in_array($licenseName, $obligationLicenseNames)) {
136 if (array_key_exists($groupBy, $groupedOb)) {
137 $currentLics = &$groupedOb[$groupBy][
'license'];
138 if (!in_array($licenseName, $currentLics)) {
139 $currentLics[] = $licenseName;
145 "license" => array($licenseName)
147 $groupedOb[$groupBy] = $singleOb;
162 foreach ($licenseStatements as $licenseStatement) {
163 $licenseId[] = $licenseStatement[
"licenseId"];
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
getBulkAddLicenseList($uploadId, $groupId)
Get list of licenses added by Monk bulk.
groupObligations($obligations, $uploadId)
Group obligations based on $groupBy.
contentOnly($licenseStatements)
From a list of license statements, return only license id.
getObligations($licenseStatements, $mainLicenseStatements, $uploadId, $groupId)
For given list of license statements, return obligations and white lists.