7 namespace Fossology\Lib\Report;
26 use Symfony\Component\DependencyInjection\ContainerBuilder;
61 function __construct()
66 $this->
dbManager = $this->container->get(
'db.manager');
67 $this->uploadDao = $this->container->get(
'dao.upload');
68 $this->licenseDao = $this->container->get(
'dao.license');
69 $this->clearingDao = $this->container->get(
'dao.clearing');
70 $this->licenseMap =
null;
82 array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED,
83 UploadTreeProxy::OPT_ITEM_FILTER =>
"AND (lft BETWEEN ".$itemTreeBounds->
getLeft().
" AND ".$itemTreeBounds->
getRight().
")",
84 UploadTreeProxy::OPT_GROUP_ID => $groupId),
86 'already_cleared_uploadtree' . $itemTreeBounds->
getUploadId());
88 $alreadyClearedUploadTreeView->materialize();
89 $filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
90 $alreadyClearedUploadTreeView->unmaterialize();
92 $uploadTreeIds = array_keys($filesWithLicenses);
93 foreach ($uploadTreeIds as $uploadTreeId) {
94 if (!array_key_exists($uploadTreeId, $filesWithLicenses)) {
95 $filesWithLicenses[$uploadTreeId] =
new FileNode();
97 $filesWithLicenses[$uploadTreeId]->setIsCleared(
false === array_key_exists($uploadTreeId, $filesThatShouldStillBeCleared));
111 if ($this->licenseMap ===
null) {
115 $scannerAgents = array_keys($this->agentNames);
116 $scanJobProxy =
new ScanJobProxy($this->container->get(
'dao.agent'), $uploadId);
117 $scanJobProxy->createAgentStatus($scannerAgents);
118 $scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
119 if (empty($scannerIds)) {
123 $stmt = __METHOD__ .
'.scanner_findings';
124 $sql =
"SELECT DISTINCT uploadtree_pk,rf_fk FROM $tableName ut, license_file
125 WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any($1)";
126 $param = array(
'{'.implode(
',',$scannerIds).
'}');
127 if ($tableName ==
'uploadtree_a') {
128 $param[] = $uploadId;
129 $sql .=
" AND upload_fk=$".count($param);
132 $sql .=
" GROUP BY uploadtree_pk,rf_fk";
133 $rows = $this->
dbManager->getRows($sql, $param, $stmt);
134 foreach ($rows as $row) {
135 $reportedLicenseId = $this->licenseMap->getProjectedId($row[
'rf_fk']);
136 $foundLicense = $this->licenseDao->getLicenseById($reportedLicenseId);
137 if ($foundLicense !==
null && $foundLicense->getShortName() !=
'Void') {
138 $reportLicId =
"$reportedLicenseId-" . md5($foundLicense->getText());
140 $foundLicense->getSpdxId(), LicenseRef::SPDXREF_PREFIX);
142 if (!array_key_exists($row[
'uploadtree_pk'], $filesWithLicenses)) {
143 $filesWithLicenses[$row[
'uploadtree_pk']] =
new FileNode();
145 if ($foundLicense->getShortName() !=
'No_license_found') {
146 $filesWithLicenses[$row[
'uploadtree_pk']]->addScanner($reportLicId);
148 $filesWithLicenses[$row[
'uploadtree_pk']]->addScanner(
"");
150 if (!array_key_exists($reportLicId, $licensesInDocument)) {
152 ->setLicenseObj($foundLicense)
153 ->setCustomText(
false)
154 ->setListedLicense($listedLicense);
166 public function addCopyrightResults(&$filesWithLicenses, $uploadId)
168 $agentName = array(
'copyright',
'reso');
170 $copyrightDao = $this->container->get(
'dao.copyright');
172 $scanJobProxy =
new ScanJobProxy($this->container->get(
'dao.agent'),
175 $scanJobProxy->createAgentStatus($agentName);
176 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
177 if (!array_key_exists($agentName[0], $selectedScanners)) {
180 $latestAgentId[] = $selectedScanners[$agentName[0]];
181 if (array_key_exists($agentName[1], $selectedScanners)) {
182 $latestAgentId[] = $selectedScanners[$agentName[1]];
184 $ids = implode(
',', $latestAgentId);
185 $extrawhere =
' agent_fk IN ('.$ids.
')';
187 $uploadtreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
188 $allScannerEntries = $copyrightDao->getScannerEntries(
'copyright', $uploadtreeTable, $uploadId, $type=
'statement', $extrawhere);
189 $allEditedEntries = $copyrightDao->getEditedEntries(
'copyright_decision', $uploadtreeTable, $uploadId, $decisionType=
null);
190 foreach ($allScannerEntries as $finding) {
191 if (!array_key_exists($finding[
'uploadtree_pk'], $filesWithLicenses)) {
192 $filesWithLicenses[$finding[
'uploadtree_pk']] =
new FileNode();
194 $filesWithLicenses[$finding[
'uploadtree_pk']]->addCopyright(\
convertToUTF8($finding[
'content'],
false));
196 foreach ($allEditedEntries as $finding) {
197 if (!array_key_exists($finding[
'uploadtree_pk'], $filesWithLicenses)) {
198 $filesWithLicenses[$finding[
'uploadtree_pk']] =
new FileNode();
200 $filesWithLicenses[$finding[
'uploadtree_pk']]->addCopyright(\
convertToUTF8($finding[
'textfinding'],
false));
213 ItemTreeBounds $itemTreeBounds, $groupId, $agentObj, &$licensesInDocument)
215 if ($this->licenseMap ===
null) {
219 $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
221 $filesWithLicenses = array();
222 $clearingsProceeded = 0;
223 foreach ($clearingDecisions as $clearingDecision) {
224 $clearingsProceeded += 1;
225 if (($clearingsProceeded&2047)==0) {
226 $agentObj->heartbeat(0);
228 if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
232 foreach ($clearingDecision->getClearingEvents() as $clearingEvent) {
233 $clearingLicense = $clearingEvent->getClearingLicense();
234 if ($clearingLicense->isRemoved()) {
238 if (!array_key_exists($clearingDecision->getUploadTreeId(),
239 $filesWithLicenses)) {
240 $filesWithLicenses[$clearingDecision->getUploadTreeId()] =
new FileNode();
244 $filesWithLicenses[$clearingDecision->getUploadTreeId()]
245 ->addComment($clearingLicense->getComment());
247 $filesWithLicenses[$clearingDecision->getUploadTreeId()]
248 ->addAcknowledgement($clearingLicense->getAcknowledgement());
249 $reportedLicenseId = $this->licenseMap->getProjectedId($clearingLicense->getLicenseId());
250 $concludedLicense = $this->licenseDao->getLicenseById($reportedLicenseId, $groupId);
251 if ($clearingEvent->getReportinfo()) {
252 $customLicenseText = $clearingEvent->getReportinfo();
253 $reportedLicenseShortname = $concludedLicense->getShortName() .
'-' .
254 md5($customLicenseText);
257 $reportLicId =
"$reportedLicenseId-" . md5($customLicenseText);
258 $filesWithLicenses[$clearingDecision->getUploadTreeId()]
259 ->addConcludedLicense($reportLicId);
260 if (!array_key_exists($reportLicId, $licensesInDocument)) {
261 $licenseObj =
new License($concludedLicense->getId(),
262 $reportedLicenseShortname, $concludedLicense->getFullName(),
263 $concludedLicense->getRisk(), $customLicenseText,
264 $concludedLicense->getUrl(), $concludedLicense->getDetectorType(),
265 $concludedLicense->getSpdxId());
267 ->setLicenseObj($licenseObj)
268 ->setCustomText(
true)
269 ->setListedLicense(
false);
272 $reportLicId = $concludedLicense->getId() .
"-" .
273 md5($concludedLicense->getText());
274 $filesWithLicenses[$clearingDecision->getUploadTreeId()]
275 ->addConcludedLicense($reportLicId);
276 if (!array_key_exists($reportLicId, $licensesInDocument)) {
277 $licenseObj = $this->licenseDao->getLicenseById($reportedLicenseId, $groupId);
279 $licenseObj->getSpdxId(), LicenseRef::SPDXREF_PREFIX);
281 ->setLicenseObj($licenseObj)
282 ->setCustomText(
false)
283 ->setListedLicense($listedLicense);
288 return $filesWithLicenses;
304 $sqlCheck =
"SELECT 1 FROM reportgen WHERE upload_fk = $1 AND filepath = $2";
305 $row = $this->
dbManager->getSingleRow($sqlCheck, [$upload_fk, $filepath],
306 __METHOD__.
'.checkReportgenEntry');
309 $sqlUpdate =
"UPDATE reportgen SET job_fk = $1 WHERE upload_fk = $2 AND filepath = $3";
310 $this->
dbManager->getSingleRow($sqlUpdate, [$job_fk, $upload_fk, $filepath],
311 __METHOD__.
'.updateReportgen');
313 $this->
dbManager->insertTableRow(
'reportgen',
314 [
'upload_fk' => $upload_fk,
'job_fk' => $job_fk,
'filepath' => $filepath],
Structure of an Agent with all required parameters.
Wrapper class for license map.
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
addScannerResults(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds, $groupId, &$licensesInDocument)
Attach finding agents to the files and return names of scanners.
updateOrInsertReportgenEntry($upload_fk, $job_fk, $filepath)
addClearingStatus(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds, $groupId)
Add clearing status to the files.
getFilesWithLicensesFromClearings(ItemTreeBounds $itemTreeBounds, $groupId, $agentObj, &$licensesInDocument)
Given an ItemTreeBounds, get the files with clearings.
static stringStartsWith($haystack, $needle)
if(! defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)
fo_dbManager * dbManager
fo_dbManager object