48 const NAME =
"ajax_explorer";
50 private $uploadtree_tablename =
"";
60 private $clearingFilter;
62 private $licenseProjector;
64 private $filesThatShouldStillBeCleared;
66 private $filesToBeCleared;
74 protected $agentNames = AgentRef::AGENT_LIST;
76 public function __construct()
78 parent::__construct(self::NAME, array(
79 self::TITLE => _(
"Ajax: License Browser"),
80 self::DEPENDENCIES => array(
"license"),
82 self::REQUIRES_LOGIN =>
false 85 $this->uploadDao = $this->
getObject(
'dao.upload');
86 $this->licenseDao = $this->
getObject(
'dao.license');
87 $this->clearingDao = $this->
getObject(
'dao.clearing');
88 $this->agentDao = $this->
getObject(
'dao.agent');
89 $this->clearingFilter = $this->
getObject(
'businessrules.clearing_decision_filter');
90 $this->filesThatShouldStillBeCleared = [];
91 $this->filesToBeCleared = [];
92 $this->alreadyClearedUploadTreeView = NULL;
93 $this->noLicenseUploadTreeView = NULL;
96 public function __destruct()
99 if ($this->alreadyClearedUploadTreeView !== NULL) {
100 $this->alreadyClearedUploadTreeView->unmaterialize();
102 if ($this->noLicenseUploadTreeView !== NULL) {
103 $this->noLicenseUploadTreeView->unmaterialize();
111 protected function handle(Request $request)
113 $upload = intval($request->get(
"upload"));
115 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
116 throw new \Exception(
"Permission Denied");
119 $item = intval($request->get(
"item"));
121 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
122 $left = $itemTreeBounds->getLeft();
124 throw new \Exception(
"Job unpack/adj2nest hasn't completed.");
127 $scannerAgents = array_keys($this->agentNames);
128 $scanJobProxy =
new ScanJobProxy($this->agentDao, $upload);
129 $scanJobProxy->createAgentStatus($scannerAgents);
130 $selectedAgentId = intval($request->get(
'agentId'));
131 $tag_pk = intval($request->get(
'tag'));
133 $UniqueTagArray = array();
134 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
135 $vars = $this->
createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
137 return new JsonResponse(array(
138 'sEcho' => intval($request->get(
'sEcho')),
139 'aaData' => $vars[
'fileData'],
140 'iTotalRecords' => intval($request->get(
'totalRecords')),
141 'iTotalDisplayRecords' => $vars[
'iTotalDisplayRecords']
157 if (!empty($selectedAgentId)) {
158 $agentName = $this->agentDao->getAgentName($selectedAgentId);
159 $selectedScanners = array($agentName=>$selectedAgentId);
161 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
166 $isFlat = isset($_GET[
'flatten']);
169 $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
171 $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->
getItemId());
174 $searchMap = array();
176 $a = explode(
':',$pair);
177 if (count($a) == 1) {
178 $searchMap[
'head'] = $pair;
180 $searchMap[$a[0]] = $a[1];
184 if (array_key_exists(
'ext', $searchMap) && strlen($searchMap[
'ext'])>=1) {
185 $options[UploadTreeProxy::OPT_EXT] = $searchMap[
'ext'];
187 if (array_key_exists(
'head', $searchMap) && strlen($searchMap[
'head'])>=1) {
188 $options[UploadTreeProxy::OPT_HEAD] = $searchMap[
'head'];
191 $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
192 $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId;
196 $options[UploadTreeProxy::OPT_CONCLUDE_REF] = $rfId;
199 if ($openFilter==
'true' || $openFilter==
'checked') {
200 $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
202 $options[UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED] =
true;
207 $vars[
'iTotalDisplayRecords'] = $descendantView->
count();
209 $columnNamesInDatabase = array($isFlat?
'ufile_name':
'lft');
210 $defaultOrder = array(array(0,
"asc"));
211 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
216 $orderString .=
" OFFSET $offset";
219 $orderString .=
" LIMIT $limit";
223 $sql = $descendantView->getDbViewQuery().
" $orderString";
224 $dbManager = $this->
getObject(
'db.manager');
226 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
227 $res = $dbManager->execute($stmt,$descendantView->getParams());
228 $descendants = $dbManager->fetchAll($res);
229 $dbManager->freeResult($res);
232 if (!empty($tagId)) {
235 if (empty($descendants)) {
236 $vars[
'fileData'] = array();
241 $firstChild = reset($descendants);
242 $lastChild = end($descendants);
243 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
245 $nameRange = array();
248 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId, $isFlat);
249 $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisions($allDecisions);
252 $isFlat, $groupId, $editedMappedLicenses, $itemTreeBounds, $nameRange);
256 $tableData = array();
258 $ModLicView = &$Plugins[plugin_find_id(
"view-license")];
259 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
260 foreach ($descendants as $child) {
264 $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $baseUri, $ModLicView, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
267 $vars[
'fileData'] = $tableData;
286 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
288 $fileId = $child[
'pfile_fk'];
289 $childUploadTreeId = $child[
'uploadtree_pk'];
291 if (!empty($fileId) && !empty($ModLicView)) {
293 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
294 if ($selectedAgentId) {
295 $linkUri .=
"&agentId=$selectedAgentId";
301 if ($isContainer && !$isFlat) {
302 $fatChild = $this->uploadDao->getFatItemArray($child[
'uploadtree_pk'], $uploadId, $this->
uploadtree_tablename);
303 $uploadtree_pk = $fatChild[
'item_id'];
304 $childUploadTreeId = $uploadtree_pk;
306 $fileId = $upload[
'pfile_fk'];
307 $parent = $upload[
'realparent'];
308 $parentItemTreeBound = $this->uploadDao->getItemTreeBounds($parent, $this->
uploadtree_tablename);
310 $pfileLicenses = array_replace($pfileLicenses,
312 $groupId, $editedMappedLicenses, $parentItemTreeBound));
314 $linkUri =
"$uri&item=" . $uploadtree_pk;
315 if ($selectedAgentId) {
316 $linkUri .=
"&agentId=$selectedAgentId";
318 $child[
'ufile_name'] = $fatChild[
'ufile_name'];
320 $isContainer =
false;
322 }
else if ($isContainer) {
324 $linkUri =
"$uri&item=" . $uploadtree_pk;
325 if ($selectedAgentId) {
326 $linkUri .=
"&agentId=$selectedAgentId";
332 $fileName = $child[
'ufile_name'];
334 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
335 }
else if (!empty($linkUri)) {
336 $fileName =
"<a href='$linkUri'>$fileName</a>";
339 $childItemTreeBounds =
342 $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
343 $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
344 $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId);
346 $licenseEntries = array();
347 if (array_key_exists($fileId, $pfileLicenses)) {
348 foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
349 $agentEntries = array();
350 foreach ($rfInfo as $agent => $match) {
351 $agentName = $this->agentNames[$agent];
352 $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>";
354 if ($match[
'match_percentage'] > 0) {
355 $agentEntry .=
": $match[match_percentage]%";
357 $agentEntries[] = $agentEntry;
359 $licenseEntries[] = $shortName .
" [" . implode(
"][", $agentEntries) .
"]";
364 if (
false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses,$childUploadTreeId, $fileId))) {
365 $editedLicenses = $decision->getPositiveLicenses();
367 $editedLicenses = array();
371 $concludedLicenses = array();
373 foreach ($editedLicenses as $licenseRef) {
374 $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId());
375 $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(),$licenseRef->getShortName());
376 $concludedLicenses[$projectedId] = $projectedName;
379 $editedLicenseList = implode(
', ', $concludedLicenses);
380 $licenseList = implode(
', ', $licenseEntries);
384 $getTextEditUser = _(
"Edit");
385 $fileListLinks .=
"[<a href='#' onclick='openUserModal($childUploadTreeId)' >$getTextEditUser</a>]";
388 $getTextEditBulk = _(
"Bulk");
389 $fileListLinks .=
"[<a href='#' onclick='openBulkModal($childUploadTreeId)' >$getTextEditBulk</a>]";
391 $fileListLinks .=
"<input type='checkbox' id='selectedForIrrelevant' value='".$childUploadTreeId.
"'>";
392 $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId()
393 , $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0;
395 $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId()
396 , $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0;
398 $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared;
400 $img = ($filesCleared == $filesToBeCleared) ?
'green' :
'red';
403 if (!empty($licenseList) && empty($editedLicenseList)) {
405 (strpos($licenseList, LicenseDao::NO_LICENSE_FOUND) !==
false)
407 (count(explode(
",", $licenseList)) == 1)
412 $isDecisionTBD = $this->clearingDao->isDecisionTBD($childUploadTreeId, $groupId);
413 $img = $isDecisionTBD ?
'yellow' : $img;
416 $isDecisionDNU = $this->clearingDao->isDecisionDNU($childUploadTreeId, $groupId);
417 $img = $isDecisionDNU ?
'redGreen' : $img;
419 return array($fileName, $licenseList, $editedLicenseList, $img,
"$filesCleared/$filesToBeCleared", $fileListLinks);
435 &$editedMappedLicenses, $itemTreeBounds, $nameRange = array())
441 foreach ($agentIds as $agentName => $agentId) {
442 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId(
443 $itemTreeBounds, $agentId, $isFlat, $nameRange);
444 foreach ($licensePerPfile as $pfile => $licenseRow) {
445 foreach ($licenseRow as $licId => $row) {
446 $lic = $this->licenseProjector->getProjectedShortname($licId);
447 $pfileLicenses[$pfile][$lic][$agentName] = $row;
452 if ($this->alreadyClearedUploadTreeView === NULL) {
455 $itemTreeBounds->getUploadId(),
457 UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED,
458 UploadTreeProxy::OPT_ITEM_FILTER =>
"AND (lft BETWEEN " .
459 $itemTreeBounds->getLeft() .
" AND " . $itemTreeBounds->getRight() .
")",
460 UploadTreeProxy::OPT_GROUP_ID => $groupId
461 ), $itemTreeBounds->getUploadTreeTableName(),
462 $viewName =
'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
464 $this->alreadyClearedUploadTreeView->
materialize();
468 $this->filesThatShouldStillBeCleared = array_replace(
469 $this->filesThatShouldStillBeCleared,
470 $this->alreadyClearedUploadTreeView->countMaskedNonArtifactChildren(
471 $itemTreeBounds->getItemId()));
473 $this->filesThatShouldStillBeCleared = array_replace(
474 $this->filesThatShouldStillBeCleared,
475 $this->alreadyClearedUploadTreeView->getNonArtifactDescendants(
479 if ($this->noLicenseUploadTreeView === NULL) {
482 $itemTreeBounds->getUploadId(),
484 UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
485 UploadTreeProxy::OPT_ITEM_FILTER =>
"AND (lft BETWEEN " .
486 $itemTreeBounds->getLeft() .
" AND " . $itemTreeBounds->getRight() .
")",
487 UploadTreeProxy::OPT_GROUP_ID => $groupId
488 ), $itemTreeBounds->getUploadTreeTableName(),
489 $viewName =
'no_license_uploadtree' . $itemTreeBounds->getUploadId());
493 $this->filesToBeCleared = array_replace($this->filesToBeCleared,
494 $this->noLicenseUploadTreeView->countMaskedNonArtifactChildren(
495 $itemTreeBounds->getItemId()));
497 $this->filesToBeCleared = array_replace($this->filesToBeCleared,
498 $this->noLicenseUploadTreeView->getNonArtifactDescendants($itemTreeBounds));
501 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
503 $editedMappedLicenses = array_replace($editedMappedLicenses,
504 $this->clearingFilter->filterCurrentClearingDecisions($allDecisions));
505 return $pfileLicenses;
Traceback_uri()
Get the URI without query to this location.
updateTheFindingsAndDecisions($agentIds, $isFlat, $groupId, &$editedMappedLicenses, $itemTreeBounds, $nameRange=array())
Fetch the license findings and decisions.
$alreadyClearedUploadTreeView
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
Wrapper class for license map.
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk)...
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
char * uploadtree_tablename
upload.uploadtree_tablename
createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
static getGroupId()
Get the current user's group id.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
materialize()
create temp table