FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Fossology\Lib\Application\LicenseCsvImport Class Reference

Import licenses from CSV. More...

Collaboration diagram for Fossology\Lib\Application\LicenseCsvImport:
Collaboration graph

Public Member Functions

 __construct (DbManager $dbManager, UserDao $userDao)
 
 setDelimiter ($delimiter=',')
 Update the delimiter. More...
 
 setEnclosure ($enclosure='"')
 Update the enclosure. More...
 
 handleFile ($filename, $fileExtension)
 Read the CSV line by line and import it. More...
 
 handleRowJson ($row)
 

Protected Attributes

 $dbManager
 
 $userDao
 
 $delimiter = ','
 
 $enclosure = '"'
 
 $headrow = null
 
 $nkMap = array()
 
 $mdkMap = array()
 
 $alias
 

Private Member Functions

 handleCsv ($row)
 
 handleHeadCsv ($row)
 Handle a row as head row. More...
 
 updateLicense ($row, $rfPk)
 Update the license info in the DB. More...
 
 handleCsvLicense ($row)
 Handle a single row from CSV. More...
 
 insertMapIfNontrivial ($fromName, $toName, $usage)
 Insert in license_map table if the license conclusion is non-trivial. More...
 
 getKeyFromShortname ($shortname, $groupFk=null)
 Get the license id using license shortname from DB or nkMap. More...
 
 getKeyFromMd5 ($licenseText)
 
 setMap ($from, $to, $usage)
 Update license mappings. More...
 
 insertNewLicense ($row, $tableName="license_ref")
 Insert a new license in DB. More...
 

Detailed Description

Import licenses from CSV.

Definition at line 24 of file LicenseCsvImport.php.

Constructor & Destructor Documentation

◆ __construct()

Fossology\Lib\Application\LicenseCsvImport::__construct ( DbManager  $dbManager,
UserDao  $userDao 
)

Constructor

Parameters
DbManager$dbManagerDB manager to use
UserDao$userDaoUser Dao to use

Definition at line 70 of file LicenseCsvImport.php.

Member Function Documentation

◆ getKeyFromMd5()

Fossology\Lib\Application\LicenseCsvImport::getKeyFromMd5 (   $licenseText)
private

Get the license id using license text's checksum from DB or mdkMap.

Parameters
string$licenseTextLicense text
Returns
integer License id

Definition at line 436 of file LicenseCsvImport.php.

◆ getKeyFromShortname()

Fossology\Lib\Application\LicenseCsvImport::getKeyFromShortname (   $shortname,
  $groupFk = null 
)
private

Get the license id using license shortname from DB or nkMap.

Parameters
string$shortnameShortname of the license.
Returns
int License id

Definition at line 407 of file LicenseCsvImport.php.

◆ handleCsv()

Fossology\Lib\Application\LicenseCsvImport::handleCsv (   $row)
private

Handle a single row read from the CSV. If headrow is not set, then handle current row as head row.

Parameters
array$rowSingle row from CSV
Returns
string $log Log messages

Definition at line 182 of file LicenseCsvImport.php.

◆ handleCsvLicense()

Fossology\Lib\Application\LicenseCsvImport::handleCsvLicense (   $row)
private

Handle a single row from CSV.

The function checks if the license text hash is already in the DB, then updates it. Otherwise inserts new row in the DB.

Parameters
array$rowCSV row to be inserted.
Returns
string Log messages.

Definition at line 347 of file LicenseCsvImport.php.

◆ handleFile()

Fossology\Lib\Application\LicenseCsvImport::handleFile (   $filename,
  $fileExtension 
)

Read the CSV line by line and import it.

Parameters
string$filenameLocation of the CSV file.
Returns
string message Error message, if any. Otherwise Read csv: <count> licenses on success.

Definition at line 100 of file LicenseCsvImport.php.

◆ handleHeadCsv()

Fossology\Lib\Application\LicenseCsvImport::handleHeadCsv (   $row)
private

Handle a row as head row.

Parameters
array$rowHead row to be handled.
Exceptions

Definition at line 212 of file LicenseCsvImport.php.

◆ handleRowJson()

Fossology\Lib\Application\LicenseCsvImport::handleRowJson (   $row)

Handle a single row read from the JSON. If the key matches values from alias array then replace it with key

Parameters
array$row
Returns
array $newArray

Definition at line 145 of file LicenseCsvImport.php.

◆ insertMapIfNontrivial()

Fossology\Lib\Application\LicenseCsvImport::insertMapIfNontrivial (   $fromName,
  $toName,
  $usage 
)
private

Insert in license_map table if the license conclusion is non-trivial.

If the from and to are not same and from exists in database, then the conclusion is non-trivial.

Parameters
string$fromNameParent license name
string$toNameLicense name
string$usageUsage of the license
Returns
boolean True if license is non-trivial, false otherwise.

Definition at line 390 of file LicenseCsvImport.php.

◆ insertNewLicense()

Fossology\Lib\Application\LicenseCsvImport::insertNewLicense (   $row,
  $tableName = "license_ref" 
)
private

Insert a new license in DB.

Creates a new main license/candidate license based on table name sent and if the required group exists in DB.

Parameters
array$rowRows comming from CSV
string$tableNameTable where this new license should go to
Returns
string Log messages

Definition at line 494 of file LicenseCsvImport.php.

◆ setDelimiter()

Fossology\Lib\Application\LicenseCsvImport::setDelimiter (   $delimiter = ',')

Update the delimiter.

Parameters
string$delimiterNew delimiter to use.

Definition at line 80 of file LicenseCsvImport.php.

◆ setEnclosure()

Fossology\Lib\Application\LicenseCsvImport::setEnclosure (   $enclosure = '"')

Update the enclosure.

Parameters
string$enclosureNew enclosure to use.

Definition at line 89 of file LicenseCsvImport.php.

◆ setMap()

Fossology\Lib\Application\LicenseCsvImport::setMap (   $from,
  $to,
  $usage 
)
private

Update license mappings.

First check if the mapping already exists for the license, then update it. If the mapping does not exists, then insert it.

Parameters
integer$fromThe new mapping license
integer$toThe license to be updated
integer$usageThe usage
Returns
boolean False if mapping could not be updated or $from is empty.

Definition at line 459 of file LicenseCsvImport.php.

◆ updateLicense()

Fossology\Lib\Application\LicenseCsvImport::updateLicense (   $row,
  $rfPk 
)
private

Update the license info in the DB.

Parameters
array$rowRow with new values.
array$rfPkMatched license ID.
Returns
string Log messages.

Definition at line 236 of file LicenseCsvImport.php.

Member Data Documentation

◆ $alias

array Fossology\Lib\Application\LicenseCsvImport::$alias
protected
Initial value:
= array(
'shortname'=>array('shortname','Short Name'),
'licensetype'=>array('licensetype','License Type'),
'fullname'=>array('fullname','Long Name'),
'spdx_id'=>array('spdx_id', 'SPDX ID'),
'text'=>array('text','Full Text'),
'parent_shortname'=>array('parent_shortname','Decider Short Name'),
'report_shortname'=>array('report_shortname','Regular License Text Short Name'),
'url'=>array('url','URL'),
'notes'=>array('notes'),
'source'=>array('source','Foreign ID'),
'risk'=>array('risk','risk_level'),
'group'=>array('group','License group'),
'obligations'=>array('obligations','License obligations')
)

Alias for headers

Definition at line 49 of file LicenseCsvImport.php.

◆ $dbManager

DbManager Fossology\Lib\Application\LicenseCsvImport::$dbManager
protected

DB manager to use

Definition at line 28 of file LicenseCsvImport.php.

◆ $delimiter

string Fossology\Lib\Application\LicenseCsvImport::$delimiter = ','
protected

Delimiter used in CSV

Definition at line 34 of file LicenseCsvImport.php.

◆ $enclosure

string Fossology\Lib\Application\LicenseCsvImport::$enclosure = '"'
protected

Enclosure used in CSV

Definition at line 37 of file LicenseCsvImport.php.

◆ $headrow

null array Fossology\Lib\Application\LicenseCsvImport::$headrow = null
protected

Header of CSV

Definition at line 40 of file LicenseCsvImport.php.

◆ $mdkMap

array Fossology\Lib\Application\LicenseCsvImport::$mdkMap = array()
protected

Map based on license text MD5

Definition at line 46 of file LicenseCsvImport.php.

◆ $nkMap

array Fossology\Lib\Application\LicenseCsvImport::$nkMap = array()
protected

Map based on license shortname

Definition at line 43 of file LicenseCsvImport.php.

◆ $userDao

UserDao Fossology\Lib\Application\LicenseCsvImport::$userDao
protected

User DAO to use

Definition at line 31 of file LicenseCsvImport.php.


The documentation for this class was generated from the following file: