Skip to content

Commit

Permalink
#110 and #111: add field value for additional services
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed May 24, 2016
1 parent 8e3ca81 commit a823b76
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 7 deletions.
39 changes: 39 additions & 0 deletions src/main/java/alfio/model/AdditionalServiceFieldValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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 AdditionalServiceFieldValue {

private final int additionalServiceId;
private final int ticketFieldConfigurationId;
private final String name;
private final String value;

public AdditionalServiceFieldValue(@Column("additional_service_id_fk") int additionalServiceId,
@Column("ticket_field_configuration_id_fk") int ticketFieldConfigurationId,
@Column("field_name") String name,
@Column("field_value") String value) {
this.additionalServiceId = additionalServiceId;
this.ticketFieldConfigurationId = ticketFieldConfigurationId;
this.name = name;
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
/**
*/
@Getter
public class TicketFieldNameAndValue {
public class FieldNameAndValue {

private final String name;
private final String value;

public TicketFieldNameAndValue(@Column("field_name") String name,
@Column("field_value") String value) {
public FieldNameAndValue(@Column("field_name") String name,
@Column("field_value") String value) {
this.name =name;
this.value = value;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/alfio/model/TicketFieldConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum Context {
private final boolean required;
private final List<String> restrictedValues;
private final Context context;
private Integer additionalServiceId;


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

public boolean isInputField() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package alfio.repository;

import alfio.model.AdditionalServiceDescription;
import ch.digitalfondue.npjt.Bind;
import ch.digitalfondue.npjt.Query;
import ch.digitalfondue.npjt.QueryRepository;

import java.util.List;

@QueryRepository
public interface AdditionalServiceDescriptionRepository {

@Query("select additional_service_id_fk, locale, type, value from additional_service_description where additional_service_id_fk = :additionalServiceId")
List<AdditionalServiceDescription> findAllByAdditionalServiceId(@Bind("additionalServiceId") int additionalServiceId);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package alfio.repository;

import alfio.model.AdditionalServiceFieldValue;
import alfio.model.FieldNameAndValue;
import ch.digitalfondue.npjt.Bind;
import ch.digitalfondue.npjt.Query;
import ch.digitalfondue.npjt.QueryRepository;

import java.util.List;

@QueryRepository
public interface AdditionalServiceFieldValueRepository {

@Query("select a.additional_service_id_fk, a.ticket_field_configuration_id_fk, b.field_name, a.field_value from additional_service_field_value a, ticket_field_configuration b where a.additional_service_id_fk = :additionalServiceId and a.ticket_field_configuration_id_fk = b.id and b.context = 'ADDITIONAL_SERVICE'")
List<AdditionalServiceFieldValue> findAllByAdditionalServiceId(@Bind("additionalServiceId") int id);

@Query("update additional_service_field_value set field_value = :value where additional_service_id_fk = :additionalServiceId and ticket_field_configuration_id_fk = :fieldConfigurationId")
int updateValue(@Bind("additionalServiceId") int additionalServiceId, @Bind("fieldConfigurationId") int fieldConfigurationId, @Bind("value") String value);

@Query("insert into additional_service_field_value(additional_service_id_fk, ticket_field_configuration_id_fk, field_value) values (:ticketId, :fieldConfigurationId, :value)")
int insertValue(@Bind("additionalServiceId") int additionalServiceId, @Bind("fieldConfigurationId") int fieldConfigurationId, @Bind("value") String value);

@Query("delete from additional_service_field_value where additional_service_id_fk = :additionalServiceId and ticket_field_configuration_id_fk = :fieldConfigurationId")
int deleteValue(@Bind("additionalServiceId") int ticketId, @Bind("fieldConfigurationId") int fieldConfigurationId);

@Query("delete from additional_service_field_value where ticket_field_configuration_id_fk = :fieldConfigurationId")
int deleteValues(@Bind("fieldConfigurationId") int ticketFieldConfigurationId);

@Query("select field_name, field_value from additional_service_field_value inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where additional_service_id_fk = :additionalServiceId and context = 'ADDITIONAL_SERVICE'")
List<FieldNameAndValue> findNameAndValue(@Bind("additionalServiceId") int additionalServiceId);

}
6 changes: 3 additions & 3 deletions src/main/java/alfio/repository/TicketFieldRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ AffectedRowCountAndKey<Integer> insertConfiguration(@Bind("eventId") int eventId
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 and context = 'ATTENDEE'")
List<TicketFieldNameAndValue> findNameAndValue(@Bind("ticketId") int ticketId);
List<FieldNameAndValue> findNameAndValue(@Bind("ticketId") int ticketId);

default void updateOrInsert(Map<String, String> values, Ticket ticket, Event event) {
int ticketId = ticket.getId();
Expand Down Expand Up @@ -107,7 +107,7 @@ default boolean hasOptionalData(int ticketId) {
@Query("update ticket_field_configuration set field_order = :order where id = :id")
int updateFieldOrder(@Bind("id") int id, @Bind("order") int order);

@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")
@Query("select ticket_field_configuration.* from ticket_field_configuration inner join event on event.id = event_id_fk where short_name = :eventShortName and ticket_field_configuration.context = 'ATTENDEE' order by field_order asc")
List<TicketFieldConfiguration> findAdditionalFieldsForEvent(@Bind("eventShortName") String eventName);

@Query("select count(*) from ticket_field_configuration where event_id_fk = :eventId and context = 'ATTENDEE'")
Expand All @@ -124,7 +124,7 @@ default Map<Integer, TicketFieldDescription> findTranslationsFor(Locale locale,
}

default Map<String, String> findAllValuesForTicketId(int ticketId) {
return findNameAndValue(ticketId).stream().filter(t -> t.getName() != null && t.getValue() != null).collect(Collectors.toMap(TicketFieldNameAndValue::getName, TicketFieldNameAndValue::getValue));
return findNameAndValue(ticketId).stream().filter(t -> t.getName() != null && t.getValue() != null).collect(Collectors.toMap(FieldNameAndValue::getName, FieldNameAndValue::getValue));
}

// required for deleting a field
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--
-- 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 ticket_field_configuration add column additional_service_id_fk integer;
alter table ticket_field_configuration add FOREIGN KEY (additional_service_id_fk) REFERENCES ADDITIONAL_SERVICE(ID);

-- drop old constraints
alter table ticket_field_configuration drop constraint "unique_ticket_field_configuration";
-- add new constraints
alter table ticket_field_configuration add constraint "unique_ticket_field_configuration" unique(event_id_fk, field_name, additional_service_id_fk, context);

create table additional_service_field_value(
additional_service_id_fk int not null,
ticket_field_configuration_id_fk int not null,
field_value varchar(2048),
PRIMARY KEY (additional_service_id_fk, ticket_field_configuration_id_fk)
);

alter table additional_service_field_value add foreign key(additional_service_id_fk) references additional_service(id);
alter table additional_service_field_value add foreign key(ticket_field_configuration_id_fk) references ticket_field_configuration(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--
-- 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 ticket_field_configuration add column additional_service_id_fk integer;
alter table ticket_field_configuration add FOREIGN KEY (additional_service_id_fk) REFERENCES ADDITIONAL_SERVICE(ID);

-- drop old constraints
alter table ticket_field_configuration drop index "unique_ticket_field_configuration";
-- add new constraints
alter table ticket_field_configuration add constraint "unique_ticket_field_configuration" unique(event_id_fk, field_name, additional_service_id_fk, context);

create table additional_service_field_value(
additional_service_id_fk int not null,
ticket_field_configuration_id_fk int not null,
field_value varchar(2048),
PRIMARY KEY (additional_service_id_fk, ticket_field_configuration_id_fk)
) ENGINE=InnoDB CHARACTER SET=utf8 COLLATE utf8_bin;

alter table additional_service_field_value add foreign key(additional_service_id_fk) references additional_service(id);
alter table additional_service_field_value add foreign key(ticket_field_configuration_id_fk) references ticket_field_configuration(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--
-- 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 ticket_field_configuration add column additional_service_id_fk integer;
alter table ticket_field_configuration add FOREIGN KEY (additional_service_id_fk) REFERENCES ADDITIONAL_SERVICE(ID);

-- drop old constraints
alter table ticket_field_configuration drop constraint "unique_ticket_field_configuration";
-- add new constraints
alter table ticket_field_configuration add constraint "unique_ticket_field_configuration" unique(event_id_fk, field_name, additional_service_id_fk, context);

create table additional_service_field_value(
additional_service_id_fk int not null,
ticket_field_configuration_id_fk int not null,
field_value varchar(2048),
PRIMARY KEY (additional_service_id_fk, ticket_field_configuration_id_fk)
);

alter table additional_service_field_value add foreign key(additional_service_id_fk) references additional_service(id);
alter table additional_service_field_value add foreign key(ticket_field_configuration_id_fk) references ticket_field_configuration(id);

0 comments on commit a823b76

Please sign in to comment.