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

Helper class for Obligation CSV Import. More...

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

Public Member Functions

 __construct (DbManager $dbManager)
 
 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)
 
 AssociateWithLicenses ($licList, $obPk, $candidate=False)
 Associate selected licenses to the obligation. More...
 
 updateOtherFields ($exists, $row)
 Update other fields of the obligation. More...
 

Protected Attributes

 $dbManager
 
 $delimiter = ','
 
 $enclosure = '"'
 
 $headrow = null
 
 $alias
 

Private Member Functions

 handleCsv ($row)
 
 handleHeadCsv ($row)
 Handle a row as head row. More...
 
 getKeyFromTopicAndText ($row)
 Get the Obligation key from obligation topic and obligation text. More...
 
 compareLicList ($exists, $listFromCsv, $candidate, $row)
 Compare licenses from Database and CSV. More...
 
 reArrangeString ($string)
 
 clearListFromDb ($exists, $candidate)
 Clear all license maps for given obligation. More...
 
 handleCsvObligation ($row)
 Handle a single row from CSV. More...
 

Detailed Description

Helper class for Obligation CSV Import.

Definition at line 22 of file ObligationCsvImport.php.

Constructor & Destructor Documentation

◆ __construct()

Fossology\Lib\Application\ObligationCsvImport::__construct ( DbManager  $dbManager)

Constructor

Parameters
DbManager$dbManagerDB manager to use

Definition at line 53 of file ObligationCsvImport.php.

Member Function Documentation

◆ AssociateWithLicenses()

Fossology\Lib\Application\ObligationCsvImport::AssociateWithLicenses (   $licList,
  $obPk,
  $candidate = False 
)

Associate selected licenses to the obligation.

Parameters
array$licListList of licenses to be associated
int$obPkThe id of the newly created obligation
boolean$candidateDo we handle candidate licenses?
Returns
string The list of associated licences

Definition at line 307 of file ObligationCsvImport.php.

◆ clearListFromDb()

Fossology\Lib\Application\ObligationCsvImport::clearListFromDb (   $exists,
  $candidate 
)
private

Clear all license maps for given obligation.

Parameters
int$existsExisting obligation key
bool$candidateIs a candidate obligation?
Returns
boolean Always true

Definition at line 231 of file ObligationCsvImport.php.

◆ compareLicList()

Fossology\Lib\Application\ObligationCsvImport::compareLicList (   $exists,
  $listFromCsv,
  $candidate,
  $row 
)
private

Compare licenses from Database and CSV.

Parameters
bool$existsExisting license id
array$listFromCsvList of obligations from CSV
bool$candidateIs a candidate obligation?
array$rowUnused
Returns
int strcmp() diff

Definition at line 204 of file ObligationCsvImport.php.

◆ getKeyFromTopicAndText()

Fossology\Lib\Application\ObligationCsvImport::getKeyFromTopicAndText (   $row)
private

Get the Obligation key from obligation topic and obligation text.

Parameters
array$rowCSV array with topic and text keys
Returns
boolean|int False if not found, key otherwise.

Definition at line 189 of file ObligationCsvImport.php.

◆ handleCsv()

Fossology\Lib\Application\ObligationCsvImport::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 150 of file ObligationCsvImport.php.

◆ handleCsvObligation()

Fossology\Lib\Application\ObligationCsvImport::handleCsvObligation (   $row)
private

Handle a single row from CSV.

The function checks if the obligation text hash is already in the DB, then update the license associations. Otherwise make a new entry in the DB.

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

Definition at line 246 of file ObligationCsvImport.php.

◆ handleFile()

Fossology\Lib\Application\ObligationCsvImport::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 83 of file ObligationCsvImport.php.

◆ handleHeadCsv()

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

Handle a row as head row.

Parameters
array$rowHead row to be handled.
Exceptions

Definition at line 171 of file ObligationCsvImport.php.

◆ handleRowJson()

Fossology\Lib\Application\ObligationCsvImport::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 128 of file ObligationCsvImport.php.

◆ reArrangeString()

Fossology\Lib\Application\ObligationCsvImport::reArrangeString (   $string)
private

The function takes a string delimited by ;, explodes it, sort the result and joins them back using , as new delimiter.

Parameters
string$stringString to be rearranged.
Returns
string Rearranged string.

Definition at line 218 of file ObligationCsvImport.php.

◆ setDelimiter()

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

Update the delimiter.

Parameters
string$delimiterNew delimiter to use.

Definition at line 63 of file ObligationCsvImport.php.

◆ setEnclosure()

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

Update the enclosure.

Parameters
string$enclosureNew enclosure to use.

Definition at line 72 of file ObligationCsvImport.php.

◆ updateOtherFields()

Fossology\Lib\Application\ObligationCsvImport::updateOtherFields (   $exists,
  $row 
)

Update other fields of the obligation.

Fields updated are:

  • classification
  • modifications
  • comment
    Parameters
    int$existsObligation key
    array$rowRow from CSV.

Definition at line 351 of file ObligationCsvImport.php.

Member Data Documentation

◆ $alias

array Fossology\Lib\Application\ObligationCsvImport::$alias
protected
Initial value:
= array(
'type'=>array('type','Type'),
'topic'=>array('topic','Obligation or Risk topic'),
'text'=>array('text','Full Text'),
'classification'=>array('classification','Classification'),
'modifications'=>array('modifications','Apply on modified source code'),
'comment'=>array('comment','Comment'),
'licnames'=>array('licnames','Associated Licenses'),
'candidatenames'=>array('candidatenames','Associated candidate Licenses')
)

Alias for headers

Definition at line 38 of file ObligationCsvImport.php.

◆ $dbManager

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

DB manager to be used

Definition at line 26 of file ObligationCsvImport.php.

◆ $delimiter

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

Delimiter used in the CSV

Definition at line 29 of file ObligationCsvImport.php.

◆ $enclosure

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

Ecnlosure used in the CSV

Definition at line 32 of file ObligationCsvImport.php.

◆ $headrow

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

Header of CSV

Definition at line 35 of file ObligationCsvImport.php.


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