FOSSology  4.4.0
Open Source License Compliance by Open Source Software
unifiedreport.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Shaheem Azmal, anupam.ghosh@siemens.com
4  SPDX-FileCopyrightText: © 2017-2018 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
88 define("REPORT_AGENT_NAME", "unifiedreport");
89 
102 use PhpOffice\PhpWord\Element\Section;
103 use PhpOffice\PhpWord\IOFactory;
104 use PhpOffice\PhpWord\PhpWord;
105 use PhpOffice\PhpWord\SimpleType\JcTable;
106 use PhpOffice\PhpWord\Style\Table;
108 
109 include_once(__DIR__ . "/version.php");
110 include_once(__DIR__ . "/reportStatic.php");
111 include_once(__DIR__ . "/reportSummary.php");
112 
117 class UnifiedReport extends Agent
118 {
123 
128 
133 
134 
139 
144 
149 
154 
159 
164 
169 
174 
178  private $reportutils;
179 
183  private $otherGetter;
184 
188  private $uploadDao;
189 
193  private $userDao;
194 
198  private $rowHeight = 500;
199 
203  private $tablestyle = array("borderSize" => 2,
204  "name" => "Arial",
205  "borderColor" => "000000",
206  "cellSpacing" => 5,
207  "alignment" => JcTable::START,
208  "layout" => Table::LAYOUT_FIXED
209  );
210 
214  private $subHeadingStyle = array("size" => 9,
215  "align" => "center",
216  "bold" => true
217  );
218 
222  private $licenseColumn = array("size" => "9",
223  "bold" => true
224  );
225 
229  private $licenseTextColumn = array("name" => "Courier New",
230  "size" => 9,
231  "bold" => false
232  );
233 
237  private $filePathColumn = array("size" => "9",
238  "bold" => false
239  );
240 
244  private $groupBy;
245 
246  function __construct()
247  {
248  $this->cpClearedGetter = new XpClearedGetter("copyright", "statement");
249  $this->ipraClearedGetter = new XpClearedGetter("ipra", "ipra");
250  $this->eccClearedGetter = new XpClearedGetter("ecc", "ecc");
251  $this->licenseClearedGetter = new LicenseClearedGetter();
252  $this->licenseMainGetter = new LicenseMainGetter();
253  $this->bulkMatchesGetter = new BulkMatchesGetter();
254  $this->licenseIrrelevantGetter = new LicenseIrrelevantGetter();
255  $this->licenseIrrelevantCommentGetter = new LicenseIrrelevantGetter(false);
256  $this->licenseDNUGetter = new LicenseDNUGetter();
257  $this->licenseDNUCommentGetter = new LicenseDNUGetter(false);
258  $this->licenseNonFunctionalGetter = new LicenseNonFunctionalGetter();
259  $this->licenseNonFunctionalCommentGetter = new LicenseNonFunctionalGetter(false);
260  $this->otherGetter = new OtherGetter();
261  $this->obligationsGetter = new ObligationsGetter();
262  $this->reportutils = new ReportUtils();
263 
264  parent::__construct(REPORT_AGENT_NAME, AGENT_VERSION, AGENT_REV);
265 
266  $this->uploadDao = $this->container->get("dao.upload");
267  $this->userDao = $this->container->get("dao.user");
268  }
269 
270 
275  function processUploadId($uploadId)
276  {
279 
280  $this->heartbeat(0);
281 
282  $licenses = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, "license", false);
283  $this->heartbeat(empty($licenses) ? 0 : count($licenses["statements"]));
284 
285  $licensesMain = $this->licenseMainGetter->getCleared($uploadId, $this, $groupId, true, null, false);
286  $this->heartbeat(empty($licensesMain) ? 0 : count($licensesMain["statements"]));
287 
288  $licensesHist = $this->licenseClearedGetter->getLicenseHistogramForReport($uploadId, $groupId);
289  $this->heartbeat(empty($licensesHist) ? 0 : count($licensesHist["statements"]));
290 
291  $bulkLicenses = $this->bulkMatchesGetter->getCleared($uploadId, $this, $groupId, true, null, false);
292  $this->heartbeat(empty($bulkLicenses) ? 0 : count($bulkLicenses["statements"]));
293 
294  $this->licenseClearedGetter->setOnlyAcknowledgements(true);
295  $licenseAcknowledgements = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, "license", false);
296  $this->heartbeat(empty($licenseAcknowledgements) ? 0 : count($licenseAcknowledgements["statements"]));
297 
298  $this->licenseClearedGetter->setOnlyComments(true);
299  $licenseComments = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, null, false);
300  $this->heartbeat(empty($licenseComments) ? 0 : count($licenseComments["statements"]));
301 
302  $licensesIrre = $this->licenseIrrelevantGetter->getCleared($uploadId, $this, $groupId, true, null, false);
303  $this->heartbeat(empty($licensesIrre) ? 0 : count($licensesIrre["statements"]));
304 
305  $licensesIrreComment = $this->licenseIrrelevantCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
306  $this->heartbeat(empty($licensesIrreComment) ? 0 : count($licensesIrreComment["statements"]));
307 
308  $licensesDNU = $this->licenseDNUGetter->getCleared($uploadId, $this, $groupId, true, null, false);
309  $this->heartbeat(empty($licensesDNU) ? 0 : count($licensesDNU["statements"]));
310 
311  $licensesDNUComment = $this->licenseDNUCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
312  $this->heartbeat(empty($licensesDNUComment) ? 0 : count($licensesDNUComment["statements"]));
313 
314  $licensesNonFunctional = $this->licenseNonFunctionalGetter->getCleared($uploadId, $this, $groupId, true, null, false);
315  $this->heartbeat(empty($licensesNonFunctional) ? 0 : count($licensesNonFunctional["statements"]));
316 
317  $licensesNonFunctionalComment = $this->licenseNonFunctionalCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
318  $this->heartbeat(empty($licensesNonFunctionalComment) ? 0 : count($licensesNonFunctionalComment["statements"]));
319 
320  $copyrights = $this->cpClearedGetter->getCleared($uploadId, $this, $groupId, true, "copyright", true);
321  $this->heartbeat(empty($copyrights["scannerFindings"]) ? 0 : count($copyrights["scannerFindings"]) + count($copyrights["userFindings"]));
322 
323  $ecc = $this->eccClearedGetter->getCleared($uploadId, $this, $groupId, true, "ecc", false);
324  $this->heartbeat(empty($ecc) ? 0 : count($ecc["statements"]));
325 
326  $ipra = $this->ipraClearedGetter->getCleared($uploadId, $this, $groupId, true, "ipra", false);
327  $this->heartbeat(empty($ip) ? 0 : count($ip["statements"]));
328 
329  $otherStatement = $this->otherGetter->getReportData($uploadId);
330  $this->heartbeat(empty($otherStatement) ? 0 : count($otherStatement));
331  $otherStatement['includeDNU'] = (count($licensesDNU["statements"]) > 0) ? true : false;
332  $otherStatement['includeNonFunctional'] = (count($licensesNonFunctional["statements"]) > 0) ? true : false;
333 
334  $contents = array(
335  "licenses" => $licenses,
336  "bulkLicenses" => $bulkLicenses,
337  "licenseAcknowledgements" => $licenseAcknowledgements,
338  "licenseComments" => $licenseComments,
339  "copyrights" => $copyrights,
340  "ecc" => $ecc,
341  "ipra" => $ipra,
342  "licensesIrre" => $licensesIrre,
343  "licensesIrreComment" => $licensesIrreComment,
344  "licensesDNU" => $licensesDNU,
345  "licensesDNUComment" => $licensesDNUComment,
346  "licensesNonFunctional" => $licensesNonFunctional,
347  "licensesNonFunctionalComment" => $licensesNonFunctionalComment,
348  "licensesMain" => $licensesMain,
349  "licensesHist" => $licensesHist,
350  "otherStatement" => $otherStatement
351  );
352 
353  $this->writeReport($contents, $uploadId, $groupId, $userId);
354  return true;
355  }
356 
363  private function documentSettingsAndStyles(PhpWord &$phpWord, $timestamp, $userName)
364  {
365 
366  $topHeading = array("size" => 22,
367  "bold" => true,
368  "underline" => "single"
369  );
370 
371  $mainHeading = array("size" => 20,
372  "bold" => true,
373  "color" => "000000"
374  );
375 
376  $subHeading = array("size" => 16,
377  "italic" => true
378  );
379 
380  $subSubHeading = array("size" => 14,
381  "bold" => true
382  );
383 
384  $paragraphStyle = array("spaceAfter" => 0,
385  "spaceBefore" => 0,
386  "spacing" => 0
387  );
388 
389  $phpWord->addNumberingStyle('hNum',
390  array('type' => 'multilevel', 'levels' => array(
391  array('pStyle' => 'Heading01', 'format' => 'bullet', 'text' => ''),
392  array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%2.'),
393  array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%2.%3.'),
394  array('pStyle' => 'Heading4', 'format' => 'decimal', 'text' => '%2.%3.%4.'),
395  )
396  )
397  );
398 
399  /* Adding styles for the document*/
400  $phpWord->setDefaultFontName("Arial");
401  $phpWord->addTitleStyle(1, $topHeading, array('numStyle' => 'hNum', 'numLevel' => 0));
402  $phpWord->addTitleStyle(2, $mainHeading, array('numStyle' => 'hNum', 'numLevel' => 1));
403  $phpWord->addTitleStyle(3, $subHeading, array('numStyle' => 'hNum', 'numLevel' => 2));
404  $phpWord->addTitleStyle(4, $subSubHeading, array('numStyle' => 'hNum', 'numLevel' => 3));
405  $phpWord->addParagraphStyle("pStyle", $paragraphStyle);
406 
407  /* Setting document properties*/
408  $properties = $phpWord->getDocInfo();
409  $properties->setCreator($userName);
410  $properties->setCompany("Your Organisation");
411  $properties->setTitle("Clearing Report");
412  $properties->setDescription("OSS clearing report by Fossology tool");
413  $properties->setSubject("Copyright (C) ".date("Y", $timestamp).", Your Organisation");
414  }
415 
423  private function globalLicenseTable(Section $section, $mainLicenses, $titleSubHeading, $heading)
424  {
425  $firstColLen = 2000;
426  $secondColLen = 9500;
427  $thirdColLen = 4000;
428 
429  $section->addTitle(htmlspecialchars($heading), 2);
430  $section->addText($titleSubHeading, $this->subHeadingStyle);
431 
432  $table = $section->addTable($this->tablestyle);
433  if (!empty($mainLicenses)) {
434  foreach ($mainLicenses as $licenseMain) {
435  if ($licenseMain["risk"] == "4" || $licenseMain["risk"] == "5") {
436  $styleColumn = array("bgColor" => "F9A7B0");
437  } elseif ($licenseMain["risk"] == "2" || $licenseMain["risk"] == "3") {
438  $styleColumn = array("bgColor" => "FEFF99");
439  } else {
440  $styleColumn = array("bgColor" => "FFFFFF");
441  }
442  $table->addRow($this->rowHeight);
443  $cell1 = $table->addCell($firstColLen, $styleColumn);
444  $cell1->addText(htmlspecialchars($licenseMain["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
445  $cell2 = $table->addCell($secondColLen);
446  // replace new line character
447  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseMain["text"], ENT_DISALLOWED));
448  $licenseText = str_replace("\r", "", $licenseText);
449  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
450  if (!empty($licenseMain["files"])) {
451  $cell3 = $table->addCell($thirdColLen, $styleColumn);
452  asort($licenseMain["files"]);
453  foreach ($licenseMain["files"] as $fileName) {
454  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
455  }
456  } else {
457  $cell3 = $table->addCell($thirdColLen, $styleColumn)->addText("");
458  }
459  }
460  } else {
461  $table->addRow($this->rowHeight);
462  $table->addCell($firstColLen)->addText("");
463  $table->addCell($secondColLen)->addText("");
464  $table->addCell($thirdColLen)->addText("");
465  }
466  $section->addTextBreak();
467  }
468 
477  private function bulkLicenseTable(Section $section, $title, $licenses, $titleSubHeading)
478  {
479  $firstColLen = 2000;
480  $secondColLen = 9500;
481  $thirdColLen = 4000;
482  if (!empty($title)) {
483  $section->addTitle(htmlspecialchars($title), 2);
484  }
485  $section->addText($titleSubHeading, $this->subHeadingStyle);
486 
487  $table = $section->addTable($this->tablestyle);
488  if (!empty($licenses)) {
489  foreach ($licenses as $licenseStatement) {
490  $table->addRow($this->rowHeight);
491  $cell1 = $table->addCell($firstColLen, "pStyle");
492  $cell1->addText(htmlspecialchars($licenseStatement["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
493  $cell2 = $table->addCell($secondColLen, "pStyle");
494  // replace new line character
495  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseStatement["text"], ENT_DISALLOWED));
496  $licenseText = str_replace("\r", "", $licenseText);
497  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
498  $cell3 = $table->addCell($thirdColLen, "pStyle");
499  asort($licenseStatement["files"]);
500  foreach ($licenseStatement["files"] as $fileName) {
501  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
502  }
503  }
504  } else {
505  $table->addRow($this->rowHeight);
506  $table->addCell($firstColLen)->addText("");
507  $table->addCell($secondColLen)->addText("");
508  $table->addCell($thirdColLen)->addText("");
509  }
510  $section->addTextBreak();
511  }
512 
521  private function licensesTable(Section $section, $title, $licenses, $riskarray, $titleSubHeading)
522  {
523  $firstColLen = 2000;
524  $secondColLen = 9500;
525  $thirdColLen = 4000;
526  $emptyFlag = false;
527 
528  $section->addTitle(htmlspecialchars($title), 2);
529  $section->addText($titleSubHeading, $this->subHeadingStyle);
530 
531  $table = $section->addTable($this->tablestyle);
532  if (!empty($licenses)) {
533  foreach ($licenses as $licenseStatement) {
534  if (in_array($licenseStatement['risk'], $riskarray['riskLevel'])) {
535  $emptyFlag = true;
536  $table->addRow($this->rowHeight);
537  $cell1 = $table->addCell($firstColLen, $riskarray['color']);
538  $cell1->addText(htmlspecialchars($licenseStatement["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
539  $cell2 = $table->addCell($secondColLen);
540  // replace new line character
541  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseStatement["text"], ENT_DISALLOWED));
542  $licenseText = str_replace("\r", "", $licenseText);
543  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
544  $cell3 = $table->addCell($thirdColLen, $riskarray['color']);
545  asort($licenseStatement["files"]);
546  foreach ($licenseStatement["files"] as $fileName) {
547  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
548  }
549  } else {
550  continue;
551  }
552  }
553  }
554 
555  if (empty($emptyFlag)) {
556  $table->addRow($this->rowHeight);
557  $table->addCell($firstColLen)->addText("");
558  $table->addCell($secondColLen)->addText("");
559  $table->addCell($thirdColLen)->addText("");
560  }
561  $section->addTextBreak();
562  }
563 
572  private function getRowsAndColumnsForCEI(Section $section, $title, $statementsCEI, $titleSubHeading, $text="")
573  {
574  $smallRowHeight = 50;
575  $firstColLen = 6500;
576  $secondColLen = 5000;
577  $thirdColLen = 4000;
578  $textStyle = array("size" => 10, "bold" => true);
579 
580  $section->addTitle(htmlspecialchars($title), 2);
581  if (!empty($text)) {
582  $section->addText($text, $textStyle);
583  }
584  $section->addText($titleSubHeading, $this->subHeadingStyle);
585 
586  $table = $section->addTable($this->tablestyle);
587  if (!empty($statementsCEI)) {
588  foreach ($statementsCEI as $statements) {
589  if (!empty($statements['content'])) {
590  $table->addRow($smallRowHeight);
591  $cell1 = $table->addCell($firstColLen);
592  $text = html_entity_decode($statements['content']);
593  $cell1->addText(htmlspecialchars($text, ENT_DISALLOWED), $this->licenseTextColumn, "pStyle");
594  $cell2 = $table->addCell($secondColLen);
595  $cell2->addText(htmlspecialchars($statements['comments'], ENT_DISALLOWED), $this->licenseTextColumn, "pStyle");
596  $cell3 = $table->addCell($thirdColLen);
597  asort($statements["files"]);
598  foreach ($statements['files'] as $fileName) {
599  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
600  }
601  }
602  }
603  } else {
604  $table->addRow($this->rowHeight);
605  $table->addCell($firstColLen)->addText("");
606  $table->addCell($secondColLen)->addText("");
607  $table->addCell($thirdColLen)->addText("");
608  }
609  $section->addTextBreak();
610  }
611 
619  private function getRowsAndColumnsForIrre(Section $section, $title, $licensesIrre, $titleSubHeading)
620  {
621  $firstColLen = 5000;
622  $secondColLen = 5000;
623  $thirdColLen = 5000;
624  $rowWidth = 200;
625 
626  $section->addTitle(htmlspecialchars($title), 2);
627  $section->addText($titleSubHeading, $this->subHeadingStyle);
628 
629  $table = $section->addTable($this->tablestyle);
630  if (!empty($licensesIrre)) {
631  foreach ($licensesIrre as $statements) {
632  $table->addRow($rowWidth, "pStyle");
633  $cell1 = $table->addCell($firstColLen)->addText(htmlspecialchars($statements['content']),null, "pStyle");
634  $cell2 = $table->addCell($secondColLen)->addText(htmlspecialchars($statements['fileName']),null, "pStyle");
635  $cell3 = $table->addCell($thirdColLen);
636  asort($statements["licenses"]);
637  foreach ($statements['licenses'] as $licenseName) {
638  $cell3->addText(htmlspecialchars($licenseName), $this->filePathColumn, "pStyle");
639  }
640  }
641  } else {
642  $table->addRow($this->rowHeight);
643  $table->addCell($firstColLen, "pStyle")->addText("");
644  $table->addCell($secondColLen, "pStyle")->addText("");
645  $table->addCell($thirdColLen, "pStyle")->addText("");
646  }
647  $section->addTextBreak();
648  }
649 
657  private function licenseHistogram(Section $section, $dataHistogram, $titleSubHeading, $heading)
658  {
659  $firstColLen = 2000;
660  $secondColLen = 2000;
661  $thirdColLen = 5000;
662 
663  $section->addTitle(htmlspecialchars($heading), 2);
664  $section->addText($titleSubHeading, $this->subHeadingStyle);
665 
666  $table = $section->addTable($this->tablestyle);
667 
668  foreach ($dataHistogram as $licenseData) {
669  $table->addRow($this->rowHeight);
670  $table->addCell($firstColLen)->addText($licenseData['scannerCount'], "pStyle");
671  $table->addCell($secondColLen)->addText($licenseData['editedCount'], "pStyle");
672  $table->addCell($thirdColLen)->addText(htmlspecialchars($licenseData['licenseShortname']), "pStyle");
673  }
674  $section->addTextBreak();
675  }
676 
677 
689  private function writeReport($contents, $uploadId, $groupId, $userId)
690  {
691  global $SysConf;
692 
693  $userName = $this->userDao->getUserName($userId);
694  $groupName = $this->userDao->getGroupNameById($groupId);
695  $packageName = $this->uploadDao->getUpload($uploadId)->getFilename();
696  //replace '(',')',' ' with '_' to avoid conflict while creating report.
697  $packageName = str_replace('(','_',$packageName);
698  $packageName = str_replace(' ','_',$packageName);
699  $packageName = str_replace(')','_',$packageName);
700 
701  $parentItem = $this->uploadDao->getParentItemBounds($uploadId);
702  $docLayout = array("orientation" => "landscape",
703  "marginLeft" => "950",
704  "marginRight" => "950",
705  "marginTop" => "950",
706  "marginBottom" => "950"
707  );
708 
709  /* Creating the new DOCX */
710  $phpWord = new PhpWord();
711 
712  /* Get start time */
713  $jobInfo = $this->dbManager->getSingleRow("SELECT extract(epoch FROM jq_starttime) "
714  ." AS ts, jq_cmd_args FROM jobqueue WHERE jq_job_fk=$1", array($this->jobId));
715  $timestamp = $jobInfo['ts'];
716  $packageUri = "";
717  if (!empty($jobInfo['jq_cmd_args'])) {
718  $packageUri = trim($jobInfo['jq_cmd_args']);
719  $packageUri = preg_replace("/api\/.*/i", "", $packageUri); // Remove api/v1/report
720  $packageUri .= "?mod=showjobs&upload=" . $uploadId;
721  }
722 
723  /* Applying document properties and styling */
724  $this->documentSettingsAndStyles($phpWord, $timestamp, $userName);
725 
726  /* Creating document layout */
727  $section = $phpWord->addSection($docLayout);
728 
729  $reportSummarySection = new ReportSummary();
730  $reportStaticSection = new ReportStatic($timestamp);
731 
732  list($obligations, $whiteLists) = $this->obligationsGetter->getObligations($contents['licenses']['statements'],
733  $contents['licensesMain']['statements'], $uploadId, $groupId);
734 
735  /* Header starts */
736  $reportStaticSection->reportHeader($section);
737 
738  list($contents['licensesMain']['statements'], $contents['licenses']['statements']) = $this->licenseClearedGetter->updateIdentifiedGlobalLicenses($contents['licensesMain']['statements'], $contents['licenses']['statements']);
739 
740  /* Summery table */
741  $assignedToUserId = $this->uploadDao->getAssignee($uploadId, $groupId);
742  if ($assignedToUserId != 1) {
743  $assignedToUserName = $this->userDao->getUserName($assignedToUserId);
744  } else {
745  $assignedToUserName = "";
746  }
747  $reportSummarySection->summaryTable($section, $uploadId, $userName,
748  $contents['licensesMain']['statements'], $contents['licenses']['statements'],
749  $contents['licensesHist']['statements'], $contents['otherStatement'], $timestamp, $groupName, $packageUri, $assignedToUserName);
750 
751  if (!empty($contents['otherStatement']['ri_unifiedcolumns'])) {
752  $unifiedColumns = (array) json_decode($contents['otherStatement']['ri_unifiedcolumns'], true);
753  } else {
754  $unifiedColumns = UploadDao::UNIFIED_REPORT_HEADINGS;
755  }
756 
757  $heading = array_keys($unifiedColumns['assessment'])[0];
758  $isEnabled = array_values($unifiedColumns['assessment'])[0];
759  if ($isEnabled) {
760  /* Assessment summery table */
761  $bookMarkCell = $reportStaticSection->assessmentSummaryTable($section, $contents['otherStatement'], $heading);
762  }
763 
764  $heading = array_keys($unifiedColumns['compliancetasks'])[0];
765  $isEnabled = array_values($unifiedColumns['compliancetasks'])[0];
766  if ($isEnabled) {
767  /* Todoinfo table */
768  $reportStaticSection->todoTable($section, $heading);
769  /* Todoobligation table */
770  $reportStaticSection->todoObliTable($section, $obligations);
771  }
772 
773  $heading = array_keys($unifiedColumns['acknowledgements'])[0];
774  $isEnabled = array_values($unifiedColumns['acknowledgements'])[0];
775  if ($isEnabled) {
776  /* Display acknowledgement */
777  $titleSubHeadingAcknowledgement = "(Reference to the license, Text of acknowledgements, File path)";
778  $this->bulkLicenseTable($section, $heading, $contents['licenseAcknowledgements']['statements'], $titleSubHeadingAcknowledgement);
779  }
780 
781  $heading = array_keys($unifiedColumns['exportrestrictions'])[0];
782  $isEnabled = array_values($unifiedColumns['exportrestrictions'])[0];
783  if ($isEnabled) {
784  /* Display Ecc statements and files */
785  $titleSubHeadingCEI = "(Statements, Comments, File path)";
786  $section->addBookmark("eccInternalLink");
787  $textEcc ="The content of this paragraph is not the result of the evaluation"
788  ." of the export control experts (the ECCN). It contains information"
789  ." found by the scanner which shall be taken in consideration by"
790  ." the export control experts during the evaluation process. If"
791  ." the scanner identifies an ECCN it will be listed here. (NOTE:"
792  ." The ECCN is seen as an attribute of the component release and"
793  ." thus it shall be present in the component catalogue.";
794  $this->getRowsAndColumnsForCEI($section, $heading, $contents['ecc']['statements'], $titleSubHeadingCEI, $textEcc);
795  }
796 
797  $heading = array_keys($unifiedColumns['intellectualProperty'])[0];
798  $isEnabled = array_values($unifiedColumns['intellectualProperty'])[0];
799  if ($isEnabled) {
800  /* Display IPRA statements and files */
801  $heading = "Patent Relevant Statements";
802  $textIpra = "The content of this paragraph is not the result of the evaluation of the IP professionals. It contains information found by the scanner which shall be taken in consideration by the IP professionals during the evaluation process.";
803  $this->getRowsAndColumnsForCEI($section, $heading, $contents['ipra']['statements'], $titleSubHeadingCEI, $textIpra);
804  }
805 
806  $heading = array_keys($unifiedColumns['notes'])[0];
807  $isEnabled = array_values($unifiedColumns['notes'])[0];
808  if ($isEnabled) {
809  /* Display comments entered for report */
810  $subHeading = "Notes on individual files";
811  $reportStaticSection->notes($section, $heading, $subHeading);
812  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
813  $this->bulkLicenseTable($section, "", $contents['licenseComments']['statements'], $titleSubHeadingNotes);
814  }
815 
816  $heading = array_keys($unifiedColumns['scanresults'])[0];
817  $isEnabled = array_values($unifiedColumns['scanresults'])[0];
818  if ($isEnabled) {
819  /* Display scan results and edited results */
820  $titleSubHeadingHistogram = "(Scanner count, Concluded license count, License name)";
821  $this->licenseHistogram($section, $contents['licensesHist']['statements'], $titleSubHeadingHistogram, $heading);
822  }
823 
824  $heading = array_keys($unifiedColumns['mainlicenses'])[0];
825  $isEnabled = array_values($unifiedColumns['mainlicenses'])[0];
826  if ($isEnabled) {
827  /* Display global licenses */
828  $titleSubHeadingLicense = "(License name, License text, File path)";
829  $this->globalLicenseTable($section, $contents['licensesMain']['statements'], $titleSubHeadingLicense, $heading);
830  }
831 
832  $heading = array_keys($unifiedColumns['redlicense'])[0];
833  $isEnabled = array_values($unifiedColumns['redlicense'])[0];
834  if ($isEnabled) {
835  /* Display licenses(red) name,text and files */
836  $redLicense = array("color" => array("bgColor" => "F9A7B0"), "riskLevel" => array("5", "4"));
837  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $redLicense, $titleSubHeadingLicense);
838  }
839 
840  $heading = array_keys($unifiedColumns['yellowlicense'])[0];
841  $isEnabled = array_values($unifiedColumns['yellowlicense'])[0];
842  if ($isEnabled) {
843  /* Display licenses(yellow) name,text and files */
844  $yellowLicense = array("color" => array("bgColor" => "FEFF99"), "riskLevel" => array("3", "2"));
845  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $yellowLicense, $titleSubHeadingLicense);
846  }
847 
848  $heading = array_keys($unifiedColumns['whitelicense'])[0];
849  $isEnabled = array_values($unifiedColumns['whitelicense'])[0];
850  if ($isEnabled) {
851  /* Display licenses(white) name,text and files */
852  $whiteLicense = array("color" => array("bgColor" => "FFFFFF"), "riskLevel" => array("", "0", "1"));
853  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $whiteLicense, $titleSubHeadingLicense);
854  }
855 
856  $heading = array_keys($unifiedColumns['overviewwithwithoutobligations'])[0];
857  $isEnabled = array_values($unifiedColumns['overviewwithwithoutobligations'])[0];
858  if ($isEnabled) {
859  $titleSubHeadingObli = "(License ShortName, Obligation)";
860  $reportStaticSection->allLicensesWithAndWithoutObligations($section, $heading, $obligations, $whiteLists, $titleSubHeadingObli);
861  }
862 
863  $heading = array_keys($unifiedColumns['copyrights'])[0];
864  $isEnabled = array_values($unifiedColumns['copyrights'])[0];
865  if ($isEnabled) {
866  /* Display copyright statements and files */
867  $this->getRowsAndColumnsForCEI($section, $heading, $contents['copyrights']['scannerFindings'], $titleSubHeadingCEI);
868  }
869 
870  $heading = array_keys($unifiedColumns['copyrightsuf'])[0];
871  $isEnabled = array_values($unifiedColumns['copyrightsuf'])[0];
872  if ($isEnabled) {
873  /* Display user findings copyright statements and files */
874  $this->getRowsAndColumnsForCEI($section, $heading, $contents['copyrights']['userFindings'], $titleSubHeadingCEI);
875  }
876 
877  $heading = array_keys($unifiedColumns['bulkfindings'])[0];
878  $isEnabled = array_values($unifiedColumns['bulkfindings'])[0];
879  if ($isEnabled) {
880  /* Display Bulk findings name,text and files */
881  $this->bulkLicenseTable($section, $heading, $contents['bulkLicenses']['statements'], $titleSubHeadingLicense);
882  }
883 
884  $heading = array_keys($unifiedColumns['licensenf'])[0];
885  $isEnabled = array_values($unifiedColumns['licensenf'])[0];
886  if ($isEnabled) {
887  /* Display NON-Functional Licenses license files */
888  $reportStaticSection->getNonFunctionalLicenses($section, $heading);
889  }
890 
891  $heading = array_keys($unifiedColumns['irrelevantfiles'])[0];
892  $isEnabled = array_values($unifiedColumns['irrelevantfiles'])[0];
893  if ($isEnabled) {
894  /* Display irrelavant license files */
895  $titleSubHeadingIrre = "(Path, Files, Licenses)";
896  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesIrre']['statements'], $titleSubHeadingIrre);
897 
898  /* Display irrelavant file license comment */
899  $subHeading = "Comment for Irrelevant files";
900  $section->addTitle(htmlspecialchars("$subHeading"), 3);
901  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
902  $this->bulkLicenseTable($section, "", $contents['licensesIrreComment']['statements'], $titleSubHeadingNotes);
903  }
904 
905  $heading = array_keys($unifiedColumns['dnufiles'])[0];
906  $isEnabled = array_values($unifiedColumns['dnufiles'])[0];
907  if ($isEnabled) {
908  /* Display Do not use license files */
909  if ($contents['otherStatement']['includeDNU']) {
910  // adding an internal bookmark
911  $columnStyleWithUnderline = array("size" => 11, "color" => "0000A0", 'underline' => 'single');
912  $section->addBookmark('DNUBookmark');
913  $bookMarkCell->addLink('DNUBookmark', htmlspecialchars(' NOTE: DO NOT USE files found! Please check Do not use files section', ENT_COMPAT, 'UTF-8'), $columnStyleWithUnderline, "pStyle", true);
914  }
915  $titleSubHeadingIrre = "(Path, Files, Licenses)";
916  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesDNU']['statements'], $titleSubHeadingIrre);
917 
918  /* Display Do not use file license comment */
919  $subHeading = "Comment for Do not use files";
920  $section->addTitle(htmlspecialchars("$subHeading"), 3);
921  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
922  $this->bulkLicenseTable($section, "", $contents['licensesDNUComment']['statements'], $titleSubHeadingNotes);
923  }
924 
925  /* Display Non functional license files */
926  $heading = "Non functional Files";
927  if ($contents['otherStatement']['includeNonFunctional']) {
928  // adding an internal bookmark
929  $columnStyleWithUnderline = array("size" => 11, "color" => "0000A0", 'underline' => 'single');
930  $section->addBookmark('nonFunctionalBookmark');
931  $bookMarkCell->addLink('nonFunctionalBookmark', htmlspecialchars(' NOTE: Non functional files found! Please check Non functional files section', ENT_COMPAT, 'UTF-8'), $columnStyleWithUnderline, "pStyle", true);
932  }
933  $titleSubHeadingIrre = "(Path, Files, Licenses)";
934  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesNonFunctional']['statements'], $titleSubHeadingIrre);
935 
936  /* Display Non functional file license comment */
937  $subHeading = "Comment for Non functional files";
938  $section->addTitle(htmlspecialchars("$subHeading"), 3);
939  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
940  $this->bulkLicenseTable($section, "", $contents['licensesNonFunctionalComment']['statements'], $titleSubHeadingNotes);
941 
942  $heading = array_keys($unifiedColumns['changelog'])[0];
943  $isEnabled = array_values($unifiedColumns['changelog'])[0];
944  if ($isEnabled) {
945  /* clearing protocol change log table */
946  $reportStaticSection->clearingProtocolChangeLogTable($section, $heading);
947  }
948 
949  /* Footer starts */
950  $reportStaticSection->reportFooter($phpWord, $section, $contents['otherStatement']);
951 
952  $fileBase = $SysConf["FOSSOLOGY"]["path"]."/report/";
953  if (!is_dir($fileBase)) {
954  mkdir($fileBase, 0777, true);
955  }
956  umask(0022);
957  $fileName = $fileBase. "Clearing_Report_".$packageName.".docx";
958  $objWriter = IOFactory::createWriter($phpWord, "Word2007");
959  $objWriter->save($fileName);
960 
961  $this->updateReportTable($uploadId, $this->jobId, $fileName);
962  }
963 
964 
971  private function updateReportTable($uploadId, $jobId, $filename)
972  {
973  $this->reportutils->updateOrInsertReportgenEntry($uploadId, $jobId, $filename);
974  }
975 }
976 
977 $agent = new UnifiedReport();
978 $agent->scheduler_connect();
979 $agent->run_scheduler_event_loop();
980 $agent->scheduler_disconnect(0);
Structure of an Agent with all required parameters.
Definition: Agent.php:41
heartbeat($newProcessed)
Send hear beat to the scheduler.
Definition: Agent.php:203
Handles static part of report.
Handles report summary.
Generates unified report.
globalLicenseTable(Section $section, $mainLicenses, $titleSubHeading, $heading)
Generate global license table.
documentSettingsAndStyles(PhpWord &$phpWord, $timestamp, $userName)
Setting default heading styles and paragraph styles.
licensesTable(Section $section, $title, $licenses, $riskarray, $titleSubHeading)
This function lists out the red, white & yellow licenses.
getRowsAndColumnsForIrre(Section $section, $title, $licensesIrre, $titleSubHeading)
Irrelevant files in report.
bulkLicenseTable(Section $section, $title, $licenses, $titleSubHeading)
This function lists out the bulk licenses, comments of identified licenses.
licenseHistogram(Section $section, $dataHistogram, $titleSubHeading, $heading)
License histogram into report.
writeReport($contents, $uploadId, $groupId, $userId)
Writes the report to a file.
processUploadId($uploadId)
Given an upload ID, process the items in it.
updateReportTable($uploadId, $jobId, $filename)
Update database with generated report path.
getRowsAndColumnsForCEI(Section $section, $title, $statementsCEI, $titleSubHeading, $text="")
Copyright or ecc table.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
int jobId
The id of the job.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
const REPORT_AGENT_NAME