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); }
public function testGetSuccessfulAgents() { $otherAgentName = 'drinkMe'; $otherAgentId = 603; $successfulAgents = array($this->agentName => array(new AgentRef($this->agentId, $this->agentName, 'a0815'), new AgentRef($this->agentId - 1, $this->agentName, 'beforeA0815')), $otherAgentName => array(new AgentRef($otherAgentId, $otherAgentName, 'coffee'))); $this->pretendScanAgentStatus($successfulAgents); $expected = array_merge($successfulAgents[$this->agentName], $successfulAgents[$otherAgentName]); $ids = $this->scanJobProxy->getSuccessfulAgents(); assertThat($ids, is(equalTo($expected))); }
/** * \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); }
/** * @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; }
/** * @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}"; }
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)); }
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; }
/** * @param $tagId * @param ItemTreeBounds $itemTreeBounds * @param $UniqueTagArray * @param $selectedAgentId * @param int $groupId * @param ScanJobProxy $scanJobProxy * @return array */ private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy) { if (!empty($selectedAgentId)) { $agentName = $this->agentDao->getAgentName($selectedAgentId); $selectedScanners = array($agentName => $selectedAgentId); } else { $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds(); } /** change the license result when selecting one version of nomos */ $uploadId = $itemTreeBounds->getUploadId(); $isFlat = isset($_GET['flatten']); if ($isFlat) { $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds); } else { $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId()); } $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems'); $vars['iTotalDisplayRecords'] = $descendantView->count(); $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft'); $defaultOrder = array(array(0, "asc")); $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder); $offset = GetParm('iDisplayStart', PARM_INTEGER); $limit = GetParm('iDisplayLength', PARM_INTEGER); if ($offset) { $orderString .= " OFFSET {$offset}"; } if ($limit) { $orderString .= " LIMIT {$limit}"; } /* Get ALL the items under this Uploadtree_pk */ $sql = $descendantView->getDbViewQuery() . " {$orderString}"; $dbManager = $this->getObject('db.manager'); $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql); $res = $dbManager->execute($stmt, $descendantView->getParams()); $descendants = $dbManager->fetchAll($res); $dbManager->freeResult($res); /* Filter out Children that don't have tag */ if (!empty($tagId)) { TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName()); } if (empty($descendants)) { $vars['fileData'] = array(); return $vars; } if ($isFlat) { $firstChild = reset($descendants); $lastChild = end($descendants); $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']); } else { $nameRange = array(); } /******* File Listing ************/ $pfileLicenses = array(); foreach ($selectedScanners as $agentName => $agentId) { $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange); foreach ($licensePerPfile as $pfile => $licenseRow) { foreach ($licenseRow as $licId => $row) { $lic = $this->licenseProjector->getProjectedShortname($licId); $pfileLicenses[$pfile][$lic][$agentName] = $row; } } } $baseUri = Traceback_uri() . '?mod=fileBrowse' . Traceback_parm_keep(array('upload', 'folder', 'show')); $tableData = array(); global $Plugins; $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds(); foreach ($descendants as $child) { if (empty($child)) { continue; } $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds); } $vars['fileData'] = $tableData; return $vars; }
/** * @param $tagId * @param ItemTreeBounds $itemTreeBounds * @param $UniqueTagArray * @param $selectedAgentId * @param int $groupId * @param ScanJobProxy $scanJobProxy * @return array */ private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy) { if (!empty($selectedAgentId)) { $agentName = $this->agentDao->getAgentName($selectedAgentId); $selectedScanners = array($agentName => $selectedAgentId); } else { $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds(); } /** change the license result when selecting one version of nomos */ $uploadId = $itemTreeBounds->getUploadId(); $isFlat = isset($_GET['flatten']); if ($isFlat) { $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds); } else { $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId()); } $searchMap = array(); foreach (explode(' ', GetParm('sSearch', PARM_RAW)) as $pair) { $a = explode(':', $pair); if (count($a) == 1) { $searchMap['head'] = $pair; } else { $searchMap[$a[0]] = $a[1]; } } if (array_key_exists('ext', $searchMap) && strlen($searchMap['ext']) >= 1) { $options[UploadTreeProxy::OPT_EXT] = $searchMap['ext']; } if (array_key_exists('head', $searchMap) && strlen($searchMap['head']) >= 1) { $options[UploadTreeProxy::OPT_HEAD] = $searchMap['head']; } if (($rfId = GetParm('scanFilter', PARM_INTEGER)) > 0) { $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners; $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId; } if (($rfId = GetParm('conFilter', PARM_INTEGER)) > 0) { $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId(); $options[UploadTreeProxy::OPT_CONCLUDE_REF] = $rfId; } $openFilter = GetParm('openCBoxFilter', PARM_RAW); if ($openFilter == 'true' || $openFilter == 'checked') { $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners; $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId(); $options[UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED] = true; } $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems'); $vars['iTotalDisplayRecords'] = $descendantView->count(); $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft'); $defaultOrder = array(array(0, "asc")); $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder); $offset = GetParm('iDisplayStart', PARM_INTEGER); $limit = GetParm('iDisplayLength', PARM_INTEGER); if ($offset) { $orderString .= " OFFSET {$offset}"; } if ($limit) { $orderString .= " LIMIT {$limit}"; } /* Get ALL the items under this Uploadtree_pk */ $sql = $descendantView->getDbViewQuery() . " {$orderString}"; $dbManager = $this->getObject('db.manager'); $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql); $res = $dbManager->execute($stmt, $descendantView->getParams()); $descendants = $dbManager->fetchAll($res); $dbManager->freeResult($res); /* Filter out Children that don't have tag */ if (!empty($tagId)) { TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName()); } if (empty($descendants)) { $vars['fileData'] = array(); return $vars; } if ($isFlat) { $firstChild = reset($descendants); $lastChild = end($descendants); $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']); } else { $nameRange = array(); } /******* File Listing ************/ $pfileLicenses = array(); foreach ($selectedScanners as $agentName => $agentId) { $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange); foreach ($licensePerPfile as $pfile => $licenseRow) { foreach ($licenseRow as $licId => $row) { $lic = $this->licenseProjector->getProjectedShortname($licId); $pfileLicenses[$pfile][$lic][$agentName] = $row; } } } $alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'already_cleared_uploadtree' . $itemTreeBounds->getUploadId()); $alreadyClearedUploadTreeView->materialize(); if (!$isFlat) { $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId()); } else { $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds); } $alreadyClearedUploadTreeView->unmaterialize(); $noLicenseUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense", UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'no_license_uploadtree' . $itemTreeBounds->getUploadId()); $noLicenseUploadTreeView->materialize(); if (!$isFlat) { $this->filesToBeCleared = $noLicenseUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId()); } else { $this->filesToBeCleared = $noLicenseUploadTreeView->getNonArtifactDescendants($itemTreeBounds); } $noLicenseUploadTreeView->unmaterialize(); $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId, $isFlat); $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisions($allDecisions); $baseUri = Traceback_uri() . '?mod=license' . Traceback_parm_keep(array('upload', 'folder', 'show')); $tableData = array(); global $Plugins; $ModLicView =& $Plugins[plugin_find_id("view-license")]; $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds(); foreach ($descendants as $child) { if (empty($child)) { continue; } $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $baseUri, $ModLicView, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds); } $vars['fileData'] = $tableData; return $vars; }