24 const MAX_CHAR_LIMIT =
"32767";
25 const TEXT_MAX_CHAR_LIMIT =
"The maximum number of characters per cell in a CSV file(32,767) exceeded, Please edit this license text in UI";
34 private $map = array();
45 $this->usageId = $usageId?:self::CONCLUSION;
46 $this->groupId = $groupId;
48 if ($this->usageId == self::TRIVIAL && !$full) {
53 $query = $licenseView->asCTE()
54 .
' SELECT distinct on(rf_pk) rf_pk rf_fk, rf_shortname parent_shortname,
55 rf_spdx_id AS parent_spdx_id, rf_parent, rf_fullname AS parent_fullname
57 SELECT r1.rf_pk, r2.rf_shortname, r2.rf_spdx_id, usage,
58 rf_parent, r2.rf_fullname FROM '.$licenseView->getDbViewName()
59 .
' r1 inner join license_map on usage=$1 and rf_fk=r1.rf_pk
60 left join license_ref r2 on rf_parent=r2.rf_pk
62 SELECT rf_pk, rf_shortname, rf_spdx_id, -1 usage, rf_pk rf_parent,
63 rf_fullname FROM '.$licenseView->getDbViewName()
64 .
') full_map ORDER BY rf_pk,usage DESC';
66 $stmt = __METHOD__.
".$this->usageId,$groupId,full";
68 $query = $licenseView->asCTE()
69 .
' SELECT rf_fk, rf_shortname AS parent_shortname, rf_spdx_id AS parent_spdx_id, '
70 .
'rf_parent, rf_fullname AS parent_fullname FROM license_map, '.$licenseView->getDbViewName()
71 .
' WHERE rf_pk=rf_parent AND rf_fk!=rf_parent AND usage=$1';
72 $stmt = __METHOD__.
".$this->usageId,$groupId";
74 $dbManager->prepare($stmt,$query);
75 $res = $dbManager->execute($stmt,array($this->usageId));
76 while ($row = $dbManager->fetchArray($res)) {
77 $this->map[$row[
'rf_fk']] = $row;
79 $dbManager->freeResult($res);
89 if (array_key_exists($licenseId, $this->map)) {
90 return $this->map[$licenseId][
'rf_parent'];
105 if (array_key_exists($licenseId, $this->map)) {
106 return $this->map[$licenseId][
'parent_shortname'];
120 if (array_key_exists($licenseId, $this->map)) {
122 $this->map[$licenseId][
'parent_spdx_id']);
136 if (array_key_exists($licenseId, $this->map)) {
137 $licenseName = $this->map[$licenseId][
'parent_fullname'];
138 if (empty($licenseName)) {
152 return $this->usageId;
161 return $this->groupId;
171 array(
'columns'=>array(
'rf_pk',
'rf_shortname',
'rf_spdx_id',
'rf_fullname')),
173 $query = $licenseView->asCTE()
174 .
' SELECT rf_pk, rf_shortname, rf_spdx_id, rf_fullname FROM '.$licenseView->getDbViewName()
175 .
' LEFT JOIN license_map ON rf_pk=rf_fk AND rf_fk!=rf_parent AND usage=$1'
176 .
' WHERE license_map_pk IS NULL';
177 $stmt = __METHOD__.
".$this->usageId,$this->groupId";
179 $res = $this->
dbManager->execute($stmt,array($this->usageId));
181 while ($row = $this->
dbManager->fetchArray($res)) {
182 $topLevel[$row[
'rf_pk']] =
new LicenseRef($row[
'rf_pk'],$row[
'rf_shortname'],$row[
'rf_fullname'],$row[
'rf_spdx_id']);
193 return "SELECT bot.rf_pk rf_origin, top.rf_pk, top.rf_shortname, top.rf_fullname, top.rf_spdx_id FROM license_ref bot "
194 .
"LEFT JOIN license_map ON bot.rf_pk=rf_fk AND usage=$usageExpr "
195 .
"INNER JOIN license_ref top ON rf_parent=top.rf_pk OR rf_parent IS NULL AND bot.rf_pk=top.rf_pk";
206 $tableName = $candidate ?
"obligation_candidate_map" :
"obligation_map";
207 $sql =
"SELECT distinct(ob_fk) FROM $tableName WHERE rf_fk = $1;";
208 $ob_fks = $this->
dbManager->getRows($sql, [$license_ref],
209 __METHOD__ . $tableName);
211 foreach ($ob_fks as $row) {
212 $returnVal[] = $row[
'ob_fk'];
Wrapper class for license map.
static getMappedLicenseRefView($usageExpr=' $1')
Query to get license map view along with license ref.
getProjectedSpdxId($licenseId, $defaultID=null)
For a given license id, get the projected SPDX ID (or shortname if ID does not exist).
getProjectedShortname($licenseId, $defaultName=null)
For a given license id, get the projected shortname.
getProjectedId($licenseId)
For a given license id, get the projected id.
__construct(DbManager $dbManager, $groupId, $usageId=null, $full=false)
getObligationsForLicenseRef($license_ref, $candidate=false)
Get all Obligations attached with given license ref.
getProjectedName($licenseId, $defaultName=null)
For a given license id, get the projected fullname. If empty, get the shortname instead.
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
fo_dbManager * dbManager
fo_dbManager object
Contains business rules for FOSSology.