示例#1
0
 public function testGetFileTreeBounds()
 {
     $uploadTreeId = 103;
     $left = 1;
     $uploadId = 101;
     $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name)" . " VALUES ({$uploadTreeId}, NULL, {$uploadId}, 1, 33792, {$left}, 2, 'WXwindows.txt');", __METHOD__ . '.insert.data');
     /** @var ItemTreeBounds $itemTreeBounds */
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId);
     assertThat($itemTreeBounds, anInstanceOf('Fossology\\Lib\\Data\\Tree\\ItemTreeBounds'));
     assertThat($uploadId, equalTo($itemTreeBounds->getUploadId()));
     assertThat($left, equalTo($itemTreeBounds->getLeft()));
 }
示例#2
0
 function processClearingEventOfCurrentJob()
 {
     $userId = $this->userId;
     $groupId = $this->groupId;
     $jobId = $this->jobId;
     $eventsOfThisJob = $this->clearingDao->getEventIdsOfJob($jobId);
     foreach ($eventsOfThisJob as $uploadTreeId => $additionalEventsFromThisJob) {
         $containerBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId);
         foreach ($this->loopContainedItems($containerBounds) as $itemTreeBounds) {
             $this->processClearingEventsForItem($itemTreeBounds, $userId, $groupId, $additionalEventsFromThisJob);
         }
     }
 }
示例#3
0
 /** @group Functional */
 public function testRunMonkScan()
 {
     $this->setUpTables();
     $this->setUpRepo();
     list($output, $retCode) = $this->runMonk($uploadId = 1);
     $this->rmRepo();
     $this->assertEquals($retCode, 0, 'monk failed: ' . $output);
     $this->assertEquals(6, $this->getHeartCount($output));
     $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");
     $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(7));
     $expectedHighlight = new Highlight(18, 35825, Highlight::MATCH, 20, 35819);
     $expectedHighlight->setLicenseId($matchedLicense->getId());
     $this->assertEquals(array($expectedHighlight), $highlights);
     $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(11));
     $expectedHighlights = array();
     $expectedHighlights[] = new Highlight(18, 339, Highlight::MATCH, 20, 350);
     $expectedHighlights[] = new Highlight(340, 347, Highlight::CHANGED, 351, 357);
     $expectedHighlights[] = new Highlight(348, 35149, Highlight::MATCH, 358, 35819);
     foreach ($expectedHighlights as $expectedHighlight) {
         $expectedHighlight->setLicenseId($matchedLicense->getId());
     }
     assertThat($highlights, containsInAnyOrder($expectedHighlights));
 }
 /**
  * @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;
     $vars['micromenu'] = Dir2Browse($this->Name, $item, NULL, $showBox = 0, "Browse", -1, '', '', $this->uploadtree_tablename);
     $vars['licenseArray'] = $this->licenseDao->getLicenseArray();
     $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['content'] = js_url();
     return $this->render("browse.html.twig", $this->mergeWithDefault($vars));
 }
 function doEdit($userId, $groupId, $itemId)
 {
     $licenses = GetParm("licenseNumbersToBeSubmitted", PARM_RAW);
     $removed = $_POST['removed'] === 't' || $_POST['removed'] === 'true';
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId);
     $uploadId = $itemTreeBounds->getUploadId();
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $jobId = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     if (isset($licenses)) {
         if (!is_array($licenses)) {
             return $this->errorJson("bad license array");
         }
         foreach ($licenses as $licenseId) {
             if (intval($licenseId) <= 0) {
                 return $this->errorJson("bad license");
             }
             $this->clearingDao->insertClearingEvent($itemId, $userId, $groupId, $licenseId, $removed, ClearingEventTypes::USER, $reportInfo = '', $comment = '', $jobId);
         }
     }
     /** @var agent_fodecider $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $conflictStrategyId = null;
     $errorMsg = "";
     $jq_pk = $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, array(), $conflictStrategyId);
     /** after changing one license, purge all the report cache */
     ReportCachePurgeAll();
     //Todo: Change sql statement of fossology/src/buckets/agent/leaf.c line 124 to take the newest valid license, then uncomment this line
     // $this->ChangeBuckets(); // change bucket accordingly
     if (empty($errorMsg) && $jq_pk > 0) {
         return new JsonResponse(array("jqid" => $jq_pk));
     } else {
         return $this->errorJson($errorMsg, 500);
     }
 }
 /**
  * @param int $userId
  * @param int
  * @param int $lastItem
  * @return array
  */
 protected function updateLastItem($userId, $groupId, $lastItem)
 {
     $type = GetParm("clearingTypes", PARM_INTEGER);
     $global = GetParm("globalDecision", PARM_STRING) === "on";
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($lastItem);
     $itemBounds = $this->uploadDao->getItemTreeBounds($lastItem, $uploadTreeTableName);
     $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
 }
 protected function doUndo($itemId, $hash, $type)
 {
     $item = $this->uploadDao->getItemTreeBounds($itemId, $this->uploadtree_tablename);
     $cpTable = $this->getTableName($type);
     if ($cpTable != 'copyright') {
         return new Response('There is not undo for ' . $cpTable, Response::HTTP_NOT_IMPLEMENTED, array('Content-type' => 'text/plain'));
     }
     $this->copyrightDao->rollbackTable($item, $hash, Auth::getUserId(), $cpTable);
     return new Response('Successfully restored', Response::HTTP_OK, array('Content-type' => 'text/plain'));
 }
示例#8
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $uploadId = intval($request->get('upload'));
     if (empty($uploadId)) {
         return;
     }
     $uploadTreeId = intval($request->get('item'));
     if (empty($uploadTreeId)) {
         return;
     }
     $onlyTried = !$request->get('all');
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     /** @var ItemTreeBounds */
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
     /** @var Session */
     $session = $this->getObject('session');
     $groupId = $session->get(Auth::GROUP_ID);
     $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId, $onlyTried);
     return $this->render("bulk-history.html.twig", $this->mergeWithDefault(array('bulkHistory' => $bulkHistory)));
 }
示例#9
0
 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;
 }
示例#10
0
 /**
  * @param $itemId - uploadtree id
  * @param $uploadId - upload id
  */
 public function getCopyrightList($itemId, $uploadId)
 {
     if (empty($itemId)) {
         $itemId = $this->uploadDao->getUploadParent($uploadId);
     }
     if (!$this->selectAgentId($uploadId)) {
         echo 'no valid copyright agent found';
         return;
     }
     $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($uploadId);
     $toprow = $this->uploadDao->getItemTreeBounds($itemId, $uploadtree_tablename);
     $extraWhere = 'agent_fk=' . $this->agentId . ' AND lft>' . $toprow->getLeft() . ' AND rgt<' . $toprow->getRight();
     $allCopyrightEntries = $this->copyrightDao->getAllEntries('copyright', $uploadId, $uploadtree_tablename, empty($this->type) || $this->type == 'all' ? null : $this->type, false, null, $extraWhere);
     $modeMask = empty($this->includeContainer) ? 3 << 28 : 1 << 28;
     $sql = "SELECT uploadtree_pk, ufile_name, lft, rgt FROM {$uploadtree_tablename} \n              WHERE upload_fk=\$1 AND lft>\$2 AND rgt<\$3 AND (ufile_mode & \$4) = 0\n              ORDER BY uploadtree_pk";
     $this->dbManager->prepare($outerStmt = __METHOD__ . '.loopThroughAllRecordsInTree', $sql);
     $outerresult = $this->dbManager->execute($outerStmt, array($toprow->getUploadId(), $toprow->getLeft(), $toprow->getRight(), $modeMask));
     while ($row = $this->dbManager->fetchArray($outerresult)) {
         $this->printRow($row, $uploadtree_tablename, $allCopyrightEntries);
         //$this->uploadDao->getParentItemBounds($uploadId)->getItemId());
     }
     $this->dbManager->freeResult($outerresult);
 }
示例#11
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)) {
         throw new \Exception("Permission Denied");
     }
     $item = intval($request->get("item"));
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
     $left = $itemTreeBounds->getLeft();
     if (empty($left)) {
         throw new \Exception("Job unpack/adj2nest hasn't completed.");
     }
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->agentDao, $upload);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $selectedAgentId = intval($request->get('agentId'));
     $tag_pk = intval($request->get('tag'));
     $UniqueTagArray = array();
     $this->licenseProjector = new LicenseMap($this->getObject('db.manager'), $groupId, LicenseMap::CONCLUSION, true);
     $vars = $this->createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
     return new JsonResponse(array('sEcho' => intval($request->get('sEcho')), 'aaData' => $vars['fileData'], 'iTotalRecords' => intval($request->get('totalRecords')), 'iTotalDisplayRecords' => $vars['iTotalDisplayRecords']));
 }
示例#12
0
 private function runnerReuserScanWithARepoClearingEnhanced($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $originallyClearedItemId = 23;
     /* upload 3 in the test db is the same as upload 2 -> items 13-24 in upload 2 correspond to 33-44 */
     $reusingUploadItemShift = 20;
     $this->dbManager->queryOnce("UPDATE uploadtree_a SET pfile_fk=351 WHERE uploadtree_pk={$originallyClearedItemId}+{$reusingUploadItemShift}", __METHOD__ . '.minorChange');
     $this->uploadDao->addReusedUpload($uploadId = 3, $reusedUpload = 2, $this->groupId, $this->groupId, $reuseMode = 1);
     $repoPath = $this->testDb->getFossSysConf() . '/repo/files/';
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(4)->andReturn($repoPath . '04621571bcbabce75c4dd1c6445b87dec0995734.59cacdfce5051cd8a1d8a1f2dcce40a5.12320');
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(351)->andReturn($repoPath . 'c518ce1658140b65fa0132ad1130cb91512416bf.8e913e594d24ff3aeabe350107d97815.35829');
     list($clearingLicense1, $clearingLicense2, $addedEventIds) = $this->insertDecisionFromTwoEvents(DecisionScopes::REPO, $originallyClearedItemId);
     $clearingLicenses = array($clearingLicense1, $clearingLicense2);
     list($success, $output, $retCode) = $runner->run($uploadId, $this->userId, $this->groupId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     $newUploadClearings = $this->getFilteredClearings($uploadId, $this->groupId);
     $potentiallyReusableClearings = $this->getFilteredClearings($reusedUpload, $this->groupId);
     assertThat($newUploadClearings, is(arrayWithSize(1)));
     assertThat($potentiallyReusableClearings, is(arrayWithSize(1)));
     /** @var ClearingDecision */
     $potentiallyReusableClearing = $potentiallyReusableClearings[0];
     /** @var ClearingDecision */
     $newClearing = $newUploadClearings[0];
     /* they are actually the same ClearingDecision
      * only sameFolder and sameUpload are different */
     assertThat($newClearing, not(equalTo($potentiallyReusableClearing)));
     assertThat($newClearing->getClearingLicenses(), arrayContainingInAnyOrder($clearingLicenses));
     assertThat($newClearing->getType(), equalTo($potentiallyReusableClearing->getType()));
     assertThat($newClearing->getScope(), equalTo($potentiallyReusableClearing->getScope()));
     assertThat($newClearing->getUploadTreeId(), equalTo($potentiallyReusableClearing->getUploadTreeId() + $reusingUploadItemShift));
     /* reuser should have not created a correct local event history */
     $bounds = $this->uploadDao->getItemTreeBounds($originallyClearedItemId + $reusingUploadItemShift);
     $newEvents = $this->clearingDao->getRelevantClearingEvents($bounds, $this->groupId);
     assertThat($newEvents, is(arrayWithSize(count($clearingLicenses))));
     /** @var ClearingEvent $newEvent */
     foreach ($newEvents as $newEvent) {
         assertThat($newEvent->getEventId(), anyOf($addedEventIds));
         assertThat($newEvent->getClearingLicense(), anyOf($clearingLicenses));
     }
     $this->rmRepo();
 }
示例#13
0
 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();
 }