feature: adding setRequestTimeout to JasperServerRequestService.

feat-add-timeout-definition
Gabriel Lima 3 months ago
parent 4a59a88096
commit d0e7eedbcc

@ -7,8 +7,7 @@ use Ae3\JasperServer\Laravel\Integrator\app\Enums\ReportFormatEnum;
use Ae3\JasperServer\Laravel\Integrator\app\Services\Contracts\JasperServerRequestServiceContract; use Ae3\JasperServer\Laravel\Integrator\app\Services\Contracts\JasperServerRequestServiceContract;
use Jaspersoft\Client\Client; use Jaspersoft\Client\Client;
class JasperServerRequestService implements JasperServerRequestServiceContract class JasperServerRequestService implements JasperServerRequestServiceContract {
{
/** /**
* @var Client|null * @var Client|null
*/ */
@ -90,8 +89,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param $value * @param $value
* @return $this * @return $this
*/ */
public function addInputControl(string $key, $value): self public function addInputControl(string $key, $value): self {
{
if (!$this->inputControls) { if (!$this->inputControls) {
$this->inputControls = []; $this->inputControls = [];
} }
@ -103,8 +101,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param int $timeout * @param int $timeout
* @return $this * @return $this
*/ */
public function setRequestTimeout(int $timeout): self public function setRequestTimeout(int $timeout): self {
{
$this->requestTimeout = $timeout; $this->requestTimeout = $timeout;
return $this; return $this;
} }
@ -113,8 +110,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $format * @param string $format
* @return $this * @return $this
*/ */
public function setFormat(string $format): self public function setFormat(string $format): self {
{
$this->format = $format; $this->format = $format;
return $this; return $this;
} }
@ -123,8 +119,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param $attachmentsPrefix * @param $attachmentsPrefix
* @return $this * @return $this
*/ */
public function setAttachmentsPrefix($attachmentsPrefix): self public function setAttachmentsPrefix($attachmentsPrefix): self {
{
$this->attachmentsPrefix = $attachmentsPrefix; $this->attachmentsPrefix = $attachmentsPrefix;
return $this; return $this;
} }
@ -133,8 +128,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param bool $freshData * @param bool $freshData
* @return $this * @return $this
*/ */
public function setFreshData(bool $freshData): self public function setFreshData(bool $freshData): self {
{
$this->freshData = $freshData; $this->freshData = $freshData;
return $this; return $this;
} }
@ -143,8 +137,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param bool $interactive * @param bool $interactive
* @return $this * @return $this
*/ */
public function setInteractive(bool $interactive): self public function setInteractive(bool $interactive): self {
{
$this->interactive = $interactive; $this->interactive = $interactive;
return $this; return $this;
} }
@ -153,8 +146,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param bool $onePagePerSheet * @param bool $onePagePerSheet
* @return $this * @return $this
*/ */
public function setOnePagePerSheet(bool $onePagePerSheet): self public function setOnePagePerSheet(bool $onePagePerSheet): self {
{
$this->onePagePerSheet = $onePagePerSheet; $this->onePagePerSheet = $onePagePerSheet;
return $this; return $this;
} }
@ -163,8 +155,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $pages * @param string $pages
* @return $this * @return $this
*/ */
public function setPages(string $pages): self public function setPages(string $pages): self {
{
$this->pages = $pages; $this->pages = $pages;
return $this; return $this;
} }
@ -173,8 +164,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param bool $saveDataSnapshot * @param bool $saveDataSnapshot
* @return $this * @return $this
*/ */
public function setSaveDataSnapshot(bool $saveDataSnapshot): self public function setSaveDataSnapshot(bool $saveDataSnapshot): self {
{
$this->saveDataSnapshot = $saveDataSnapshot; $this->saveDataSnapshot = $saveDataSnapshot;
return $this; return $this;
} }
@ -183,8 +173,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $transformerKey * @param string $transformerKey
* @return $this * @return $this
*/ */
public function setTransformerKey(string $transformerKey): self public function setTransformerKey(string $transformerKey): self {
{
$this->transformerKey = $transformerKey; $this->transformerKey = $transformerKey;
return $this; return $this;
} }
@ -193,8 +182,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $contentDisposition * @param string $contentDisposition
* @return $this * @return $this
*/ */
public function setContentDisposition(string $contentDisposition): self public function setContentDisposition(string $contentDisposition): self {
{
$this->contentDisposition = $contentDisposition; $this->contentDisposition = $contentDisposition;
return $this; return $this;
} }
@ -202,8 +190,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
/** /**
* @return string Binary data of report * @return string Binary data of report
*/ */
public function getReport(): string public function getReport(): string {
{
return $this->report; return $this->report;
} }
@ -211,8 +198,11 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $uri * @param string $uri
* @return $this * @return $this
*/ */
public function call(string $uri): self public function call(string $uri): self {
{ if (method_exists($this->client, 'setRequestTimeout')) {
$this->client->setRequestTimeout($this->requestTimeout);
}
$this->report = $this->client->reportService()->runReport( $this->report = $this->client->reportService()->runReport(
$uri, $uri,
$this->format, $this->format,
@ -232,8 +222,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
/** /**
* @return void * @return void
*/ */
public function inline(): void public function inline(): void {
{
$this->setContentDisposition(ContentDispositionEnum::INLINE); $this->setContentDisposition(ContentDispositionEnum::INLINE);
$this->setHeader($this->report); $this->setHeader($this->report);
echo $this->getReport(); echo $this->getReport();
@ -243,8 +232,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string|null $filename * @param string|null $filename
* @return void * @return void
*/ */
public function download(?string $filename = null): void public function download(?string $filename = null): void {
{
if (in_array($this->format, ReportFormatEnum::downloadable())) { if (in_array($this->format, ReportFormatEnum::downloadable())) {
$this->setContentDisposition(ContentDispositionEnum::ATTACHMENT); $this->setContentDisposition(ContentDispositionEnum::ATTACHMENT);
$this->setHeader($this->report, $filename); $this->setHeader($this->report, $filename);
@ -258,8 +246,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string|null $filename * @param string|null $filename
* @return void * @return void
*/ */
private function setHeader(string $report, ?string $filename = null) private function setHeader(string $report, ?string $filename = null) {
{
if (!$filename) { if (!$filename) {
$filename = uniqid(); $filename = uniqid();
} }
@ -279,8 +266,7 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
* @param string $filename * @param string $filename
* @return string * @return string
*/ */
private function appendFormatExtension(string $filename): string private function appendFormatExtension(string $filename): string {
{ return $filename . '.' . $this->format;
return $filename . '.' . $this->format; }
}
} }

Loading…
Cancel
Save