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;
107 
108 include_once(__DIR__ . "/version.php");
109 include_once(__DIR__ . "/reportStatic.php");
110 include_once(__DIR__ . "/reportSummary.php");
111 
116 class UnifiedReport extends Agent
117 {
122 
127 
132 
133 
138 
143 
148 
153 
158 
163 
168 
173 
177  private $otherGetter;
178 
182  private $uploadDao;
183 
187  private $userDao;
188 
192  private $rowHeight = 500;
193 
197  private $tablestyle = array("borderSize" => 2,
198  "name" => "Arial",
199  "borderColor" => "000000",
200  "cellSpacing" => 5,
201  "alignment" => JcTable::START,
202  "layout" => Table::LAYOUT_FIXED
203  );
204 
208  private $subHeadingStyle = array("size" => 9,
209  "align" => "center",
210  "bold" => true
211  );
212 
216  private $licenseColumn = array("size" => "9",
217  "bold" => true
218  );
219 
223  private $licenseTextColumn = array("name" => "Courier New",
224  "size" => 9,
225  "bold" => false
226  );
227 
231  private $filePathColumn = array("size" => "9",
232  "bold" => false
233  );
234 
238  private $groupBy;
239 
240  function __construct()
241  {
242  $this->cpClearedGetter = new XpClearedGetter("copyright", "statement");
243  $this->ipraClearedGetter = new XpClearedGetter("ipra", "ipra");
244  $this->eccClearedGetter = new XpClearedGetter("ecc", "ecc");
245  $this->licenseClearedGetter = new LicenseClearedGetter();
246  $this->licenseMainGetter = new LicenseMainGetter();
247  $this->bulkMatchesGetter = new BulkMatchesGetter();
248  $this->licenseIrrelevantGetter = new LicenseIrrelevantGetter();
249  $this->licenseIrrelevantCommentGetter = new LicenseIrrelevantGetter(false);
250  $this->licenseDNUGetter = new LicenseDNUGetter();
251  $this->licenseDNUCommentGetter = new LicenseDNUGetter(false);
252  $this->licenseNonFunctionalGetter = new LicenseNonFunctionalGetter();
253  $this->licenseNonFunctionalCommentGetter = new LicenseNonFunctionalGetter(false);
254  $this->otherGetter = new OtherGetter();
255  $this->obligationsGetter = new ObligationsGetter();
256 
257  parent::__construct(REPORT_AGENT_NAME, AGENT_VERSION, AGENT_REV);
258 
259  $this->uploadDao = $this->container->get("dao.upload");
260  $this->userDao = $this->container->get("dao.user");
261  }
262 
263 
268  function processUploadId($uploadId)
269  {
272 
273  $this->heartbeat(0);
274 
275  $licenses = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, "license", false);
276  $this->heartbeat(empty($licenses) ? 0 : count($licenses["statements"]));
277 
278  $licensesMain = $this->licenseMainGetter->getCleared($uploadId, $this, $groupId, true, null, false);
279  $this->heartbeat(empty($licensesMain) ? 0 : count($licensesMain["statements"]));
280 
281  $licensesHist = $this->licenseClearedGetter->getLicenseHistogramForReport($uploadId, $groupId);
282  $this->heartbeat(empty($licensesHist) ? 0 : count($licensesHist["statements"]));
283 
284  $bulkLicenses = $this->bulkMatchesGetter->getCleared($uploadId, $this, $groupId, true, null, false);
285  $this->heartbeat(empty($bulkLicenses) ? 0 : count($bulkLicenses["statements"]));
286 
287  $this->licenseClearedGetter->setOnlyAcknowledgements(true);
288  $licenseAcknowledgements = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, "license", false);
289  $this->heartbeat(empty($licenseAcknowledgements) ? 0 : count($licenseAcknowledgements["statements"]));
290 
291  $this->licenseClearedGetter->setOnlyComments(true);
292  $licenseComments = $this->licenseClearedGetter->getCleared($uploadId, $this, $groupId, true, null, false);
293  $this->heartbeat(empty($licenseComments) ? 0 : count($licenseComments["statements"]));
294 
295  $licensesIrre = $this->licenseIrrelevantGetter->getCleared($uploadId, $this, $groupId, true, null, false);
296  $this->heartbeat(empty($licensesIrre) ? 0 : count($licensesIrre["statements"]));
297 
298  $licensesIrreComment = $this->licenseIrrelevantCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
299  $this->heartbeat(empty($licensesIrreComment) ? 0 : count($licensesIrreComment["statements"]));
300 
301  $licensesDNU = $this->licenseDNUGetter->getCleared($uploadId, $this, $groupId, true, null, false);
302  $this->heartbeat(empty($licensesDNU) ? 0 : count($licensesDNU["statements"]));
303 
304  $licensesDNUComment = $this->licenseDNUCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
305  $this->heartbeat(empty($licensesDNUComment) ? 0 : count($licensesDNUComment["statements"]));
306 
307  $licensesNonFunctional = $this->licenseNonFunctionalGetter->getCleared($uploadId, $this, $groupId, true, null, false);
308  $this->heartbeat(empty($licensesNonFunctional) ? 0 : count($licensesNonFunctional["statements"]));
309 
310  $licensesNonFunctionalComment = $this->licenseNonFunctionalCommentGetter->getCleared($uploadId, $this, $groupId, true, null, false);
311  $this->heartbeat(empty($licensesNonFunctionalComment) ? 0 : count($licensesNonFunctionalComment["statements"]));
312 
313  $copyrights = $this->cpClearedGetter->getCleared($uploadId, $this, $groupId, true, "copyright", true);
314  $this->heartbeat(empty($copyrights["scannerFindings"]) ? 0 : count($copyrights["scannerFindings"]) + count($copyrights["userFindings"]));
315 
316  $ecc = $this->eccClearedGetter->getCleared($uploadId, $this, $groupId, true, "ecc", false);
317  $this->heartbeat(empty($ecc) ? 0 : count($ecc["statements"]));
318 
319  $ipra = $this->ipraClearedGetter->getCleared($uploadId, $this, $groupId, true, "ipra", false);
320  $this->heartbeat(empty($ip) ? 0 : count($ip["statements"]));
321 
322  $otherStatement = $this->otherGetter->getReportData($uploadId);
323  $this->heartbeat(empty($otherStatement) ? 0 : count($otherStatement));
324  $otherStatement['includeDNU'] = (count($licensesDNU["statements"]) > 0) ? true : false;
325  $otherStatement['includeNonFunctional'] = (count($licensesNonFunctional["statements"]) > 0) ? true : false;
326 
327  $contents = array(
328  "licenses" => $licenses,
329  "bulkLicenses" => $bulkLicenses,
330  "licenseAcknowledgements" => $licenseAcknowledgements,
331  "licenseComments" => $licenseComments,
332  "copyrights" => $copyrights,
333  "ecc" => $ecc,
334  "ipra" => $ipra,
335  "licensesIrre" => $licensesIrre,
336  "licensesIrreComment" => $licensesIrreComment,
337  "licensesDNU" => $licensesDNU,
338  "licensesDNUComment" => $licensesDNUComment,
339  "licensesNonFunctional" => $licensesNonFunctional,
340  "licensesNonFunctionalComment" => $licensesNonFunctionalComment,
341  "licensesMain" => $licensesMain,
342  "licensesHist" => $licensesHist,
343  "otherStatement" => $otherStatement
344  );
345 
346  $this->writeReport($contents, $uploadId, $groupId, $userId);
347  return true;
348  }
349 
356  private function documentSettingsAndStyles(PhpWord &$phpWord, $timestamp, $userName)
357  {
358 
359  $topHeading = array("size" => 22,
360  "bold" => true,
361  "underline" => "single"
362  );
363 
364  $mainHeading = array("size" => 20,
365  "bold" => true,
366  "color" => "000000"
367  );
368 
369  $subHeading = array("size" => 16,
370  "italic" => true
371  );
372 
373  $subSubHeading = array("size" => 14,
374  "bold" => true
375  );
376 
377  $paragraphStyle = array("spaceAfter" => 0,
378  "spaceBefore" => 0,
379  "spacing" => 0
380  );
381 
382  $phpWord->addNumberingStyle('hNum',
383  array('type' => 'multilevel', 'levels' => array(
384  array('pStyle' => 'Heading01', 'format' => 'bullet', 'text' => ''),
385  array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%2.'),
386  array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%2.%3.'),
387  array('pStyle' => 'Heading4', 'format' => 'decimal', 'text' => '%2.%3.%4.'),
388  )
389  )
390  );
391 
392  /* Adding styles for the document*/
393  $phpWord->setDefaultFontName("Arial");
394  $phpWord->addTitleStyle(1, $topHeading, array('numStyle' => 'hNum', 'numLevel' => 0));
395  $phpWord->addTitleStyle(2, $mainHeading, array('numStyle' => 'hNum', 'numLevel' => 1));
396  $phpWord->addTitleStyle(3, $subHeading, array('numStyle' => 'hNum', 'numLevel' => 2));
397  $phpWord->addTitleStyle(4, $subSubHeading, array('numStyle' => 'hNum', 'numLevel' => 3));
398  $phpWord->addParagraphStyle("pStyle", $paragraphStyle);
399 
400  /* Setting document properties*/
401  $properties = $phpWord->getDocInfo();
402  $properties->setCreator($userName);
403  $properties->setCompany("Your Organisation");
404  $properties->setTitle("Clearing Report");
405  $properties->setDescription("OSS clearing report by Fossology tool");
406  $properties->setSubject("Copyright (C) ".date("Y", $timestamp).", Your Organisation");
407  }
408 
416  private function globalLicenseTable(Section $section, $mainLicenses, $titleSubHeading, $heading)
417  {
418  $firstColLen = 2000;
419  $secondColLen = 9500;
420  $thirdColLen = 4000;
421 
422  $section->addTitle(htmlspecialchars($heading), 2);
423  $section->addText($titleSubHeading, $this->subHeadingStyle);
424 
425  $table = $section->addTable($this->tablestyle);
426  if (!empty($mainLicenses)) {
427  foreach ($mainLicenses as $licenseMain) {
428  if ($licenseMain["risk"] == "4" || $licenseMain["risk"] == "5") {
429  $styleColumn = array("bgColor" => "F9A7B0");
430  } elseif ($licenseMain["risk"] == "2" || $licenseMain["risk"] == "3") {
431  $styleColumn = array("bgColor" => "FEFF99");
432  } else {
433  $styleColumn = array("bgColor" => "FFFFFF");
434  }
435  $table->addRow($this->rowHeight);
436  $cell1 = $table->addCell($firstColLen, $styleColumn);
437  $cell1->addText(htmlspecialchars($licenseMain["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
438  $cell2 = $table->addCell($secondColLen);
439  // replace new line character
440  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseMain["text"], ENT_DISALLOWED));
441  $licenseText = str_replace("\r", "", $licenseText);
442  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
443  if (!empty($licenseMain["files"])) {
444  $cell3 = $table->addCell($thirdColLen, $styleColumn);
445  asort($licenseMain["files"]);
446  foreach ($licenseMain["files"] as $fileName) {
447  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
448  }
449  } else {
450  $cell3 = $table->addCell($thirdColLen, $styleColumn)->addText("");
451  }
452  }
453  } else {
454  $table->addRow($this->rowHeight);
455  $table->addCell($firstColLen)->addText("");
456  $table->addCell($secondColLen)->addText("");
457  $table->addCell($thirdColLen)->addText("");
458  }
459  $section->addTextBreak();
460  }
461 
470  private function bulkLicenseTable(Section $section, $title, $licenses, $titleSubHeading)
471  {
472  $firstColLen = 2000;
473  $secondColLen = 9500;
474  $thirdColLen = 4000;
475  if (!empty($title)) {
476  $section->addTitle(htmlspecialchars($title), 2);
477  }
478  $section->addText($titleSubHeading, $this->subHeadingStyle);
479 
480  $table = $section->addTable($this->tablestyle);
481  if (!empty($licenses)) {
482  foreach ($licenses as $licenseStatement) {
483  $table->addRow($this->rowHeight);
484  $cell1 = $table->addCell($firstColLen, "pStyle");
485  $cell1->addText(htmlspecialchars($licenseStatement["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
486  $cell2 = $table->addCell($secondColLen, "pStyle");
487  // replace new line character
488  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseStatement["text"], ENT_DISALLOWED));
489  $licenseText = str_replace("\r", "", $licenseText);
490  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
491  $cell3 = $table->addCell($thirdColLen, "pStyle");
492  asort($licenseStatement["files"]);
493  foreach ($licenseStatement["files"] as $fileName) {
494  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
495  }
496  }
497  } else {
498  $table->addRow($this->rowHeight);
499  $table->addCell($firstColLen)->addText("");
500  $table->addCell($secondColLen)->addText("");
501  $table->addCell($thirdColLen)->addText("");
502  }
503  $section->addTextBreak();
504  }
505 
514  private function licensesTable(Section $section, $title, $licenses, $riskarray, $titleSubHeading)
515  {
516  $firstColLen = 2000;
517  $secondColLen = 9500;
518  $thirdColLen = 4000;
519  $emptyFlag = false;
520 
521  $section->addTitle(htmlspecialchars($title), 2);
522  $section->addText($titleSubHeading, $this->subHeadingStyle);
523 
524  $table = $section->addTable($this->tablestyle);
525  if (!empty($licenses)) {
526  foreach ($licenses as $licenseStatement) {
527  if (in_array($licenseStatement['risk'], $riskarray['riskLevel'])) {
528  $emptyFlag = true;
529  $table->addRow($this->rowHeight);
530  $cell1 = $table->addCell($firstColLen, $riskarray['color']);
531  $cell1->addText(htmlspecialchars($licenseStatement["content"], ENT_DISALLOWED), $this->licenseColumn, "pStyle");
532  $cell2 = $table->addCell($secondColLen);
533  // replace new line character
534  $licenseText = str_replace("\n", "</w:t>\n<w:br />\n<w:t xml:space=\"preserve\">", htmlspecialchars($licenseStatement["text"], ENT_DISALLOWED));
535  $licenseText = str_replace("\r", "", $licenseText);
536  $cell2->addText($licenseText, $this->licenseTextColumn, "pStyle");
537  $cell3 = $table->addCell($thirdColLen, $riskarray['color']);
538  asort($licenseStatement["files"]);
539  foreach ($licenseStatement["files"] as $fileName) {
540  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
541  }
542  } else {
543  continue;
544  }
545  }
546  }
547 
548  if (empty($emptyFlag)) {
549  $table->addRow($this->rowHeight);
550  $table->addCell($firstColLen)->addText("");
551  $table->addCell($secondColLen)->addText("");
552  $table->addCell($thirdColLen)->addText("");
553  }
554  $section->addTextBreak();
555  }
556 
565  private function getRowsAndColumnsForCEI(Section $section, $title, $statementsCEI, $titleSubHeading, $text="")
566  {
567  $smallRowHeight = 50;
568  $firstColLen = 6500;
569  $secondColLen = 5000;
570  $thirdColLen = 4000;
571  $textStyle = array("size" => 10, "bold" => true);
572 
573  $section->addTitle(htmlspecialchars($title), 2);
574  if (!empty($text)) {
575  $section->addText($text, $textStyle);
576  }
577  $section->addText($titleSubHeading, $this->subHeadingStyle);
578 
579  $table = $section->addTable($this->tablestyle);
580  if (!empty($statementsCEI)) {
581  foreach ($statementsCEI as $statements) {
582  if (!empty($statements['content'])) {
583  $table->addRow($smallRowHeight);
584  $cell1 = $table->addCell($firstColLen);
585  $text = html_entity_decode($statements['content']);
586  $cell1->addText(htmlspecialchars($text, ENT_DISALLOWED), $this->licenseTextColumn, "pStyle");
587  $cell2 = $table->addCell($secondColLen);
588  $cell2->addText(htmlspecialchars($statements['comments'], ENT_DISALLOWED), $this->licenseTextColumn, "pStyle");
589  $cell3 = $table->addCell($thirdColLen);
590  asort($statements["files"]);
591  foreach ($statements['files'] as $fileName) {
592  $cell3->addText(htmlspecialchars($fileName), $this->filePathColumn, "pStyle");
593  }
594  }
595  }
596  } else {
597  $table->addRow($this->rowHeight);
598  $table->addCell($firstColLen)->addText("");
599  $table->addCell($secondColLen)->addText("");
600  $table->addCell($thirdColLen)->addText("");
601  }
602  $section->addTextBreak();
603  }
604 
612  private function getRowsAndColumnsForIrre(Section $section, $title, $licensesIrre, $titleSubHeading)
613  {
614  $firstColLen = 5000;
615  $secondColLen = 5000;
616  $thirdColLen = 5000;
617  $rowWidth = 200;
618 
619  $section->addTitle(htmlspecialchars($title), 2);
620  $section->addText($titleSubHeading, $this->subHeadingStyle);
621 
622  $table = $section->addTable($this->tablestyle);
623  if (!empty($licensesIrre)) {
624  foreach ($licensesIrre as $statements) {
625  $table->addRow($rowWidth, "pStyle");
626  $cell1 = $table->addCell($firstColLen)->addText(htmlspecialchars($statements['content']),null, "pStyle");
627  $cell2 = $table->addCell($secondColLen)->addText(htmlspecialchars($statements['fileName']),null, "pStyle");
628  $cell3 = $table->addCell($thirdColLen);
629  asort($statements["licenses"]);
630  foreach ($statements['licenses'] as $licenseName) {
631  $cell3->addText(htmlspecialchars($licenseName), $this->filePathColumn, "pStyle");
632  }
633  }
634  } else {
635  $table->addRow($this->rowHeight);
636  $table->addCell($firstColLen, "pStyle")->addText("");
637  $table->addCell($secondColLen, "pStyle")->addText("");
638  $table->addCell($thirdColLen, "pStyle")->addText("");
639  }
640  $section->addTextBreak();
641  }
642 
650  private function licenseHistogram(Section $section, $dataHistogram, $titleSubHeading, $heading)
651  {
652  $firstColLen = 2000;
653  $secondColLen = 2000;
654  $thirdColLen = 5000;
655 
656  $section->addTitle(htmlspecialchars($heading), 2);
657  $section->addText($titleSubHeading, $this->subHeadingStyle);
658 
659  $table = $section->addTable($this->tablestyle);
660 
661  foreach ($dataHistogram as $licenseData) {
662  $table->addRow($this->rowHeight);
663  $table->addCell($firstColLen)->addText($licenseData['scannerCount'], "pStyle");
664  $table->addCell($secondColLen)->addText($licenseData['editedCount'], "pStyle");
665  $table->addCell($thirdColLen)->addText(htmlspecialchars($licenseData['licenseShortname']), "pStyle");
666  }
667  $section->addTextBreak();
668  }
669 
670 
682  private function writeReport($contents, $uploadId, $groupId, $userId)
683  {
684  global $SysConf;
685 
686  $userName = $this->userDao->getUserName($userId);
687  $groupName = $this->userDao->getGroupNameById($groupId);
688  $packageName = $this->uploadDao->getUpload($uploadId)->getFilename();
689  //replace '(',')',' ' with '_' to avoid conflict while creating report.
690  $packageName = str_replace('(','_',$packageName);
691  $packageName = str_replace(' ','_',$packageName);
692  $packageName = str_replace(')','_',$packageName);
693 
694  $parentItem = $this->uploadDao->getParentItemBounds($uploadId);
695  $docLayout = array("orientation" => "landscape",
696  "marginLeft" => "950",
697  "marginRight" => "950",
698  "marginTop" => "950",
699  "marginBottom" => "950"
700  );
701 
702  /* Creating the new DOCX */
703  $phpWord = new PhpWord();
704 
705  /* Get start time */
706  $jobInfo = $this->dbManager->getSingleRow("SELECT extract(epoch FROM jq_starttime) "
707  ." AS ts, jq_cmd_args FROM jobqueue WHERE jq_job_fk=$1", array($this->jobId));
708  $timestamp = $jobInfo['ts'];
709  $packageUri = "";
710  if (!empty($jobInfo['jq_cmd_args'])) {
711  $packageUri = trim($jobInfo['jq_cmd_args']);
712  $packageUri = preg_replace("/api\/.*/i", "", $packageUri); // Remove api/v1/report
713  $packageUri .= "?mod=showjobs&upload=" . $uploadId;
714  }
715 
716  /* Applying document properties and styling */
717  $this->documentSettingsAndStyles($phpWord, $timestamp, $userName);
718 
719  /* Creating document layout */
720  $section = $phpWord->addSection($docLayout);
721 
722  $reportSummarySection = new ReportSummary();
723  $reportStaticSection = new ReportStatic($timestamp);
724 
725  list($obligations, $whiteLists) = $this->obligationsGetter->getObligations($contents['licenses']['statements'],
726  $contents['licensesMain']['statements'], $uploadId, $groupId);
727 
728  /* Header starts */
729  $reportStaticSection->reportHeader($section);
730 
731  list($contents['licensesMain']['statements'], $contents['licenses']['statements']) = $this->licenseClearedGetter->updateIdentifiedGlobalLicenses($contents['licensesMain']['statements'], $contents['licenses']['statements']);
732 
733  /* Summery table */
734  $assignedToUserId = $this->uploadDao->getAssignee($uploadId, $groupId);
735  if ($assignedToUserId != 1) {
736  $assignedToUserName = $this->userDao->getUserName($assignedToUserId);
737  } else {
738  $assignedToUserName = "";
739  }
740  $reportSummarySection->summaryTable($section, $uploadId, $userName,
741  $contents['licensesMain']['statements'], $contents['licenses']['statements'],
742  $contents['licensesHist']['statements'], $contents['otherStatement'], $timestamp, $groupName, $packageUri, $assignedToUserName);
743 
744  if (!empty($contents['otherStatement']['ri_unifiedcolumns'])) {
745  $unifiedColumns = (array) json_decode($contents['otherStatement']['ri_unifiedcolumns'], true);
746  } else {
747  $unifiedColumns = UploadDao::UNIFIED_REPORT_HEADINGS;
748  }
749 
750  $heading = array_keys($unifiedColumns['assessment'])[0];
751  $isEnabled = array_values($unifiedColumns['assessment'])[0];
752  if ($isEnabled) {
753  /* Assessment summery table */
754  $bookMarkCell = $reportStaticSection->assessmentSummaryTable($section, $contents['otherStatement'], $heading);
755  }
756 
757  $heading = array_keys($unifiedColumns['compliancetasks'])[0];
758  $isEnabled = array_values($unifiedColumns['compliancetasks'])[0];
759  if ($isEnabled) {
760  /* Todoinfo table */
761  $reportStaticSection->todoTable($section, $heading);
762  /* Todoobligation table */
763  $reportStaticSection->todoObliTable($section, $obligations);
764  }
765 
766  $heading = array_keys($unifiedColumns['acknowledgements'])[0];
767  $isEnabled = array_values($unifiedColumns['acknowledgements'])[0];
768  if ($isEnabled) {
769  /* Display acknowledgement */
770  $titleSubHeadingAcknowledgement = "(Reference to the license, Text of acknowledgements, File path)";
771  $this->bulkLicenseTable($section, $heading, $contents['licenseAcknowledgements']['statements'], $titleSubHeadingAcknowledgement);
772  }
773 
774  $heading = array_keys($unifiedColumns['exportrestrictions'])[0];
775  $isEnabled = array_values($unifiedColumns['exportrestrictions'])[0];
776  if ($isEnabled) {
777  /* Display Ecc statements and files */
778  $titleSubHeadingCEI = "(Statements, Comments, File path)";
779  $section->addBookmark("eccInternalLink");
780  $textEcc ="The content of this paragraph is not the result of the evaluation"
781  ." of the export control experts (the ECCN). It contains information"
782  ." found by the scanner which shall be taken in consideration by"
783  ." the export control experts during the evaluation process. If"
784  ." the scanner identifies an ECCN it will be listed here. (NOTE:"
785  ." The ECCN is seen as an attribute of the component release and"
786  ." thus it shall be present in the component catalogue.";
787  $this->getRowsAndColumnsForCEI($section, $heading, $contents['ecc']['statements'], $titleSubHeadingCEI, $textEcc);
788  }
789 
790  $heading = array_keys($unifiedColumns['intellectualProperty'])[0];
791  $isEnabled = array_values($unifiedColumns['intellectualProperty'])[0];
792  if ($isEnabled) {
793  /* Display IPRA statements and files */
794  $heading = "Patent Relevant Statements";
795  $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.";
796  $this->getRowsAndColumnsForCEI($section, $heading, $contents['ipra']['statements'], $titleSubHeadingCEI, $textIpra);
797  }
798 
799  $heading = array_keys($unifiedColumns['notes'])[0];
800  $isEnabled = array_values($unifiedColumns['notes'])[0];
801  if ($isEnabled) {
802  /* Display comments entered for report */
803  $subHeading = "Notes on individual files";
804  $reportStaticSection->notes($section, $heading, $subHeading);
805  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
806  $this->bulkLicenseTable($section, "", $contents['licenseComments']['statements'], $titleSubHeadingNotes);
807  }
808 
809  $heading = array_keys($unifiedColumns['scanresults'])[0];
810  $isEnabled = array_values($unifiedColumns['scanresults'])[0];
811  if ($isEnabled) {
812  /* Display scan results and edited results */
813  $titleSubHeadingHistogram = "(Scanner count, Concluded license count, License name)";
814  $this->licenseHistogram($section, $contents['licensesHist']['statements'], $titleSubHeadingHistogram, $heading);
815  }
816 
817  $heading = array_keys($unifiedColumns['mainlicenses'])[0];
818  $isEnabled = array_values($unifiedColumns['mainlicenses'])[0];
819  if ($isEnabled) {
820  /* Display global licenses */
821  $titleSubHeadingLicense = "(License name, License text, File path)";
822  $this->globalLicenseTable($section, $contents['licensesMain']['statements'], $titleSubHeadingLicense, $heading);
823  }
824 
825  $heading = array_keys($unifiedColumns['redlicense'])[0];
826  $isEnabled = array_values($unifiedColumns['redlicense'])[0];
827  if ($isEnabled) {
828  /* Display licenses(red) name,text and files */
829  $redLicense = array("color" => array("bgColor" => "F9A7B0"), "riskLevel" => array("5", "4"));
830  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $redLicense, $titleSubHeadingLicense);
831  }
832 
833  $heading = array_keys($unifiedColumns['yellowlicense'])[0];
834  $isEnabled = array_values($unifiedColumns['yellowlicense'])[0];
835  if ($isEnabled) {
836  /* Display licenses(yellow) name,text and files */
837  $yellowLicense = array("color" => array("bgColor" => "FEFF99"), "riskLevel" => array("3", "2"));
838  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $yellowLicense, $titleSubHeadingLicense);
839  }
840 
841  $heading = array_keys($unifiedColumns['whitelicense'])[0];
842  $isEnabled = array_values($unifiedColumns['whitelicense'])[0];
843  if ($isEnabled) {
844  /* Display licenses(white) name,text and files */
845  $whiteLicense = array("color" => array("bgColor" => "FFFFFF"), "riskLevel" => array("", "0", "1"));
846  $this->licensesTable($section, $heading, $contents['licenses']['statements'], $whiteLicense, $titleSubHeadingLicense);
847  }
848 
849  $heading = array_keys($unifiedColumns['overviewwithwithoutobligations'])[0];
850  $isEnabled = array_values($unifiedColumns['overviewwithwithoutobligations'])[0];
851  if ($isEnabled) {
852  $titleSubHeadingObli = "(License ShortName, Obligation)";
853  $reportStaticSection->allLicensesWithAndWithoutObligations($section, $heading, $obligations, $whiteLists, $titleSubHeadingObli);
854  }
855 
856  $heading = array_keys($unifiedColumns['copyrights'])[0];
857  $isEnabled = array_values($unifiedColumns['copyrights'])[0];
858  if ($isEnabled) {
859  /* Display copyright statements and files */
860  $this->getRowsAndColumnsForCEI($section, $heading, $contents['copyrights']['scannerFindings'], $titleSubHeadingCEI);
861  }
862 
863  $heading = array_keys($unifiedColumns['copyrightsuf'])[0];
864  $isEnabled = array_values($unifiedColumns['copyrightsuf'])[0];
865  if ($isEnabled) {
866  /* Display user findings copyright statements and files */
867  $this->getRowsAndColumnsForCEI($section, $heading, $contents['copyrights']['userFindings'], $titleSubHeadingCEI);
868  }
869 
870  $heading = array_keys($unifiedColumns['bulkfindings'])[0];
871  $isEnabled = array_values($unifiedColumns['bulkfindings'])[0];
872  if ($isEnabled) {
873  /* Display Bulk findings name,text and files */
874  $this->bulkLicenseTable($section, $heading, $contents['bulkLicenses']['statements'], $titleSubHeadingLicense);
875  }
876 
877  $heading = array_keys($unifiedColumns['licensenf'])[0];
878  $isEnabled = array_values($unifiedColumns['licensenf'])[0];
879  if ($isEnabled) {
880  /* Display NON-Functional Licenses license files */
881  $reportStaticSection->getNonFunctionalLicenses($section, $heading);
882  }
883 
884  $heading = array_keys($unifiedColumns['irrelevantfiles'])[0];
885  $isEnabled = array_values($unifiedColumns['irrelevantfiles'])[0];
886  if ($isEnabled) {
887  /* Display irrelavant license files */
888  $titleSubHeadingIrre = "(Path, Files, Licenses)";
889  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesIrre']['statements'], $titleSubHeadingIrre);
890 
891  /* Display irrelavant file license comment */
892  $subHeading = "Comment for Irrelevant files";
893  $section->addTitle(htmlspecialchars("$subHeading"), 3);
894  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
895  $this->bulkLicenseTable($section, "", $contents['licensesIrreComment']['statements'], $titleSubHeadingNotes);
896  }
897 
898  $heading = array_keys($unifiedColumns['dnufiles'])[0];
899  $isEnabled = array_values($unifiedColumns['dnufiles'])[0];
900  if ($isEnabled) {
901  /* Display Do not use license files */
902  if ($contents['otherStatement']['includeDNU']) {
903  // adding an internal bookmark
904  $columnStyleWithUnderline = array("size" => 11, "color" => "0000A0", 'underline' => 'single');
905  $section->addBookmark('DNUBookmark');
906  $bookMarkCell->addLink('DNUBookmark', htmlspecialchars(' NOTE: DO NOT USE files found! Please check Do not use files section', ENT_COMPAT, 'UTF-8'), $columnStyleWithUnderline, "pStyle", true);
907  }
908  $titleSubHeadingIrre = "(Path, Files, Licenses)";
909  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesDNU']['statements'], $titleSubHeadingIrre);
910 
911  /* Display Do not use file license comment */
912  $subHeading = "Comment for Do not use files";
913  $section->addTitle(htmlspecialchars("$subHeading"), 3);
914  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
915  $this->bulkLicenseTable($section, "", $contents['licensesDNUComment']['statements'], $titleSubHeadingNotes);
916  }
917 
918  /* Display Non functional license files */
919  $heading = "Non functional Files";
920  if ($contents['otherStatement']['includeNonFunctional']) {
921  // adding an internal bookmark
922  $columnStyleWithUnderline = array("size" => 11, "color" => "0000A0", 'underline' => 'single');
923  $section->addBookmark('nonFunctionalBookmark');
924  $bookMarkCell->addLink('nonFunctionalBookmark', htmlspecialchars(' NOTE: Non functional files found! Please check Non functional files section', ENT_COMPAT, 'UTF-8'), $columnStyleWithUnderline, "pStyle", true);
925  }
926  $titleSubHeadingIrre = "(Path, Files, Licenses)";
927  $this->getRowsAndColumnsForIrre($section, $heading, $contents['licensesNonFunctional']['statements'], $titleSubHeadingIrre);
928 
929  /* Display Non functional file license comment */
930  $subHeading = "Comment for Non functional files";
931  $section->addTitle(htmlspecialchars("$subHeading"), 3);
932  $titleSubHeadingNotes = "(License name, Comment Entered, File path)";
933  $this->bulkLicenseTable($section, "", $contents['licensesNonFunctionalComment']['statements'], $titleSubHeadingNotes);
934 
935  $heading = array_keys($unifiedColumns['changelog'])[0];
936  $isEnabled = array_values($unifiedColumns['changelog'])[0];
937  if ($isEnabled) {
938  /* clearing protocol change log table */
939  $reportStaticSection->clearingProtocolChangeLogTable($section, $heading);
940  }
941 
942  /* Footer starts */
943  $reportStaticSection->reportFooter($phpWord, $section, $contents['otherStatement']);
944 
945  $fileBase = $SysConf["FOSSOLOGY"]["path"]."/report/";
946  if (!is_dir($fileBase)) {
947  mkdir($fileBase, 0777, true);
948  }
949  umask(0022);
950  $fileName = $fileBase. "$packageName"."_clearing_report_".date("D_M_d_m_Y_h_i_s").".docx";
951  $objWriter = IOFactory::createWriter($phpWord, "Word2007");
952  $objWriter->save($fileName);
953 
954  $this->updateReportTable($uploadId, $this->jobId, $fileName);
955  }
956 
957 
964  private function updateReportTable($uploadId, $jobId, $filename)
965  {
966  $this->dbManager->getSingleRow("INSERT INTO reportgen(upload_fk, job_fk, filepath) VALUES($1,$2,$3)",
967  array($uploadId, $jobId, $filename), __METHOD__);
968  }
969 }
970 
971 $agent = new UnifiedReport();
972 $agent->scheduler_connect();
973 $agent->run_scheduler_event_loop();
974 $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