113 $fileDescription, $isPublic, $ignoreScm, $uploadType)
115 $uploadedFile = $request->getUploadedFiles();
116 $body = $request->getParsedBody();
118 if (! empty($ignoreScm) && ($ignoreScm ==
"true" || $ignoreScm)) {
124 if (empty($uploadedFile) ||
125 ! isset($uploadedFile[$this->uploadFilePage::FILE_INPUT_NAME])) {
126 if (empty($uploadType)) {
127 return array(
false,
"Missing 'uploadType' header",
128 "Send file with parameter " . $this->uploadFilePage::FILE_INPUT_NAME .
129 " or define 'uploadType' header with appropriate body.",
133 return $this->
handleUpload($body, $uploadType, $folderId,
134 $fileDescription, $isPublic, $ignoreScm);
136 $uploadedFile = $uploadedFile[$this->uploadFilePage::FILE_INPUT_NAME];
138 $fileDescription, $isPublic, $ignoreScm);
153 $isPublic, $ignoreScm = 0)
155 $path = $uploadedFile->file;
156 $originalName = $uploadedFile->getClientFilename();
157 $originalMime = $uploadedFile->getClientMediaType();
158 $originalError = $uploadedFile->getError();
159 $symfonyFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(
160 $path, $originalName, $originalMime, $originalError);
161 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
162 $symfonySession = $GLOBALS[
'container']->get(
'session');
163 $symfonySession->set(
164 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
166 $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
168 $symfonyRequest->request->set($this->uploadFilePage::DESCRIPTION_INPUT_NAME,
170 $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
172 $symfonyRequest->setSession($symfonySession);
173 $symfonyRequest->request->set(
174 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
175 $symfonyRequest->request->set(
'public', $isPublic);
176 $symfonyRequest->request->set(
'scm', $ignoreScm);
178 return $this->uploadFilePage->handleRequest($symfonyRequest);
192 private function handleUpload($body, $uploadType, $folderId, $fileDescription,
193 $isPublic, $ignoreScm = 0)
196 switch ($uploadType) {
207 $message =
"Invalid 'uploadType'";
208 $statusDescription =
"uploadType should be any of (" .
209 implode(
",", self::VALID_UPLOAD_TYPES) .
")";
211 $sanity = array(
false, $message, $statusDescription, $code);
213 if ($sanity !==
true) {
216 $uploadResponse =
false;
217 switch ($uploadType) {
220 $fileDescription, $isPublic, $ignoreScm);
224 $fileDescription, $isPublic, $ignoreScm);
228 $fileDescription, $isPublic, $ignoreScm);
231 return $uploadResponse;
247 $statusDescription =
"";
250 if (! array_key_exists(
"vcsType", $vcsData) ||
251 ! in_array($vcsData[
"vcsType"], self::VALID_VCS_TYPES)) {
252 $message =
"Missing vcsType";
253 $statusDescription =
"vcsType should be any of (" .
254 implode(
", ", self::VALID_VCS_TYPES) .
")";
258 if ($vcsData[
"vcsType"] ==
"git") {
264 if (! array_key_exists(
"vcsUrl", $vcsData)) {
265 $message =
"Missing vcsUrl";
266 $statusDescription =
"vcsUrl should be passed.";
270 if (! array_key_exists(
"vcsName", $vcsData)) {
271 $vcsData[
"vcsName"] =
"";
273 if (! array_key_exists(
"vcsUsername", $vcsData)) {
274 $vcsData[
"vcsUsername"] =
"";
276 if (! array_key_exists(
"vcsPassword", $vcsData)) {
277 $vcsData[
"vcsPassword"] =
"";
279 if (! array_key_exists(
"vcsBranch", $vcsData)) {
280 $vcsData[
"vcsBranch"] =
"";
282 $vcsData[
"vcsType"] = $vcsType;
284 return array(
false, $message, $statusDescription, $code);
302 $statusDescription =
"";
305 if (! array_key_exists(
"url", $urlData)) {
306 $message =
"Missing url";
307 $statusDescription =
"Missing upload url from request";
311 if (! array_key_exists(
"name", $urlData)) {
312 $urlData[
"name"] =
"";
314 if (! array_key_exists(
"accept", $urlData)) {
315 $urlData[
"accept"] =
"";
317 if (! array_key_exists(
"reject", $urlData)) {
318 $urlData[
"reject"] =
"";
320 if (! array_key_exists(
"maxRecursionDepth", $urlData)) {
321 $urlData[
"maxRecursionDepth"] =
"";
324 return array(
false, $message, $statusDescription, $code);
342 $statusDescription =
"";
345 if (! array_key_exists(
"path", $srvData)) {
346 $message =
"Missing path";
347 $statusDescription =
"Missing upload path from request";
351 if (! array_key_exists(
"name", $srvData)) {
352 $srvData[
"name"] =
"";
355 return array(
false, $message, $statusDescription, $code);
371 $isPublic, $ignoreScm)
373 $vcsType = $vcsData[
"vcsType"];
374 $vcsUrl = $vcsData[
"vcsUrl"];
375 $vcsName = $vcsData[
"vcsName"];
376 $vcsUsername = $vcsData[
"vcsUsername"];
377 $vcsPasswd = $vcsData[
"vcsPassword"];
378 $vcsBranch = $vcsData[
"vcsBranch"];
380 $symfonySession = $GLOBALS[
'container']->get(
'session');
381 $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
384 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
385 $symfonyRequest->setSession($symfonySession);
387 $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
389 $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
391 $symfonyRequest->request->set($this->uploadVcsPage::GETURL_PARAM, $vcsUrl);
392 $symfonyRequest->request->set(
393 $this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
394 $symfonyRequest->request->set(
'public', $isPublic);
395 $symfonyRequest->request->set(
'name', $vcsName);
396 $symfonyRequest->request->set(
'vcstype', $vcsType);
397 $symfonyRequest->request->set(
'username', $vcsUsername);
398 $symfonyRequest->request->set(
'passwd', $vcsPasswd);
399 $symfonyRequest->request->set(
'branch', $vcsBranch);
400 $symfonyRequest->request->set(
'scm', $ignoreScm);
402 return $this->uploadVcsPage->handleRequest($symfonyRequest);
415 $isPublic, $ignoreScm)
417 $url = $urlData[
"url"];
418 $name = $urlData[
"name"];
419 $accept = $urlData[
"accept"];
420 $reject = $urlData[
"reject"];
421 $maxRecursionDepth = $urlData[
"maxRecursionDepth"];
423 $symfonySession = $GLOBALS[
'container']->get(
'session');
424 $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
427 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
428 $symfonyRequest->setSession($symfonySession);
430 $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
432 $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
434 $symfonyRequest->request->set(
435 $this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
436 $symfonyRequest->request->set(
'public', $isPublic);
437 $symfonyRequest->request->set($this->uploadUrlPage::NAME_PARAM, $name);
438 $symfonyRequest->request->set($this->uploadUrlPage::ACCEPT_PARAM, $accept);
439 $symfonyRequest->request->set($this->uploadUrlPage::REJECT_PARAM, $reject);
440 $symfonyRequest->request->set($this->uploadUrlPage::GETURL_PARAM, $url);
441 $symfonyRequest->request->set($this->uploadUrlPage::LEVEL_PARAM,
443 $symfonyRequest->request->set(
'scm', $ignoreScm);
445 return $this->uploadUrlPage->handleRequest($symfonyRequest);
458 $isPublic, $ignoreScm)
460 $path = $srvData[
"path"];
461 $name = $srvData[
"name"];
463 $symfonySession = $GLOBALS[
'container']->get(
'session');
464 $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
467 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
468 $symfonyRequest->setSession($symfonySession);
470 $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
472 $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
474 $symfonyRequest->request->set(
475 $this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
476 $symfonyRequest->request->set(
'public', $isPublic);
477 $symfonyRequest->request->set($this->uploadSrvPage::SOURCE_FILES_FIELD,
479 $symfonyRequest->request->set($this->uploadSrvPage::NAME_PARAM, $name);
480 $symfonyRequest->request->set(
'scm', $ignoreScm);
482 return $this->uploadSrvPage->handleRequest($symfonyRequest);
494 $restHelper = $container->get(
'helper.restHelper');
495 $uploadDao = $restHelper->getUploadDao();
496 $dbManager = $restHelper->getDbHelper()->getDbManager();
497 $clearingDao = $container->get(
'dao.clearing');
498 $copyrightDao = $container->get(
'dao.copyright');
499 $agentDao = $container->get(
'dao.agent');
501 $agentName =
"copyright";
503 $totalClearings = $clearingDao->getTotalDecisionCount($uploadId, $groupId);
504 $clearingCount = $clearingDao->getClearingDecisionsCount($uploadId,
506 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
507 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
508 $uploadTreeTableName);
510 $scanProx->createAgentStatus([$agentName]);
511 $agents = $scanProx->getLatestSuccessfulAgentIds();
513 if (array_key_exists($agentName, $agents) && ! empty($agents[$agentName])) {
514 $copyrightCount = count(
515 $copyrightDao->getAllEntriesReport($agentName, $uploadId,
516 $uploadTreeTableName, null,
false, null,
"C.agent_fk = " .
517 $agents[$agentName], $groupId));
520 $mainLicenses = $this->
getMainLicenses($dbManager, $uploadId, $groupId);
522 $uiLicense = $restHelper->getPlugin(
"license");
523 $hist = $uiLicense->getUploadHist($itemTreeBounds);
526 $summary->setUploadId($uploadId);
527 $summary->setUploadName($uploadDao->getUpload($uploadId)->getFilename());
528 if ($mainLicenses !== null) {
529 $summary->setMainLicense(implode(
",", $mainLicenses));
531 $summary->setUniqueLicenses($hist[
'uniqueLicenseCount']);
532 $summary->setTotalLicenses($hist[
'scannerLicenseCount']);
533 $summary->setUniqueConcludedLicenses($hist[
'editedUniqueLicenseCount']);
534 $summary->setTotalConcludedLicenses($hist[
'editedLicenseCount']);
535 $summary->setFilesToBeCleared($totalClearings - $clearingCount);
536 $summary->setFilesCleared($clearingCount);
537 $summary->setClearingStatus($uploadDao->getStatus($uploadId, $groupId));
538 $summary->setCopyrightCount($copyrightCount);
551 $sql =
"SELECT rf_shortname FROM upload_clearing_license ucl, license_ref" 552 .
" WHERE ucl.group_fk=$1 AND upload_fk=$2 AND ucl.rf_fk=rf_pk;";
553 $stmt = __METHOD__.
'.collectMainLicenses';
554 $rows = $dbManager->getRows($sql, array($groupId, $uploadId), $stmt);
559 foreach ($rows as $row) {
560 array_push($mainLicenses, $row[
'rf_shortname']);
562 return $mainLicenses;
573 public function getUploadLicenseList($uploadId, $agents, $printContainers)
576 $restHelper = $container->get(
'helper.restHelper');
577 $uploadDao = $restHelper->getUploadDao();
578 $agentDao = $container->get(
'dao.agent');
580 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
581 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
584 $scanProx->createAgentStatus($agents);
585 $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
590 $licenseListObj = $restHelper->getPlugin(
'export-list');
591 $licenseList = $licenseListObj->createListOfLines($uploadTreeTableName,
592 $parent->getItemId(), $agent_ids, -1,
true,
'', !$printContainers);
593 if (array_key_exists(
"warn", $licenseList)) {
594 unset($licenseList[
"warn"]);
generateVcsUpload($vcsData, $folderId, $fileDescription, $isPublic, $ignoreScm)
generateSrvUpload($srvData, $folderName, $fileDescription, $isPublic, $ignoreScm)
sanitizeUrlData(&$urlData)
Check if the passed URL object is correct or not.
createFileUpload($uploadedFile, $folderId, $fileDescription, $isPublic, $ignoreScm=0)
handleUpload($body, $uploadType, $folderId, $fileDescription, $isPublic, $ignoreScm=0)
createNewUpload(ServerRequestInterface $request, $folderId, $fileDescription, $isPublic, $ignoreScm, $uploadType)
generateUploadSummary($uploadId, $groupId)
Model class to hold Upload info.
generateUrlUpload($urlData, $folderName, $fileDescription, $isPublic, $ignoreScm)
getMainLicenses($dbManager, $uploadId, $groupId)
Handle new file uploads from Slim framework and move to FOSSology.
sanitizeVcsData(&$vcsData)
Check if the passed VCS object is correct or not.
sanitizeSrvData(&$srvData)
Check if the passed server upload object is correct or not.