8 namespace Fossology\Lib\Report;
24 private $onlyComments =
false;
26 private $onlyAcknowledgements =
false;
34 private $licenseCache = array();
36 protected $agentNames = AgentRef::AGENT_LIST;
38 public function __construct()
42 $this->clearingDao = $container->get(
'dao.clearing');
43 $this->licenseDao = $container->get(
'dao.license');
44 $this->agentDao = $container->get(
'dao.agent');
46 parent::__construct($groupBy =
'text');
49 protected function getStatements($uploadId, $uploadTreeTableName, $groupId =
null)
51 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId,$uploadTreeTableName);
52 $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
53 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
54 $licenseMap =
new LicenseMap($dbManager, $groupId, LicenseMap::REPORT);
55 $ungroupedStatements = array();
56 foreach ($clearingDecisions as $clearingDecision) {
57 if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
61 foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
62 if ($clearingLicense->isRemoved()) {
66 $comment = $clearingLicense->getComment();
67 if ($this->onlyComments && !($comment)) {
71 $acknowledgement = $clearingLicense->getAcknowledgement();
72 if ($this->onlyAcknowledgements && !($acknowledgement)) {
76 $originLicenseId = $clearingLicense->getLicenseId();
77 $licenseId = $licenseMap->getProjectedId($originLicenseId);
79 if ($this->onlyAcknowledgements) {
80 $text = $acknowledgement;
82 }
else if ($this->onlyComments) {
86 $reportInfo = $clearingLicense->getReportInfo();
89 $acknowledgement = $clearingLicense->getAcknowledgement();
92 $ungroupedStatements[] = array(
93 'licenseId' => $licenseId,
95 'content' => $licenseMap->getProjectedSpdxId(
96 $originLicenseId, $clearingLicense->getSpdxId()),
97 'uploadtree_pk' => $clearingDecision->getUploadTreeId(),
99 'acknowledgement' => $acknowledgement
104 return $ungroupedStatements;
112 public function getCleared($uploadId, $objectAgent, $groupId=
null,
113 $extended=
true, $agentCall=
null, $isUnifiedReport=
false)
115 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
116 $ungroupedStatements = $this->
getStatements($uploadId, $uploadTreeTableName,
118 $this->changeTreeIdsToPaths($ungroupedStatements, $uploadTreeTableName,
120 if ($this->onlyAcknowledgements || $this->onlyComments) {
123 return $this->groupStatements($ungroupedStatements, $extended, $agentCall,
124 $isUnifiedReport, $objectAgent);
135 $statements = array();
137 foreach ($ungrupedStatements as $statement) {
138 $licenseId = $statement[
'licenseId'];
140 $content = htmlspecialchars($content, ENT_DISALLOWED);
142 $text = htmlspecialchars($text, ENT_DISALLOWED);
143 $fileName = $statement[
'fileName'];
145 $statementKey = md5(
"$content.$text");
146 if (!array_key_exists($statementKey, $statements)) {
147 $statements[$statementKey] = [
148 "licenseId" => $licenseId,
149 "content" => $content,
151 "files" => [$fileName]
154 if (!in_array($fileName, $statements[$statementKey][
"files"])) {
155 $statements[$statementKey][
"files"][] = $fileName;
161 if ($countLoop % 500 == 0) {
162 $objectAgent->heartbeat(0);
165 $statements = array_values($statements);
166 usort($statements,
function($a, $b) {
167 return strnatcmp($a[
"content"], $b[
"content"]);
169 if (!empty($objectAgent)) {
170 $objectAgent->heartbeat(count($statements));
172 return array(
"statements" => array_values($statements));
180 $this->onlyAcknowledgements =
false;
181 $this->onlyComments = $displayOnlyCommentedLicenseClearings;
189 $this->onlyComments =
false;
190 $this->onlyAcknowledgements = $displayOnlyAcknowledgements;
199 if (!array_key_exists($licenseId, $this->licenseCache)) {
200 $this->licenseCache[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId);
203 if ($this->licenseCache[$licenseId] !==
null) {
204 return $this->licenseCache[$licenseId]->getText();
216 if (!array_key_exists($licenseId, $this->licenseCache)) {
217 $this->licenseCache[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId);
220 if ($this->licenseCache[$licenseId] !==
null) {
221 return $this->licenseCache[$licenseId]->getRisk();
233 $LicenseHistArray = array();
234 $scannerAgents = array_keys($this->agentNames);
235 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
236 $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
237 $allAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
238 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId);
239 $scannerLicenseHistogram = $this->licenseDao->getLicenseHistogram($itemTreeBounds, $allAgentIds);
240 $editedLicensesHist = $this->clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $groupId);
241 $noScannerLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $scannerLicenseHistogram)
242 ? $scannerLicenseHistogram[LicenseDao::NO_LICENSE_FOUND][
'count'] : 0;
243 $editedNoLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $editedLicensesHist)
244 ? $editedLicensesHist[LicenseDao::NO_LICENSE_FOUND][
'count'] : 0;
246 $totalLicenses = array_unique(array_merge(array_keys($scannerLicenseHistogram), array_keys($editedLicensesHist)));
247 foreach ($totalLicenses as $licenseShortName) {
249 if (array_key_exists($licenseShortName, $scannerLicenseHistogram)) {
250 $count = $scannerLicenseHistogram[$licenseShortName][
'unique'];
252 $editedCount = array_key_exists($licenseShortName, $editedLicensesHist) ? $editedLicensesHist[$licenseShortName][
'count'] : 0;
254 if (array_key_exists($licenseShortName, $scannerLicenseHistogram)) {
255 $licenseReportId = $scannerLicenseHistogram[$licenseShortName][
'spdx_id'];
257 $licenseReportId = $editedLicensesHist[$licenseShortName][
'spdx_id'];
260 if (strcmp($licenseShortName, LicenseDao::NO_LICENSE_FOUND) !== 0) {
261 $LicenseHistArray[] = array(
"scannerCount" => $count,
"editedCount" => $editedCount,
"licenseShortname" => $licenseReportId);
263 $LicenseHistArray[] = array(
"scannerCount" => $noScannerLicenseFoundCount,
"editedCount" => $editedNoLicenseFoundCount,
"licenseShortname" => $licenseReportId);
266 return $LicenseHistArray;
277 return strcmp($licenses1[
'licenseId'], $licenses2[
'licenseId']);
288 $onlyMainLic = array_udiff($licensesMain, $licenses, array($this,
"checkLicenseId"));
289 $mainLicensesInIdentifiedFiles = array_uintersect($licenses, $licensesMain, array($this,
"checkLicenseId"));
290 $onlyLicense = array_udiff($licenses, $licensesMain, array($this,
"checkLicenseId"));
292 array_values(array_merge($onlyMainLic, $mainLicensesInIdentifiedFiles)),
293 array_values($onlyLicense)
Structure of an Agent with all required parameters.
Wrapper class for license map.
getStatements($uploadId, $uploadTreeTableName, $groupId=null)
setOnlyComments($displayOnlyCommentedLicenseClearings)
updateIdentifiedGlobalLicenses($licensesMain, $licenses)
Copy identified global licenses.
setOnlyAcknowledgements($displayOnlyAcknowledgements)
getCachedLicenseRisk($licenseId, $groupId)
checkLicenseId($licenses1, $licenses2)
callback to compare licenses
getCleared($uploadId, $objectAgent, $groupId=null, $extended=true, $agentCall=null, $isUnifiedReport=false)
groupStatementsSpecial($ungrupedStatements, $objectAgent)
getHistogram($uploadId, $groupId)
getCachedLicenseText($licenseId, $groupId)
if(! defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)