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 'reportType' => $this->outputFormat);
108 $text = sprintf(_(
"Generating ". $this->outputFormat .
" report for '%s'"), $upload->getFilename());
109 $vars[
'content'] =
"<h2>".$text.
"</h2>";
110 $content = $this->renderer->load(
"report.html.twig")->render($vars);
111 $message =
'<h3 id="jobResult"></h3>';
112 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
114 $showJobsPlugin->OutputOpen();
115 return $showJobsPlugin->getResponse();
125 if (count($uploads) == 0) {
128 return '--uploadsAdd='. implode(
',', array_keys($uploads));
141 $uploadId = $upload->getId();
142 $SpdxThreeAgent =
plugin_find(
'agent_'.$this->outputFormat);
146 $dbManager = $this->
getObject(
'db.manager');
147 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job '
148 .
'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';
149 $params = array($SpdxThreeAgent->AgentName,$uploadId,$userId,$groupId);
152 $sql .=
' AND jq_cmd_args=$5';
153 $params[] = $jqCmdArgs;
156 $sql .=
' AND jq_cmd_args IS NULL';
158 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
159 if (!empty($scheduled)) {
160 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
162 if (empty($jqCmdArgs)) {
163 $jobName = $upload->getFilename();
165 $jobName =
"Multi File SPDX3";
167 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
169 $jobQueueId = $SpdxThreeAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
170 if ($jobQueueId < 0) {
171 throw new \Exception(_(
"Cannot schedule").
": ".$error);
173 return array($jobId,$jobQueueId, $error);
183 protected function getUpload($uploadId, $groupId)
185 if ($uploadId <= 0) {
186 throw new \Exception(_(
"parameter error: $uploadId"));
189 $uploadDao = $this->
getObject(
'dao.upload');
190 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
191 throw new \Exception(_(
"permission denied"));
194 $upload = $uploadDao->getUpload($uploadId);
195 if ($upload ===
null) {
196 throw new \Exception(_(
'cannot find uploadId'));
212 $outputFormat = self::DEFAULT_OUTPUT_FORMAT, $addUploads = array())
219 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).