8 namespace Fossology\Spdx\UI;
14 use Symfony\Component\HttpFoundation\Request;
29 function __construct()
32 if (strcmp($possibleOutputFormat,
"") !== 0 &&
33 strcmp($possibleOutputFormat,self::DEFAULT_OUTPUT_FORMAT) !== 0 &&
34 ctype_alnum($possibleOutputFormat)) {
35 $this->outputFormat = $possibleOutputFormat;
37 parent::__construct(self::NAME, array(
38 self::TITLE => _(
"SPDX2 generation"),
40 self::REQUIRES_LOGIN =>
true
50 $text = _(
"Generate SPDX report in RDF format");
51 menu_insert(
"Browse-Pfile::Export SPDX RDF report", 0, self::NAME .
'&outputFormat=spdx2', $text);
52 menu_insert(
"UploadMulti::Generate SPDX", 0, self::NAME, $text);
54 $text = _(
"Generate SPDX report in tag:value format");
55 menu_insert(
"Browse-Pfile::Export SPDX tag:value report", 0, self::NAME .
'&outputFormat=spdx2tv', $text);
57 $text = _(
"Generate CSV report (with SPDX IDs)");
58 menu_insert(
"Browse-Pfile::Export CSV report (SPDX)", 0, self::NAME .
'&outputFormat=spdx2csv', $text);
60 $text = _(
"Generate Debian Copyright file");
61 menu_insert(
"Browse-Pfile::Export DEP5 report", 0, self::NAME .
'&outputFormat=dep5', $text);
68 protected function handle(Request $request)
72 $uploadIds = $request->get(
'uploads') ?: array();
73 $uploadIds[] = intval($request->get(
'upload'));
74 $addUploads = array();
75 foreach ($uploadIds as $uploadId) {
76 if (empty($uploadId)) {
80 $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
81 }
catch(Exception $e) {
82 return $this->flushContent($e->getMessage());
85 $folderId = $request->get(
'folder');
86 if (!empty($folderId)) {
88 $folderDao = $this->
getObject(
'dao.folder');
89 $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
90 foreach ($folderUploads as $uploadProgress) {
91 $addUploads[$uploadProgress->getId()] = $uploadProgress;
94 if (empty($addUploads)) {
95 return $this->flushContent(_(
'No upload selected'));
97 $upload = array_pop($addUploads);
100 }
catch (\Exception $ex) {
101 return $this->flushContent($ex->getMessage());
104 $vars = array(
'jqPk' => $jobQueueId,
105 'downloadLink' =>
Traceback_uri().
"?mod=download&report=".$jobId,
106 'reportType' => $this->outputFormat);
107 $text = sprintf(_(
"Generating ". $this->outputFormat .
" report for '%s'"), $upload->getFilename());
108 $vars[
'content'] =
"<h2>".$text.
"</h2>";
109 $content = $this->renderer->load(
"report.html.twig")->render($vars);
110 $message =
'<h3 id="jobResult"></h3>';
111 $request->duplicate(array(
'injectedMessage'=>$message,
'injectedFoot'=>$content,
'mod'=>
'showjobs'))->overrideGlobals();
113 $showJobsPlugin->OutputOpen();
114 return $showJobsPlugin->getResponse();
124 if (count($uploads) == 0) {
127 return '--uploadsAdd='. implode(
',', array_keys($uploads));
140 $uploadId = $upload->getId();
141 $spdxTwoAgent =
plugin_find(
'agent_'.$this->outputFormat);
145 $dbManager = $this->
getObject(
'db.manager');
146 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job '
147 .
'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';
148 $params = array($spdxTwoAgent->AgentName,$uploadId,$userId,$groupId);
151 $sql .=
' AND jq_cmd_args=$5';
152 $params[] = $jqCmdArgs;
155 $sql .=
' AND jq_cmd_args IS NULL';
157 $scheduled = $dbManager->getSingleRow($sql,$params,$log);
158 if (!empty($scheduled)) {
159 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
161 if (empty($jqCmdArgs)) {
162 $jobName = $upload->getFilename();
164 $jobName =
"Multi File SPDX2";
166 $jobId = JobAddJob($userId, $groupId, $jobName, $uploadId);
168 $jobQueueId = $spdxTwoAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
169 if ($jobQueueId < 0) {
170 throw new \Exception(_(
"Cannot schedule").
": ".$error);
172 return array($jobId,$jobQueueId, $error);
182 protected function getUpload($uploadId, $groupId)
184 if ($uploadId <= 0) {
185 throw new \Exception(_(
"parameter error: $uploadId"));
188 $uploadDao = $this->
getObject(
'dao.upload');
189 if (!$uploadDao->isAccessible($uploadId, $groupId)) {
190 throw new \Exception(_(
"permission denied"));
193 $upload = $uploadDao->getUpload($uploadId);
194 if ($upload ===
null) {
195 throw new \Exception(_(
'cannot find uploadId'));
211 $outputFormat = self::DEFAULT_OUTPUT_FORMAT, $addUploads = array())
218 register_plugin(
new SpdxTwoGeneratorUi());
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.
uploadsAdd($uploads)
Add multiple uploads to the report.
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())
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).