30 require_once
'ReportImportConfiguration.php';
42 private $copyrightDao;
47 protected $agent_pk = -1;
49 protected $groupId = -1;
51 protected $userId = -1;
53 protected $jobId = -1;
55 protected $nserIsAdmin =
false;
58 protected $configuration;
72 function __construct($agent_pk, $userDao, $licenseDao, $clearingDao, $copyrightDao, $dbManager, $groupId, $userId, $jobId, $configuration)
74 $this->userDao = $userDao;
75 $this->clearingDao = $clearingDao;
76 $this->licenseDao = $licenseDao;
77 $this->copyrightDao = $copyrightDao;
80 $this->groupId = $groupId;
81 $this->userId = $userId;
82 $this->
jobId = $jobId;
84 $this->configuration = $configuration;
86 $userRow = $userDao->getUserByPk($userId);
95 $pfiles = $data->getPfiles();
96 if(
sizeof($pfiles) === 0)
101 if($this->configuration->isCreateLicensesInfosAsFindings() ||
102 $this->configuration->isCreateConcludedLicensesAsFindings() ||
103 $this->configuration->isCreateConcludedLicensesAsConclusions())
105 $licenseInfosInFile = $data->getLicenseInfosInFile();
106 $licensesConcluded = $data->getLicensesConcluded();
108 $licensePKsInFile = array();
109 foreach($licenseInfosInFile as $dataItem)
111 if (strcasecmp($dataItem->getLicenseId(),
"noassertion") == 0)
116 $licensePKsInFile[] = $licenseId;
119 $licensePKsConcluded = array();
120 foreach ($licensesConcluded as $dataItem)
122 if (strcasecmp($dataItem->getLicenseId(),
"noassertion") == 0)
127 $licensePKsConcluded[$licenseId] = $dataItem->getCustomText();
133 if($this->configuration->isAddCopyrightInformation())
135 $this->insertFoundCopyrightTextsToDB($data->getCopyrightTexts(),
148 $licenseShortName = $dataItem->getLicenseId();
149 $license = $this->licenseDao->getLicenseByShortName($licenseShortName, $groupId);
150 if ($license !== null)
152 return $license->getId();
154 elseif (! $this->licenseDao->isNewLicense($licenseShortName, $groupId))
156 throw new \Exception(
'shortname already in use');
158 elseif ($dataItem->isSetLicenseCandidate())
160 echo
"INFO: No license with shortname=\"$licenseShortName\" found ... ";
162 $licenseCandidate = $dataItem->getLicenseCandidate();
163 if($this->configuration->isCreateLicensesAsCandidate() || !$this->userIsAdmin)
165 echo
"Creating it as license candidate ...\n";
166 $licenseId = $this->licenseDao->insertUploadLicense($licenseShortName, $licenseCandidate->getText(), $groupId);
167 $this->licenseDao->updateCandidate(
169 $licenseCandidate->getShortName(),
170 $licenseCandidate->getFullName(),
171 $licenseCandidate->getText(),
172 $licenseCandidate->getUrl(),
173 "Created for ReportImport with jobId=[".$this->jobId.
"]",
180 echo
"creating it as license ...\n";
181 $licenseText =
trim($licenseCandidate->getText());
182 return $this->licenseDao->insertLicense($licenseCandidate->getShortName(), $licenseText, $licenseCandidate->getSpdxCompatible());
195 if($this->configuration->isCreateLicensesInfosAsFindings())
200 if($this->configuration->isCreateConcludedLicensesAsFindings())
205 if($this->configuration->isCreateConcludedLicensesAsConclusions())
207 $removeLicenseIds = array();
208 foreach ($licensePKsInFile as $licenseId)
210 if(! array_key_exists($licenseId,$licensePKsConcluded))
212 $removeLicenseIds[] = $licenseId;
226 if(
sizeof($addLicenseIds) == 0)
231 foreach ($pfiles as $pfile)
234 foreach ($addLicenseIds as $licenseId => $licenseText)
237 $eventIds[] = $this->clearingDao->insertClearingEvent(
238 $pfile[
'uploadtree_pk'],
243 ClearingEventTypes::IMPORT,
248 foreach ($removeLicenseIds as $licenseId)
251 $eventIds[] = $this->clearingDao->insertClearingEvent(
252 $pfile[
'uploadtree_pk'],
257 ClearingEventTypes::IMPORT,
262 $this->clearingDao->createDecisionFromEvents(
263 $pfile[
'uploadtree_pk'],
266 $this->configuration->getConcludeLicenseDecisionType(),
267 DecisionScopes::ITEM,
278 foreach ($pfiles as $pfile)
280 foreach($licenseIds as $licenseId)
283 "INSERT INTO license_file (rf_fk, agent_fk, pfile_fk) VALUES ($1,$2,$3) RETURNING fl_pk",
284 array($licenseId, $this->
agent_pk, $pfile[
'pfile_pk']),
285 __METHOD__.
"forReportImport");
290 public function insertFoundCopyrightTextsToDB($copyrightTexts, $entries)
292 foreach ($copyrightTexts as $copyrightText)
294 $this->insertFoundCopyrightTextToDB($copyrightText, $entries);
298 public function insertFoundCopyrightTextToDB($copyrightText, $entries)
300 $copyrightLines = array_map(
"trim", explode(
"\n",$copyrightText));
301 foreach ($copyrightLines as $copyrightLine)
303 if(empty($copyrightLine))
308 foreach ($entries as $entry)
310 $this->saveAsCopyrightFindingToDB(
trim($copyrightLine), $entry[
'pfile_pk']);
315 private function saveAsCopyrightFindingToDB($content, $pfile_fk)
317 $curDecisions = $this->copyrightDao->getDecisions(
"copyright_decision", $pfile_fk);
318 foreach ($curDecisions as $decision)
320 if($decision[
'textfinding'] == $content){
325 $this->copyrightDao->saveDecision(
"copyright_decision", $pfile_fk, $this->userId , DecisionTypes::IDENTIFIED,
326 "", $content,
"imported via reportImport");
__construct($agent_pk, $userDao, $licenseDao, $clearingDao, $copyrightDao, $dbManager, $groupId, $userId, $jobId, $configuration)
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
saveAsDecisionToDB($addLicenseIds, $removeLicenseIds, $pfiles)
int jobId
The id of the job.
saveAsLicenseFindingToDB($licenseIds, $pfiles)
fo_dbManager * dbManager
fo_dbManager object
insertLicenseInformationToDB($licensePKsInFile, $licensePKsConcluded, $pfiles)
getIdForDataItemOrCreateLicense($dataItem, $groupId)
char * trim(char *ptext)
Trimming whitespace.