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, array_unique(array_merge($whiteLists, $newWhiteList)));
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 foreach ($bulkHistory as $key => $value) {
100 if (empty($value[
'id'])) {
101 unset($bulkHistory[$key]);
104 $licenseLists = array_column($bulkHistory,
'addedLicenses');
105 $allLicenses = array();
106 foreach ($licenseLists as $licenseList) {
107 $allLicenses = array_unique(array_merge($allLicenses, $licenseList));
109 foreach ($allLicenses as $allLicense) {
110 $license = $this->licenseDao->getLicenseByShortName($allLicense);
111 if (!empty($license)) {
112 $licenseId[] = $license->getId();
126 $groupedOb = array();
128 $row = $this->uploadDao->getReportInfo($uploadId);
129 $excludedObligations = (array) json_decode($row[
'ri_excluded_obligations'],
true);
130 foreach ($obligations as $obligation ) {
131 $obTopic = $obligation[
'ob_topic'];
132 $obText = $obligation[
'ob_text'];
134 $obligation[
'rf_spdx_id']);
136 if (!empty($excludedObligations) && array_key_exists($obTopic, $excludedObligations)) {
137 $obligationLicenseNames = $excludedObligations[$obTopic];
139 $obligationLicenseNames = array();
141 if (!in_array($licenseName, $obligationLicenseNames)) {
142 if (array_key_exists($groupBy, $groupedOb)) {
143 $currentLics = &$groupedOb[$groupBy][
'license'];
144 if (!in_array($licenseName, $currentLics)) {
145 $currentLics[] = $licenseName;
151 "license" => array($licenseName)
153 $groupedOb[$groupBy] = $singleOb;
156 if (!in_array($licenseName, $whiteList)) {
157 $whiteList[] = $licenseName;
164 foreach ($groupedOb as $obli) {
165 $whiteList = array_diff($whiteList, $obli[
'license']);
167 return [$groupedOb, $whiteList];
178 foreach ($licenseStatements as $licenseStatement) {
179 $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.
list_t type structure used to keep various lists. (e.g. there are multiple lists).