<commit_before><?php

/**
 * This file is part of tenside/core-bundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core-bundle
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME> <<EMAIL>>
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
 * @link       https://github.com/tenside/core-bundle
 * @filesource
 */

namespace Tenside\CoreBundle\Controller;

use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Process\Process;
use Tenside\CoreBundle\Annotation\ApiDescription;
use Tenside\Core\Config\TensideJsonConfig;
use Tenside\Core\Task\Task;
use Tenside\Core\Util\JsonArray;

/**
 * Lists and executes queued tasks.
 */
class TaskRunnerController extends AbstractController
{
    /**
     * Retrieve the task list.
     *
     * @return JsonResponse
     *
     * @ApiDoc(
     *   section="tasks",
     *   statusCodes = {
     *     200 = "When everything worked out ok"
     *   },
     *   authentication = true,
     *   authenticationRoles = {
     *     "ROLE_MANIPULATE_REQUIREMENTS"
     *   },
     * )
     * @ApiDescription(
     *   response={
     *     "<task-id>[]" = {
     *       "children" = {
     *         "id" = {
     *           "dataType" = "string",
     *           "description" = "The task id."
     *         },
     *         "type" = {
     *           "dataType" = "string",
     *           "description" = "The type of the task."
     *         }
     *       }
     *     }
     *   }
     * )
     */
    public function getTasksAction()
    {
        $result = [];
        $list   = $this->getTensideTasks();
        foreach ($list->getIds() as $taskId) {
            $result[$taskId] = [
                'id'   => $taskId,
                'type' => $list->getTask($taskId)->getType()
            ];
        }

        return JsonResponse::create($result)
            ->setEncodingOptions((JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_FORCE_OBJECT));
    }

    /**
     * Retrieve the given task task.
     *
     * @param string  $taskId  The id of the task to retrieve.
     *
     * @param Request $request The request.
     *
     * @return JsonResponse
     *
     * @throws NotFoundHttpException When the task could not be found.
     *
     * @ApiDoc(
     *   section="tasks",
     *   statusCodes = {
     *     200 = "When everything worked out ok"
     *   },
     *   authentication = true,
     *   authenticationRoles = {
     *     "ROLE_MANIPULATE_REQUIREMENTS"
     *   },
     * )
     * @ApiDescription(
     *   response={
     *     "status" = {
     *       "dataType" = "string",<commit_msg>Add documentation for offset filter in task_get<commit_after><?php

/**
 * This file is part of tenside/core-bundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core-bundle
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME> <<EMAIL>>
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
 * @link       https://github.com/tenside/core-bundle
 * @filesource
 */

namespace Tenside\CoreBundle\Controller;

use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Process\Process;
use Tenside\CoreBundle\Annotation\ApiDescription;
use Tenside\Core\Config\TensideJsonConfig;
use Tenside\Core\Task\Task;
use Tenside\Core\Util\JsonArray;

/**
 * Lists and executes queued tasks.
 */
class TaskRunnerController extends AbstractController
{
    /**
     * Retrieve the task list.
     *
     * @return JsonResponse
     *
     * @ApiDoc(
     *   section="tasks",
     *   statusCodes = {
     *     200 = "When everything worked out ok"
     *   },
     *   authentication = true,
     *   authenticationRoles = {
     *     "ROLE_MANIPULATE_REQUIREMENTS"
     *   },
     * )
     * @ApiDescription(
     *   response={
     *     "<task-id>[]" = {
     *       "children" = {
     *         "id" = {
     *           "dataType" = "string",
     *           "description" = "The task id."
     *         },
     *         "type" = {
     *           "dataType" = "string",
     *           "description" = "The type of the task."
     *         }
     *       }
     *     }
     *   }
     * )
     */
    public function getTasksAction()
    {
        $result = [];
        $list   = $this->getTensideTasks();
        foreach ($list->getIds() as $taskId) {
            $result[$taskId] = [
                'id'   => $taskId,
                'type' => $list->getTask($taskId)->getType()
            ];
        }

        return JsonResponse::create($result)
            ->setEncodingOptions((JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_FORCE_OBJECT));
    }

    /**
     * Retrieve the given task task.
     *
     * @param string  $taskId  The id of the task to retrieve.
     *
     * @param Request $request The request.
     *
     * @return JsonResponse
     *
     * @throws NotFoundHttpException When the task could not be found.
     *
     * @ApiDoc(
     *   section="tasks",
     *   statusCodes = {
     *     200 = "When everything worked out ok"
     *   },
     *   authentication = true,
     *   authenticationRoles = {
     *     "ROLE_MANIPULATE_REQUIREMENTS"
     *   },
     *   filters = {
     *     {
     *       "name"="offset",
     *       "dataType" = "int",
     *       "description"="If present, the output will be returned from the given byte offset."
     *     }
     *   }
     * )
     * @ApiDescription(
     *   response={
     *     "status" = {
     *       "dataType" = "string",
{'fraction_non_alphanumeric': 0.12691365584813227, 'fraction_numerical': 0.003061849357011635, 'mean_word_length': 2.052803738317757, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 43, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1444665', 'n_tokens_mistral': 2041, 'n_tokens_neox': 2034, 'n_words': 429}