Skip to content

Commit

Permalink
initial work for #110 and #111
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed May 20, 2016
1 parent 9fc68c3 commit 8e3ca81
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void createAdditionalFields(int eventId, EventModification em) {
private void insertAdditionalField(int eventId, AdditionalField f, int order) {
List<String> restrictedValues = Optional.ofNullable(f.getRestrictedValues()).orElseGet(Collections::emptyList).stream().map(EventModification.RestrictedValue::getValue).collect(Collectors.toList());
String serializedRestrictedValues = "select".equals(f.getType()) ? Json.GSON.toJson(restrictedValues) : null;
int configurationId = ticketFieldRepository.insertConfiguration(eventId, f.getName(), order, f.getType(), serializedRestrictedValues, f.getMaxLength(), f.getMinLength(), f.isRequired()).getKey();
int configurationId = ticketFieldRepository.insertConfiguration(eventId, f.getName(), order, f.getType(), serializedRestrictedValues, f.getMaxLength(), f.getMinLength(), f.isRequired(), TicketFieldConfiguration.Context.ATTENDEE).getKey();
f.getDescription().forEach((locale, value) -> {
ticketFieldRepository.insertDescription(configurationId, locale, Json.GSON.toJson(value));
});
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/alfio/model/AdditionalService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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/>.
*/
package alfio.model;

import ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.Column;
import lombok.Getter;

import java.math.BigDecimal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Optional;

@Getter
public class AdditionalService {


public enum VatType {
INHERITED,
NONE,
CUSTOM_INCLUDED,
CUSTOM_EXCLUDED
}

private final int id;
private final int eventId;
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 VatType vatType;

public AdditionalService(@Column("id") int id,
@Column("event_id_fk") int eventId,
@Column("price_cts") int priceInCents,
@Column("fix_price") boolean fixPrice,
@Column("ordinal") int ordinal,
@Column("available_qty") int availableQuantity,
@Column("max_qty_per_order") int maxQtyPerOrder,
@Column("inception_ts") ZonedDateTime utcInception,
@Column("expiration_ts") ZonedDateTime utcExpiration,
@Column("vat") BigDecimal vat,
@Column("vat_type") VatType vatType) {
this.id = id;
this.eventId = eventId;
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;
}

public ZonedDateTime getInception(ZoneId zoneId) {
return Optional.ofNullable(utcInception).map(i -> i.withZoneSameInstant(zoneId)).orElseGet(() -> ZonedDateTime.now(zoneId).minus(1L, ChronoUnit.HOURS));
}

public ZonedDateTime getExpiration(ZoneId zoneId) {
return Optional.ofNullable(utcExpiration).map(i -> i.withZoneSameInstant(zoneId)).orElseGet(() -> ZonedDateTime.now(zoneId).plus(1L, ChronoUnit.HOURS));
}
}
44 changes: 44 additions & 0 deletions src/main/java/alfio/model/AdditionalServiceDescription.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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/>.
*/
package alfio.model;

import ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.Column;
import lombok.Getter;

@Getter
public class AdditionalServiceDescription {

public enum AdditionalServiceDescriptionType {
TITLE, DESCRIPTION
}

private final Integer additionalServiceId;
private final String locale;
private final AdditionalServiceDescriptionType type;
private final String value;

public AdditionalServiceDescription(@Column("additional_service_id_fk") Integer additionalServiceId,
@Column("locale") String locale,
@Column("type") AdditionalServiceDescriptionType type,
@Column("value") String value) {
this.additionalServiceId = additionalServiceId;
this.locale = locale;
this.type = type;
this.value = value;
}

}
10 changes: 9 additions & 1 deletion src/main/java/alfio/model/TicketFieldConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

@Getter
public class TicketFieldConfiguration {

public enum Context {
ATTENDEE, ADDITIONAL_SERVICE
}

private final int id;
private final int eventId;
private final String name;
Expand All @@ -35,6 +40,7 @@ public class TicketFieldConfiguration {
private final Integer minLength;
private final boolean required;
private final List<String> restrictedValues;
private final Context context;


public TicketFieldConfiguration(@Column("id") int id,
Expand All @@ -45,7 +51,8 @@ public TicketFieldConfiguration(@Column("id") int id,
@Column("field_maxlength") Integer maxLength,
@Column("field_minlength") Integer minLength,
@Column("field_required") boolean required,
@Column("field_restricted_values") String restrictedValues) {
@Column("field_restricted_values") String restrictedValues,
@Column("context") Context context) {
this.id = id;
this.eventId = eventId;
this.name = name;
Expand All @@ -55,6 +62,7 @@ public TicketFieldConfiguration(@Column("id") int id,
this.minLength = minLength;
this.required = required;
this.restrictedValues = restrictedValues == null ? Collections.emptyList() : Json.GSON.fromJson(restrictedValues, new TypeToken<List<String>>(){}.getType());
this.context = context;
}

public boolean isInputField() {
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/alfio/repository/AdditionalServiceRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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/>.
*/
package alfio.repository;

import alfio.model.AdditionalService;
import ch.digitalfondue.npjt.*;

import java.math.BigDecimal;
import java.time.ZonedDateTime;
import java.util.List;

@QueryRepository
public interface AdditionalServiceRepository {

@Query("select * from additional_service where event_id = :eventId")
List<AdditionalService> loadAllForEvent(@Bind("eventId") int eventId);

@Query("insert into additional_service (event_id_fk, price_cts, fix_price, ordinal, available_qty, max_qty_per_order, inception_ts, expiration_ts, vat, vat_type) " +
"values(:eventId, :priceCts, :fixPrice, :ordinal, :availableQty, :maxQtyPerOrder, :inceptionTs, :expirationTs, :vat, :vatType)")
@AutoGeneratedKey("id")
AffectedRowCountAndKey<Integer> insert(@Bind("eventId") int eventId, @Bind("priceCts") int priceInCents, @Bind("fixPrice") boolean fixPrice,
@Bind("ordinal") int ordinal, @Bind("availableQty") int availableQuantity, @Bind("maxQtyPerOrder") int maxQtyPerOrder,
@Bind("inceptionTs") ZonedDateTime inception, @Bind("expirationTs") ZonedDateTime expiration, @Bind("vat") BigDecimal vat,
@Bind("vatType") AdditionalService.VatType vatType);

@Query("update additional_service set price_cts = :priceCts, fix_price = :fixPrice, ordinal = :ordinal, available_qty = :availableQty, max_qty_per_order = :maxQtyPerOrder," +
" inception_ts = :inceptionTs, expiration_ts = :expirationTs, vat = :vat, vat_type = :vatType where id = :id")
int update(@Bind("id") int id, @Bind("priceCts") int priceInCents, @Bind("fixPrice") boolean fixPrice,
@Bind("ordinal") int ordinal, @Bind("availableQty") int availableQuantity, @Bind("maxQtyPerOrder") int maxQtyPerOrder,
@Bind("inceptionTs") ZonedDateTime inception, @Bind("expirationTs") ZonedDateTime expiration, @Bind("vat") BigDecimal vat,
@Bind("vatType") AdditionalService.VatType vatType);

}
26 changes: 13 additions & 13 deletions src/main/java/alfio/repository/TicketFieldRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
@QueryRepository
public interface TicketFieldRepository {

@Query("select count(*) from ticket_field_value where ticket_id_fk = :ticketId and field_value is not null and field_value <> ''")
@Query("select count(*) from ticket_field_value where ticket_id_fk = :ticketId and field_value is not null and field_value <> '' and context = 'ATTENDEE'")
Integer countFilledOptionalData(@Bind("ticketId") int id);

@Query("select ticket_id_fk, ticket_field_configuration_id_fk, field_name, field_value from ticket_field_value inner join ticket_field_configuration on id = ticket_field_configuration_id_fk where ticket_id_fk = :ticketId")
@Query("select a.ticket_id_fk, a.ticket_field_configuration_id_fk, b.field_name, a.field_value from ticket_field_value a, ticket_field_configuration b where a.ticket_id_fk = :ticketId and a.ticket_field_configuration_id_fk = b.id and b.context = 'ATTENDEE'")
List<TicketFieldValue> findAllByTicketId(@Bind("ticketId") int id);

@Query("insert into ticket_field_configuration(event_id_fk, field_name, field_order, field_type, field_restricted_values, field_maxlength, field_minlength, field_required) " +
" values (:eventId, :name, :order, :type, :restrictedValues, :maxLength, :minLength, :required)")
@Query("insert into ticket_field_configuration(event_id_fk, field_name, field_order, field_type, field_restricted_values, field_maxlength, field_minlength, field_required, context) " +
" values (:eventId, :name, :order, :type, :restrictedValues, :maxLength, :minLength, :required, :context)")
@AutoGeneratedKey("id")
AffectedRowCountAndKey<Integer> insertConfiguration(@Bind("eventId") int eventId, @Bind("name") String name, @Bind("order") int order, @Bind("type") String type, @Bind("restrictedValues") String restrictedValues,
@Bind("maxLength") Integer maxLength, @Bind("minLength") Integer minLength, @Bind("required") boolean required);
@Bind("maxLength") Integer maxLength, @Bind("minLength") Integer minLength, @Bind("required") boolean required, @Bind("context")TicketFieldConfiguration.Context context);


@Query("insert into ticket_field_description(ticket_field_configuration_id_fk, field_locale, description) values (:ticketConfigurationId, :locale, :description)")
Expand All @@ -55,16 +55,16 @@ AffectedRowCountAndKey<Integer> insertConfiguration(@Bind("eventId") int eventId
@Query("delete from ticket_field_value where ticket_id_fk = :ticketId and ticket_field_configuration_id_fk = :fieldConfigurationId")
int deleteValue(@Bind("ticketId") int ticketId, @Bind("fieldConfigurationId") int fieldConfigurationId);

@Query("select ticket_field_configuration_id_fk, field_locale, description from ticket_field_description inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where field_locale = :locale and event_id_fk = :eventId")
@Query("select ticket_field_configuration_id_fk, field_locale, description from ticket_field_description inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where field_locale = :locale and event_id_fk = :eventId and context = 'ATTENDEE'")
List<TicketFieldDescription> findDescriptions(@Bind("eventId") int eventId, @Bind("locale") String locale);

@Query("select ticket_field_description.* from ticket_field_description inner join ticket_field_configuration on ticket_field_configuration_id_fk = id inner join event on event.id = event_id_fk where short_name = :eventShortName")
@Query("select ticket_field_description.* from ticket_field_description inner join ticket_field_configuration on ticket_field_configuration_id_fk = id inner join event on event.id = event_id_fk where short_name = :eventShortName and context = 'ATTENDEE'")
List<TicketFieldDescription> findDescriptions(@Bind("eventShortName") String eventShortName);

@Query("SELECT field_name FROM ticket_field_configuration inner join event on event.id = event_id_fk where short_name = :eventShortName order by field_order asc ")
@Query("SELECT field_name FROM ticket_field_configuration inner join event on event.id = event_id_fk where short_name = :eventShortName and context = 'ATTENDEE' order by field_order asc ")
List<String> findFieldsForEvent(@Bind("eventShortName") String eventShortName);

@Query("select field_name, field_value from ticket_field_value inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where ticket_id_fk = :ticketId")
@Query("select field_name, field_value from ticket_field_value inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where ticket_id_fk = :ticketId and context = 'ATTENDEE'")
List<TicketFieldNameAndValue> findNameAndValue(@Bind("ticketId") int ticketId);

default void updateOrInsert(Map<String, String> values, Ticket ticket, Event event) {
Expand Down Expand Up @@ -98,7 +98,7 @@ default boolean hasOptionalData(int ticketId) {
}


@Query("select * from ticket_field_configuration where event_id_fk = :eventId order by field_order asc")
@Query("select * from ticket_field_configuration where event_id_fk = :eventId and context = 'ATTENDEE' order by field_order asc")
List<TicketFieldConfiguration> findAdditionalFieldsForEvent(@Bind("eventId") int eventId);

@Query("select * from ticket_field_configuration where id = :id")
Expand All @@ -110,13 +110,13 @@ default boolean hasOptionalData(int ticketId) {
@Query("select ticket_field_configuration.* from ticket_field_configuration inner join event on event.id = event_id_fk where short_name = :eventShortName order by field_order asc")
List<TicketFieldConfiguration> findAdditionalFieldsForEvent(@Bind("eventShortName") String eventName);

@Query("select count(*) from ticket_field_configuration where event_id_fk = :eventId")
@Query("select count(*) from ticket_field_configuration where event_id_fk = :eventId and context = 'ATTENDEE'")
Integer countAdditionalFieldsForEvent(@Bind("eventId") int eventId);

@Query("select max(field_order) from ticket_field_configuration where event_id_fk = :eventId")
@Query("select max(field_order) from ticket_field_configuration where event_id_fk = :eventId and context = 'ATTENDEE'")
Integer findMaxOrderValue(@Bind("eventId") int eventId);

@Query("select count(*) from ticket_field_configuration where event_id_fk = :eventId and field_required = true")
@Query("select count(*) from ticket_field_configuration where event_id_fk = :eventId and field_required = true and context = 'ATTENDEE'")
Integer countRequiredAdditionalFieldsForEvent(@Bind("eventId") int eventId);

default Map<Integer, TicketFieldDescription> findTranslationsFor(Locale locale, int eventId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--
-- 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/>.
--

create table additional_service (
id integer identity NOT NULL,
event_id_fk integer not null,
price_cts integer,
fix_price boolean not null,
ordinal integer DEFAULT 0 not null,
available_qty integer DEFAULT -1 not null,
max_qty_per_order integer DEFAULT -1 not null,
inception_ts timestamp with time zone,
expiration_ts timestamp with time zone,
vat DECIMAL(5,2),
vat_type varchar(50) not null
);

alter table additional_service add FOREIGN KEY (event_id_fk) REFERENCES event(id);

create table additional_service_description (
additional_service_id_fk integer not null,
locale varchar(8) not null,
type varchar(16) not null,
value varchar(2048) not null
);

alter table additional_service_description add PRIMARY KEY (additional_service_id_fk, locale, type);
alter table additional_service_description add FOREIGN KEY (additional_service_id_fk) REFERENCES additional_service(id);

create table additional_service_item (
id integer identity NOT NULL,
additional_service_id_fk integer NOT NULL,
original_price_cts integer,
paid_price_cts integer
);
alter table additional_service_item add FOREIGN KEY (additional_service_id_fk) REFERENCES additional_service(id);

alter table ticket_field_configuration add COLUMN context varchar(50) DEFAULT 'ATTENDEE' not NULL;
Loading

0 comments on commit 8e3ca81

Please sign in to comment.