39 'type'=>array(
'type',
'Type'),
40 'topic'=>array(
'topic',
'Obligation or Risk topic'),
41 'text'=>array(
'text',
'Full Text'),
42 'classification'=>array(
'classification',
'Classification'),
43 'modifications'=>array(
'modifications',
'Apply on modified source code'),
44 'comment'=>array(
'comment',
'Comment'),
45 'licnames'=>array(
'licnames',
'Associated Licenses'),
46 'candidatenames'=>array(
'candidatenames',
'Associated candidate Licenses')
56 $this->obligationMap = $GLOBALS[
'container']->get(
'businessrules.obligationmap');
85 if (!is_file($filename) || ($handle = fopen($filename,
'r')) ===
false) {
86 return _(
'Internal error');
91 while (($row = fgetcsv($handle,0,$this->delimiter,$this->enclosure)) !==
false) {
98 $msg .= _(
'Read csv').(
": $cnt ")._(
'obligations');
101 return $msg .= _(
'Error while parsing file').
': '.$e->getMessage();
115 if ($this->headrow===
null) {
121 foreach (array(
'type',
'topic',
'text',
'classification',
'modifications',
'comment',
'licnames',
'candidatenames') as $needle) {
122 $mRow[$needle] = $row[$this->headrow[$needle]];
137 foreach (array(
'type',
'topic',
'text',
'classification',
'modifications',
'comment',
'licnames',
'candidatenames') as $needle) {
138 $col = ArrayOperation::multiSearch($this->alias[$needle], $row);
139 if (
false === $col) {
140 throw new \Exception(
"Undetermined position of $needle");
154 $req = array($row[
'topic'], $row[
'text']);
155 $row = $this->
dbManager->getSingleRow(
'SELECT ob_pk FROM obligation_ref WHERE ob_topic=$1 AND ob_md5=md5($2)',$req);
156 return ($row ===
false) ? false : $row[
'ob_pk'];
169 $getList = $this->obligationMap->getLicenseList($exists, $candidate);
172 return strcmp($listFromDb, $listFromCsv);
183 $string = explode(
";", $string);
185 return implode(
",", $string);
197 $this->obligationMap->unassociateLicenseFromObligation($exists, $licId, $candidate);
214 $associatedLicenses =
"";
215 $candidateLicenses =
"";
217 if ($exists !==
false) {
218 $msg =
"Obligation topic '$row[topic]' already exists in DB (id=".$exists.
"),";
219 if ( $this->
compareLicList($exists, $row[
'licnames'],
false, $row) === 0 ) {
220 $msg .=
" No Changes in AssociateLicense";
223 if (!empty($row[
'licnames'])) {
226 $msg .=
" Updated AssociatedLicense license";
228 if ($this->
compareLicList($exists, $row[
'candidatenames'],
true, $row) === 0) {
229 $msg .=
" No Changes in CandidateLicense";
232 if (!empty($row[
'candidatenames'])) {
235 $msg .=
" Updated CandidateLicense";
238 return $msg .
"\n" . $associatedLicenses .
"\n";
241 $stmtInsert = __METHOD__.
'.insert';
242 $dbManager->prepare($stmtInsert,
'INSERT INTO obligation_ref (ob_type,ob_topic,ob_text,ob_classification,ob_modifications,ob_comment,ob_md5)'
243 .
' VALUES ($1,$2,$3,$4,$5,$6,md5($3)) RETURNING ob_pk');
244 $resi =
$dbManager->execute($stmtInsert,array($row[
'type'],$row[
'topic'],$row[
'text'],$row[
'classification'],$row[
'modifications'],$row[
'comment']));
248 if (!empty($row[
'licnames'])) {
251 if (!empty($row[
'candidatenames'])) {
255 $message =
"License association results for obligation '$row[topic]':\n";
256 $message .=
"$associatedLicenses";
257 $message .=
"$candidateLicenses";
258 $message .=
"Obligation with id=$new[ob_pk] was added successfully.\n";
272 $associatedLicenses =
"";
275 $licenses = explode(
";",$licList);
276 foreach ($licenses as $license) {
277 $licIds = $this->obligationMap->getIdFromShortname($license, $candidate);
279 if (empty($licIds)) {
280 $message .=
"License $license could not be found in the DB.\n";
282 $updated = $this->obligationMap->associateLicenseFromLicenseList($obPk,
283 $licIds, $candidate);
286 if ($associatedLicenses ==
"") {
287 $associatedLicenses =
"$license";
289 $associatedLicenses .=
";$license";
294 if (!empty($associatedLicenses)) {
295 $message .=
"$associatedLicenses were associated.\n";
298 $message .= $candidate ?
"candidate":
"";
299 $message .=
"licenses were associated.\n";
316 $this->
dbManager->getSingleRow(
'UPDATE obligation_ref SET ob_classification=$2, ob_modifications=$3, ob_comment=$4 where ob_pk=$1',
317 array($exists, $row[
'classification'], $row[
'modifications'], $row[
'comment']),
318 __METHOD__ .
'.updateOtherOb');
Helper class for Obligation CSV Import.
setDelimiter($delimiter=',')
Update the delimiter.
setEnclosure($enclosure='"')
Update the enclosure.
clearListFromDb($exists, $candidate)
Clear all license maps for given obligation.
handleHeadCsv($row)
Handle a row as head row.
handleFile($filename)
Read the CSV line by line and import it.
getKeyFromTopicAndText($row)
Get the Obligation key from obligation topic and obligation text.
handleCsvObligation($row)
Handle a single row from CSV.
updateOtherFields($exists, $row)
Update other fields of the obligation.
__construct(DbManager $dbManager)
AssociateWithLicenses($licList, $obPk, $candidate=False)
Associate selected licenses to the obligation.
compareLicList($exists, $listFromCsv, $candidate, $row)
Compare licenses from Database and CSV.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.