Skip to content

Commit

Permalink
#333 add UPDATE_TICKET_CATEGORY event for auditing
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Sep 20, 2017
1 parent 66c32b7 commit f1aa5ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class EventManager {
private final Flyway flyway;
private final Environment environment;
private final OrganizationRepository organizationRepository;
private final AuditingRepository auditingRepository;


public Event getSingleEvent(String eventName, String username) {
Expand Down Expand Up @@ -568,6 +569,11 @@ private void updateCategory(TicketCategoryModification tc, boolean freeOfCharge,
handlePriceChange(event, original, updated);

insertOrUpdateTicketCategoryDescription(tc.getId(), tc, event);

//

auditingRepository.insertUpdateTicketInCategoryId(tc.getId());

}

private void handleTicketAllocationStrategyChange(Event event, TicketCategory original, TicketCategoryModification updated) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/model/Audit.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum EntityType {
}

public enum EventType {
RESERVATION_CREATE, RESERVATION_COMPLETE, RESERVATION_OFFLINE_PAYMENT_CONFIRMED, CANCEL_RESERVATION_EXPIRED, CANCEL_RESERVATION, UPDATE_EVENT, CANCEL_TICKET, REFUND, CHECK_IN, REVERT_CHECK_IN, UPDATE_TICKET
RESERVATION_CREATE, RESERVATION_COMPLETE, RESERVATION_OFFLINE_PAYMENT_CONFIRMED, CANCEL_RESERVATION_EXPIRED, CANCEL_RESERVATION, UPDATE_EVENT, CANCEL_TICKET, REFUND, CHECK_IN, REVERT_CHECK_IN, UPDATE_TICKET, UPDATE_TICKET_CATEGORY
}

private final String reservationId;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/alfio/repository/AuditingRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ default int insert(String reservationId, Integer userId, Integer eventId, Audit.

@Query("select * from auditing_user where reservation_id = :reservationId order by event_time asc")
List<Audit> findAllForReservation(@Bind("reservationId") String reservationId);



@Query("insert into auditing(reservation_id, user_id, event_id, event_type, event_time, entity_type, entity_id, modifications) " +
" select tickets_reservation_id, null, event_id, 'UPDATE_TICKET_CATEGORY', sysdate, 'TICKET', concat('', id), null from ticket where category_id = :ticketCategoryId and tickets_reservation_id is not null")
int insertUpdateTicketInCategoryId(@Bind("ticketCategoryId") int id);
}
10 changes: 5 additions & 5 deletions src/test/java/alfio/manager/EventManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class EventManagerTest {{
TicketCategory updated = mock(TicketCategory.class);
TicketRepository ticketRepository = it.usesMock(TicketRepository.class);
NamedParameterJdbcTemplate jdbc = it.usesMock(NamedParameterJdbcTemplate.class);
EventManager eventManager = new EventManager(null, null, null, null, null, ticketRepository, null, null, jdbc, null, pluginManager, null, null, null, null, null, null, null);
EventManager eventManager = new EventManager(null, null, null, null, null, ticketRepository, null, null, jdbc, null, pluginManager, null, null, null, null, null, null, null, null);
when(original.getId()).thenReturn(20);
when(updated.getId()).thenReturn(30);
when(original.getSrcPriceCts()).thenReturn(1000);
Expand Down Expand Up @@ -92,7 +92,7 @@ public class EventManagerTest {{

describe("handlePriceChange", it -> {
TicketRepository ticketRepository = it.usesMock(TicketRepository.class);
EventManager eventManager = new EventManager(null, null, null, null, null, ticketRepository, null, null, null, null, pluginManager, null, null, null, null, null, null, null);
EventManager eventManager = new EventManager(null, null, null, null, null, ticketRepository, null, null, null, null, pluginManager, null, null, null, null, null, null, null, null);
TicketCategory original = mock(TicketCategory.class);
TicketCategory updated = mock(TicketCategory.class);
Event event = mock(Event.class);
Expand Down Expand Up @@ -130,7 +130,7 @@ public class EventManagerTest {{
describe("handleTokenModification", it -> {
SpecialPriceRepository specialPriceRepository = it.usesMock(SpecialPriceRepository.class);
NamedParameterJdbcTemplate jdbc = it.usesMock(NamedParameterJdbcTemplate.class);
EventManager eventManager = new EventManager(null, null, null, null, null, null, specialPriceRepository, null, jdbc, null, pluginManager, null, null, null, null, null, null, null);
EventManager eventManager = new EventManager(null, null, null, null, null, null, specialPriceRepository, null, jdbc, null, pluginManager, null, null, null, null, null, null, null, null);
TicketCategory original = mock(TicketCategory.class);
TicketCategory updated = mock(TicketCategory.class);

Expand Down Expand Up @@ -194,7 +194,7 @@ public class EventManagerTest {{
TicketCategoryRepository ticketCategoryRepository = it.usesMock(TicketCategoryRepository.class);
TicketCategoryDescriptionRepository ticketCategoryDescriptionRepository = it.usesMock(TicketCategoryDescriptionRepository.class);
EventRepository eventRepository = it.usesMock(EventRepository.class);
EventManager eventManager = new EventManager(null, eventRepository, null, ticketCategoryRepository, ticketCategoryDescriptionRepository, null, null, null, null, null, pluginManager, null, null, null, null, null, null, null);
EventManager eventManager = new EventManager(null, eventRepository, null, ticketCategoryRepository, ticketCategoryDescriptionRepository, null, null, null, null, null, pluginManager, null, null, null, null, null, null, null, null);
Event event = mock(Event.class);
int availableSeats = 20;
when(eventRepository.countExistingTickets(0)).thenReturn(availableSeats);
Expand Down Expand Up @@ -249,7 +249,7 @@ public class EventManagerTest {{
TicketCategory ticketCategory = it.usesMock(TicketCategory.class);

OrganizationRepository organizationRepository = it.usesMock(OrganizationRepository.class);
EventManager eventManager = new EventManager(userManager, eventRepository, eventDescriptionRepository, ticketCategoryRepository, ticketCategoryDescriptionRepository, ticketRepository, specialPriceRepository, null, null, null, pluginManager, null, null, null, null, null, null, organizationRepository);
EventManager eventManager = new EventManager(userManager, eventRepository, eventDescriptionRepository, ticketCategoryRepository, ticketCategoryDescriptionRepository, ticketRepository, specialPriceRepository, null, null, null, pluginManager, null, null, null, null, null, null, organizationRepository, null);
when(event.getId()).thenReturn(eventId);
when(event.getOrganizationId()).thenReturn(organizationId);
Organization organization = mock(Organization.class);
Expand Down

0 comments on commit f1aa5ab

Please sign in to comment.