Skip to content

Commit

Permalink
#110 and #111: add additional service fields to EventModification
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed May 25, 2016
1 parent 57564eb commit 3d20152
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
56 changes: 50 additions & 6 deletions src/main/java/alfio/model/modification/EventModification.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;


import java.math.BigDecimal;

import java.util.*;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;


@Getter
Expand Down Expand Up @@ -59,6 +61,7 @@ public class EventModification {
private final int locales;

private final List<AdditionalField> ticketFields;
private final List<AdditionalService> additionalServices;

@JsonCreator
public EventModification(@JsonProperty("id") Integer id,
Expand All @@ -85,7 +88,8 @@ public EventModification(@JsonProperty("id") Integer id,
@JsonProperty("freeOfCharge") boolean freeOfCharge,
@JsonProperty("geoLocation") LocationDescriptor locationDescriptor,
@JsonProperty("locales") int locales,
@JsonProperty("ticketFields") List<AdditionalField> ticketFields) {
@JsonProperty("ticketFields") List<AdditionalField> ticketFields,
@JsonProperty("additionalServices") List<AdditionalService> additionalServices) {
this.id = id;
this.eventType = eventType;
this.websiteUrl = websiteUrl;
Expand All @@ -106,7 +110,8 @@ public EventModification(@JsonProperty("id") Integer id,
this.vat = vat;
this.vatIncluded = vatIncluded;
this.locationDescriptor = locationDescriptor;
this.allowedPaymentProxies = Optional.ofNullable(allowedPaymentProxies).orElse(Collections.<PaymentProxy>emptyList());
this.additionalServices = additionalServices;
this.allowedPaymentProxies = Optional.ofNullable(allowedPaymentProxies).orElse(Collections.emptyList());
this.ticketCategories = ticketCategories;
this.freeOfCharge = freeOfCharge;
this.locales = locales;
Expand Down Expand Up @@ -141,6 +146,7 @@ public static class AdditionalField {
private final Map<String, Description> description;


@JsonCreator
public AdditionalField(@JsonProperty("order") int order,
@JsonProperty("name") String name,
@JsonProperty("type") String type,
Expand Down Expand Up @@ -168,6 +174,7 @@ public static class Description {
//restricted value -> description
private final Map<String, String> restrictedValues;

@JsonCreator
public Description(@JsonProperty("label") String label,
@JsonProperty("placeholder") String placeholder,
@JsonProperty("restrictedValues") Map<String, String> restrictedValues) {
Expand All @@ -180,9 +187,46 @@ public Description(@JsonProperty("label") String label,
@Getter
public static class RestrictedValue {
private final String value;

@JsonCreator
public RestrictedValue(@JsonProperty("value") String value) {
this.value = value;
}
}

@Getter
public static class AdditionalService {
private final int priceInCents;
private final boolean fixPrice;
private final int ordinal;
private final int availableQuantity;
private final int maxQtyPerOrder;
private final ZonedDateTime utcInception;
private final ZonedDateTime utcExpiration;
private final BigDecimal vat;
private final alfio.model.AdditionalService.VatType vatType;
private final List<AdditionalField> additionalServiceFields;

public AdditionalService(@JsonProperty("priceInCents") int priceInCents,
@JsonProperty("fixPrice") boolean fixPrice,
@JsonProperty("ordinal") int ordinal,
@JsonProperty("availableQuantity") int availableQuantity,
@JsonProperty("maxQtyPerOrder") int maxQtyPerOrder,
@JsonProperty("inception") ZonedDateTime utcInception,
@JsonProperty("expiration") ZonedDateTime utcExpiration,
@JsonProperty("vat") BigDecimal vat,
@JsonProperty("vatType") alfio.model.AdditionalService.VatType vatType,
@JsonProperty("additionalServiceFields") List<AdditionalField> additionalServiceFields) {

this.priceInCents = priceInCents;
this.fixPrice = fixPrice;
this.ordinal = ordinal;
this.availableQuantity = availableQuantity;
this.maxQtyPerOrder = maxQtyPerOrder;
this.utcInception = utcInception;
this.utcExpiration = utcExpiration;
this.vat = vat;
this.vatType = vatType;
this.additionalServiceFields = additionalServiceFields;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void prepareEnv() {
"muh location", desc,
new DateTimeModification(LocalDate.now(), LocalTime.now()),
new DateTimeModification(LocalDate.now(), LocalTime.now()),
BigDecimal.TEN, "CHF", 20, BigDecimal.ONE, true, null, ticketsCategory, false, new LocationDescriptor("","","",""), 7, null);
BigDecimal.TEN, "CHF", 20, BigDecimal.ONE, true, null, ticketsCategory, false, new LocationDescriptor("","","",""), 7, null, null);
eventManager.createEvent(em);

event = eventManager.getSingleEvent("eventShortName", "test");
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/alfio/manager/EventManagerIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void testIncreaseEventSeatsWithAnUnboundedCategory() {
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, null,
DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()),
event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null);
event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
Expand All @@ -255,7 +255,7 @@ public void testIncreaseEventSeatsWithABoundedCategory() {
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, null,
DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()),
event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null);
event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
Expand All @@ -275,7 +275,7 @@ public void testDecreaseEventSeatsWithAnUnboundedCategory() {
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, null,
DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()),
event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null);
event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
Expand All @@ -295,7 +295,7 @@ public void testDecreaseEventSeatsWithABoundedCategory() {
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, null,
DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()),
event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null);
event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
Expand Down Expand Up @@ -377,6 +377,7 @@ public void testUpdateEventHeader() {
false,
null,
7,
null,
null);

eventManager.updateEventHeader(event, em, username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import alfio.manager.TicketReservationManager;
import alfio.manager.support.PartialTicketPDFGenerator;
import alfio.manager.user.UserManager;
import alfio.model.*;
import alfio.model.Event;
import alfio.model.SpecialPrice;
import alfio.model.Ticket;
import alfio.model.TicketReservation;
import alfio.model.modification.*;
import alfio.model.modification.support.LocationDescriptor;
import alfio.model.plugin.PluginConfigOption;
Expand Down Expand Up @@ -132,7 +135,7 @@ private Pair<Event,String> initEvent(List<TicketCategoryModification> categories
"muh location", desc,
new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now().plusHours(1)),
BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, null, categories, false, new LocationDescriptor("","","",""), 7, null);
BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, null, categories, false, new LocationDescriptor("","","",""), 7, null, null);
eventManager.createEvent(em);
return Pair.of(eventManager.getSingleEvent(eventName, username), username);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/alfio/test/util/IntegrationTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static Map<String, String> c(String dialect, String driver, String url,

public static void initSystemProperties() {
String dialect = System.getProperty("dbenv", "HSQLDB");
DB_CONF.get(dialect).forEach((prop, val) -> System.setProperty(prop, val));
DB_CONF.get(dialect).forEach(System::setProperty);
}

public static void ensureMinimalConfiguration(ConfigurationRepository configurationRepository) {
Expand Down Expand Up @@ -102,7 +102,7 @@ public static Pair<Event, String> initEvent(List<TicketCategoryModification> cat
"muh location", desc,
new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
new DateTimeModification(expiration.toLocalDate(), expiration.toLocalTime()),
BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, Arrays.asList(PaymentProxy.OFFLINE), categories, false, new LocationDescriptor("","","",""), 7, null);
BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, Collections.singletonList(PaymentProxy.OFFLINE), categories, false, new LocationDescriptor("","","",""), 7, null, null);
eventManager.createEvent(em);
return Pair.of(eventManager.getSingleEvent(eventName, username), username);
}
Expand Down

0 comments on commit 3d20152

Please sign in to comment.