9 namespace Fossology\Spdx\UI;
15 use Symfony\Component\HttpFoundation\Request;
30 function __construct()
33 if (strcmp($possibleOutputFormat,
"") !== 0 &&
34 strcmp($possibleOutputFormat,self::DEFAULT_OUTPUT_FORMAT) !== 0 &&
35 ctype_alnum($possibleOutputFormat)) {
36 $this->outputFormat = $possibleOutputFormat;
38 parent::__construct(self::NAME, array(
39 self::TITLE => _(
"SPDX3 generation"),
41 self::REQUIRES_LOGIN =>
true
51 $text = _(
"Generate SPDX3.0 report in JSON-LD format");
52 menu_insert(
"Browse-Pfile::Export SPDX3.0 JSON-LD report", 0, self::NAME .
'&outputFormat=spdx3jsonld', $text);
53 menu_insert(
"UploadMulti::Generate SPDX3.0", 0, self::NAME, $text);
55 $text = _(
"Generate SPDX3.0 report in JSON format");
56 menu_insert(
"Browse-Pfile::Export SPDX3.0 JSON report", 0, self::NAME .
'&outputFormat=spdx3json', $text);
58 $text = _(
"Generate SPDX3.0 report in RDF format");
59 menu_insert(
"Browse-Pfile::Export SPDX3.0 RDF report", 0, self::NAME .
'&outputFormat=spdx3rdf', $text);
61 $text = _(
"Generate SPDX3.0 report in tag/value format");
62 menu_insert(
"Browse-Pfile::Export SPDX3.0 tag/value report", 0, self::NAME .
'&outputFormat=spdx3tv', $text);
69 protected function handle(Request $request)
73 $uploadIds = $request->get(
'uploads') ?: array();
74 $uploadIds[] = intval($request->get(
'upload'));
75 $addUploads = array();
76 foreach ($uploadIds as $uploadId) {
77 if (empty($uploadId)) {
81 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
82 }
catch(Exception $e) {
83 return $this->flushContent($e->getMessage());
86 $folderId = $request->get(
'folder');
87 if (!empty($folderId)) {
89 $folderDao = $this->
getObject(
'dao.folder');
90 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
91 foreach ($folderUploads as $uploadProgress) {
92 $addUploads[$uploadProgress->getId()] = $uploadProgress;
95 if (empty($addUploads)) {
96 return $this->flushContent(_(
'No upload selected'));
98 $upload = array_pop($addUploads);
101 }
catch (\Exception $ex) {
102 return $this->flushContent($ex->getMessage());
105 $vars = array(
'jqPk' => $jobQueueId,
106 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
107 'showJobsLink' =>
Traceback_uri().
"?mod=showjobs&upload=".$upload->getId(),
108 'reportType' => $this->outputFormat);
109 $text = sprintf(_(
"Generating ". $this->outputFormat .
" report for '%s'"), $upload->getFilename());
110 $vars[
'content'] =
"<h2>".$text.
"</h2>";
111 $content = $this->renderer->load(
"report.html.twig")->render($vars);
112 $message =
'<h3 id="jobResult"></h3>';
113 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
115 $showJobsPlugin->OutputOpen();
116 return $showJobsPlugin->getResponse();
126 if (count($uploads) == 0) {
129 return '--uploadsAdd='. implode(
',', array_keys($uploads));
142 $uploadId = $upload->getId();
143 $SpdxThreeAgent =
plugin_find(
'agent_'.$this->outputFormat);
147 $dbManager = $this->
getObject(
'db.manager');
148 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job '
149 .
'WHERE jq_job_fk=job_pk AND jq_type=$1 AND job_group_fk=$4 AND job_user_fk=$3 AND jq_args=$2 AND jq_endtime IS NULL';
150 $params = array($SpdxThreeAgent->AgentName,$uploadId,$userId,$groupId);
153 $sql .=
' AND jq_cmd_args=$5';
154 $params[] = $jqCmdArgs;
157 $sql .=
' AND jq_cmd_args IS NULL';
159 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
160 if (!empty($scheduled)) {
161 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
163 if (empty($jqCmdArgs)) {
164 $jobName = $upload->getFilename();
166 $jobName =
"Multi File SPDX3";
168 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
170 $jobQueueId = $SpdxThreeAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
171 if ($jobQueueId < 0) {
172 throw new \Exception(_(
"Cannot schedule").
": ".$error);
174 return array($jobId,$jobQueueId, $error);
184 protected function getUpload($uploadId, $groupId)
186 if ($uploadId <= 0) {
187 throw new \Exception(_(
"parameter error: $uploadId"));
190 $uploadDao = $this->
getObject(
'dao.upload');
191 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
192 throw new \Exception(_(
"permission denied"));
195 $upload = $uploadDao->getUpload($uploadId);
196 if ($upload ===
null) {
197 throw new \Exception(_(
'cannot find uploadId'));
213 $outputFormat = self::DEFAULT_OUTPUT_FORMAT, $addUploads = array())
220 register_plugin(
new SpdxThreeGeneratorUi());
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
Call SPDX3 agent to generate report from UI.
getJobAndJobqueue($groupId, $upload, $addUploads)
Get the Job ID and Job queue ID.
const DEFAULT_OUTPUT_FORMAT
Default report format.
scheduleAgent($groupId, $upload, $outputFormat=self::DEFAULT_OUTPUT_FORMAT, $addUploads=array())
uploadsAdd($uploads)
Add multiple uploads to the report.
const NAME
Mod name of the plugin.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
char * trim(char *ptext)
Trimming whitespace.
list_t type structure used to keep various lists. (e.g. there are multiple lists).