29 use Symfony\Component\HttpFoundation\JsonResponse;
30 use Symfony\Component\HttpFoundation\Request;
31 use Symfony\Component\HttpFoundation\Response;
40 const NAME =
"ajax_explorer";
42 private $uploadtree_tablename =
"";
46 private $compatibilityDao;
54 private $clearingFilter;
56 private $licenseProjector;
58 private $filesThatShouldStillBeCleared;
60 private $filesToBeCleared;
68 protected $agentNames = AgentRef::AGENT_LIST;
73 public function __construct()
75 parent::__construct(self::NAME, array(
76 self::TITLE => _(
"Ajax: License Browser"),
77 self::DEPENDENCIES => array(
"license"),
79 self::REQUIRES_LOGIN =>
false
82 $this->uploadDao = $this->
getObject(
'dao.upload');
83 $this->compatibilityDao = $this->
getObject(
'dao.compatibility');
84 $this->licenseDao = $this->
getObject(
'dao.license');
85 $this->clearingDao = $this->
getObject(
'dao.clearing');
86 $this->agentDao = $this->
getObject(
'dao.agent');
87 $this->clearingFilter = $this->
getObject(
'businessrules.clearing_decision_filter');
88 $this->filesThatShouldStillBeCleared = [];
89 $this->filesToBeCleared = [];
90 $this->alreadyClearedUploadTreeView = NULL;
91 $this->noLicenseUploadTreeView = NULL;
92 $this->cacheClearedCounter = [];
95 public function __destruct()
98 if ($this->alreadyClearedUploadTreeView !== NULL) {
99 $this->alreadyClearedUploadTreeView->unmaterialize();
101 if ($this->noLicenseUploadTreeView !== NULL) {
102 $this->noLicenseUploadTreeView->unmaterialize();
112 $upload = intval($request->get(
"upload"));
114 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
115 throw new \Exception(
"Permission Denied");
118 $item = intval($request->get(
"item"));
121 $left = $itemTreeBounds->getLeft();
123 throw new \Exception(
"Job unpack/adj2nest hasn't completed.");
126 $scannerAgents = array_keys($this->agentNames);
127 $scanJobProxy =
new ScanJobProxy($this->agentDao, $upload);
128 $scanJobProxy->createAgentStatus($scannerAgents);
129 $selectedAgentId = intval($request->get(
'agentId'));
130 $tag_pk = intval($request->get(
'tag'));
132 $UniqueTagArray = array();
133 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
134 $vars = $this->
createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy, $request);
136 return new JsonResponse(array(
137 'sEcho' => intval($request->get(
'sEcho')),
138 'aaData' => $vars[
'fileData'],
139 'iTotalRecords' => intval($request->get(
'totalRecords')),
140 'iTotalDisplayRecords' => $vars[
'iTotalDisplayRecords']
157 if (!empty($selectedAgentId)) {
158 $agentName = $this->agentDao->getAgentName($selectedAgentId);
159 $selectedScanners = array($agentName=>$selectedAgentId);
161 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
166 $isFlat = $request->get(
'flatten') !==
null;
169 $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
171 $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->
getItemId());
174 $searchMap = array();
175 foreach (explode(
' ',$request->get(
'sSearch')) as $pair) {
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'];
190 if (($rfId=$request->get(
'scanFilter'))>0) {
191 $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
192 $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId;
194 if (($rfId=$request->get(
'conFilter'))>0) {
196 $options[UploadTreeProxy::OPT_CONCLUDE_REF] = $rfId;
198 $openFilter = $request->get(
'openCBoxFilter');
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"));
212 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($request->get(
'fromRest') ? $request->request->all(): $request->query->all(), $columnNamesInDatabase, $defaultOrder);
214 $offset = $request->get(
'iDisplayStart');
215 $limit = $request->get(
'iDisplayLength');
217 $orderString .=
" OFFSET $offset";
220 $orderString .=
" LIMIT $limit";
224 $sql = $descendantView->getDbViewQuery().
" $orderString";
225 $dbManager = $this->
getObject(
'db.manager');
227 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
228 $res = $dbManager->execute($stmt,$descendantView->getParams());
229 $descendants = $dbManager->fetchAll($res);
230 $dbManager->freeResult($res);
233 if (!empty($tagId)) {
236 if (empty($descendants)) {
237 $vars[
'fileData'] = array();
242 $firstChild = reset($descendants);
243 $lastChild = end($descendants);
244 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
246 $nameRange = array();
249 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId, $isFlat);
250 $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisions($allDecisions);
253 $isFlat, $groupId, $editedMappedLicenses, $itemTreeBounds, $nameRange);
257 $tableData = array();
259 $ModLicView = &$Plugins[plugin_find_id(
"view-license")];
260 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
261 foreach ($descendants as $child) {
265 $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $baseUri, $ModLicView, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds, $request);
268 $vars[
'fileData'] = $tableData;
288 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds, $request)
290 $fileDetails = array(
291 "fileName" =>
"",
"id" =>
"",
"uploadId" => $uploadId,
"agentId" =>
"",
"isContainer" =>
false,
294 $fileId = $child[
'pfile_fk'];
295 $childUploadTreeId = $child[
'uploadtree_pk'];
297 if (!empty($fileId) && !empty($ModLicView)) {
299 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
300 $fileDetails[
"id"] = intval($childUploadTreeId);
301 $fileDetails[
"uploadId"] = $uploadId;
302 if ($selectedAgentId) {
303 $linkUri .=
"&agentId=$selectedAgentId";
304 $fileDetails[
"agentId"] = $selectedAgentId;
310 if ($isContainer && !$isFlat) {
311 $fatChild = $this->uploadDao->getFatItemArray($child[
'uploadtree_pk'], $uploadId, $this->
uploadtree_tablename);
312 $uploadtree_pk = $fatChild[
'item_id'];
313 $childUploadTreeId = $uploadtree_pk;
315 $fileId = $upload[
'pfile_fk'];
316 $parent = $upload[
'realparent'];
317 $parentItemTreeBound = $this->uploadDao->getItemTreeBounds($parent, $this->
uploadtree_tablename);
319 $pfileLicenses = array_replace($pfileLicenses,
321 $groupId, $editedMappedLicenses, $parentItemTreeBound));
323 $linkUri =
"$uri&item=" . $uploadtree_pk;
324 $fileDetails[
"id"] = intval($uploadtree_pk);
325 if ($selectedAgentId) {
326 $linkUri .=
"&agentId=$selectedAgentId";
327 $fileDetails[
"agentId"] = $selectedAgentId;
329 $child[
'ufile_name'] = $fatChild[
'ufile_name'];
331 $isContainer =
false;
333 }
else if ($isContainer) {
335 $linkUri =
"$uri&item=" . $uploadtree_pk;
336 $fileDetails[
"id"] = intval($uploadtree_pk);
337 $fileDetails[
"isContainer"] =
true;
338 if ($selectedAgentId) {
339 $linkUri .=
"&agentId=$selectedAgentId";
340 $fileDetails[
"agentId"] = $selectedAgentId;
346 $fileName = $child[
'ufile_name'];
348 $fileDetails[
"fileName"] = $fileName;
349 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
350 }
else if (!empty($linkUri)) {
351 $fileDetails[
"fileName"] = $fileName;
352 $fileName =
"<a href='$linkUri'>$fileName</a>";
355 $childItemTreeBounds =
356 new ItemTreeBounds($childUploadTreeId, $this->
uploadtree_tablename, $child[
'upload_fk'], $child[
'lft'], $child[
'rgt']);
357 $totalFilesCount = $this->uploadDao->countPlainFiles($childItemTreeBounds);
358 $licenseEntriesRest = array();
360 $fileDetails[
"isContainer"] =
true;
361 $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
362 $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
363 $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId);
365 if ($request->get(
'fromRest')) {
366 foreach ($licenseEntries as $shortName) {
367 $lookedupLicense = $this->licenseDao->getLicenseByShortName($shortName, $groupId);
368 if ($lookedupLicense !==
null) {
369 $licenseEntriesRest[] = array(
370 "id" => $lookedupLicense->getId(),
371 "name" => $shortName,
378 $licenseEntries = array();
379 if (array_key_exists($fileId, $pfileLicenses)) {
380 foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
381 $agentEntries = array();
382 $agentEntriesRest = array();
383 foreach ($rfInfo as $agent => $match) {
384 $agentName = $this->agentNames[$agent];
385 $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>";
387 if ($match[
'match_percentage'] > 0) {
388 $agentEntry .=
": $match[match_percentage]%";
390 $agentEntries[] = $agentEntry;
391 $agentEntriesRest[] = array(
392 "name" => $agentName,
393 "id" => intval($match[
'agent_id']),
394 "matchPercentage" => intval($match[
'match_percentage']),
398 $lookedupLicense = $this->licenseDao->getLicenseByShortName($shortName, $groupId);
399 if ($lookedupLicense !==
null) {
400 $licenseEntriesRest[] = array(
401 "id" => $lookedupLicense->getId(),
402 "name" => $shortName,
403 "agents" => $agentEntriesRest,
409 $compatible = $this->compatibilityDao->getCompatibilityForFile($childItemTreeBounds, $shortName);
410 }
catch (InvalidAgentStageException) {
415 $licenseHtml =
"<span class='text-danger font-weight-bold'>$shortName</span>";
417 $licenseHtml = $shortName;
419 $licenseEntries[] =
"$licenseHtml [" . implode(
"][", $agentEntries) .
"]";
424 if (
false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses,$childUploadTreeId, $fileId))) {
425 $editedLicenses = $decision->getPositiveLicenses();
427 $editedLicenses = array();
430 $concludedLicensesRest = array();
431 $concludedLicenses = array();
433 foreach ($editedLicenses as $licenseRef) {
434 $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId());
435 $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(),$licenseRef->getShortName());
436 $concludedLicenses[$projectedId] = $projectedName;
437 $concludedLicensesRest[] = array(
'id' => $projectedId,
'name' => $projectedName);
440 $editedLicenseList = implode(
', ', $concludedLicenses);
441 $licenseList = implode(
', ', $licenseEntries);
445 $getTextEditUser = _(
"Edit");
446 $fileListLinks .=
"[<a href='#' onclick='openUserModal($childUploadTreeId)' >$getTextEditUser</a>]";
449 $getTextEditBulk = _(
"Bulk");
450 $fileListLinks .=
"[<a href='#' data-toggle='modal' data-target='#bulkModal' onclick='openBulkModal($childUploadTreeId)' >$getTextEditBulk</a>]";
452 $fileListLinks .=
"<input type='checkbox' class='selectedForIrrelevant' class='info-bullet view-license-rc-size' value='".$childUploadTreeId.
"'>";
453 $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId()
454 , $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0;
456 $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId()
457 , $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0;
459 $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared;
461 $img = ($filesCleared == $filesToBeCleared) ?
'green' :
'red';
464 if (!empty($licenseList) && empty($editedLicenseList)) {
466 (strpos($licenseList, LicenseDao::NO_LICENSE_FOUND) !==
false)
468 (count(explode(
",", $licenseList)) == 1)
473 $isDecisionTBD = $this->clearingDao->isDecisionCheck($childUploadTreeId, $groupId, DecisionTypes::TO_BE_DISCUSSED);
474 $img = $isDecisionTBD ?
'yellow' : $img;
477 $isDecisionDNU = $this->clearingDao->isDecisionCheck($childUploadTreeId, $groupId, DecisionTypes::DO_NOT_USE);
478 $isDecisionNonFunctional = $this->clearingDao->isDecisionCheck($childUploadTreeId, $groupId, DecisionTypes::NON_FUNCTIONAL);
480 $img = ($isDecisionDNU || $isDecisionNonFunctional) ?
'redGreen' : $img;
482 return $request->get(
'fromRest') ? array(
483 "fileDetails" => $fileDetails,
484 "licenseList" => $licenseEntriesRest,
485 "editedLicenseList" => $concludedLicensesRest,
486 "clearingStatus" => $img,
487 "clearingProgress" => array(
488 "filesCleared" => intval($filesCleared),
489 "filesToBeCleared" => intval($filesToBeCleared),
490 "totalFilesCount" => intval($totalFilesCount)
492 ) : array($fileName, $licenseList, $editedLicenseList, $img,
"$filesCleared / $filesToBeCleared / $totalFilesCount", $fileListLinks);
508 &$editedMappedLicenses, $itemTreeBounds, $nameRange = array())
514 foreach ($agentIds as $agentName => $agentId) {
515 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId(
516 $itemTreeBounds, $agentId, $isFlat, $nameRange);
517 foreach ($licensePerPfile as $pfile => $licenseRow) {
518 foreach ($licenseRow as $licId => $row) {
519 $lic = $this->licenseProjector->getProjectedShortname($licId);
520 $pfileLicenses[$pfile][$lic][$agentName] = $row;
525 if ($this->alreadyClearedUploadTreeView === NULL) {
528 $itemTreeBounds->getUploadId(),
530 UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED,
531 UploadTreeProxy::OPT_ITEM_FILTER =>
"AND (lft BETWEEN " .
532 $itemTreeBounds->getLeft() .
" AND " . $itemTreeBounds->getRight() .
")",
533 UploadTreeProxy::OPT_GROUP_ID => $groupId
534 ), $itemTreeBounds->getUploadTreeTableName(),
535 $viewName =
'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
537 $this->alreadyClearedUploadTreeView->materialize();
540 if ($this->noLicenseUploadTreeView === NULL) {
543 $itemTreeBounds->getUploadId(),
545 UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
546 UploadTreeProxy::OPT_ITEM_FILTER =>
"AND (lft BETWEEN " .
547 $itemTreeBounds->getLeft() .
" AND " . $itemTreeBounds->getRight() .
")",
548 UploadTreeProxy::OPT_GROUP_ID => $groupId
549 ), $itemTreeBounds->getUploadTreeTableName(),
550 $viewName =
'no_license_uploadtree' . $itemTreeBounds->getUploadId());
551 $this->noLicenseUploadTreeView->materialize();
555 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
557 $editedMappedLicenses = array_replace($editedMappedLicenses,
558 $this->clearingFilter->filterCurrentClearingDecisions($allDecisions));
559 return $pfileLicenses;
570 $itemId = $itemTreeBounds->getItemId();
571 if (in_array($itemId, $this->cacheClearedCounter)) {
575 $this->cacheClearedCounter[] = $itemId;
577 $this->filesThatShouldStillBeCleared = array_replace(
578 $this->filesThatShouldStillBeCleared,
579 $this->alreadyClearedUploadTreeView->countMaskedNonArtifactChildren(
581 $this->filesToBeCleared = array_replace($this->filesToBeCleared,
582 $this->noLicenseUploadTreeView->countMaskedNonArtifactChildren(
585 $this->filesThatShouldStillBeCleared = array_replace(
586 $this->filesThatShouldStillBeCleared,
587 $this->alreadyClearedUploadTreeView->getNonArtifactDescendants(
589 $this->filesToBeCleared = array_replace($this->filesToBeCleared,
590 $this->noLicenseUploadTreeView->getNonArtifactDescendants($itemTreeBounds));
595 register_plugin(
new AjaxExplorer());
char * uploadtree_tablename
upload.uploadtree_tablename
Contains the constants and helpers for authentication of user.
static getGroupId()
Get the current user's group id.
Various utility functions to filter ClearingDecision.
Wrapper class for license map.
Exception when an agent's stage is invalid.
updateTheFindingsAndDecisions($agentIds, $isFlat, $groupId, &$editedMappedLicenses, $itemTreeBounds, $nameRange=array())
Fetch the license findings and decisions.
updateFilesToBeCleared($isFlat, $itemTreeBounds)
$alreadyClearedUploadTreeView
createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy, $request)
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk).
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
Traceback_uri()
Get the URI without query to this location.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.