예제 #1
0
 public function testCreateAgentStatus()
 {
     $successfulAgents = array(array('agent_id' => $this->agentId, 'agent_rev' => 'a0815', 'agent_name' => $this->agentName));
     $this->agentDaoMock->shouldReceive('getSuccessfulAgentEntries')->with($this->agentName, $this->uploadId)->andReturn($successfulAgents);
     $this->agentDaoMock->shouldReceive('getRunningAgentIds')->never();
     $this->agentDaoMock->shouldReceive('getCurrentAgentRef')->with($this->agentName)->andReturn(new AgentRef($this->agentId, $this->agentName, 'a0815'));
     $fakedAgentName = 'ghost';
     $this->agentDaoMock->shouldReceive('arsTableExists')->with(M::anyOf($this->agentName, $fakedAgentName))->andReturn(true, false)->twice();
     $vars = $this->scanJobProxy->createAgentStatus(array($this->agentName, $fakedAgentName));
     assertThat($vars, is(array(array('successfulAgents' => $successfulAgents, 'uploadId' => $this->uploadId, 'agentName' => $this->agentName, 'currentAgentId' => $this->agentId, 'currentAgentRev' => 'a0815'))));
 }
예제 #2
0
 protected function getStatements($uploadId, $uploadTreeTableName, $groupId = null)
 {
     $agentName = $this->tableName;
     $scanJobProxy = new ScanJobProxy($GLOBALS['container']->get('dao.agent'), $uploadId);
     $scanJobProxy->createAgentStatus(array($agentName));
     $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     if (!array_key_exists($agentName, $selectedScanners)) {
         return array();
     }
     $latestXpAgentId = $selectedScanners[$agentName];
     if (!empty($this->extrawhere)) {
         $this->extrawhere .= ' AND';
     }
     $this->extrawhere .= ' agent_fk=' . $latestXpAgentId;
     return $this->copyrightDao->getAllEntries($this->tableName, $uploadId, $uploadTreeTableName, $this->type, $this->getOnlyCleared, DecisionTypes::IDENTIFIED, $this->extrawhere);
 }
예제 #3
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']));
 }
예제 #4
0
 /**
  * \brief Given an $Uploadtree_pk, display:
  *   - The histogram for the directory BY LICENSE.
  *   - The file listing for the directory.
  */
 private function showUploadHist(ItemTreeBounds $itemTreeBounds)
 {
     $groupId = Auth::getGroupId();
     $selectedAgentId = GetParm('agentId', PARM_INTEGER);
     $tag_pk = GetParm("tag", PARM_INTEGER);
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->agentDao, $uploadId);
     $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
     $agentMap = $scanJobProxy->getAgentMap();
     $vars = array('agentId' => GetParm('agentId', PARM_INTEGER), 'agentShowURI' => Traceback_uri() . '?mod=' . Traceback_parm(), 'agentMap' => $agentMap, 'scanners' => $scannerVars);
     $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
     if (!empty($agentMap)) {
         $licVars = $this->createLicenseHistogram($itemTreeBounds->getItemId(), $tag_pk, $itemTreeBounds, $selectedAgentIds, $groupId);
         $vars = array_merge($vars, $licVars);
     }
     $this->licenseProjector = new LicenseMap($this->getObject('db.manager'), $groupId, LicenseMap::CONCLUSION, true);
     $dirVars = $this->countFileListing($itemTreeBounds);
     $childCount = $dirVars['iTotalRecords'];
     /***************************************
      * Problem: $ChildCount can be zero if you have a container that does not
      * unpack to a directory.  For example:
      * file.gz extracts to archive.txt that contains a license.
      * Same problem seen with .pdf and .Z files.
      * Solution: if $ChildCount == 0, then just view the license!
      *
      * $ChildCount can also be zero if the directory is empty.
      * **************************************/
     if ($childCount == 0) {
         return new RedirectResponse("?mod=view-license" . Traceback_parm_keep(array("upload", "item")));
     }
     $vars['licenseUri'] = Traceback_uri() . "?mod=popup-license&rf=";
     $vars['bulkUri'] = Traceback_uri() . "?mod=popup-license";
     return array_merge($vars, $dirVars);
 }
예제 #5
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param $licenseId
  * @param $selectedAgentId
  * @param $highlightId
  * @param int $clearingId
  * @param int $uploadId
  * @return Highlight[]
  */
 private function getSelectedHighlighting(ItemTreeBounds $itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId)
 {
     $unmaskAgents = $selectedAgentId;
     if (empty($selectedAgentId)) {
         $scanJobProxy = new ScanJobProxy($this->agentsDao, $uploadId);
         $scanJobProxy->createAgentStatus(array('nomos', 'monk', 'ninka'));
         $unmaskAgents = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     $highlightEntries = $this->highlightDao->getHighlightEntries($itemTreeBounds, $licenseId, $unmaskAgents, $highlightId, $clearingId);
     $groupId = Auth::getGroupId();
     if ($selectedAgentId > 0 || $clearingId > 0) {
         $this->highlightProcessor->addReferenceTexts($highlightEntries, $groupId);
     } else {
         $this->highlightProcessor->flattenHighlights($highlightEntries, array("K", "K "));
     }
     return $highlightEntries;
 }
예제 #6
0
파일: spdx2.php 프로젝트: rlintu/fossology
 /**
  * @param string[][][] &$filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addScannerResults(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds)
 {
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->container->get('dao.agent'), $uploadId);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     if (empty($scannerIds)) {
         return;
     }
     $selectedScanners = '{' . implode(',', $scannerIds) . '}';
     $tableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . '.scanner_findings';
     $sql = "SELECT DISTINCT uploadtree_pk,rf_fk FROM {$tableName} ut, license_file\n      WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any(\$1)";
     $param = array($selectedScanners);
     if ($tableName == 'uploadtree_a') {
         $param[] = $uploadId;
         $sql .= " AND upload_fk=\$" . count($param);
         $stmt .= $tableName;
     }
     $sql .= " GROUP BY uploadtree_pk,rf_fk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, $param);
     while ($row = $this->dbManager->fetchArray($res)) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($row['rf_fk']);
         $shortName = $this->licenseMap->getProjectedShortname($reportedLicenseId);
         if ($shortName != 'No_license_found' && $shortName != 'Void') {
             $filesWithLicenses[$row['uploadtree_pk']]['scanner'][] = $shortName;
             $this->includedLicenseIds[$reportedLicenseId] = true;
         }
     }
     $this->dbManager->freeResult($res);
     return "licenseInfoInFile determined by Scanners {$selectedScanners}";
 }
예제 #7
0
 protected function handle(Request $request)
 {
     $vars = array();
     $uploadId = intval($request->get('upload'));
     $uploadTreeId = intval($request->get('item'));
     if (empty($uploadTreeId) || empty($uploadId)) {
         $text = _("Empty Input");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad($vars);
     }
     if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
         $text = _("Permission Denied");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad();
     }
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName);
     if (Isdir($uploadEntry['ufile_mode']) || Iscontainer($uploadEntry['ufile_mode'])) {
         $parent = $this->uploadDao->getUploadParent($uploadEntry['upload_fk']);
         if (!isset($parent)) {
             return $this->responseBad();
         }
         $uploadTree = $this->uploadDao->getNextItem($uploadEntry['upload_fk'], $parent);
         if ($uploadTree === UploadDao::NOT_FOUND) {
             return $this->responseBad();
         }
         $uploadTreeId = $uploadTree->getId();
         return new RedirectResponse(Traceback_uri() . '?mod=' . $this->getName() . Traceback_parm_keep(array('show', 'upload')) . "&item={$uploadTreeId}");
     }
     if (empty($uploadTreeId)) {
         return $this->responseBad('No item selected.');
     }
     $copyrightDecisionMap = $this->decisionTypes->getMap();
     $vars['micromenu'] = Dir2Browse($this->modBack, $uploadTreeId, NULL, $showBox = 0, "View", -1, '', '', $uploadTreeTableName);
     $lastItem = GetParm("lastItem", PARM_INTEGER);
     $changed = GetParm("changedSomething", PARM_STRING);
     $userId = Auth::getUserId();
     if (!empty($lastItem) && $changed == "true") {
         $lastUploadEntry = $this->uploadDao->getUploadEntry($lastItem, $uploadTreeTableName);
         $clearingType = $_POST['clearingTypes'];
         $description = $_POST['description'];
         $textFinding = $_POST['textFinding'];
         $comment = $_POST['comment'];
         $this->copyrightDao->saveDecision($this->decisionTableName, $lastUploadEntry['pfile_fk'], $userId, $clearingType, $description, $textFinding, $comment);
     }
     $scanJobProxy = new ScanJobProxy($this->agentDao, $uploadId);
     $scanJobProxy->createAgentStatus(array($this->agentName));
     $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     $highlights = array();
     if (array_key_exists($this->agentName, $selectedScanners)) {
         $latestXpAgentId = $selectedScanners[$this->agentName];
         $highlights = $this->copyrightDao->getHighlights($uploadTreeId, $this->tableName, $latestXpAgentId, $this->typeToHighlightTypeMap);
     }
     if (count($highlights) < 1) {
         $vars['message'] = _("No ") . $this->tableName . _(" data is available for this file.");
     }
     /* @var $view ui_view */
     $view = plugin_find("view");
     $theView = $view->getView(null, null, $showHeader = 0, "", $highlights, false, true);
     list($pageMenu, $textView) = $theView;
     list($description, $textFinding, $comment, $decisionType) = $this->copyrightDao->getDecision($this->decisionTableName, $uploadEntry['pfile_fk']);
     $vars['description'] = $description;
     $vars['textFinding'] = $textFinding;
     $vars['comment'] = $comment;
     $vars['itemId'] = $uploadTreeId;
     $vars['uploadId'] = $uploadId;
     $vars['pageMenu'] = $pageMenu;
     $vars['textView'] = $textView;
     $vars['legendBox'] = $this->legendBox();
     $vars['uri'] = Traceback_uri() . "?mod=" . $this->Name;
     $vars['optionName'] = $this->optionName;
     $vars['formName'] = "CopyRightForm";
     $vars['ajaxAction'] = $this->ajaxAction;
     $vars['skipOption'] = $this->skipOption;
     $vars['selectedClearingType'] = $decisionType;
     $vars['clearingTypes'] = $copyrightDecisionMap;
     $vars['xptext'] = $this->xptext;
     $agentId = intval($request->get("agent"));
     $vars = array_merge($vars, $this->additionalVars($uploadId, $uploadTreeId, $agentId));
     return $this->render('ui-cp-view.html.twig', $this->mergeWithDefault($vars));
 }
예제 #8
0
 private static function getAgentFilter($options, $uploadId = 0)
 {
     if (!array_key_exists(self::OPT_SKIP_THESE, $options)) {
         return '';
     }
     $skipThese = $options[self::OPT_SKIP_THESE];
     if ($skipThese != "noLicense" && $skipThese != self::OPT_SKIP_ALREADY_CLEARED) {
         return '';
     }
     if (array_key_exists(self::OPT_AGENT_SET, $options)) {
         $agentIds = 'array[' . implode(',', $options[self::OPT_AGENT_SET]) . ']';
         $agentFilter = " AND lf.agent_fk=ANY({$agentIds})";
     } else {
         $scanJobProxy = new ScanJobProxy($GLOBALS['container']->get('dao.agent'), $uploadId);
         $scanJobProxy->createAgentStatus(array('nomos', 'monk', 'ninka'));
         $latestAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
         $agentFilter = $latestAgentIds ? " AND lf.agent_fk=ANY(array[" . implode(',', $latestAgentIds) . "])" : "AND 0=1";
     }
     return $agentFilter;
 }