70 public function getJobs($request, $response, $args)
72 $query = $request->getQueryParams();
76 if ($request->hasHeader(
'limit')) {
77 $limit = $request->getHeaderLine(
'limit');
78 $page = $request->getHeaderLine(
'page');
82 if ((isset($limit) && (! is_numeric($limit) || $limit < 0)) ||
83 (! is_numeric($page) || $page < 1)) {
84 $returnVal =
new Info(400,
85 "Limit and page cannot be smaller than 1 and has to be numeric!",
87 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
92 if (isset($args[
'id'])) {
93 $id = intval($args[
'id']);
94 if (! $this->dbHelper->doesIdExist(
"job",
"job_pk", $id)) {
95 $returnVal =
new Info(404,
"Job id " . $id .
" doesn't exist",
97 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
106 if (array_key_exists(self::UPLOAD_PARAM, $query)) {
109 $response, $limit, $page);
125 $folder = $request->getHeaderLine(
"folderId");
126 $upload = $request->getHeaderLine(
"uploadId");
127 if (is_numeric($folder) && is_numeric($upload) && $folder > 0 && $upload > 0) {
128 $scanOptionsJSON = $request->getParsedBody();
129 if (empty($scanOptionsJSON)) {
130 $error =
new Info(403,
"No agents selected!", InfoType::ERROR);
131 return $response->withJson($error->getArray(), $error->getCode());
133 $parametersSent =
false;
135 if (array_key_exists(
"analysis", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"analysis"])) {
136 $analysis->setUsingArray($scanOptionsJSON[
"analysis"]);
137 $parametersSent =
true;
140 if (array_key_exists(
"decider", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"decider"])) {
141 $decider->setUsingArray($scanOptionsJSON[
"decider"]);
142 $parametersSent =
true;
144 $reuser =
new Reuser(0, 0,
false,
false);
146 if (array_key_exists(
"reuse", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"reuse"])) {
147 $reuser->setUsingArray($scanOptionsJSON[
"reuse"]);
148 $parametersSent =
true;
150 }
catch (\UnexpectedValueException $e) {
151 $error =
new Info($e->getCode(), $e->getMessage(), InfoType::ERROR);
152 return $response->withJson($error->getArray(), $error->getCode());
155 if (! $parametersSent) {
156 $error =
new Info(403,
"No parameters selected for agents!",
158 return $response->withJson($error->getArray(), $error->getCode());
161 $scanOptions =
new ScanOptions($analysis, $reuser, $decider);
162 $info = $scanOptions->scheduleAgents($folder, $upload);
163 return $response->withJson($info->getArray(), $info->getCode());
165 $error =
new Info(400,
"Folder id and upload id should be integers!", InfoType::ERROR);
166 return $response->withJson($error->getArray(), $error->getCode());
181 list($jobs, $count) = $this->dbHelper->getJobs($id, $limit, $page);
183 foreach ($jobs as $job) {
185 $finalJobs[] = $job->getArray();
188 $finalJobs = $finalJobs[0];
190 return $response->withHeader(
"X-Total-Pages", $count)->withJson($finalJobs, 200);
204 if (! $this->dbHelper->doesIdExist(
"upload",
"upload_pk", $uploadId)) {
205 $returnVal =
new Info(404,
"Upload id " . $uploadId .
" doesn't exist",
207 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
209 list($jobs, $count) = $this->dbHelper->getJobs(null, $limit, $page, $uploadId);
211 foreach ($jobs as $job) {
213 $finalJobs[] = $job->getArray();
215 return $response->withHeader(
"X-Total-Pages", $count)->withJson($finalJobs, 200);
225 $jobDao = $this->restHelper->getJobDao();
232 if (empty($job->getUploadId())) {
233 $sql =
"SELECT jq_pk, jq_end_bits from jobqueue WHERE jq_job_fk = $1;";
234 $statement = __METHOD__ .
".getJqpk";
235 $rows = $this->dbHelper->getDbManager()->getRows($sql, [$job->getId()],
237 if (count($rows) > 0) {
238 $jobqueue[$rows[0][
'jq_pk']] = $rows[0][
'jq_end_bits'];
241 $jobqueue = $jobDao->getAllJobStatus($job->getUploadId(),
242 $job->getUserId(), $job->getGroupId());
246 $job->getUploadId()));
248 $job->setStatus($this->
getJobStatus(array_keys($jobqueue)));
260 $showJobDao = $this->restHelper->getShowJobDao();
261 $eta = $showJobDao->getEstimatedTime($jobId,
'', 0, $uploadId);
262 $eta = explode(
":", $eta);
263 if (count($eta) > 1) {
264 $eta = ($eta[0] * 3600) + ($eta[1] * 60) + ($eta[2]);
279 $showJobDao = $this->restHelper->getShowJobDao();
282 foreach ($jobqueue as $jobId) {
283 $jobInfo = $showJobDao->getDataForASingleJob($jobId);
284 $endtext = $jobInfo[
'jq_endtext'];
287 $jobStatus |= self::JOB_COMPLETED;
292 $jobStatus |= self::JOB_STARTED;
295 if (empty($jobInfo[
'jq_endtime'])) {
296 $jobStatus |= self::JOB_QUEUED;
298 $jobStatus |= self::JOB_FAILED;
303 $jobStatusString =
"";
304 if ($jobStatus & self::JOB_STARTED) {
306 $jobStatusString =
"Processing";
307 }
else if ($jobStatus & self::JOB_QUEUED) {
308 $jobStatusString =
"Queued";
309 }
else if ($jobStatus & self::JOB_FAILED) {
311 $jobStatusString =
"Failed";
314 $jobStatusString =
"Completed";
316 return $jobStatusString;
Base controller for REST calls.
Model to hold add settings for new scan.
Model to hold info required by Reuser agent.
createJob($request, $response, $args)
Controller for Job model.
getUploadEtaInSeconds($jobId, $uploadId)
updateEtaAndStatus(&$job)
getJobs($request, $response, $args)
getFilteredResults($uploadId, $response, $limit, $page)
Model to hold analysis settings.
Info model to contain general error and return values.
getAllResults($id, $response, $limit, $page)