43 private $map = array();
54 $this->usageId = $usageId?:self::CONCLUSION;
55 $this->groupId = $groupId;
57 if ($this->usageId == self::TRIVIAL && !$full) {
62 $query = $licenseView->asCTE()
63 .
' SELECT distinct on(rf_pk) rf_pk rf_fk, rf_shortname parent_shortname, rf_parent FROM ( 64 SELECT r1.rf_pk, r2.rf_shortname, usage, rf_parent FROM '.$licenseView->getDbViewName()
65 .
' r1 inner join license_map on usage=$1 and rf_fk=r1.rf_pk 66 left join license_ref r2 on rf_parent=r2.rf_pk 68 SELECT rf_pk, rf_shortname, -1 usage, rf_pk rf_parent from '.$licenseView->getDbViewName()
69 .
') full_map ORDER BY rf_pk,usage DESC';
71 $stmt = __METHOD__.
".$this->usageId,$groupId,full";
73 $query = $licenseView->asCTE()
74 .
' SELECT rf_fk, rf_shortname parent_shortname, rf_parent FROM license_map, '.$licenseView->getDbViewName()
75 .
' WHERE rf_pk=rf_parent AND rf_fk!=rf_parent AND usage=$1';
76 $stmt = __METHOD__.
".$this->usageId,$groupId";
78 $dbManager->
prepare($stmt,$query);
79 $res = $dbManager->
execute($stmt,array($this->usageId));
81 $this->map[$row[
'rf_fk']] = $row;
93 if (array_key_exists($licenseId, $this->map)) {
94 return $this->map[$licenseId][
'rf_parent'];
109 if (array_key_exists($licenseId, $this->map)) {
110 return $this->map[$licenseId][
'parent_shortname'];
121 return $this->usageId;
130 return $this->groupId;
140 array(
'columns'=>array(
'rf_pk',
'rf_shortname',
'rf_fullname')),
142 $query = $licenseView->asCTE()
143 .
' SELECT rf_pk, rf_shortname, rf_fullname FROM '.$licenseView->getDbViewName()
144 .
' LEFT JOIN license_map ON rf_pk=rf_fk AND rf_fk!=rf_parent AND usage=$1' 145 .
' WHERE license_map_pk IS NULL';
146 $stmt = __METHOD__.
".$this->usageId,$this->groupId";
148 $res = $this->
dbManager->execute($stmt,array($this->usageId));
150 while ($row = $this->
dbManager->fetchArray($res)) {
151 $topLevel[$row[
'rf_pk']] =
new LicenseRef($row[
'rf_pk'],$row[
'rf_shortname'],$row[
'rf_fullname']);
162 return "SELECT bot.rf_pk rf_origin, top.rf_pk, top.rf_shortname, top.rf_fullname FROM ONLY license_ref bot " 163 .
"LEFT JOIN license_map ON bot.rf_pk=rf_fk AND usage=$usageExpr " 164 .
"INNER JOIN license_ref top ON rf_parent=top.rf_pk OR rf_parent IS NULL AND bot.rf_pk=top.rf_pk";
175 $tableName = $candidate ?
"obligation_candidate_map" :
"obligation_map";
176 $sql =
"SELECT distinct(ob_fk) FROM $tableName WHERE rf_fk = $1;";
177 $ob_fks = $this->
dbManager->getRows($sql, [$license_ref],
178 __METHOD__ . $tableName);
180 foreach ($ob_fks as $row) {
181 $returnVal[] = $row[
'ob_fk'];
__construct(DbManager $dbManager, $groupId, $usageId=null, $full=false)
prepare($statementName, $sqlStatement)
Wrapper class for license map.
Contains business rules for FOSSology.
getProjectedId($licenseId)
For a given license id, get the projected id.
fo_dbManager * dbManager
fo_dbManager object
execute($statementName, $params=array())
static getMappedLicenseRefView($usageExpr='$1')
Query to get license map view along with license ref.
getObligationsForLicenseRef($license_ref, $candidate=false)
Get all Obligations attached with given license ref.
getProjectedShortname($licenseId, $defaultName=null)
For a given license id, get the projected shortname.