Skip to content

Commit

Permalink
Samsung External Registration Feed
Browse files Browse the repository at this point in the history
* fixing attendee not found by email

Change-Id: I0c65057de74eaedd6299c90655fef7e795cfa04e
  • Loading branch information
smarcet committed Jun 9, 2023
1 parent 5f7c8ea commit 1172f07
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/Services/Apis/Samsung/DecryptedListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function __construct(string $key, string $content, string $forum){
$list = json_decode($dec->getData(), true);
if(!is_array($list))
throw new InvalidResponse(sprintf("invalid data field on response %s", $content));

if(count($list) == 0)
throw new EmptyResponse("response not found");

$this->payload = $list;
}

Expand Down
3 changes: 3 additions & 0 deletions app/Services/Apis/Samsung/DecryptedSingleResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function __construct(string $key, string $content, string $forum){
if(!is_array($list))
throw new InvalidResponse(sprintf("invalid data field on response %s", $content));
$this->payload = count($list) == 1 ? $list[0] : $list;

if(count($this->payload) == 0)
throw new EmptyResponse("response not found");
}


Expand Down
34 changes: 28 additions & 6 deletions app/Services/Apis/Samsung/SamsungRegistrationAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use GuzzleHttp\Client;
use Exception;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
Expand Down Expand Up @@ -91,11 +90,19 @@ public function checkUser(Summit $summit, string $userId, string $region = Regio
}
catch (RequestException $ex) {
Log::warning($ex->getMessage());
return null;
return [];
}
catch(EmptyResponse $ex){
Log::warning($ex->getMessage());
return [];
}
catch (InvalidResponse $ex){
Log::warning($ex->getMessage());
return [];
}
catch (Exception $ex) {
Log::error($ex->getMessage());
return null;
return [];
}
}

Expand All @@ -114,7 +121,6 @@ public function checkEmail(Summit $summit,string $email, string $region = Region

Log::debug(sprintf("SamsungRegistrationAPI::checkEmail POST %s payload %s", $this->endpoint, $request));


// http://docs.guzzlephp.org/en/stable/request-options.html
$response = $this->client->request('POST',
$this->endpoint,
Expand All @@ -138,11 +144,19 @@ public function checkEmail(Summit $summit,string $email, string $region = Region
}
catch (RequestException $ex) {
Log::warning($ex->getMessage());
return null;
return [];
}
catch(EmptyResponse $ex){
Log::warning($ex->getMessage());
return [];
}
catch (InvalidResponse $ex){
Log::warning($ex->getMessage());
return [];
}
catch (Exception $ex) {
Log::error($ex->getMessage());
return null;
return [];
}
}

Expand Down Expand Up @@ -182,6 +196,14 @@ public function userList(Summit $summit, string $region = Regions::US)
Log::warning($ex->getMessage());
return null;
}
catch(EmptyResponse $ex){
Log::warning($ex->getMessage());
return null;
}
catch(InvalidResponse $ex){
Log::warning($ex->getMessage());
return null;
}
catch (Exception $ex) {
Log::error($ex->getMessage());
return null;
Expand Down
4 changes: 4 additions & 0 deletions app/Services/Model/Imp/RegistrationIngestionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public function ingestExternalAttendee($summit_id, $index, $external_attendee, I
$cancelled = $external_attendee['cancelled'] ?? false;

$ticket_type = $summit->getTicketTypeByExternalId($ticket_class['id']);

if (is_null($ticket_type)) {
// create ticket type if it does not exists
Log::debug(sprintf("RegistrationIngestionService::ingestSummit: ticket class %s does not exists", $ticket_class['id']));
Expand Down Expand Up @@ -640,6 +641,9 @@ public function ingestSummit(Summit $summit): void
Log::debug(sprintf("RegistrationIngestionService::ingestSummit getting external attendees page %s", $page));
$response = $feed->getAttendees($page, $summit->getExternalRegistrationFeedLastIngestDate());

if(is_null($response))
throw new ValidationException("Response is empty");

if ($response->hasData()) {
$shouldMarkProcess = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ public function find(): ?SummitAttendeeTicket
Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find ticket_criteria %s", $this->ticket_criteria));

if($this->feed->isValidQRCode($this->ticket_criteria)){
Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find ticket_criteria %s is a valid QRCode", $this->ticket_criteria));
$externalAttendeeId = $this->feed->getExternalUserIdFromQRCode($this->ticket_criteria);
// check first if we have it locally
$attendee = $this->attendee_repository->getBySummitAndExternalId
(
$this->summit, $externalAttendeeId
);

if(!is_null($attendee) && !$attendee->hasTickets()){
Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find attendee %s has no tickets, re fetch it from external feed", $externalAttendeeId));
$attendee = null;
}

if(is_null($attendee)) {

Log::debug
Expand Down Expand Up @@ -123,15 +129,22 @@ public function find(): ?SummitAttendeeTicket

return $attendee->getFirstTicket();
}

if(filter_var($this->ticket_criteria, FILTER_VALIDATE_EMAIL)){

Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find ticket_criteria %s is a valid email", $this->ticket_criteria));
$externalAttendeeEmail = $this->ticket_criteria;
// check first if we have it locally
$attendee = $this->attendee_repository->getBySummitAndEmail
(
$this->summit, $externalAttendeeEmail
);

if(!is_null($attendee) && !$attendee->hasTickets()){
Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find attendee %s has no tickets, re fetch it from external feed", $externalAttendeeEmail));
$attendee = null;
}

if(is_null($attendee)) {

Log::debug
Expand Down Expand Up @@ -170,6 +183,7 @@ public function find(): ?SummitAttendeeTicket
}
return $attendee->getFirstTicket();
}
Log::debug(sprintf("TicketFinderByExternalFeedStrategy::find ticket_criteria %s is not a valid QRCode or email", $this->ticket_criteria));
return null;
}
}

0 comments on commit 1172f07

Please sign in to comment.