Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage multiple sponsors scan #1205

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public void downloadSponsorScanExport(@PathVariable("eventName") String eventNam
header.addAll(fields.stream().map(TicketFieldConfiguration::getName).collect(toList()));
header.add("Sponsor notes");
header.add("Lead Status");
header.add("Operator");

Stream<String[]> sponsorScans = userManager.findAllEnabledUsers(principal.getName()).stream()
.map(u -> Pair.of(u, userManager.getUserRole(u)))
Expand All @@ -460,6 +461,7 @@ public void downloadSponsorScanExport(@PathVariable("eventName") String eventNam

line.add(sponsorScan.getNotes());
line.add(sponsorScan.getLeadStatus().name());
line.add(sponsorScan.getOperator());
return line.toArray(new String[0]);
});

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/alfio/controller/api/v1/AttendeeApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
@Log4j2
public class AttendeeApiController {

public static final String ALFIO_OPERATOR_HEADER = "Alfio-Operator";
private final AttendeeManager attendeeManager;

@Autowired
Expand All @@ -72,15 +73,19 @@ public ResponseEntity<String> handleGenericException(RuntimeException e) {


@PostMapping("/sponsor-scan")
public ResponseEntity<TicketAndCheckInResult> scanBadge(@RequestBody SponsorScanRequest request, Principal principal) {
return ResponseEntity.ok(attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier, request.notes, request.leadStatus, principal.getName()));
public ResponseEntity<TicketAndCheckInResult> scanBadge(@RequestBody SponsorScanRequest request,
Principal principal,
@RequestHeader(name = ALFIO_OPERATOR_HEADER, required = false) String operator) {
return ResponseEntity.ok(attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier, request.notes, request.leadStatus, principal.getName(), operator));
}

@PostMapping("/sponsor-scan/bulk")
public ResponseEntity<List<TicketAndCheckInResult>> scanBadges(@RequestBody List<SponsorScanRequest> requests, Principal principal) {
public ResponseEntity<List<TicketAndCheckInResult>> scanBadges(@RequestBody List<SponsorScanRequest> requests,
Principal principal,
@RequestHeader(name = ALFIO_OPERATOR_HEADER, required = false) String operator) {
String username = principal.getName();
return ResponseEntity.ok(requests.stream()
.map(request -> attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier, request.notes, request.leadStatus, username))
.map(request -> attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier, request.notes, request.leadStatus, username, operator))
.collect(Collectors.toList()));
}

Expand Down
20 changes: 15 additions & 5 deletions src/main/java/alfio/manager/AttendeeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

@Component
@AllArgsConstructor
public class AttendeeManager {

public static final String DEFAULT_OPERATOR_ID = "__DEFAULT__";
private final SponsorScanRepository sponsorScanRepository;
private final EventRepository eventRepository;
private final TicketRepository ticketRepository;
Expand All @@ -51,7 +53,12 @@ public class AttendeeManager {
private final AdditionalServiceItemRepository additionalServiceItemRepository;
private final ClockProvider clockProvider;

public TicketAndCheckInResult registerSponsorScan(String eventShortName, String ticketUid, String notes, SponsorScan.LeadStatus leadStatus, String username) {
public TicketAndCheckInResult registerSponsorScan(String eventShortName,
String ticketUid,
String notes,
SponsorScan.LeadStatus leadStatus,
String username,
String operatorId) {
int userId = userRepository.getByUsername(username).getId();
Optional<EventAndOrganizationId> maybeEvent = eventRepository.findOptionalEventAndOrganizationIdByShortName(eventShortName);
if(maybeEvent.isEmpty()) {
Expand All @@ -66,12 +73,13 @@ public TicketAndCheckInResult registerSponsorScan(String eventShortName, String
if(ticket.getStatus() != Ticket.TicketStatus.CHECKED_IN) {
return new TicketAndCheckInResult(new TicketWithCategory(ticket, null), new DefaultCheckInResult(CheckInStatus.INVALID_TICKET_STATE, "not checked-in"));
}
Optional<ZonedDateTime> existingRegistration = sponsorScanRepository.getRegistrationTimestamp(userId, event.getId(), ticket.getId());
var operator = Objects.requireNonNullElse(operatorId, DEFAULT_OPERATOR_ID);
Optional<ZonedDateTime> existingRegistration = sponsorScanRepository.getRegistrationTimestamp(userId, event.getId(), ticket.getId(), operator);
if(existingRegistration.isEmpty()) {
ZoneId eventZoneId = eventRepository.getZoneIdByEventId(event.getId());
sponsorScanRepository.insert(userId, ZonedDateTime.now(clockProvider.withZone(eventZoneId)), event.getId(), ticket.getId(), notes, leadStatus);
sponsorScanRepository.insert(userId, ZonedDateTime.now(clockProvider.withZone(eventZoneId)), event.getId(), ticket.getId(), notes, leadStatus, operator);
} else {
sponsorScanRepository.updateNotesAndLeadStatus(userId, event.getId(), ticket.getId(), notes, leadStatus);
sponsorScanRepository.updateNotesAndLeadStatus(userId, event.getId(), ticket.getId(), notes, leadStatus, operator);
}
return new TicketAndCheckInResult(new TicketWithCategory(ticket, null), new DefaultCheckInResult(CheckInStatus.SUCCESS, "success"));
}
Expand Down Expand Up @@ -107,7 +115,9 @@ private List<SponsorAttendeeData> loadAttendeesData(EventAndOrganizationId event
.map(scan -> {
Ticket ticket = scan.getTicket();
return new SponsorAttendeeData(ticket.getUuid(), scan.getSponsorScan().getTimestamp().format(EventUtil.JSON_DATETIME_FORMATTER), ticket.getFullName(), ticket.getEmail());
}).collect(Collectors.toList());
})
.distinct()
.collect(Collectors.toList());
}

}
5 changes: 3 additions & 2 deletions src/main/java/alfio/model/DetailedScanData.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public DetailedScanData(@Column("t_id") int ticketId,
@Column("s_event_id") int scanEventId,
@Column("s_ticket_id") int scanTicketId,
@Column("s_notes") String notes,
@Column("s_lead_status") SponsorScan.LeadStatus leadStatus) {
@Column("s_lead_status") SponsorScan.LeadStatus leadStatus,
@Column("s_operator") String operator) {
this.ticket = new Ticket(ticketId, ticketUuid, ticketCreation, ticketCategoryId,
ticketStatus, ticketEventId, ticketsReservationId, ticketFullName, ticketFirstName,
ticketLastName, ticketEmail, ticketLockedAssignment, ticketUserLanguage, ticketSrcPriceCts,
ticketFinalPriceCts, ticketVatCts, ticketDiscountCts, extReference, currencyCode, ticketTags,
ticketSubscriptionId, ticketVatStatus);
this.sponsorScan = new SponsorScan(scanUserId, scanTimestamp, scanEventId, scanTicketId, notes, leadStatus);
this.sponsorScan = new SponsorScan(scanUserId, scanTimestamp, scanEventId, scanTicketId, notes, leadStatus, operator);
}
}
5 changes: 4 additions & 1 deletion src/main/java/alfio/model/SponsorScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ public enum LeadStatus {
private final int ticketId;
private final String notes;
private final LeadStatus leadStatus;
private final String operator;


public SponsorScan(@Column("user_id") int userId,
@Column("creation") ZonedDateTime timestamp,
@Column("event_id") int eventId,
@Column("ticket_id") int ticketId,
@Column("notes") String notes,
@Column("lead_status") LeadStatus leadStatus) {
@Column("lead_status") LeadStatus leadStatus,
@Column("operator") String operator) {
this.userId = userId;
this.timestamp = timestamp;
this.eventId = eventId;
this.ticketId = ticketId;
this.notes = notes;
this.leadStatus = leadStatus;
this.operator = operator;
}
}
16 changes: 9 additions & 7 deletions src/main/java/alfio/repository/SponsorScanRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,31 @@ public interface SponsorScanRepository {

ZonedDateTime DEFAULT_TIMESTAMP = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);

@Query("select creation from sponsor_scan where user_id = :userId and event_id = :eventId and ticket_id = :ticketId")
Optional<ZonedDateTime> getRegistrationTimestamp(@Bind("userId") int userId, @Bind("eventId") int eventId, @Bind("ticketId") int ticketId);
@Query("select creation from sponsor_scan where user_id = :userId and event_id = :eventId and ticket_id = :ticketId and operator = :operator")
Optional<ZonedDateTime> getRegistrationTimestamp(@Bind("userId") int userId, @Bind("eventId") int eventId, @Bind("ticketId") int ticketId, @Bind("operator") String operator);

@Query("insert into sponsor_scan (user_id, creation, event_id, ticket_id, notes, lead_status) values(:userId, :creation, :eventId, :ticketId, :notes, :leadStatus)")
@Query("insert into sponsor_scan (user_id, creation, event_id, ticket_id, notes, lead_status, operator) values(:userId, :creation, :eventId, :ticketId, :notes, :leadStatus, :operator)")
int insert(@Bind("userId") int userId,
@Bind("creation") ZonedDateTime creation,
@Bind("eventId") int eventId,
@Bind("ticketId") int ticketId,
@Bind("notes") String notes,
@Bind("leadStatus") SponsorScan.LeadStatus leadStatus);
@Bind("leadStatus") SponsorScan.LeadStatus leadStatus,
@Bind("operator") String operator);

@Query("update sponsor_scan set notes = :notes, lead_status = :leadStatus where user_id = :userId and event_id = :eventId and ticket_id = :ticketId")
@Query("update sponsor_scan set notes = :notes, lead_status = :leadStatus where user_id = :userId and event_id = :eventId and ticket_id = :ticketId and operator = :operator")
int updateNotesAndLeadStatus(@Bind("userId") int userId,
@Bind("eventId") int eventId,
@Bind("ticketId") int ticketId,
@Bind("notes") String notes,
@Bind("leadStatus") SponsorScan.LeadStatus leadStatus);
@Bind("leadStatus") SponsorScan.LeadStatus leadStatus,
@Bind("operator") String operator);

@Query("select t.id t_id, t.uuid t_uuid, t.creation t_creation, t.category_id t_category_id, t.status t_status, t.event_id t_event_id," +
" t.src_price_cts t_src_price_cts, t.final_price_cts t_final_price_cts, t.vat_cts t_vat_cts, t.discount_cts t_discount_cts, t.tickets_reservation_id t_tickets_reservation_id," +
" t.full_name t_full_name, t.first_name t_first_name, t.last_name t_last_name, t.email_address t_email_address, t.locked_assignment t_locked_assignment," +
" t.user_language t_user_language, t.ext_reference t_ext_reference, t.currency_code t_currency_code, t.tags t_tags, t.subscription_id_fk t_subscription_id, t.vat_status t_vat_status," +
" s.user_id s_user_id, s.creation s_creation, s.event_id s_event_id, s.ticket_id s_ticket_id, s.notes s_notes, s.lead_status s_lead_status, " +
" s.user_id s_user_id, s.creation s_creation, s.event_id s_event_id, s.ticket_id s_ticket_id, s.notes s_notes, s.lead_status s_lead_status, s.operator s_operator, " +
" (case when s.lead_status = 'HOT' then 2 when s.lead_status = 'WARM' then 1 else 0 end) as priority"+
" from sponsor_scan s, ticket t where s.event_id = :eventId and s.user_id = :userId and s.creation > :start and s.ticket_id = t.id order by priority desc, s.creation")
List<DetailedScanData> loadSponsorData(@Bind("eventId") int eventId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

alter table sponsor_scan add column operator text not null default '__DEFAULT__';
alter table sponsor_scan drop constraint "spsc_unique_ticket";
alter table sponsor_scan add constraint "spsc_unique_ticket" unique(event_id, ticket_id, user_id, operator);