14 namespace Fossology\DecisionImporter;
23 use UnexpectedValueException;
25 require_once
"FoDecisionData.php";
143 foreach ($clearingDecisionList as $oldDecisionId => $decisionItem) {
144 if ($decisionItem[
"new_itemid"] !==
null) {
145 $newCdId = $this->
dbManager->insertTableRow(
"clearing_decision", [
146 "uploadtree_fk" => $decisionItem[
"new_itemid"],
147 "pfile_fk" => $decisionItem[
"new_pfile"],
148 "decision_type" => $decisionItem[
"decision_type"],
149 "group_fk" => $this->groupId,
150 "user_fk" => $this->userId,
151 "scope" => $decisionItem[
"scope"],
152 "date_added" => $decisionItem[
"date_added"]
153 ], __METHOD__ .
".insertCd",
"clearing_decision_pk");
157 $clearingDecisionList[$oldDecisionId][
"new_decision"] = $newCdId;
169 foreach ($clearingEventList as $oldEventId => $eventItem) {
170 if ($eventItem[
"new_itemid"] !==
null) {
171 $newCeId = $this->
dbManager->insertTableRow(
"clearing_event", [
172 "uploadtree_fk" => $eventItem[
"new_itemid"],
173 "rf_fk" => $eventItem[
"new_rfid"],
174 "removed" => $eventItem[
"removed"],
175 "user_fk" => $this->userId,
176 "group_fk" => $this->groupId,
178 "type_fk" => $eventItem[
"type_fk"],
179 "comment" => $eventItem[
"comment"],
180 "reportinfo" => $eventItem[
"reportinfo"],
181 "acknowledgement" => $eventItem[
"acknowledgement"],
182 "date_added" => $eventItem[
"date_added"]
183 ], __METHOD__ .
".insertCe",
"clearing_event_pk");
187 $clearingEventList[$oldEventId][
"new_event"] = $newCeId;
198 foreach ($clearingDecisionEventList as $oldCdId => $ceList) {
199 $newCdId = $clearingDecisionList[$oldCdId][
"new_decision"];
200 if ($newCdId ===
null) {
203 foreach ($ceList as $oldCeId) {
204 $newCeId = $clearingEventList[$oldCeId][
"new_event"];
205 if ($newCeId ===
null) {
208 $this->
dbManager->insertTableRow(
"clearing_decision_event", [
209 "clearing_decision_fk" => $newCdId,
210 "clearing_event_fk" => $newCeId
211 ], __METHOD__ .
".insertCdCe");
217 ->setClearingEventList($clearingEventList);
230 "ri_ga_checkbox_selection" => $reportInfo[
"ri_ga_checkbox_selection"],
231 "ri_spdx_selection" => $reportInfo[
"ri_spdx_selection"],
232 "ri_excluded_obligations" => $reportInfo[
"ri_excluded_obligations"],
233 "ri_reviewed" => $reportInfo[
"ri_reviewed"],
234 "ri_footer" => $reportInfo[
"ri_footer"],
235 "ri_report_rel" => $reportInfo[
"ri_report_rel"],
236 "ri_community" => $reportInfo[
"ri_community"],
237 "ri_component" => $reportInfo[
"ri_component"],
238 "ri_version" => $reportInfo[
"ri_version"],
239 "ri_release_date" => $reportInfo[
"ri_release_date"],
240 "ri_sw360_link" => $reportInfo[
"ri_sw360_link"],
241 "ri_general_assesment" => $reportInfo[
"ri_general_assesment"],
242 "ri_ga_additional" => $reportInfo[
"ri_ga_additional"],
243 "ri_ga_risk" => $reportInfo[
"ri_ga_risk"],
244 "ri_department" => $reportInfo[
"ri_department"],
245 "ri_depnotes" => $reportInfo[
"ri_depnotes"],
246 "ri_exportnotes" => $reportInfo[
"ri_exportnotes"],
247 "ri_copyrightnotes" => $reportInfo[
"ri_copyrightnotes"],
248 "ri_unifiedcolumns" => $reportInfo[
"ri_unifiedcolumns"],
249 "ri_globaldecision" => $reportInfo[
"ri_globaldecision"],
250 "ri_component_id" => $reportInfo[
"ri_component_id"],
251 "ri_component_type" => $reportInfo[
"ri_component_type"]
253 $existsSql =
"SELECT ri_pk FROM report_info WHERE upload_fk = $1;";
254 $existsStatement = __METHOD__ .
".reportInfoExists";
256 if ($this->
dbManager->getSingleRow($existsSql, [$this->uploadId], $existsStatement)) {
257 $this->
dbManager->updateTableRow(
"report_info", $assocParams,
"upload_fk", $this->uploadId,
258 __METHOD__ .
".updateReportInfo");
260 $this->
dbManager->insertTableRow(
"report_info", $assocParams, __METHOD__ .
".insertReportInfo");
277 string $agentName,
int $jobId): void
280 if ($agentName ==
"copyright") {
283 $capitalizedAgentName =
strtoupper(substr($agentName, 0, 1)) . substr($agentName, 1);
284 $cxListMethod =
"get" . $capitalizedAgentName .
"List";
285 $decisionListMethod =
"get" . $capitalizedAgentName .
"DecisionList";
286 $eventListMethod =
"get" . $capitalizedAgentName .
"EventList";
287 $cxList = $reportData->$cxListMethod();
288 $decisionList = $reportData->$decisionListMethod();
289 $eventList = $reportData->$eventListMethod();
291 if (!$cxList and !$decisionList and !$eventList) {
296 if (!$this->agentDao->arsTableExists($agentName)) {
298 throw new UnexpectedValueException(
"No agent '$agentName' exists on server.");
300 $latestAgentId = $this->agentDao->getCurrentAgentId($agentName);
301 $this->
createCxJobs($agentName, $jobId, $latestAgentId);
302 $cxExistSql =
"SELECT " . $agentName .
"_pk FROM $agentName WHERE pfile_fk = $1 AND agent_fk = $2 AND hash = $3;";
303 $cxExistStatement = __METHOD__ .
".$agentName" .
"Exist";
305 $ceExistSql =
"SELECT " . $agentName .
"_event_pk FROM " . $agentName .
306 "_event WHERE uploadtree_fk = $1 AND hash = $2 AND is_enabled = $3;";
307 $ceExistStatement = __METHOD__ .
".$agentName" .
"EventExist";
310 foreach ($cxList as $oldId => $cItem) {
311 $newCp = $this->
dbManager->getSingleRow($cxExistSql, [
315 ], $cxExistStatement);
316 if (empty($newCp) && !empty($cItem[
"new_pfile"]) && !empty($cItem[
"hash"])) {
317 $newCp = $this->
dbManager->insertTableRow($agentName, [
318 "agent_fk" => $latestAgentId,
319 "pfile_fk" => $cItem[
"new_pfile"],
320 "content" => $cItem[
"content"],
322 "hash" => $cItem[
"hash"],
323 "copy_startbyte" => $cItem[
"copy_startbyte"],
324 "copy_endbyte" => $cItem[
"copy_endbyte"]
325 ], __METHOD__ .
".insertCp." . $agentName, $agentName .
"_pk");
327 $newCp = $newCp[$agentName .
"_pk"];
329 $cxList[$oldId][
"new_id"] = $newCp;
341 foreach ($decisionList as $oldId => $decisionItem) {
342 $newDecision = $this->copyrightDao->saveDecision($agentName .
"_decision", $decisionItem[
'new_pfile'],
343 $this->userId, $decisionItem[
'clearing_decision_type_fk'], $decisionItem[
'description'],
344 $decisionItem[
'textfinding'], $decisionItem[
'comment']);
345 $decisionList[$oldId][
"new_id"] = $newDecision;
357 foreach ($eventList as $eventItem) {
358 if ($eventItem[
"new_itemid"] ==
null) {
359 echo
"ItemId of event hash " . $eventItem[
"hash"] .
" is NULL\n";
362 $ceId = $this->
dbManager->getSingleRow($ceExistSql, [
363 $eventItem[
"new_itemid"],
365 $eventItem[
"is_enabled"]
366 ], $ceExistStatement);
368 $this->
dbManager->insertTableRow($agentName .
"_event", [
369 "upload_fk" => $this->uploadId,
370 "uploadtree_fk" => $eventItem[
"new_itemid"],
371 $agentName .
"_fk" => $cxList[$eventItem[
"old_cpid"]][
"new_id"],
372 "content" => $eventItem[
"content"],
373 "hash" => $eventItem[
"hash"],
374 "is_enabled" => $eventItem[
"is_enabled"],
375 "scope" => $eventItem[
"scope"]
376 ], __METHOD__ .
".insertCe." . $agentName);
388 $cxListMethod =
"set" . $capitalizedAgentName .
"List";
389 $reportData->$cxListMethod($cxList);
400 private function createCxJobs(
string $agentName,
int $currentJobId,
int $agentId): void
402 $scanJobProxy =
new ScanJobProxy($this->agentDao, $this->uploadId);
403 $scanJobProxy->createAgentStatus(array($agentName));
404 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
405 if (!empty($selectedScanners)) {
408 $markJobCompletedSql =
"UPDATE jobqueue SET jq_end_bits = 1, jq_endtext = 'Completed', jq_endtime = NOW(), " .
409 "jq_starttime = NOW() WHERE jq_pk = $1;";
410 $markJobCompletedStatement = __METHOD__ .
".markComplete";
412 $jqId =
JobQueueAdd($currentJobId, $agentName, $this->uploadId,
"no", NULL);
413 $this->
dbManager->getSingleRow($markJobCompletedSql, [$jqId], $markJobCompletedStatement);
415 $arsId = $this->agentDao->writeArsRecord($agentName, $agentId, $this->uploadId);
416 $this->agentDao->writeArsRecord($agentName, $agentId, $this->uploadId, $arsId,
true);
439 $parentItem = $this->uploadDao->getUploadParent($this->uploadId);
442 foreach ($licenseRefBulkList as $oldId => $licenseRefBulkItem) {
444 if (empty($oldEventId)) {
445 echo
"No clearing event for old LRB: $oldId\n";
448 $licenseRemovals = [];
449 foreach ($licenseSetBulkList[$oldId] as $licenseSetItem) {
450 $licenseRemovals[$licenseSetItem[
"new_rfid"]] = [
451 $licenseSetItem[
"removing"],
452 $licenseSetItem[
"comment"],
453 $licenseSetItem[
"reportinfo"],
454 $licenseSetItem[
"acknowledgement"],
458 $newLrbId = $this->licenseDao->insertBulkLicense($this->userId, $this->groupId, $parentItem, $licenseRemovals,
459 $licenseRefBulkItem[
"rf_text"], $licenseRefBulkItem[
"ignore_irrelevant"],
460 $licenseRefBulkItem[
"bulk_delimiters"], $licenseRefBulkItem[
"scan_findings"]);
461 $licenseRefBulkList[$oldId][
"new_lrbid"] = $newLrbId;
463 $clearingEventList[$oldEventId][
"new_lrbid"] = $newLrbId;
464 $clearingEventList[$oldEventId][
"job_fk"] = $jobId;
476 foreach ($clearingEventList as $clearingEventItem) {
477 if (array_key_exists(
"job_fk", $clearingEventItem)) {
479 "job_fk" => $clearingEventItem[
"job_fk"]
481 $this->
dbManager->updateTableRow(
"clearing_event", $assocParams,
"clearing_event_pk",
482 $clearingEventItem[
"new_event"], __METHOD__ .
".updateCeJob");
495 foreach ($highlightBulkList as $highlightBulkItem) {
497 "clearing_event_fk" => $clearingEventList[$highlightBulkItem[
"old_ceid"]][
"new_event"],
498 "lrb_fk" => $licenseRefBulkList[$highlightBulkItem[
"old_lrbid"]][
"new_lrbid"],
499 "start" => $highlightBulkItem[
"start"],
500 "len" => $highlightBulkItem[
"len"]
502 $this->
dbManager->insertTableRow(
"highlight_bulk", $assocParams, __METHOD__ .
".insertHighlightBulk");
511 ->setClearingEventList($clearingEventList);
522 foreach ($clearingEventList as $index => $clearingEventId) {
523 if ($clearingEventId[
"old_lrbid"] == $oldLrbId) {
538 $markJobCompletedSql =
"UPDATE jobqueue SET jq_end_bits = 1, jq_endtext = 'Completed', jq_endtime = NOW(), " .
539 "jq_starttime = NOW() WHERE jq_pk = $1;";
540 $markJobCompletedStatement = __METHOD__ .
".markComplete";
542 $upload = $this->uploadDao->getUpload($this->uploadId);
543 $uploadName = $upload->getFilename();
544 $latestDeciderAgentId = $this->agentDao->getCurrentAgentId(
"deciderjob");
545 $latestMonkBulkAgentId = $this->agentDao->getCurrentAgentId(
"monkbulk");
546 $jobId = JobAddJob($this->userId, $this->groupId, $uploadName, $this->uploadId);
548 $monkbulkJobId =
JobQueueAdd($jobId,
"monkbulk", $bulkId,
"no",
null);
549 $deciderJobId =
JobQueueAdd($jobId,
"deciderjob", $this->uploadId,
"no", [$monkbulkJobId]);
551 $monkbulkArsId = $this->agentDao->writeArsRecord(
"monkbulk", $latestMonkBulkAgentId, $this->uploadId);
552 $this->agentDao->writeArsRecord(
"monkbulk", $latestDeciderAgentId, $this->uploadId, $monkbulkArsId,
true);
553 $this->
dbManager->getSingleRow($markJobCompletedSql, [$monkbulkJobId], $markJobCompletedStatement);
555 $deciderArsId = $this->agentDao->writeArsRecord(
"deciderjob", $latestDeciderAgentId, $this->uploadId);
556 $this->agentDao->writeArsRecord(
"deciderjob", $latestDeciderAgentId, $this->uploadId, $deciderArsId,
true);
557 $this->
dbManager->getSingleRow($markJobCompletedSql, [$deciderJobId], $markJobCompletedStatement);
571 foreach ($mainLicenseList as $mainLicenseItem) {
572 $this->clearingDao->makeMainLicense(
$uploadId,
$groupId, $mainLicenseItem[
"new_rfid"]);
Import decisions generated by Decision Exporter from JSON files.
createMonkBulkJobs(int $bulkId)
setUploadId(int $uploadId)
createClearingDecisions(FoDecisionData &$reportData, DecisionImporterAgent &$agentObj)
createMainLicenses(FoDecisionData &$reportData, int $uploadId, int $groupId)
getClearingEventForLrb(array $clearingEventList, int $oldLrbId)
createCxJobs(string $agentName, int $currentJobId, int $agentId)
createReportData(FoDecisionData &$reportData)
createCopyrightData(FoDecisionData &$reportData, DecisionImporterAgent &$agentObj, string $agentName, int $jobId)
Create copyright and sibling agent's related data in DB.
createMonkBulkData(FoDecisionData &$reportData, DecisionImporterAgent &$agentObj)
Create monkbulk findings from the report.
__construct(DbManager $dbManager, AgentDao $agentDao, CopyrightDao $copyrightDao, LicenseDao $licenseDao, UploadDao $uploadDao, ClearingDao $clearingDao)
setLicenseRefBulkList(array $license_ref_bulkList)
setClearingDecisionList(array $clearing_decisionList)
getClearingDecisionEventList()
getClearingDecisionList()
heartbeat($newProcessed)
Send hear beat to the scheduler.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
fo_dbManager * dbManager
fo_dbManager object
FUNCTION char * strtoupper(char *s)
Helper function to upper case a string.