FOSSology  4.4.0
Open Source License Compliance by Open Source Software
FoDecisionData.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
4  SPDX-FileCopyrightText: © 2022 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
14 namespace Fossology\DecisionImporter;
15 
20 {
22  private $pfileList;
23 
25  private $uploadtreeList;
26 
28  private $clearing_decisionList;
29 
31  private $clearing_eventList;
32 
34  private $clearing_decision_eventList;
35 
37  private $license_ref_bulkList;
38 
40  private $license_set_bulkList;
41 
43  private $highlight_bulk;
44 
46  private $copyrightList;
47 
49  private $copyright_decisionList;
50 
52  private $copyright_eventList;
53 
55  private $eccList;
56 
58  private $ecc_decisionList;
59 
61  private $ecc_eventList;
62 
64  private $ipraList;
65 
67  private $ipra_decisionList;
68 
70  private $ipra_eventList;
71 
73  private $report_info;
74 
76  private $licensesList;
77 
79  private $mainLicenseList;
80 
81  private function __construct()
82  {
83  }
84 
90  public static function createFromFile(string $path): FoDecisionData
91  {
92  $decisionData = new self();
93  $data = json_decode(file_get_contents($path), true);
94  $decisionData->insertPfileList($data['pfile'])
95  ->insertUploadtreeList($data['uploadtree'])
96  ->insertClearingDecisionList($data['clearing_decision'])
97  ->insertClearingEventList($data['clearing_event'])
98  ->insertClearingDecisionEventList($data['clearing_decision_event'])
99  ->insertLicenseRefBulk($data['license_ref_bulk'])
100  ->insertLicenseSetBulk($data['license_set_bulk'])
101  ->insertHighlightBulk($data['highlight_bulk'])
102  ->insertCopyrightList($data['copyright'])
103  ->insertCopyrightDecisionList($data['copyright_decision'])
104  ->insertCopyrightEventList($data['copyright_event'])
105  ->insertEccList($data['ecc'])
106  ->insertEccDecisionList($data['ecc_decision'])
107  ->insertEccEventList($data['ecc_event'])
108  ->insertIpraList($data['ipra'])
109  ->insertIpraDecisionList($data['ipra_decision'])
110  ->insertIpraEventList($data['ipra_event'])
111  ->insertReportInfo($data['report_info'])
112  ->insertLicensesList($data['licenses'])
113  ->insertMainListList($data['upload_clearing_license']);
114  return $decisionData;
115  }
116 
121  private function insertMainListList(array $mainLicenseList): FoDecisionData
122  {
123  $this->mainLicenseList = [];
124  foreach ($mainLicenseList as $mainLicenseItem) {
125  $this->mainLicenseList[$mainLicenseItem] = [
126  "old_rfid" => $mainLicenseItem
127  ];
128  }
129  return $this;
130  }
131 
136  private function insertLicensesList(array $licensesList): FoDecisionData
137  {
138  $this->licensesList = [];
139  foreach ($licensesList as $licenseItem) {
140  $this->licensesList[$licenseItem['rf_pk']] = $licenseItem;
141  }
142  return $this;
143  }
144 
149  private function insertReportInfo(array $report_info): FoDecisionData
150  {
151  $this->report_info = $report_info;
152  return $this;
153  }
154 
159  private function insertIpraEventList(array $ipra_eventList): FoDecisionData
160  {
161  $this->ipra_eventList = [];
162  foreach ($ipra_eventList as $ipraEventItem) {
163  $this->ipra_eventList[] = $this->createEventItem($ipraEventItem, "ipra");
164  }
165  return $this;
166  }
167 
173  private function createEventItem(array $eventItemData, string $agentName): array
174  {
175  return [
176  "old_cpid" => $eventItemData[$agentName . '_fk'],
177  "old_itemid" => $eventItemData['uploadtree_fk'],
178  "content" => $eventItemData['content'],
179  "hash" => $eventItemData['hash'],
180  "is_enabled" => $eventItemData['is_enabled'],
181  "scope" => $eventItemData['scope'],
182  ];
183  }
184 
189  private function insertIpraDecisionList(array $ipra_decisionList): FoDecisionData
190  {
191  $this->ipra_decisionList = [];
192  foreach ($ipra_decisionList as $ipraDecisionItem) {
193  $this->ipra_decisionList[$ipraDecisionItem['ipra_decision_pk']] =
194  $this->createDecisionItem($ipraDecisionItem);
195  }
196  return $this;
197  }
198 
203  private function createDecisionItem(array $decisionItemData): array
204  {
205  return [
206  "old_pfile" => $decisionItemData['pfile_fk'],
207  "clearing_decision_type_fk" => $decisionItemData['clearing_decision_type_fk'],
208  "description" => $decisionItemData['description'],
209  "textfinding" => $decisionItemData['textfinding'],
210  "hash" => $decisionItemData['hash'],
211  "comment" => $decisionItemData['comment'],
212  ];
213  }
214 
219  private function insertIpraList(array $ipraList): FoDecisionData
220  {
221  $this->ipraList = [];
222  foreach ($ipraList as $ipraItem) {
223  $this->ipraList[$ipraItem['ipra_pk']] = $this->createCxItem($ipraItem);
224  }
225  return $this;
226  }
227 
232  private function createCxItem(array $cxItemData): array
233  {
234  return [
235  "old_pfile" => $cxItemData['pfile_fk'],
236  "content" => $cxItemData['content'],
237  "hash" => $cxItemData['hash'],
238  "copy_startbyte" => $cxItemData['copy_startbyte'],
239  "copy_endbyte" => $cxItemData['copy_endbyte'],
240  ];
241  }
242 
247  private function insertEccEventList(array $ecc_eventList): FoDecisionData
248  {
249  $this->ecc_eventList = [];
250  foreach ($ecc_eventList as $eccEventItem) {
251  $this->ecc_eventList[] = $this->createEventItem($eccEventItem, "ecc");
252  }
253  return $this;
254  }
255 
260  private function insertEccDecisionList(array $ecc_decisionList): FoDecisionData
261  {
262  $this->ecc_decisionList = [];
263  foreach ($ecc_decisionList as $eccDecisionItem) {
264  $this->ecc_decisionList[$eccDecisionItem['ecc_decision_pk']] = $this->createDecisionItem($eccDecisionItem);
265  }
266  return $this;
267  }
268 
273  private function insertEccList(array $eccList): FoDecisionData
274  {
275  $this->eccList = [];
276  foreach ($eccList as $eccItem) {
277  $this->eccList[$eccItem['ecc_pk']] = $this->createCxItem($eccItem);
278  }
279  return $this;
280  }
281 
286  private function insertCopyrightEventList(array $copyright_eventList): FoDecisionData
287  {
288  $this->copyright_eventList = [];
289  foreach ($copyright_eventList as $copyrightEventItem) {
290  $this->copyright_eventList[] = $this->createEventItem($copyrightEventItem, "copyright");
291  }
292  return $this;
293  }
294 
299  private function insertCopyrightDecisionList(array $copyright_decisionList): FoDecisionData
300  {
301  $this->copyright_decisionList = [];
302  foreach ($copyright_decisionList as $copyrightDecisionItem) {
303  $this->copyright_decisionList[$copyrightDecisionItem['copyright_decision_pk']] =
304  $this->createDecisionItem($copyrightDecisionItem);
305  }
306  return $this;
307  }
308 
313  private function insertCopyrightList(array $copyrightList): FoDecisionData
314  {
315  $this->copyrightList = [];
316  foreach ($copyrightList as $copyrightItem) {
317  $this->copyrightList[$copyrightItem['copyright_pk']] = $this->createCxItem($copyrightItem);
318  }
319  return $this;
320  }
321 
326  private function insertHighlightBulk(array $highlightBulkList): FoDecisionData
327  {
328  $this->highlight_bulk = [];
329  foreach ($highlightBulkList as $highlightBulkItem) {
330  $this->highlight_bulk[] = [
331  "old_ceid" => $highlightBulkItem['clearing_event_fk'],
332  "old_lrbid" => $highlightBulkItem['lrb_fk'],
333  "start" => $highlightBulkItem['start'],
334  "len" => $highlightBulkItem['len'],
335  ];
336  }
337  return $this;
338  }
339 
344  private function insertLicenseSetBulk(array $licenseSetBulkList): FoDecisionData
345  {
346  $this->license_set_bulkList = [];
347  foreach ($licenseSetBulkList as $licenseSetBulkItem) {
348  if (!array_key_exists($licenseSetBulkItem["lrb_fk"], $this->license_set_bulkList)) {
349  $this->license_set_bulkList[$licenseSetBulkItem["lrb_fk"]] = [];
350  }
351  $this->license_set_bulkList[$licenseSetBulkItem["lrb_fk"]][] = [
352  "old_rfid" => $licenseSetBulkItem['rf_fk'],
353  "removing" => $licenseSetBulkItem['removing'] == "t",
354  "comment" => $licenseSetBulkItem['comment'],
355  "reportinfo" => $licenseSetBulkItem['reportinfo'],
356  "acknowledgement" => $licenseSetBulkItem['acknowledgement'],
357  ];
358  }
359  return $this;
360  }
361 
366  private function insertLicenseRefBulk(array $licenseRefBulkList): FoDecisionData
367  {
368  $this->license_ref_bulkList = [];
369  foreach ($licenseRefBulkList as $licenseRefBulkItem) {
370  $this->license_ref_bulkList[$licenseRefBulkItem["lrb_pk"]] = [
371  "rf_text" => $licenseRefBulkItem['rf_text'],
372  "old_itemid" => $licenseRefBulkItem['uploadtree_fk'],
373  "ignore_irrelevant" => $licenseRefBulkItem['ignore_irrelevant'] == "t",
374  "bulk_delimiters" => $licenseRefBulkItem['bulk_delimiters'],
375  "scan_findings" => $licenseRefBulkItem['scan_findings'],
376  ];
377  }
378  return $this;
379  }
380 
385  private function insertClearingDecisionEventList(array $clearing_decision_eventList): FoDecisionData
386  {
387  $this->clearing_decision_eventList = [];
388  foreach ($clearing_decision_eventList as $clearingDecisionEventItem) {
389  if (!array_key_exists($clearingDecisionEventItem['clearing_decision_fk'], $this->clearing_decision_eventList)) {
390  $this->clearing_decision_eventList[$clearingDecisionEventItem['clearing_decision_fk']] = [];
391  }
392  $this->clearing_decision_eventList[$clearingDecisionEventItem['clearing_decision_fk']][] =
393  $clearingDecisionEventItem['clearing_event_fk'];
394  }
395  return $this;
396  }
397 
402  private function insertClearingEventList(array $clearing_eventList): FoDecisionData
403  {
404  $this->clearing_eventList = [];
405  foreach ($clearing_eventList as $clearingEventItem) {
406  $this->clearing_eventList[$clearingEventItem['clearing_event_pk']] = [
407  "old_itemid" => $clearingEventItem['uploadtree_fk'],
408  "old_rfid" => $clearingEventItem['rf_fk'],
409  "removed" => $clearingEventItem['removed'],
410  "old_lrbid" => $clearingEventItem['lrb_pk'],
411  "type_fk" => $clearingEventItem['type_fk'],
412  "comment" => $clearingEventItem['comment'],
413  "reportinfo" => $clearingEventItem['reportinfo'],
414  "acknowledgement" => $clearingEventItem['acknowledgement'],
415  "date_added" => $clearingEventItem['date_added'],
416  ];
417  }
418  return $this;
419  }
420 
425  private function insertClearingDecisionList(array $clearing_decisionList): FoDecisionData
426  {
427  $this->clearing_decisionList = [];
428  foreach ($clearing_decisionList as $clearingDecisionItem) {
429  $this->clearing_decisionList[$clearingDecisionItem['clearing_decision_pk']] = [
430  "old_itemid" => $clearingDecisionItem['uploadtree_fk'],
431  "old_pfile" => $clearingDecisionItem['pfile_fk'],
432  "decision_type" => $clearingDecisionItem['decision_type'],
433  "scope" => $clearingDecisionItem['scope'],
434  "date_added" => $clearingDecisionItem['date_added'],
435  ];
436  }
437  return $this;
438  }
439 
444  private function insertUploadtreeList(array $uploadtreeList): FoDecisionData
445  {
446  $this->uploadtreeList = [];
447  foreach ($uploadtreeList as $uploadTreeItem) {
448  $this->uploadtreeList[$uploadTreeItem['uploadtree_pk']] = [
449  "old_pfile" => $uploadTreeItem['pfile_fk'],
450  "lft" => $uploadTreeItem['lft'],
451  "rgt" => $uploadTreeItem['rgt'],
452  "path" => array_key_exists("path", $uploadTreeItem) ? $uploadTreeItem["path"] : ""
453  ];
454  }
455  return $this;
456  }
457 
462  private function insertPfileList(array $pfileList): FoDecisionData
463  {
464  $this->pfileList = [];
465  foreach ($pfileList as $oldId => $hash) {
466  $this->pfileList[$oldId] = ["hash" => $hash];
467  }
468  return $this;
469  }
470 
474  public function getMainLicenseList(): array
475  {
476  return $this->mainLicenseList;
477  }
478 
483  public function setMainLicenseList(array $mainLicenseList): FoDecisionData
484  {
485  $this->mainLicenseList = $mainLicenseList;
486  return $this;
487  }
488 
492  public function getHighlightBulk(): array
493  {
494  return $this->highlight_bulk;
495  }
496 
501  public function setHighlightBulk(array $highlight_bulk): FoDecisionData
502  {
503  $this->highlight_bulk = $highlight_bulk;
504  return $this;
505  }
506 
510  public function getPfileList(): array
511  {
512  return $this->pfileList;
513  }
514 
519  public function setPfileList(array $pfileList): FoDecisionData
520  {
521  $this->pfileList = $pfileList;
522  return $this;
523  }
524 
528  public function getUploadtreeList(): array
529  {
530  return $this->uploadtreeList;
531  }
532 
537  public function setUploadtreeList(array $uploadtreeList): FoDecisionData
538  {
539  $this->uploadtreeList = $uploadtreeList;
540  return $this;
541  }
542 
546  public function getClearingDecisionList(): array
547  {
548  return $this->clearing_decisionList;
549  }
550 
555  public function setClearingDecisionList(array $clearing_decisionList): FoDecisionData
556  {
557  $this->clearing_decisionList = $clearing_decisionList;
558  return $this;
559  }
560 
564  public function getClearingEventList(): array
565  {
566  return $this->clearing_eventList;
567  }
568 
573  public function setClearingEventList(array $clearing_eventList): FoDecisionData
574  {
575  $this->clearing_eventList = $clearing_eventList;
576  return $this;
577  }
578 
582  public function getClearingDecisionEventList(): array
583  {
584  return $this->clearing_decision_eventList;
585  }
586 
591  public function setClearingDecisionEventList(array $clearing_decision_eventList): FoDecisionData
592  {
593  $this->clearing_decision_eventList = $clearing_decision_eventList;
594  return $this;
595  }
596 
600  public function getLicenseRefBulkList(): array
601  {
602  return $this->license_ref_bulkList;
603  }
604 
609  public function setLicenseRefBulkList(array $license_ref_bulkList): FoDecisionData
610  {
611  $this->license_ref_bulkList = $license_ref_bulkList;
612  return $this;
613  }
614 
618  public function getLicenseSetBulkList(): array
619  {
620  return $this->license_set_bulkList;
621  }
622 
627  public function setLicenseSetBulkList(array $license_set_bulkList): FoDecisionData
628  {
629  $this->license_set_bulkList = $license_set_bulkList;
630  return $this;
631  }
632 
636  public function getCopyrightList(): array
637  {
638  return $this->copyrightList;
639  }
640 
645  public function setCopyrightList(array $copyrightList): FoDecisionData
646  {
647  $this->copyrightList = $copyrightList;
648  return $this;
649  }
650 
654  public function getCopyrightDecisionList(): array
655  {
656  return $this->copyright_decisionList;
657  }
658 
663  public function setCopyrightDecisionList(array $copyright_decisionList): FoDecisionData
664  {
665  $this->copyright_decisionList = $copyright_decisionList;
666  return $this;
667  }
668 
672  public function getCopyrightEventList(): array
673  {
674  return $this->copyright_eventList;
675  }
676 
681  public function setCopyrightEventList(array $copyright_eventList): FoDecisionData
682  {
683  $this->copyright_eventList = $copyright_eventList;
684  return $this;
685  }
686 
690  public function getEccList(): array
691  {
692  return $this->eccList;
693  }
694 
699  public function setEccList(array $eccList): FoDecisionData
700  {
701  $this->eccList = $eccList;
702  return $this;
703  }
704 
708  public function getEccDecisionList(): array
709  {
710  return $this->ecc_decisionList;
711  }
712 
717  public function setEccDecisionList(array $ecc_decisionList): FoDecisionData
718  {
719  $this->ecc_decisionList = $ecc_decisionList;
720  return $this;
721  }
722 
726  public function getEccEventList(): array
727  {
728  return $this->ecc_eventList;
729  }
730 
735  public function setEccEventList(array $ecc_eventList): FoDecisionData
736  {
737  $this->ecc_eventList = $ecc_eventList;
738  return $this;
739  }
740 
744  public function getIpraList(): array
745  {
746  return $this->ipraList;
747  }
748 
753  public function setIpraList(array $ipraList): FoDecisionData
754  {
755  $this->ipraList = $ipraList;
756  return $this;
757  }
758 
762  public function getIpraDecisionList(): array
763  {
764  return $this->ipra_decisionList;
765  }
766 
771  public function setIpraDecisionList(array $ipra_decisionList): FoDecisionData
772  {
773  $this->ipra_decisionList = $ipra_decisionList;
774  return $this;
775  }
776 
780  public function getIpraEventList(): array
781  {
782  return $this->ipra_eventList;
783  }
784 
789  public function setIpraEventList(array $ipra_eventList): FoDecisionData
790  {
791  $this->ipra_eventList = $ipra_eventList;
792  return $this;
793  }
794 
798  public function getReportInfo(): array
799  {
800  return $this->report_info;
801  }
802 
807  public function setReportInfo(array $report_info): FoDecisionData
808  {
809  $this->report_info = $report_info;
810  return $this;
811  }
812 
816  public function getLicensesList(): array
817  {
818  return $this->licensesList;
819  }
820 
825  public function setLicensesList(array $licensesList): FoDecisionData
826  {
827  $this->licensesList = $licensesList;
828  return $this;
829  }
830 }
insertEccDecisionList(array $ecc_decisionList)
createDecisionItem(array $decisionItemData)
setLicenseSetBulkList(array $license_set_bulkList)
insertIpraDecisionList(array $ipra_decisionList)
insertClearingDecisionList(array $clearing_decisionList)
setLicenseRefBulkList(array $license_ref_bulkList)
insertCopyrightEventList(array $copyright_eventList)
setClearingDecisionList(array $clearing_decisionList)
setEccDecisionList(array $ecc_decisionList)
setIpraDecisionList(array $ipra_decisionList)
setCopyrightEventList(array $copyright_eventList)
insertClearingDecisionEventList(array $clearing_decision_eventList)
insertLicenseSetBulk(array $licenseSetBulkList)
setCopyrightDecisionList(array $copyright_decisionList)
setClearingDecisionEventList(array $clearing_decision_eventList)
insertClearingEventList(array $clearing_eventList)
insertLicenseRefBulk(array $licenseRefBulkList)
createEventItem(array $eventItemData, string $agentName)
insertHighlightBulk(array $highlightBulkList)
setClearingEventList(array $clearing_eventList)
insertCopyrightDecisionList(array $copyright_decisionList)