Skip to content

Commit

Permalink
Merge pull request #29 from wuan/license_count_fix
Browse files Browse the repository at this point in the history
fix #27 by only counting latest agent versions
  • Loading branch information
Bob Gobeille committed Dec 4, 2014
2 parents 6950875 + 498881a commit ee3d71e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
28 changes: 20 additions & 8 deletions src/lib/php/Dao/LicenseDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public function getLicenseRefs()
public function getTopLevelLicensesPerFileId(FileTreeBounds $fileTreeBounds, $selectedAgentId = null, $filterLicenses = array('VOID'))//'No_license_found',
{
$uploadTreeTableName = $fileTreeBounds->getUploadTreeTableName();
$statementName = __METHOD__ . '.' . $uploadTreeTableName.implode("",$filterLicenses);
$selectedAgentText = $selectedAgentId ?: '-';
$statementName = __METHOD__ . '.' . $uploadTreeTableName . '.' . $selectedAgentText . '.' . implode("",$filterLicenses);
$param = array($fileTreeBounds->getUploadTreeId());

$noLicenseFoundStmt = empty($filterLicenses) ? "" : " AND rf_shortname NOT IN ("
Expand Down Expand Up @@ -159,14 +160,20 @@ public function getTopLevelLicensesPerFileId(FileTreeBounds $fileTreeBounds, $se
return $licensesPerFileId;
}


/**
* @param FileTreeBounds $fileTreeBounds
* @param string $orderStatement
* @param null|int|int[] $agentId
* @return array
*/
public function getLicenseHistogram(FileTreeBounds $fileTreeBounds, $orderStatement = "", $agentId=null)
{
$uploadTreeTableName = $fileTreeBounds->getUploadTreeTableName();
$statementName = __METHOD__ . '.' . $uploadTreeTableName . ".$orderStatement.$agentId";
$agentText = $agentId ? (is_array($agentId) ? implode(',', $agentId) : $agentId) : '-';
$statementName = __METHOD__ . '.' . $uploadTreeTableName . ".$orderStatement.$agentText";
$param = array($fileTreeBounds->getUploadId(), $fileTreeBounds->getLeft(), $fileTreeBounds->getRight());
$sql = "
SELECT LFR.rf_shortname AS license_shortname, count(*) AS count
SELECT LFR.rf_shortname AS license_shortname, count(*) AS count, count(distinct LFR.pfile_fk) AS unique
FROM license_file_ref LFR RIGHT JOIN $uploadTreeTableName UT ON LFR.pfile_fk = UT.pfile_fk ";
if (empty($agentId))
{
Expand All @@ -177,8 +184,13 @@ public function getLicenseHistogram(FileTreeBounds $fileTreeBounds, $orderStatem

if (!empty($agentId))
{
$sql .= ' AND LFR.agent_fk=$4';
$param[] = $agentId;
if (is_array($agentId)) {
$sql .= ' AND LFR.agent_fk=ANY($4)';
$param[] = '{' . implode(',', $agentId) . '}';
} else {
$sql .= ' AND LFR.agent_fk=$4';
$param[] = $agentId;
}
} else {
$sql .= ' AND LFR2.agent_fk IS NOT NULL';
}
Expand All @@ -190,9 +202,9 @@ public function getLicenseHistogram(FileTreeBounds $fileTreeBounds, $orderStatem
$this->dbManager->prepare($statementName, $sql);
$result = $this->dbManager->execute($statementName,$param);
$assocLicenseHist = array();
while ($res = $this->dbManager->fetchArray($result))
while ($row = $this->dbManager->fetchArray($result))
{
$assocLicenseHist[$res['license_shortname']] = $res['count'];
$assocLicenseHist[$row['license_shortname']] = array('count' => intval($row['count']), 'unique' => intval($row['unique']));
}
$this->dbManager->freeResult($result);
return $assocLicenseHist;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/php/View/LicenseRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function createLicenseHistogramJSarray($scannerLics, $editedLics, $upload

if (array_key_exists($licenseShortName, $scannerLics))
{
$count = $scannerLics[$licenseShortName];
$count = $scannerLics[$licenseShortName]['count'];
} else
{
$count = 0;
Expand Down
9 changes: 6 additions & 3 deletions src/www/ui/ui-browse-license.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function ShowUploadHist($Uploadtree_pk, $Uri, $tag_pk)



list($V, $allScans) = $this->createHeader($scannerAgents, $uploadId);
list($V, $allScans, $latestAgentIds) = $this->createHeader($scannerAgents, $uploadId);

if (empty($allScans))
{
Expand All @@ -189,7 +189,7 @@ function ShowUploadHist($Uploadtree_pk, $Uri, $tag_pk)

$selectedAgentId = GetParm('agentId', PARM_INTEGER);
$licenseCandidates = $this->clearingDao->getFileClearingsFolder($fileTreeBounds);
list($jsBlockLicenseHist, $VLic) = $this->createLicenseHistogram($Uploadtree_pk, $tag_pk, $fileTreeBounds, $selectedAgentId, $licenseCandidates);
list($jsBlockLicenseHist, $VLic) = $this->createLicenseHistogram($Uploadtree_pk, $tag_pk, $fileTreeBounds, $selectedAgentId ?: $latestAgentIds, $licenseCandidates);
list($ChildCount, $jsBlockDirlist, $AddInfoText) = $this->createFileListing($Uri, $tag_pk, $fileTreeBounds, $ModLicView, $UniqueTagArray, $selectedAgentId, $licenseCandidates);

/***************************************
Expand Down Expand Up @@ -677,6 +677,7 @@ private function handleAllScansEmpty($scannerAgents, $uploadId)
*/
private function createHeader($scannerAgents, $uploadId)
{
$latestAgentIds = array();
$allScans = array();
$V = ""; // total return value
foreach ($scannerAgents as $agentName)
Expand Down Expand Up @@ -741,9 +742,11 @@ private function createHeader($scannerAgents, $uploadId)
}
$V .= $this->scheduleScan($uploadId, $agentName, sprintf(_("Schedule %s scan"), $agentName));
}

$latestAgentIds[$agentName] = intval($latestRun['agent_pk']);
$V .= '<br/>';
}
return array($V, $allScans);
return array($V, $allScans, $latestAgentIds);
}

}
Expand Down

0 comments on commit ee3d71e

Please sign in to comment.