예제 #1
0
 public function testMainLicenseIds()
 {
     $this->testDb->createPlainTables(array('upload_clearing_license'));
     $uploadId = 101;
     $mainLicIdsInitially = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsInitially, is(emptyArray()));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId = 402);
     $mainLicIdsAfterAddingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOne, arrayContaining(array($licenseId)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId);
     $mainLicIdsAfterAddingOneTwice = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOneTwice, is(arrayWithSize(1)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId2 = 403);
     $mainLicIdsAfterAddingOther = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOther, arrayContainingInAnyOrder(array($licenseId, $licenseId2)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdsAfterRemovingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterRemovingOne, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdAfterRemovingSomethingNotInSet = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterRemovingSomethingNotInSet, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId + 1, $licenseId);
     $mainLicIdAfterInsertToOtherGroup = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherGroup, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId + 1, $this->groupId, $licenseId);
     $mainLicIdAfterInsertToOtherUpload = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherUpload, is(arrayWithSize(1)));
 }
예제 #2
0
파일: spdx2.php 프로젝트: rlintu/fossology
 /**
  * @param int $uploadId
  * @return string
  */
 protected function renderPackage($uploadId)
 {
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $this->heartbeat(0);
     $filesWithLicenses = $this->getFilesWithLicensesFromClearings($itemTreeBounds);
     $this->heartbeat(0);
     $this->addClearingStatus($filesWithLicenses, $itemTreeBounds);
     $this->heartbeat(0);
     $licenseComment = $this->addScannerResults($filesWithLicenses, $itemTreeBounds);
     $this->heartbeat(0);
     $this->addCopyrightResults($filesWithLicenses, $uploadId);
     $this->heartbeat(0);
     $upload = $this->uploadDao->getUpload($uploadId);
     $fileNodes = $this->generateFileNodes($filesWithLicenses, $upload->getTreeTableName());
     $mainLicenseIds = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     $mainLicenses = array();
     foreach ($mainLicenseIds as $licId) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($licId);
         $this->includedLicenseIds[$reportedLicenseId] = true;
         $mainLicenses[] = $this->licenseMap->getProjectedShortname($reportedLicenseId);
     }
     $hashes = $this->uploadDao->getUploadHashes($uploadId);
     return $this->renderString($this->getTemplateFile('package'), array('uploadId' => $uploadId, 'uri' => $this->uri, 'packageName' => $upload->getFilename(), 'uploadName' => $upload->getFilename(), 'sha1' => $hashes['sha1'], 'md5' => $hashes['md5'], 'verificationCode' => $this->getVerificationCode($upload), 'mainLicenses' => $mainLicenses, 'mainLicense' => SpdxTwoUtils::implodeLicenses($mainLicenses, "LicenseRef-"), 'licenseComments' => $licenseComment, 'fileNodes' => $fileNodes));
 }
예제 #3
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param boolean $orderAscending
  * @return array
  */
 protected function getCurrentSelectedLicensesTableData(ItemTreeBounds $itemTreeBounds, $groupId, $orderAscending)
 {
     $uploadTreeId = $itemTreeBounds->getItemId();
     $uploadId = $itemTreeBounds->getUploadId();
     $uberUri = Traceback_uri() . "?mod=view-license" . Traceback_parm_keep(array('upload', 'folder'));
     list($addedClearingResults, $removedLicenses) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
     $licenseEventTypes = new ClearingEventTypes();
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $table = array();
     /* @var $clearingResult ClearingResult */
     foreach ($addedClearingResults as $licenseShortName => $clearingResult) {
         $licenseId = $clearingResult->getLicenseId();
         $types = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
         $reportInfo = "";
         $comment = "";
         if ($clearingResult->hasClearingEvent()) {
             $licenseDecisionEvent = $clearingResult->getClearingEvent();
             $types[] = $this->getEventInfo($licenseDecisionEvent, $uberUri, $uploadTreeId, $licenseEventTypes);
             $reportInfo = $licenseDecisionEvent->getReportinfo();
             $comment = $licenseDecisionEvent->getComment();
         }
         $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
         $actionLink = "<a href=\"javascript:;\" onclick=\"removeLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></a>";
         if (in_array($clearingResult->getLicenseId(), $mainLicIds)) {
             $tooltip = _('This is a main license for the upload. Click to discard selection.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"removeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_filled_16.png\" alt=\"mainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         } else {
             $tooltip = _('Click to select this as a main license for the upload.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"makeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_16.png\" alt=\"noMainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         }
         $reportInfoField = nl2br(htmlspecialchars($reportInfo));
         $commentField = nl2br(htmlspecialchars($comment));
         $id = "{$uploadTreeId},{$licenseId}";
         $table[$licenseShortName] = array('DT_RowId' => $id, '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $types), '2' => $reportInfoField, '3' => $commentField, '4' => $actionLink);
     }
     foreach ($removedLicenses as $licenseShortName => $clearingResult) {
         if ($clearingResult->getAgentDecisionEvents()) {
             $agents = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
             $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
             $licenseId = $clearingResult->getLicenseId();
             $actionLink = "<a href=\"javascript:;\" onclick=\"addLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"add\" src=\"images/space_16.png\" alt=\"\"/></a>";
             $filled = in_array($clearingResult->getLicenseId(), $mainLicIds) ? 'filled_' : '';
             $actionLink .= ' <img src="images/icons/star_' . $filled . '16.png" alt="mainLicense"/>';
             $idArray = array($uploadTreeId, $licenseId);
             $id = implode(',', $idArray);
             $table[$licenseShortName] = array('DT_RowId' => $id, 'DT_RowClass' => 'removed', '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $agents), '2' => "-", '3' => "-", '4' => $actionLink);
         }
     }
     $valueTable = array_values($this->sortByKeys($table, $orderAscending));
     return $valueTable;
 }
 protected function getStatements($uploadId, $uploadTreeTableName, $groupId = null)
 {
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
     $dbManager = $GLOBALS['container']->get('db.manager');
     $licenseMap = new LicenseMap($dbManager, $groupId, LicenseMap::REPORT);
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $ungroupedStatements = array();
     foreach ($clearingDecisions as $clearingDecision) {
         if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
             continue;
         }
         /** @var ClearingDecision $clearingDecision */
         foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
             if ($clearingLicense->isRemoved()) {
                 continue;
             }
             if ($this->onlyComments && !($comment = $clearingLicense->getComment())) {
                 continue;
             }
             $originLicenseId = $clearingLicense->getLicenseId();
             $licenseId = $licenseMap->getProjectedId($originLicenseId);
             if (!$this->onlyComments && in_array($licenseId, $mainLicIds)) {
                 continue;
             }
             if ($this->onlyComments) {
                 $text = $comment;
             } else {
                 $reportInfo = $clearingLicense->getReportInfo();
                 $text = $reportInfo ?: $this->getCachedLicenseText($licenseId, $groupId);
             }
             $ungroupedStatements[] = array('content' => $licenseMap->getProjectedShortname($originLicenseId, $clearingLicense->getShortName()), 'uploadtree_pk' => $clearingDecision->getUploadTreeId(), 'text' => $text);
         }
     }
     return $ungroupedStatements;
 }