Skip to content

Commit

Permalink
refactoring crawler , add SPO
Browse files Browse the repository at this point in the history
  • Loading branch information
esposimo committed Apr 7, 2024
1 parent d1e1c4c commit 8f204c0
Show file tree
Hide file tree
Showing 20 changed files with 1,273 additions and 208 deletions.
4 changes: 3 additions & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"require": {
"illuminate/database": "10.39.0",
"predis/predis": "v2.2.2",
"ext-xmlreader": "*"
"ext-xmlreader": "*",
"ext-simplexml": "*",
"ext-libxml": "*"
},
"require-dev": {
"phpunit/phpunit": "11.0.1"
Expand Down
9 changes: 8 additions & 1 deletion src/mock_crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,24 @@
$a = new \pagopa\crawler\paymentlist\resp\activatePaymentNotice(new \DateTime('2024-03-10'),'activatePaymentNotice', 'RESP', $redis_cache);
$a->run();

//die();

$a = new \pagopa\crawler\paymentlist\req\nodoInviaCarrelloRPT(new \DateTime('2024-03-10'),'nodoInviaCarrelloRPT', 'REQ', $redis_cache);
$a->run();

$a = new \pagopa\crawler\paymentlist\resp\nodoInviaCarrelloRPT(new \DateTime('2024-03-10'),'nodoInviaCarrelloRPT', 'RESP', $redis_cache);
$a->run();
//die();


$a = new \pagopa\crawler\paymentlist\resp\nodoInviaCarrelloRPT(new \DateTime('2024-03-11'),'nodoInviaCarrelloRPT', 'RESP', $redis_cache);
$a->run();


$a = new \pagopa\crawler\paymentlist\req\sendPaymentOutcome(new DateTime('2024-03-10'), 'sendPaymentOutcome', 'REQ', $redis_cache);
$a->run();

$a = new \pagopa\crawler\paymentlist\resp\sendPaymentOutcome(new DateTime('2024-03-10'), 'sendPaymentOutcome', 'RESP', $redis_cache);
$a->run();
die();
//$a = new \pagopa\crawler\paymentlist\resp\activatePaymentNotice(new \DateTime('2024-03-10'),'activatePaymentNotice', 'RESP', $memcache);
//$a->run();
92 changes: 92 additions & 0 deletions src/mock_insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,98 @@





/* inserimento eventi per sendPaymentOutcome */


// activate+sendPayment OK con 2 transfer

$data_req = [
':id' => 40,
':date_event' => '2024-03-10',
':inserted_timestamp' => '2024-03-10 12:35:00.197',
':tipoevento' => 'activatePaymentNotice',
':sottotipoevento' => 'REQ',
':iddominio' => '77777777777',
':iuv' => '01000000000000030',
':ccp' => 't0000000000000000000000000000030',
':noticenumber' => '301000000000000030',
':creditorreferenceid' => '01000000000000030',
':paymenttoken' => 't0000000000000000000000000000030',
':psp' => 'AGID_01',
':stazione' => '77777777777_01',
':canale' => '88888888888_01',
':sessionid' => 'sessid_000030',
':sessionidoriginal' => '',
':uniqueid' => 'T000040',
':payload' => 'PHNvYXBlbnY6RW52ZWxvcGUgeG1sbnM6bm9kPSJodHRwOi8vcGFnb3BhLWFwaS5wYWdvcGEuZ292Lml0L25vZGUvbm9kZUZvclBzcC54c2QiIHhtbG5zOnNvYXBlbnY9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW52ZWxvcGUvIj4KCTxzb2FwZW52OkhlYWRlci8+Cgk8c29hcGVudjpCb2R5PgoJCTxub2Q6YWN0aXZhdGVQYXltZW50Tm90aWNlUmVxPgoJCQk8aWRQU1A+UFNQXzAxPC9pZFBTUD4KCQkJPGlkQnJva2VyUFNQPjg4ODg4ODg4ODg4PC9pZEJyb2tlclBTUD4KCQkJPGlkQ2hhbm5lbD44ODg4ODg4ODg4OF8wMTwvaWRDaGFubmVsPgoJCQk8cGFzc3dvcmQ+KioqKio8L3Bhc3N3b3JkPgoJCQk8cXJDb2RlPgoJCQkJPGZpc2NhbENvZGU+Nzc3Nzc3Nzc3Nzc8L2Zpc2NhbENvZGU+CgkJCQk8bm90aWNlTnVtYmVyPjMwMTAwMDAwMDAwMDAwMDAzMDwvbm90aWNlTnVtYmVyPgoJCQk8L3FyQ29kZT4KCQkJPGFtb3VudD4wLjAwPC9hbW91bnQ+CgkJPC9ub2Q6YWN0aXZhdGVQYXltZW50Tm90aWNlUmVxPgoJPC9zb2FwZW52OkJvZHk+Cjwvc29hcGVudjpFbnZlbG9wZT4=',
];
$data_resp = [
':id' => 41,
':date_event' => '2024-03-10',
':inserted_timestamp' => '2024-03-10 12:36:00.197',
':tipoevento' => 'activatePaymentNotice',
':sottotipoevento' => 'RESP',
':iddominio' => '77777777777',
':iuv' => '01000000000000030',
':ccp' => 't0000000000000000000000000000030',
':noticenumber' => '301000000000000030',
':creditorreferenceid' => '01000000000000030',
':paymenttoken' => 't0000000000000000000000000000030',
':psp' => 'AGID_01',
':stazione' => '77777777777_01',
':canale' => '88888888888_01',
':sessionid' => 'sessid_000030',
':sessionidoriginal' => '',
':uniqueid' => 'T000041',
':payload' => 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIiA/Pgo8c29hcGVudjpFbnZlbG9wZSB4bWxuczpjb21tb249Imh0dHA6Ly9wYWdvcGEtYXBpLnBhZ29wYS5nb3YuaXQveHNkL2NvbW1vbi10eXBlcy92MS4wLjAvIiB4bWxuczpuZnA9Imh0dHA6Ly9wYWdvcGEtYXBpLnBhZ29wYS5nb3YuaXQvbm9kZS9ub2RlRm9yUHNwLnhzZCIgeG1sbnM6c29hcGVudj0iaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvc29hcC9lbnZlbG9wZS8iIHhtbG5zOnhzPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSI+Cgk8c29hcGVudjpCb2R5PgoJCTxuZnA6YWN0aXZhdGVQYXltZW50Tm90aWNlUmVzPgoJCQk8b3V0Y29tZT5PSzwvb3V0Y29tZT4KCQkJPHRvdGFsQW1vdW50PjE4MC4wMDwvdG90YWxBbW91bnQ+CgkJCTxwYXltZW50RGVzY3JpcHRpb24+eHh4e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mVmZXJlbmNlSWQ+CgkJPC9uZnA6YWN0aXZhdGVQYXltZW50Tm90aWNlUmVzPgoJPC9zb2FwZW52OkJvZHk+Cjwvc29hcGVudjpFbnZlbG9wZT4=',
];
Capsule::statement($render_query, $data_req);
Capsule::statement($render_query, $data_resp);
$data_req = [
':id' => 42,
':date_event' => '2024-03-10',
':inserted_timestamp' => '2024-03-10 12:37:00.197',
':tipoevento' => 'sendPaymentOutcome',
':sottotipoevento' => 'REQ',
':iddominio' => '77777777777',
':iuv' => '01000000000000030',
':ccp' => 't0000000000000000000000000000030',
':noticenumber' => '301000000000000030',
':creditorreferenceid' => '01000000000000030',
':paymenttoken' => 't0000000000000000000000000000030',
':psp' => 'AGID_01',
':stazione' => '77777777777_01',
':canale' => '88888888888_01',
':sessionid' => 'sessid_000031',
':sessionidoriginal' => '',
':uniqueid' => 'T000042',
':payload' => 'PHNvYXA6RW52ZWxvcGUgeG1sbnM6c29hcD0iaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvc29hcC9lbnZlbG9wZS8iPgoJPHNvYXA6Qm9keT4KCQk8bnMyOnNlbmRQYXltZW50T3V0Y29tZVJlcSB4bWxuczpuczI9Imh0dHA6Ly9wYWdvcGEtYXBpLnBhZ29wYS5nb3YuaXQvbm9kZS9ub2RlRm9yUHNwLnhzZCIgeG1sbnM6bnMzPSJodHRwOi8vd3MucGFnYW1lbnRpLnRlbGVtYXRpY2kuZ292LyI+CgkJCTxpZFBTUD5BR0lEXzAxPC9pZFBTUD4KCQkJPGlkQnJva2VyUFNQPjg4ODg4ODg4ODg4PC9pZEJyb2tlclBTUD4KCQkJPGlkQ2hhbm5lbD44ODg4ODg4ODg4OF8wMTwvaWRDaGFubmVsPgoJCQk8cGFzc3dvcmQ+eHh4eHh4eHg8L3Bhc3N3b3JkPgoJCQk8cGF5bWVudFRva2VuPnQwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDMwPC9wYXltZW50VG9rZW4+CgkJCTxvdXRjb21lPk9LPC9vdXRjb21lPgoJCQk8ZGV0YWlscz4KCQkJCTxwYXltZW50TWV0aG9kPm90aGVyPC9wYXltZW50TWV0aG9kPgoJCQkJPGZlZT4xLjAwPC9mZWU+CgkJCQk8YXBwbGljYXRpb25EYXRlPjIwMjQtMDQtMDI8L2FwcGxpY2F0aW9uRGF0ZT4KCQkJCTx0cmFuc2ZlckRhdGU+MjAyNC0wNC0wMzwvdHJhbnNmZXJEYXRlPgoJCQk8L2RldGFpbHM+CgkJPC9uczI6c2VuZFBheW1lbnRPdXRjb21lUmVxPgoJPC9zb2FwOkJvZHk+Cjwvc29hcDpFbnZlbG9wZT4=',
];
$data_resp = [
':id' => 43,
':date_event' => '2024-03-10',
':inserted_timestamp' => '2024-03-10 12:38:00.197',
':tipoevento' => 'sendPaymentOutcome',
':sottotipoevento' => 'RESP',
':iddominio' => '77777777777',
':iuv' => '01000000000000030',
':ccp' => 't0000000000000000000000000000030',
':noticenumber' => '301000000000000030',
':creditorreferenceid' => '01000000000000030',
':paymenttoken' => 't0000000000000000000000000000030',
':psp' => 'AGID_01',
':stazione' => '77777777777_01',
':canale' => '88888888888_01',
':sessionid' => 'sessid_000031',
':sessionidoriginal' => '',
':uniqueid' => 'T000043',
':payload' => 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIiA/Pjxzb2FwZW52OkVudmVsb3BlIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnNvYXBlbnY9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW52ZWxvcGUvIiB4bWxuczp4cz0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOmNvbW1vbj0iaHR0cDovL3BhZ29wYS1hcGkucGFnb3BhLmdvdi5pdC94c2QvY29tbW9uLXR5cGVzL3YxLjAuMC8iIHhtbG5zOm5mcD0iaHR0cDovL3BhZ29wYS1hcGkucGFnb3BhLmdvdi5pdC9ub2RlL25vZGVGb3JQc3AueHNkIj48c29hcGVudjpCb2R5PjxuZnA6c2VuZFBheW1lbnRPdXRjb21lUmVzPjxvdXRjb21lPk9LPC9vdXRjb21lPjwvbmZwOnNlbmRQYXltZW50T3V0Y29tZVJlcz48L3NvYXBlbnY6Qm9keT48L3NvYXBlbnY6RW52ZWxvcGU+',
];
Capsule::statement($render_query, $data_req);
Capsule::statement($render_query, $data_resp);

/*
Expand Down
28 changes: 28 additions & 0 deletions src/src/crawler/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ abstract class AbstractEvent implements EventInterface
*/
protected bool $isCart = false;


/**
* Restituisce il tipo di formato previsto per il payload
* @var string
*/
protected string $typePayload = 'xml';

/**
* Contiene i dati dell'evento
* @var array
Expand Down Expand Up @@ -226,4 +233,25 @@ public function isCartEvent(): bool
{
return $this->isCart;
}


public function isValidPayload(): bool
{
$payload = $this->getPayload();
if ($this->typePayload == 'xml')
{
libxml_use_internal_errors(true);
simplexml_load_string($payload);
$errors = libxml_get_errors();
libxml_clear_errors();
return empty($errors);
}
if ($this->typePayload == 'json')
{
json_decode($payload);
return json_last_error() === JSON_ERROR_NONE;
}
return false;

}
}
85 changes: 85 additions & 0 deletions src/src/crawler/CacheObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace pagopa\crawler;

class CacheObject
{

protected array $cache_data;

public function __construct(array $cache_data)
{
$this->cache_data = $cache_data;
}

public function getKey(string $key) : string|null
{
return (array_key_exists($key, $this->cache_data)) ? $this->cache_data[$key] : null;
}

public function getId() : string
{
return $this->getKey('id');
}

public function getDateEvent() : string
{
return $this->getKey('date_event');
// $cache_value = [
// 'date_event' => $date_event,
// 'id' => $last_inserted_id,
// 'iuv' => $this->getEvent()->getIuv(0),
// 'pa_emittente' => $this->getEvent()->getPaEmittente(0),
// 'token_ccp' => $token,
// 'transfer_added' => false,
// 'esito' => false,
// 'amount_update' => false,
// 'date_wf' => json_encode(array())
// ];
}

public function getIuv() : string
{
return $this->getKey('iuv');
}

public function getPaEmittente() : string
{
return $this->getKey('pa_emittente');
}

public function getToken() : string
{
return $this->getKey('token_ccp');
}

public function getTransferAdded() : bool
{
return $this->getKey('transfer_added');
}

public function getEsito() : bool
{
return $this->getKey('esito');
}
public function getAmountUpdate() : bool
{
return $this->getKey('amount_update');
}

public function getDateWf() : string
{
return $this->getKey('date_wf');
}

public function getCacheData() : array
{
return $this->cache_data;
}

public function setKey(string $key, mixed $value) : void
{
$this->cache_data[$key] = $value;
}

}
7 changes: 7 additions & 0 deletions src/src/crawler/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,11 @@ public function getFaultString() : string|null;
public function getFaultDescription() : string|null;


/**
* Restituisce true/false se il payload è valido (check del formato json/xml)
* @return bool
*/
public function isValidPayload() : bool;


}
74 changes: 74 additions & 0 deletions src/src/crawler/PaymentListInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace pagopa\crawler;

use Illuminate\Support\Facades\Cache;
use pagopa\database\sherlock\Transaction;
use pagopa\database\sherlock\TransactionDetails;
use pagopa\database\sherlock\TransactionRe;
use pagopa\database\sherlock\Workflow;

/**
* Questa interfaccia gestisce l'analisi di un blocco di eventi della stessa tipologia (es. tutte activatePaymentNotice Request, tutte nodoInviaCarrello Req, tutte pspNotifyPayment Response, etc)
Expand Down Expand Up @@ -299,4 +303,74 @@ public function runCompleteEvent(string $message = null) : TransactionRe;
* @return bool
*/
public function isCreateTransactionEvent() : bool;


/**
* Metodo eseguito quando un viene trattato un evento di tentativo di pagamento che può inizializzare una sessione di pagamento
* (activatePaymentNotice, nodoInviaCarrelloRPT, etc)
* Restituisce un array di informazioni da storicizzare in cache
* @param int $index
* @return array|null
*/
public function createTransaction(int $index = 0) : array|null;


/**
* Metodo che viene richiamato dopo la creazione di una transazione. Riceve i dati dalla cache per associare correttamente
* i transfer al tentativo
* Restituisce un array di informazioni da storicizzare in cache
* @param CacheObject $cache
* @param int $index
* @return array|null
*/
public function detailsTransaction(CacheObject $cache, int $index = 0) : array|null;


/**
* Crea un evento di workflow per l'evento analizzato, associandolo ad ogni pagamento impattato.
* Aggiunge anche extra data alla transaction se l'evento avviene in date diverse rispetto alla nascita
* del tentativo.
* Restituisce un array di informazioni da storicizzare in cache
* @param CacheObject $cache
* @param int $index
* @return array|null
*/
public function workflow(CacheObject $cache, int $index = 0) : array|null;

/**
* Metodo che viene lanciato quando la transazione già esiste ed è necessario aggiornarla
* I dati vengono recuperati fornendo ogni pagamento presente in cache.
* Restituisce un array di informazioni da storicizzare in cache
* @param CacheObject $cache
* @param int $index
* @return array|null
*/
public function updateTransaction(CacheObject $cache, int $index = 0) : array|null;

/**
* Metodo che viene lanciato quando la transazione già esiste ed è necessario aggiornare i dettagli.
* I dati vengono recuperati fornendo ogni pagamento presente in cache.
* Restituisce un array di informazioni da storicizzare in cache
* @param CacheObject $cache
* @param int $index
* @return array|null
*/
public function updateDetails(CacheObject $cache, int $index = 0) : array|null;

/**
* Crea un pagamento, che è relativo a una chiamata senza token (es. verifyPaymentNotice).
* Restituisce un array di informazioni da storicizzare in cache
* @param int $index
* @return array|null
*/
public function createPayment(int $index = 0): array|null;

/**
* Aggiorna i dettagli di un pagamento se necessario.
* Restituisce un array di informazioni da storicizzare in cache
* @param CacheObject $cache
* @param int $index
* @return array|null
*/
public function detailsPayment(CacheObject $cache, int $index = 0): array|null;
}
3 changes: 1 addition & 2 deletions src/src/crawler/events/req/sendPaymentOutcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ public function isValid(int $index = 0): bool
$iuv = $this->getIuv(0);
$pa = $this->getPaEmittente(0);
$token = $this->getPaymentToken(0);
$date = $this->getInsertedTimestamp()->format('Y-m-d');
return ($date && $iuv && $pa && $token);
return ($iuv && $pa && $token);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/src/crawler/events/resp/sendPaymentOutcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ public function isValid(int $index = 0): bool
$iuv = $this->getIuv(0);
$pa = $this->getPaEmittente(0);
$token = $this->getPaymentToken(0);
$date = $this->getInsertedTimestamp()->format('Y-m-d');
return ($date && $iuv && $pa && $token);
return ($iuv && $pa && $token);
}

/**
Expand Down
Loading

0 comments on commit 8f204c0

Please sign in to comment.