8 namespace Fossology\Spasht;
16 use GuzzleHttp\Client;
18 include_once (__DIR__ .
"/version.php");
47 function __construct()
49 parent::__construct(SPASHT_AGENT_NAME, AGENT_VERSION, AGENT_REV);
50 $this->uploadDao = $this->container->get(
'dao.upload');
51 $this->spashtDao = $this->container->get(
'dao.spasht');
52 $this->licenseDao = $this->container->get(
'dao.license');
62 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId);
63 $pfileFileDetails = $this->uploadDao->getPFileDataPerFileName(
66 $agentId = $this->agentDao->getCurrentAgentId(
"spasht");
67 $pfileSha1AndpfileId = array();
69 foreach ($pfileFileDetails as $pfileDetail) {
70 $pfileSha1AndpfileId[$pfileDetail[
'pfile_pk']] = strtolower(
71 $pfileDetail[
'sha1']);
75 if ($uploadAvailable ===
false) {
81 $pfileSha1AndpfileId);
82 if (is_string($getNewResult)) {
83 echo
"Error: $getNewResult";
101 $result = $this->spashtDao->getComponent($uploadId);
103 if (! empty($result)) {
127 $client =
new Client([
129 'base_uri' => $SysConf[
'SYSCONFIG'][
"ClearlyDefinedURL"]
133 $uri =
'definitions/' . $details->generateUrlString();
136 if (array_key_exists(
'http_proxy', $SysConf[
'FOSSOLOGY']) &&
137 ! empty($SysConf[
'FOSSOLOGY'][
'http_proxy'])) {
138 $proxy[
'http'] = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
140 if (array_key_exists(
'https_proxy', $SysConf[
'FOSSOLOGY']) &&
141 ! empty($SysConf[
'FOSSOLOGY'][
'https_proxy'])) {
142 $proxy[
'https'] = $SysConf[
'FOSSOLOGY'][
'https_proxy'];
144 if (array_key_exists(
'no_proxy', $SysConf[
'FOSSOLOGY']) &&
145 ! empty($SysConf[
'FOSSOLOGY'][
'no_proxy'])) {
146 $proxy[
'no'] = explode(
',', $SysConf[
'FOSSOLOGY'][
'no_proxy']);
150 $res = $client->request(
'GET', $uri, [
"proxy" => $proxy]);
151 }
catch (\Exception $e) {
152 return "Unable to fetch info from $uri. " . $e->getMessage();
155 if ($res->getStatusCode() == 200) {
156 $body = json_decode($res->getBody()->getContents());
159 return "BodyNotFound";
162 $newResultBody = array();
164 foreach ($body->$dir as $key) {
165 $searchInUpload = array_search($key->hashes->sha1, $pfileSha1AndpfileId);
167 if (! empty($searchInUpload)) {
169 $temp[
'pfileId'] = $searchInUpload;
170 $temp[
'sha1'] = $key->hashes->sha1;
172 if (! empty($key->license)) {
180 if (! empty($key->attributions)) {
181 $temp[
'attributions'] = $key->attributions;
183 $temp[
'attributions'] = [
187 $newResultBody[] = $temp;
191 return $newResultBody;
193 return "UploadNotFound";
204 $strLicense = array();
205 $checkString = explode(
" ", $rawLicenses);
207 foreach ($checkString as $license) {
208 if (strcasecmp($license,
"and") === 0 || strcasecmp($license,
"or") === 0) {
211 $strSubLicense = explode(
"-", $license);
212 $partCount = count($strSubLicense);
213 if ($partCount < 2) {
214 $strLicense[] = $license;
218 $fossLicense = $license;
219 if ($partCount >= 3 &&
220 strcasecmp($strSubLicense[$partCount - 2],
"or") === 0 &&
221 strcasecmp($strSubLicense[$partCount - 1],
"later") === 0) {
223 $fossLicense = implode(
"-", array_slice($strSubLicense, 0, -2)) .
"+";
224 } elseif (strcasecmp($strSubLicense[$partCount - 1],
"only") === 0) {
226 $fossLicense = implode(
"-", array_slice($strSubLicense, 0, -1));
229 $strLicense[] = $fossLicense;
241 foreach ($body as $key) {
242 foreach ($key[
'license'] as $license) {
243 $l = $this->licenseDao->getLicenseByShortName($license);
245 if ($l !=
null && ! empty($l->getId())) {
246 $sql =
"SELECT fl_pk FROM license_file " .
247 "WHERE agent_fk = $1 AND pfile_fk = $2 AND rf_fk = $3;";
248 $statement = __METHOD__ .
".checkExists";
250 $key[
'pfileId'], $l->getId()], $statement);
251 if (! empty($row) && ! empty($row[
'fl_pk'])) {
254 $this->
dbManager->insertTableRow(
'license_file', [
256 'pfile_fk' => $key[
'pfileId'],
257 'rf_fk' => $l->getId()
258 ], __METHOD__ .
".insertLicense");
272 foreach ($body as $key) {
273 foreach ($key[
'attributions'] as $keyCopyright) {
274 if ($keyCopyright ==
"No_Copyright_Found") {
278 $hashForCopyright = hash(
"sha256", $keyCopyright);
279 $sql =
"SELECT copyright_spasht_pk FROM copyright_spasht " .
280 "WHERE agent_fk = $1 AND pfile_fk = $2 AND hash = $3 " .
281 "AND clearing_decision_type_fk = 0;";
282 $statement = __METHOD__ .
".checkExists";
286 if (! empty($row) && ! empty($row[
'copyright_spasht_pk'])) {
289 $this->
dbManager->insertTableRow(
'copyright_spasht', [
291 'pfile_fk' => $key[
'pfileId'],
292 'textfinding' => $keyCopyright,
293 'hash' => $hashForCopyright,
294 'clearing_decision_type_fk' => 0
295 ], __METHOD__ .
".insertCopyright");
Structure of an Agent with all required parameters.
heartbeat($newProcessed)
Send hear beat to the scheduler.
separateLicenses($rawLicenses)
insertLicensesSpashtAgentRecord($body, $agentId)
Insert the License Details in Spasht Agent table.
insertCopyrightSpashtAgentRecord($body, $agentId)
Insert the Copyright Details in Spasht Agent table.
processUploadId($uploadId)
Run Spasht Agent for a package.
searchUploadIdInSpasht($uploadId)
getInformation($details, $pfileSha1AndpfileId)
fo_dbManager * dbManager
fo_dbManager object