function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $licenseShortname = GetParm("lic", PARM_TEXT); $licenseId = GetParm("rf", PARM_NUMBER); $groupId = $_SESSION[Auth::GROUP_ID]; if (empty($licenseShortname) && empty($licenseId)) { return; } if ($licenseId) { $license = $this->licenseDao->getLicenseById($licenseId, $groupId); } else { $license = $this->licenseDao->getLicenseByShortName($licenseShortname, $groupId); } if ($license === null) { return; } $this->vars['shortName'] = $license->getShortName(); $this->vars['fullName'] = $license->getFullName(); $parent = $this->licenseDao->getLicenseParentById($license->getId()); if ($parent !== null) { $this->vars['parentId'] = $parent->getId(); $this->vars['parentShortName'] = $parent->getShortName(); } $licenseUrl = $license->getUrl(); if (strtolower($licenseUrl) == 'none') { $licenseUrl = NULL; } $this->vars['url'] = $licenseUrl; $this->vars['text'] = $license->getText(); $this->vars['risk'] = $license->getRisk(); return $this->render('popup_license.html.twig'); }
/** * @param Request $request * @return Response */ protected function handle(Request $request) { $vars = array('licenseCount' => $this->licenseDao->getLicenseCount(), 'project' => _("FOSSology"), 'copyright' => _("Copyright (C) 2007-2014 Hewlett-Packard Development Company, L.P.<br>\nCopyright (C) 2014-2016 Siemens AG.")); if (Auth::isAdmin()) { $repositoryApi = new RepositoryApi(); $latestRelease = $repositoryApi->getLatestRelease(); $commits = $repositoryApi->getCommitsOfLastDays(30); $commit = empty($commits) ? '' : substr($commits[0]['sha'], 0, 6); $vars = array_merge($vars, array('latestVersion' => $latestRelease, 'lastestCommit' => $commit)); } return $this->render('about.html.twig', $this->mergeWithDefault($vars)); }
/** * @param int $licenseId * @return License */ protected function getCachedLicenseText($licenseId, $groupId) { if (!array_key_exists($licenseId, $this->licenseCache)) { $this->licenseCache[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId); } return $this->licenseCache[$licenseId]->getText(); }
/** @group Functional */ public function testRunMonkBulkScanWithAnEmptySearchText() { $this->setUpTables(); $this->setUpRepo(); $userId = 2; $groupId = 2; $uploadTreeId = 1; $licenseId = 225; $removing = false; $refText = ""; $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText); $this->assertGreaterThan($expected = 0, $bulkId); $jobId = 64; list($output, $retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId); $this->rmRepo(); $this->assertEquals($retCode, 0, 'monk bulk failed: ' . $output); $bounds6 = new ItemTreeBounds(6, 'uploadtree_a', 1, 17, 18); $bounds7 = new ItemTreeBounds(7, 'uploadtree_a', 1, 15, 16); $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId); $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId); assertThat(count($relevantDecisionsItem6), is(equalTo(0))); assertThat(count($relevantDecisionsItem7), is(equalTo(0))); $bulkHighlights = $this->highlightDao->getHighlightBulk(6); assertThat(count($bulkHighlights), is(equalTo(0))); }
/** * @param Request $request * @return Response */ protected function handle(Request $request) { $upload = intval($request->get("upload")); $groupId = Auth::getGroupId(); if (!$this->uploadDao->isAccessible($upload, $groupId)) { return $this->flushContent(_("Permission Denied")); } $item = intval($request->get("item")); $vars['baseuri'] = Traceback_uri(); $vars['uploadId'] = $upload; $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload); if ($request->get('show') == 'quick') { $item = $this->uploadDao->getFatItemId($item, $upload, $this->uploadtree_tablename); } $vars['itemId'] = $item; $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename); $left = $itemTreeBounds->getLeft(); if (empty($left)) { return $this->flushContent(_("Job unpack/adj2nest hasn't completed.")); } $histVars = $this->showUploadHist($itemTreeBounds); if (is_a($histVars, 'Symfony\\Component\\HttpFoundation\\RedirectResponse')) { return $histVars; } $vars = array_merge($vars, $histVars); $vars['micromenu'] = Dir2Browse($this->Name, $item, NULL, $showBox = 0, "Browse", -1, '', '', $this->uploadtree_tablename); $allLicensesPre = $this->licenseDao->getLicenseArray(); $allLicenses = array(); foreach ($allLicensesPre as $value) { $allLicenses[$value['shortname']] = array('rf_pk' => $value['id']); } $vars['scannerLicenses'] = $allLicenses; $vars['content'] = js_url(); return $this->render("file-browse.html.twig", $this->mergeWithDefault($vars)); }
private function runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($runner) { $this->setUpTables(); $this->setUpRepo(); $monkAgentId = 5; $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licId1 = $licenseRef1->getId(); $pfile = 4; $jobId = 16; $groupId = 2; $userId = 2; $itemId = 7; $itemTreeBounds = new ItemTreeBounds($itemId, 'uploadtree_a', $uploadId = 1, 15, 16); $this->dbManager->queryOnce("DELETE FROM license_file"); /* insert NoLicenseKnown decisions */ $this->dbManager->queryOnce("INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)" . " VALUES (2, {$itemId}, {$pfile}, {$userId}, {$groupId}, " . DecisionTypes::IRRELEVANT . ", " . DecisionScopes::ITEM . ", '2015-05-04 11:43:18.276425+02')"); $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); $lastClearingId = $lastDecision->getClearingId(); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$licId1},{$pfile},{$monkAgentId})"); $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)" . " VALUES ({$jobId}, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')"); list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, ''); $this->assertTrue($success, 'cannot run runner'); $this->assertEquals($retCode, 0, 'decider failed (did you make test?): ' . $output); $newDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); assertThat($newDecision->getClearingId(), equalTo($lastClearingId)); $this->rmRepo(); }
/** @group Functional */ public function testRun() { $this->setUpTables(); $this->setUpRepo(); list($output, $retCode) = $this->runNinka($uploadId = 1); $this->rmRepo(); $this->assertEquals($retCode, 0, 'ninka failed: ' . $output); $bounds = $this->uploadDao->getParentItemBounds($uploadId); $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds); $this->assertEquals($expected = 6, count($matches)); foreach ($matches as $licenseMatch) { /** @var LicenseRef */ $matchedLicense = $licenseMatch->getLicenseRef(); switch ($licenseMatch->getFileId()) { case 7: case 4: $expectedLicense = "GPL-3.0+"; break; case 3: $expectedLicense = "UnclassifiedLicense"; break; default: $expectedLicense = "No_license_found"; break; } $this->assertEquals($expectedLicense, $matchedLicense->getShortName(), "unexpected license for fileId " . $licenseMatch->getFileId()); /** @var AgentRef */ $agentRef = $licenseMatch->getAgentRef(); $this->assertEquals($agentRef->getAgentName(), "ninka"); } }
/** * @param ItemTreeBounds $itemTreeBounds * @return LicenseMatch[][][] map licenseId->agentName->licenseMatches */ public function getLatestScannerDetectedMatches(ItemTreeBounds $itemTreeBounds) { $agentDetectedLicenses = array(); $licenseFileMatches = $this->licenseDao->getAgentFileLicenseMatches($itemTreeBounds); foreach ($licenseFileMatches as $licenseMatch) { $licenseRef = $licenseMatch->getLicenseRef(); $licenseId = $licenseRef->getId(); if ($licenseRef->getShortName() === "No_license_found") { continue; } $agentRef = $licenseMatch->getAgentRef(); $agentName = $agentRef->getAgentName(); $agentId = $agentRef->getAgentId(); $agentDetectedLicenses[$agentName][$agentId][$licenseId][] = $licenseMatch; } return $this->filterLatestScannerDetectedMatches($agentDetectedLicenses, $itemTreeBounds->getUploadId()); }
/** * @param Highlight[] $highlights * @param int|null $groupId */ public function addReferenceTexts(&$highlights, $groupId = null) { $licenses = array(); foreach ($highlights as &$highlight) { if ($highlight->hasLicenseId()) { $licenseId = $highlight->getLicenseId(); if (!array_key_exists($licenseId, $licenses)) { $licenses[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId); } /** * @var License $license */ $license = $licenses[$licenseId]; $licenseReferenceText = ": '" . $this->getReferenceText($license, $highlight) . "'"; $includeReferenceText = $highlight->getType() != Highlight::MATCH && $highlight->getRefLength() > 0; $infoText = $license->getShortName() . ($includeReferenceText ? $licenseReferenceText : ""); $highlight->setInfoText($infoText); } } }
protected function insertDecisionFromTwoEvents($scope = DecisionScopes::ITEM, $originallyClearedItemId = 23) { $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef(); $addedLicenses = array($licenseRef1, $licenseRef2); assertThat($addedLicenses, not(arrayContaining(null))); $clearingLicense1 = new ClearingLicense($licenseRef1, false, ClearingEventTypes::USER, "42", "44"); $clearingLicense2 = new ClearingLicense($licenseRef2, true, ClearingEventTypes::USER, "-42", "-44"); $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, $this->userId, $this->groupId, $licenseRef1->getId(), $clearingLicense1->isRemoved(), $clearingLicense1->getType(), $clearingLicense1->getReportinfo(), $clearingLicense1->getComment()); $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $this->groupId, $licenseRef2->getId(), $clearingLicense2->isRemoved(), $clearingLicense2->getType(), $clearingLicense2->getReportinfo(), $clearingLicense2->getComment()); $addedEventIds = array($eventId1, $eventId2); $this->clearingDao->createDecisionFromEvents($originallyClearedItemId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $scope, $addedEventIds); return array($clearingLicense1, $clearingLicense2, $addedEventIds); }
/** * @param boolean $orderAscending * @param int $groupId * @param int $uploadId * @param int $uploadTreeId * @return string */ protected function doLicenses($orderAscending, $groupId, $uploadId, $uploadTreeId) { $itemTreeBounds = $this->uploadDao->getItemTreeBoundsFromUploadId($uploadTreeId, $uploadId); list($licenseDecisions, $removed) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId); $licenseRefs = $this->licenseDao->getConclusionLicenseRefs(Auth::getGroupId(), $_GET['sSearch'], $orderAscending, array_keys($licenseDecisions)); $licenses = array(); foreach ($licenseRefs as $licenseRef) { $licenseId = $licenseRef->getId(); $shortNameWithFullTextLink = $this->urlBuilder->getLicenseTextUrl($licenseRef); $actionLink = "<a href=\"javascript:;\" onClick=\"addLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img src=\"images/space_16.png\" class=\"add\"/></a>"; $licenses[] = array($shortNameWithFullTextLink, $actionLink); } return array('sEcho' => intval($_GET['sEcho']), 'aaData' => $licenses, 'iTotalRecords' => count($licenses), 'iTotalDisplayRecords' => count($licenses)); }
public function testGetScannerDetectedLicenseDetailsNoLicenseFoundShouldBeSkipped() { $uploadId = 2; list($licenseMatch1, $licenseRef1, $agentRef1) = $this->createLicenseMatch(5, "No_license_found", 23, "nomos", 453, null); $licenseMatches = array($licenseMatch1); $this->itemTreeBounds->shouldReceive('getUploadId')->withNoArgs()->andReturn($uploadId); $this->licenseDao->shouldReceive('getAgentFileLicenseMatches')->once()->withArgs(array($this->itemTreeBounds, LicenseMap::TRIVIAL))->andReturn($licenseMatches); // $latestAgentDetectedLicenses = $this->agentLicenseEventProcessor->getScannerDetectedLicenseDetails($this->itemTreeBounds); $reflection = new \ReflectionClass($this->agentLicenseEventProcessor); $method = $reflection->getMethod('getScannerDetectedLicenseDetails'); $method->setAccessible(true); $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor, $this->itemTreeBounds); assertThat($latestAgentDetectedLicenses, is(array())); }
/** * * @param int $uploadTreeId * @param Request $request * @return int $jobQueueId */ private function getJobQueueId($uploadTreeId, Request $request) { $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId); $uploadId = intval($uploadEntry['upload_fk']); $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) { throw new Exception('permission denied'); } $bulkScope = $request->get('bulkScope'); switch ($bulkScope) { case 'u': $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId); $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable); $uploadTreeId = $topBounds->getItemId(); break; case 'f': if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) { $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId; } break; default: throw new InvalidArgumentException('bad scope request'); } $refText = $request->get('refText'); $actions = $request->get('bulkAction'); $licenseRemovals = array(); foreach ($actions as $licenseAction) { $licenseRemovals[$licenseAction['licenseId']] = $licenseAction['action'] == 'remove'; } $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText); if ($bulkId <= 0) { throw new Exception('cannot insert bulk reference'); } $upload = $this->uploadDao->getUpload($uploadId); $uploadName = $upload->getFilename(); $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId); /** @var DeciderJobAgentPlugin $deciderPlugin */ $deciderPlugin = plugin_find("agent_deciderjob"); $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId)); $conflictStrategyId = intval($request->get('forceDecision')); $errorMsg = ''; $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId); if (!empty($errorMsg)) { throw new Exception(str_replace('<br>', "\n", $errorMsg)); } return $jqId; }
private function getJobQueueId($uploadTreeId) { $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId); $uploadId = intval($uploadEntry['upload_fk']); if ($uploadId <= 0) { throw new Exception('permission denied'); } $bulkScope = filter_input(INPUT_POST, 'bulkScope'); switch ($bulkScope) { case 'u': $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId); $row = $this->dbManager->getSingleRow("SELECT uploadtree_pk FROM {$uploadTreeTable} WHERE upload_fk = \$1 ORDER BY uploadtree_pk LIMIT 1", array($uploadId), __METHOD__ . "adam" . $uploadTreeTable); $uploadTreeId = $row['uploadtree_pk']; break; case 'f': if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) { $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId; } break; default: throw new InvalidArgumentException('bad scope request'); } $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); $refText = filter_input(INPUT_POST, 'refText'); $action = filter_input(INPUT_POST, 'bulkAction'); $licenseId = GetParm('licenseId', PARM_INTEGER); $removing = $action === 'remove'; $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseId, $removing, $refText); if ($bulkId <= 0) { throw new Exception('cannot insert bulk reference'); } $upload = $this->uploadDao->getUpload($uploadId); $uploadName = $upload->getFilename(); $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId); /** @var DeciderJobAgentPlugin $deciderPlugin */ $deciderPlugin = plugin_find("agent_deciderjob"); $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId)); $conflictStrategyId = intval(filter_input(INPUT_POST, 'forceDecision')); $errorMsg = ''; $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId); if (!empty($errorMsg)) { throw new Exception(str_replace('<br>', "\n", $errorMsg)); } return $jqId; }
function createListOfLines($uploadtreeTablename, $uploadtree_pk, $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore) { /** @var ItemTreeBounds */ $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk, $uploadtreeTablename); $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId($itemTreeBounds, $agent_pks, $includeSubfolder, array(), $exclude, $ignore); /* how many lines of data do you want to display */ $currentNum = 0; foreach ($licensesPerFileName as $fileName => $licenseNames) { if ($licenseNames !== false && count($licenseNames) > 0) { if (++$currentNum > $NomostListNum) { $lines["warn"] = _("<br><b>Warning: Only the first {$NomostListNum} lines are displayed. To see the whole list, run fo_nomos_license_list from the command line.</b><br>"); // TODO: the following should be done using a "LIMIT" statement in the sql query break; } $lines[] = $fileName . ': ' . implode($licenseNames, ', ') . ''; } if (!$ignore && $licenseNames === false) { $lines[] = $fileName; } } return $lines; }
/** * @param $uploadTreeId * @param $tagId * @param ItemTreeBounds $itemTreeBounds * @param int|int[] $agentIds * @param ClearingDecision [] * @return array */ private function createLicenseHistogram($uploadTreeId, $tagId, ItemTreeBounds $itemTreeBounds, $agentIds, $groupId) { $fileCount = $this->uploadDao->countPlainFiles($itemTreeBounds); $licenseHistogram = $this->licenseDao->getLicenseHistogram($itemTreeBounds, $agentIds); $editedLicensesHist = $this->clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $groupId); $agentId = GetParm('agentId', PARM_INTEGER); $licListUri = Traceback_uri() . "?mod=license_list_files&item={$uploadTreeId}"; if ($tagId) { $licListUri .= "&tag={$tagId}"; } if ($agentId) { $licListUri .= "&agentId={$agentId}"; } /* Write license histogram to $VLic */ list($tableData, $totalScannerLicenseCount, $editedTotalLicenseCount) = $this->createLicenseHistogramJSarray($licenseHistogram, $editedLicensesHist, $licListUri); $uniqueLicenseCount = count($tableData); $scannerUniqueLicenseCount = count($licenseHistogram); $editedUniqueLicenseCount = count($editedLicensesHist); $noScannerLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $licenseHistogram) ? $licenseHistogram[LicenseDao::NO_LICENSE_FOUND]['count'] : 0; $editedNoLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $editedLicensesHist) ? $editedLicensesHist[LicenseDao::NO_LICENSE_FOUND]['count'] : 0; $vars = array('tableDataJson' => json_encode($tableData), 'uniqueLicenseCount' => $uniqueLicenseCount, 'fileCount' => $fileCount, 'scannerUniqueLicenseCount' => $scannerUniqueLicenseCount, 'editedUniqueLicenseCount' => $editedUniqueLicenseCount, 'scannerLicenseCount' => $totalScannerLicenseCount, 'editedLicenseCount' => $editedTotalLicenseCount - $editedNoLicenseFoundCount, 'noScannerLicenseFoundCount' => $noScannerLicenseFoundCount, 'editedNoLicenseFoundCount' => $editedNoLicenseFoundCount, 'scannerLicenses' => $licenseHistogram, 'editedLicenses' => $editedLicensesHist); return $vars; }
private function runnerDeciderScanWithForceDecision($runner) { $this->setUpTables(); $this->setUpRepo(); $jobId = 42; $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef(); $agentLicId = $this->licenseDao->getLicenseByShortName("Adaptec")->getRef()->getId(); $addedLicenses = array($licenseRef1, $licenseRef2); assertThat($addedLicenses, not(arrayContaining(null))); $agentId = 5; $pfile = 4; $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$agentLicId},{$pfile},{$agentId})"); $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId = 23); assertThat($this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds), is(not(emptyArray()))); $eventId1 = $this->clearingDao->insertClearingEvent($itemId, $userId = 2, $groupId = 3, $licenseRef1->getId(), false); $eventId2 = $this->clearingDao->insertClearingEvent($itemId, 5, $groupId, $licenseRef2->getId(), true); $this->dbManager->queryOnce("UPDATE clearing_event SET job_fk={$jobId}"); $addedEventIds = array($eventId1, $eventId2); list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId, $groupId, $jobId, $args = "-k1"); $this->assertTrue($success, 'cannot run runner'); $this->assertEquals($retCode, 0, 'decider failed: ' . $output); assertThat($this->getHeartCount($output), equalTo(1)); $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId); $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId); assertThat($decisions, is(arrayWithSize(1))); /** @var ClearingDecision $deciderMadeDecision */ $deciderMadeDecision = $decisions[0]; $eventIds = array(); foreach ($deciderMadeDecision->getClearingEvents() as $event) { $eventIds[] = $event->getEventId(); } assertThat($eventIds, arrayValue($addedEventIds[0])); assertThat($eventIds, arrayValue($addedEventIds[1])); assertThat($eventIds, arrayWithSize(1 + count($addedEventIds))); $this->rmRepo(); }
/** @group Functional */ public function testRunMonkTwiceOnAScan() { $this->setUpTables(); $this->setUpRepo(); list($output, $retCode) = $this->runMonk($uploadId = 1); list($output2, $retCode2) = $this->runMonk($uploadId); $this->assertEquals($retCode, 0, 'monk failed: ' . $output); $this->assertEquals(6, $this->getHeartCount($output)); $this->assertEquals($retCode2, 0, 'monk failed: ' . $output2); $this->assertEquals(0, $this->getHeartCount($output2)); $this->rmRepo(); $bounds = $this->uploadDao->getParentItemBounds($uploadId); $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds); $this->assertEquals($expected = 2, count($matches)); /** @var LicenseMatch */ $licenseMatch = $matches[0]; $this->assertEquals($expected = 4, $licenseMatch->getFileId()); /** @var LicenseRef */ $matchedLicense = $licenseMatch->getLicenseRef(); $this->assertEquals($matchedLicense->getShortName(), "GPL-3.0"); /** @var AgentRef */ $agentRef = $licenseMatch->getAgentRef(); $this->assertEquals($agentRef->getAgentName(), "monk"); }
/** * @param array $child * @param int $uploadId * @param int $selectedAgentId * @param array $pfileLicenses * @param int $groupId * @param ClearingDecision[][] $editedMappedLicenses * @param string $uri * @param null|ClearingView $ModLicView * @param array $UniqueTagArray * @param boolean $isFlat * @param int[] $latestSuccessfulAgentIds * @return array */ private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds) { $fileId = $child['pfile_fk']; $childUploadTreeId = $child['uploadtree_pk']; $linkUri = ''; if (!empty($fileId) && !empty($ModLicView)) { $linkUri = Traceback_uri(); $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}"; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } /* Determine link for containers */ $isContainer = Iscontainer($child['ufile_mode']); if ($isContainer && !$isFlat) { $fatChild = $this->uploadDao->getFatItemArray($child['uploadtree_pk'], $uploadId, $this->uploadtree_tablename); $uploadtree_pk = $fatChild['item_id']; $linkUri = "{$uri}&item=" . $uploadtree_pk; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } $child['ufile_name'] = $fatChild['ufile_name']; if (!Iscontainer($fatChild['ufile_mode'])) { $isContainer = false; } } else { if ($isContainer) { $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId; $linkUri = "{$uri}&item=" . $uploadtree_pk; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $fileName = $child['ufile_name']; if ($isContainer) { $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>"; } else { if (!empty($linkUri)) { $fileName = "<a href='{$linkUri}'>{$fileName}</a>"; } } /* show licenses under file name */ $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']); if ($isContainer) { $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds; $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array()); $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId); } else { $licenseEntries = array(); if (array_key_exists($fileId, $pfileLicenses)) { foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) { $agentEntries = array(); foreach ($rfInfo as $agent => $match) { $agentName = $this->agentNames[$agent]; $agentEntry = "<a href='?mod=view-license&upload={$child['upload_fk']}&item={$childUploadTreeId}&format=text&agentId={$match['agent_id']}&licenseId={$match['license_id']}#highlight'>" . $agentName . "</a>"; if ($match['match_percentage'] > 0) { $agentEntry .= ": {$match['match_percentage']}%"; } $agentEntries[] = $agentEntry; } $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]"; } } /* @var $decision ClearingDecision */ if (false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses, $childUploadTreeId, $fileId))) { $editedLicenses = $decision->getPositiveLicenses(); } else { $editedLicenses = array(); } } $concludedLicenses = array(); /** @var LicenseRef $licenseRef */ foreach ($editedLicenses as $licenseRef) { $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId()); $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(), $licenseRef->getShortName()); $concludedLicenses[$projectedId] = $projectedName; } $editedLicenseList = implode(', ', $concludedLicenses); $licenseList = implode(', ', $licenseEntries); $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat); $getTextEditUser = _("Edit"); $fileListLinks .= "[<a href='#' onclick='openUserModal({$childUploadTreeId})' >{$getTextEditUser}</a>]"; if ($isContainer) { $getTextEditBulk = _("Bulk"); $fileListLinks .= "[<a href='#' onclick='openBulkModal({$childUploadTreeId})' >{$getTextEditBulk}</a>]"; } $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0; $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0; $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared; $img = $filesCleared == $filesToBeCleared ? 'green' : 'red'; return array($fileName, $licenseList, $editedLicenseList, $img, "{$filesCleared}/{$filesToBeCleared}", $fileListLinks); }
public function testGetAgentFileLicenseMatchesWithLicenseMapping() { $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent', 'license_map')); $this->testDb->insertData_license_ref(); $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1", array(), __METHOD__ . '.anyLicense'); $licRefId = $lic0['rf_pk']; $licenseFileId = 1; $pfileId = 42; $agentId = 23; $matchPercent = 50; $uploadtreeId = 512; $uploadID = 123; $left = 2009; $right = 2014; $agentName = "fake"; $agentRev = 1; $lic1 = $this->dbManager->getSingleRow("SELECT * FROM license_ref WHERE rf_pk!=\$1 LIMIT 1", array($licRefId), __METHOD__ . '.anyOtherLicense'); $licVarId = $lic1['rf_pk']; $mydate = "'2014-06-04 14:01:30.551093+02'"; $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => $licVarId, 'rf_parent' => $licRefId, 'usage' => LicenseMap::CONCLUSION)); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n VALUES ({$licenseFileId}, {$licVarId}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})"); $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n VALUES ({$uploadtreeId}, {$uploadID}, {$pfileId}, {$left}, {$right})"); $stmt = __METHOD__ . '.insert.agent'; $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)"); $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true')); $licDao = new LicenseDao($this->dbManager); $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right); $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds, LicenseMap::CONCLUSION); $licenseRef = new LicenseRef($licRefId, $lic0['rf_shortname'], $lic0['rf_fullname']); $agentRef = new AgentRef($agentId, $agentName, $agentRev); $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent)); assertThat($matches, equalTo($expected)); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }
/** * @param array $child * @param int $uploadId * @param int $selectedAgentId * @param array $pfileLicenses * @param int $groupId * @param string $uri * @param array $UniqueTagArray * @param boolean $isFlat * @param int[] $latestSuccessfulAgentIds * @return array */ private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds) { $fileId = $child['pfile_fk']; $childUploadTreeId = $child['uploadtree_pk']; $linkUri = ''; if (!empty($fileId)) { $linkUri = Traceback_uri(); $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}"; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } /* Determine link for containers */ $isContainer = Iscontainer($child['ufile_mode']); if ($isContainer && !$isFlat) { $uploadtree_pk = $child['uploadtree_pk']; $linkUri = "{$uri}&item=" . $uploadtree_pk; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } else { if ($isContainer) { $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId; $linkUri = "{$uri}&item=" . $uploadtree_pk; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $fileName = $child['ufile_name']; if ($isContainer) { $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>"; } else { if (!empty($linkUri)) { $fileName = "<a href='{$linkUri}'>{$fileName}</a>"; } } /* show licenses under file name */ $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']); $licenseEntries = array(); if ($isContainer) { $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds; $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array()); } else { if (array_key_exists($fileId, $pfileLicenses)) { foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) { $agentEntries = array(); foreach ($rfInfo as $agent => $match) { $agentName = $this->agentNames[$agent]; $agentEntry = "<a href='?mod=view-license&upload={$child['upload_fk']}&item={$childUploadTreeId}&format=text&agentId={$match['agent_id']}&licenseId={$match['license_id']}#highlight'>" . $agentName . "</a>"; if ($match['match_percentage'] > 0) { $agentEntry .= ": {$match['match_percentage']}%"; } $agentEntries[] = $agentEntry; } $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]"; } } } $licenseList = implode(', ', $licenseEntries); $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat); if (!$isContainer) { $text = _("Copyright/Email/Url"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=copyright-view&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; $text = _("ReadMe_OSS"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_readmeoss&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; $text = _("SPDX"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_spdx2&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; } return array($fileName, $licenseList, $fileListLinks); }
/** * @brief extends standard Output to handle empty uploads */ function Output() { if ($this->invalidParm) { $this->vars['content'] = 'This upload contains no files!<br><a href="' . Traceback_uri() . '?mod=browse">Go back to browse view</a>'; return $this->render("include/base.html.twig"); } $uploadId = GetParm("upload", PARM_INTEGER); if (empty($uploadId)) { return new Response("", Response::HTTP_BAD_REQUEST); } $uploadTreeId = GetParm("item", PARM_INTEGER); if (empty($uploadTreeId)) { return new Response("", Response::HTTP_BAD_REQUEST); } $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); $lastItem = GetParm("lastItem", PARM_INTEGER); if (!empty($lastItem)) { $this->updateLastItem($userId, $groupId, $lastItem); } $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId); $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName); $this->vars['micromenu'] = Dir2Browse('license', $uploadTreeId, NULL, $showBox = 0, "View", -1, '', '', $uploadTreeTableName); global $Plugins; /** @var ui_view $view */ $view =& $Plugins[plugin_find_id("view")]; $licenseId = GetParm("licenseId", PARM_INTEGER); $selectedAgentId = GetParm("agentId", PARM_INTEGER); $highlightId = GetParm("highlightId", PARM_INTEGER); $clearingId = GetParm("clearingId", PARM_INTEGER); if ($clearingId !== null) { $highlightId = -1; } else { if ($highlightId !== null) { $clearingId = -1; } } $baseUri = Traceback_uri(); $this->vars['baseuri'] = $baseUri; $this->vars['uri'] = $baseUri . "?mod=" . $this->Name . Traceback_parm_keep(array('upload', 'folder')); $this->vars['bulkHistoryHighlightUri'] = $this->vars['uri']; $this->vars['optionName'] = "skipFile"; $this->vars['formName'] = "uiClearingForm"; $this->vars['ajaxAction'] = "setNextPrev"; $highlights = $this->getSelectedHighlighting($itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId); $isSingleFile = !$itemTreeBounds->containsFiles(); $hasWritePermission = $this->uploadDao->isEditable($uploadId, $groupId); $clearingDecisions = null; if ($isSingleFile || $hasWritePermission) { $clearingDecisions = $this->clearingDao->getFileClearings($itemTreeBounds, $groupId, false); } if ($isSingleFile && $hasWritePermission) { $this->vars['bulkUri'] = Traceback_uri() . "?mod=popup-license"; $licenseArray = $this->licenseDao->getLicenseArray($groupId); // $clearingDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); list($addedResults, $removedResults) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION); if (count($addedResults) + count($removedResults) > 0) { array_unshift($licenseArray, array('id' => 0, 'fullname' => '', 'shortname' => '------')); } /** @var ClearingResult $result */ foreach ($removedResults as $result) { array_unshift($licenseArray, array('id' => $result->getLicenseId(), 'fullname' => $result->getLicenseFullName(), 'shortname' => $result->getLicenseShortName())); } /** @var ClearingResult $result */ foreach ($addedResults as $result) { array_unshift($licenseArray, array('id' => $result->getLicenseId(), 'fullname' => $result->getLicenseFullName(), 'shortname' => $result->getLicenseShortName())); } $this->vars['licenseArray'] = $licenseArray; } elseif ($isSingleFile) { $this->vars['auditDenied'] = true; } $clearingHistory = array(); $selectedClearingType = false; if ($hasWritePermission) { $clearingHistory = $this->getClearingHistory($clearingDecisions); } if (count($clearingHistory) > 0) { $selectedClearingType = $this->decisionTypes->getTypeByName($clearingHistory[0]['type']); } $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId); $ModBack = GetParm("modback", PARM_STRING) ?: "license"; list($pageMenu, $textView) = $view->getView(NULL, $ModBack, 0, "", $highlights, false, true); $this->vars['uploadId'] = $uploadId; $this->vars['itemId'] = $uploadTreeId; $this->vars['pageMenu'] = $pageMenu; $this->vars['textView'] = $textView; $this->vars['legendData'] = $this->highlightRenderer->getLegendData($selectedAgentId || $clearingId); $this->vars['clearingTypes'] = $this->decisionTypes->getMap(); $this->vars['selectedClearingType'] = $selectedClearingType; $this->vars['tmpClearingType'] = $this->clearingDao->isDecisionWip($uploadTreeId, $groupId); $this->vars['clearingHistory'] = $clearingHistory; $this->vars['bulkHistory'] = $bulkHistory; $noLicenseUploadTreeView = new UploadTreeProxy($uploadId, $options = array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense", UploadTreeProxy::OPT_GROUP_ID => $groupId), $uploadTreeTableName, $viewName = 'no_license_uploadtree' . $uploadId); $filesOfInterest = $noLicenseUploadTreeView->count(); $nonClearedUploadTreeView = new UploadTreeProxy($uploadId, $options = array(UploadTreeProxy::OPT_SKIP_THESE => "alreadyCleared", UploadTreeProxy::OPT_GROUP_ID => $groupId), $uploadTreeTableName, $viewName = 'already_cleared_uploadtree' . $uploadId); $filesToBeCleared = $nonClearedUploadTreeView->count(); $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared; $this->vars['message'] = _("Cleared") . ": {$filesAlreadyCleared}/{$filesOfInterest}"; return $this->render("ui-clearing-view.html.twig"); }
function setUp() { $this->license1 = new License(10, "shortName", "fullName", "licenseFullText", 4, "URL"); $this->licenseDao = M::mock(LicenseDao::classname())->shouldReceive('getLicenseById')->with($this->license1->getId())->andReturn($this->license1)->getMock(); $this->highlight = new HighlightProcessor($this->licenseDao); }
/** * @param Request $request * @return Response */ protected function handle(Request $request) { $vars = array('licenseCount' => $this->licenseDao->getLicenseCount(), 'project' => _("FOSSology"), 'copyright' => _("Copyright (C) 2007-2014 Hewlett-Packard Development Company, L.P.<br>\nCopyright (C) 2014-2015 Siemens AG.")); return $this->render('about.html.twig', $this->mergeWithDefault($vars)); }