Ejemplo n.º 1
0
 public function testGetLicenseShortnamesContained()
 {
     $this->testDb->createPlainTables(array('license_ref', 'license_file', 'uploadtree'));
     $this->dbManager->queryOnce("CREATE TABLE \"uploadtree_a\" AS SELECT * FROM uploadtree");
     $this->testDb->createViews(array('license_file_ref'));
     $this->testDb->insertData(array('license_file', 'uploadtree_a'));
     $this->testDb->insertData_license_ref($limit = 3);
     $stmt = __METHOD__ . '.select.license_ref';
     $this->dbManager->prepare($stmt, "SELECT rf_pk,rf_shortname FROM license_ref");
     $licRes = $this->dbManager->execute($stmt);
     $licAll = array();
     while ($erg = $this->dbManager->fetchArray($licRes)) {
         $licAll[$erg['rf_pk']] = $erg['rf_shortname'];
     }
     $this->dbManager->freeResult($licRes);
     $pfileId = 42;
     $agentId = 23;
     $matchPercent = 50;
     $uploadtreeId = 512;
     $uploadId = 123;
     $left = 2009;
     $right = 2014;
     $mydate = "'2014-06-04 14:01:30.551093+02'";
     foreach ($licAll as $licenseRefNumber => $shortname) {
         $this->dbManager->queryOnce("INSERT INTO license_file (rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n            VALUES ({$licenseRefNumber}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})");
     }
     $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n            VALUES ({$uploadtreeId}, {$uploadId}, {$pfileId}, {$left}, {$right})");
     $licDao = new LicenseDao($this->dbManager);
     $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadId, $left, $right);
     $licenses = $licDao->getLicenseShortnamesContained($itemTreeBounds);
     assertThat($licenses, is(arrayContainingInAnyOrder(array_values($licAll))));
     $licensesForBadAgent = $licDao->getLicenseShortnamesContained($itemTreeBounds, array(2 * $agentId));
     assertThat($licensesForBadAgent, is(emptyArray()));
     $licensesForNoAgent = $licDao->getLicenseShortnamesContained($itemTreeBounds, array());
     assertThat($licensesForNoAgent, is(emptyArray()));
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
 }
Ejemplo n.º 2
0
 /**
  * @param array $child
  * @param int $uploadId
  * @param int $selectedAgentId
  * @param array $pfileLicenses
  * @param int $groupId
  * @param string $uri
  * @param array $UniqueTagArray
  * @param boolean $isFlat
  * @param int[] $latestSuccessfulAgentIds
  * @return array
  */
 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
 {
     $fileId = $child['pfile_fk'];
     $childUploadTreeId = $child['uploadtree_pk'];
     $linkUri = '';
     if (!empty($fileId)) {
         $linkUri = Traceback_uri();
         $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}";
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
     }
     /* Determine link for containers */
     $isContainer = Iscontainer($child['ufile_mode']);
     if ($isContainer && !$isFlat) {
         $uploadtree_pk = $child['uploadtree_pk'];
         $linkUri = "{$uri}&item=" . $uploadtree_pk;
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
     } else {
         if ($isContainer) {
             $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId;
             $linkUri = "{$uri}&item=" . $uploadtree_pk;
             if ($selectedAgentId) {
                 $linkUri .= "&agentId={$selectedAgentId}";
             }
         }
     }
     /* Populate the output ($VF) - file list */
     /* id of each element is its uploadtree_pk */
     $fileName = $child['ufile_name'];
     if ($isContainer) {
         $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>";
     } else {
         if (!empty($linkUri)) {
             $fileName = "<a href='{$linkUri}'>{$fileName}</a>";
         }
     }
     /* show licenses under file name */
     $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']);
     $licenseEntries = array();
     if ($isContainer) {
         $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
         $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
     } else {
         if (array_key_exists($fileId, $pfileLicenses)) {
             foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
                 $agentEntries = array();
                 foreach ($rfInfo as $agent => $match) {
                     $agentName = $this->agentNames[$agent];
                     $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>";
                     if ($match['match_percentage'] > 0) {
                         $agentEntry .= ": {$match['match_percentage']}%";
                     }
                     $agentEntries[] = $agentEntry;
                 }
                 $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]";
             }
         }
     }
     $licenseList = implode(', ', $licenseEntries);
     $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat);
     if (!$isContainer) {
         $text = _("Copyright/Email/Url");
         $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=copyright-view&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]";
         $text = _("ReadMe_OSS");
         $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_readmeoss&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]";
         $text = _("SPDX");
         $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_spdx2&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]";
     }
     return array($fileName, $licenseList, $fileListLinks);
 }
Ejemplo n.º 3
0
 /**
  * @param array $child
  * @param int $uploadId
  * @param int $selectedAgentId
  * @param array $pfileLicenses
  * @param int $groupId
  * @param ClearingDecision[][] $editedMappedLicenses
  * @param string $uri
  * @param null|ClearingView $ModLicView
  * @param array $UniqueTagArray
  * @param boolean $isFlat
  * @param int[] $latestSuccessfulAgentIds
  * @return array
  */
 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
 {
     $fileId = $child['pfile_fk'];
     $childUploadTreeId = $child['uploadtree_pk'];
     $linkUri = '';
     if (!empty($fileId) && !empty($ModLicView)) {
         $linkUri = Traceback_uri();
         $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}";
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
     }
     /* Determine link for containers */
     $isContainer = Iscontainer($child['ufile_mode']);
     if ($isContainer && !$isFlat) {
         $fatChild = $this->uploadDao->getFatItemArray($child['uploadtree_pk'], $uploadId, $this->uploadtree_tablename);
         $uploadtree_pk = $fatChild['item_id'];
         $linkUri = "{$uri}&item=" . $uploadtree_pk;
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
         $child['ufile_name'] = $fatChild['ufile_name'];
         if (!Iscontainer($fatChild['ufile_mode'])) {
             $isContainer = false;
         }
     } else {
         if ($isContainer) {
             $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId;
             $linkUri = "{$uri}&item=" . $uploadtree_pk;
             if ($selectedAgentId) {
                 $linkUri .= "&agentId={$selectedAgentId}";
             }
         }
     }
     /* Populate the output ($VF) - file list */
     /* id of each element is its uploadtree_pk */
     $fileName = $child['ufile_name'];
     if ($isContainer) {
         $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>";
     } else {
         if (!empty($linkUri)) {
             $fileName = "<a href='{$linkUri}'>{$fileName}</a>";
         }
     }
     /* show licenses under file name */
     $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']);
     if ($isContainer) {
         $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
         $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
         $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId);
     } else {
         $licenseEntries = array();
         if (array_key_exists($fileId, $pfileLicenses)) {
             foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
                 $agentEntries = array();
                 foreach ($rfInfo as $agent => $match) {
                     $agentName = $this->agentNames[$agent];
                     $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>";
                     if ($match['match_percentage'] > 0) {
                         $agentEntry .= ": {$match['match_percentage']}%";
                     }
                     $agentEntries[] = $agentEntry;
                 }
                 $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]";
             }
         }
         /* @var $decision ClearingDecision */
         if (false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses, $childUploadTreeId, $fileId))) {
             $editedLicenses = $decision->getPositiveLicenses();
         } else {
             $editedLicenses = array();
         }
     }
     $concludedLicenses = array();
     /** @var LicenseRef $licenseRef */
     foreach ($editedLicenses as $licenseRef) {
         $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId());
         $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(), $licenseRef->getShortName());
         $concludedLicenses[$projectedId] = $projectedName;
     }
     $editedLicenseList = implode(', ', $concludedLicenses);
     $licenseList = implode(', ', $licenseEntries);
     $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat);
     $getTextEditUser = _("Edit");
     $fileListLinks .= "[<a href='#' onclick='openUserModal({$childUploadTreeId})' >{$getTextEditUser}</a>]";
     if ($isContainer) {
         $getTextEditBulk = _("Bulk");
         $fileListLinks .= "[<a href='#' onclick='openBulkModal({$childUploadTreeId})' >{$getTextEditBulk}</a>]";
     }
     $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared;
     $img = $filesCleared == $filesToBeCleared ? 'green' : 'red';
     return array($fileName, $licenseList, $editedLicenseList, $img, "{$filesCleared}/{$filesToBeCleared}", $fileListLinks);
 }