Skip to content

Commit

Permalink
rename TicketPriceCategory to TicketPrice and all associated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed May 28, 2012
1 parent 9c80be8 commit 253f371
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 144 deletions.
Expand Up @@ -117,7 +117,7 @@ public class Show implements Serializable {
* </p>
*/
@OneToMany(mappedBy = "show", cascade = ALL, fetch = EAGER)
private Set<TicketPriceCategory> priceCategories = new HashSet<TicketPriceCategory>();
private Set<TicketPrice> ticketPrices = new HashSet<TicketPrice>();

/* Boilerplate getters and setters */

Expand Down Expand Up @@ -153,12 +153,12 @@ public void setVenue(Venue venue) {
this.venue = venue;
}

public Set<TicketPriceCategory> getPriceCategories() {
return priceCategories;
public Set<TicketPrice> getTicketPrices() {
return ticketPrices;
}

public void setPriceCategories(Set<TicketPriceCategory> priceCategories) {
this.priceCategories = priceCategories;
public void setTicketPrices(Set<TicketPrice> ticketPrices) {
this.ticketPrices = ticketPrices;
}

/* toString(), equals() and hashCode() for Show, using the natural identity of the object */
Expand Down
Expand Up @@ -39,7 +39,7 @@
@JsonIgnoreProperties("show")
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "section_id", "show_id", "ticketcategory_id" }))
@Portable
public class TicketPriceCategory implements Serializable {
public class TicketPrice implements Serializable {

/* Declaration of fields */

Expand Down Expand Up @@ -136,7 +136,7 @@ public void setPrice(float price) {
this.price = price;
}

/* equals() and hashCode() for TicketPriceCategory, using the natural identity of the object */
/* equals() and hashCode() for TicketPrice, using the natural identity of the object */

@Override
public boolean equals(Object o) {
Expand All @@ -145,7 +145,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass())
return false;

TicketPriceCategory that = (TicketPriceCategory) o;
TicketPrice that = (TicketPrice) o;

if (section != null ? !section.equals(that.section) : that.section != null)
return false;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.jboss.jdf.example.ticketmonster.model.Section;
import org.jboss.jdf.example.ticketmonster.model.Ticket;
import org.jboss.jdf.example.ticketmonster.model.TicketCategory;
import org.jboss.jdf.example.ticketmonster.model.TicketPriceCategory;
import org.jboss.jdf.example.ticketmonster.model.TicketPrice;
import org.jboss.jdf.example.ticketmonster.service.SeatAllocationService;

/**
Expand Down Expand Up @@ -65,12 +65,12 @@ public BookingService() {
}

/**
< * <p>
* <p>
* Delete a booking by id
* </p>
* @param id
* @return
= */
*/
@DELETE
@Path("/{id:[0-9][0-9]*}")
public Response deleteBooking(@PathParam("id") Long id) {
Expand Down Expand Up @@ -102,23 +102,23 @@ public Response createBooking(BookingRequest bookingRequest) {
// identify the ticket price categories in this request
Set<Long> priceCategoryIds = new HashSet<Long>();
for (TicketRequest ticketRequest : bookingRequest.getTicketRequests()) {
if (priceCategoryIds.contains(ticketRequest.getPriceCategory())) {
if (TicketPrices.contains(ticketRequest.getTicketPrice())) {
throw new RuntimeException("Duplicate price category id");
}
priceCategoryIds.add(ticketRequest.getPriceCategory());
TicketPrices.add(ticketRequest.getTicketPrice());
}

// load the entities that make up this booking's relationships
Performance performance = getEntityManager().find(Performance.class, bookingRequest.getPerformance());

// As we can have a mix of ticket types in a booking, we need to load all of them that are relevant,
// id
List<TicketPriceCategory> ticketPrices = (List<TicketPriceCategory>) getEntityManager()
.createQuery("select p from TicketPriceCategory p where p.id in :ids")
.setParameter("ids", priceCategoryIds).getResultList();
List<TicketPrice> ticketPrices = (List<TicketPrice>) getEntityManager()
.createQuery("select p from TicketPrice p where p.id in :ids")
.setParameter("ids", TicketPrices).getResultList();
// Now, map them by id
Map<Long, TicketPriceCategory> ticketPricesById = new HashMap<Long, TicketPriceCategory>();
for (TicketPriceCategory ticketPrice : ticketPrices) {
Map<Long, TicketPrice> ticketPricesById = new HashMap<Long, TicketPrice>();
for (TicketPrice ticketPrice : ticketPrices) {
ticketPricesById.put(ticketPrice.getId(), ticketPrice);
}

Expand All @@ -133,13 +133,13 @@ public Response createBooking(BookingRequest bookingRequest) {
// we want to allocate ticket requests that belong to the same section contiguously
Map<Section, Map<TicketCategory, TicketRequest>> ticketRequestsPerSection = new LinkedHashMap<Section, Map<TicketCategory, TicketRequest>>();
for (TicketRequest ticketRequest : bookingRequest.getTicketRequests()) {
final TicketPriceCategory priceCategory = ticketPricesById.get(ticketRequest.getPriceCategory());
if (!ticketRequestsPerSection.containsKey(priceCategory.getSection())) {
final TicketPrice ticketPrice = ticketPricesById.get(ticketRequest.getTicketPrice());
if (!ticketRequestsPerSection.containsKey(ticketPrice.getSection())) {
ticketRequestsPerSection
.put(priceCategory.getSection(), new LinkedHashMap<TicketCategory, TicketRequest>());
.put(ticketPrice.getSection(), new LinkedHashMap<TicketCategory, TicketRequest>());
}
ticketRequestsPerSection.get(priceCategory.getSection()).put(
ticketPricesById.get(ticketRequest.getPriceCategory()).getTicketCategory(), ticketRequest);
ticketRequestsPerSection.get(ticketPrice.getSection()).put(
ticketPricesById.get(ticketRequest.getTicketPrice()).getTicketCategory(), ticketRequest);
}

// Now, we can allocate the tickets
Expand All @@ -160,9 +160,9 @@ public Response createBooking(BookingRequest bookingRequest) {
// Now, add a ticket for each requested ticket to the booking
for (TicketCategory ticketCategory : ticketRequestsByCategories.keySet()) {
final TicketRequest ticketRequest = ticketRequestsByCategories.get(ticketCategory);
final TicketPriceCategory ticketPriceCategory = ticketPricesById.get(ticketRequest.getPriceCategory());
final TicketPrice ticketPrice = ticketPricesById.get(ticketRequest.getTicketPrice());
for (int i = 0; i < ticketRequest.getQuantity(); i++) {
Ticket ticket = new Ticket(seats.get(seatCounter + i), ticketCategory, ticketPriceCategory.getPrice());
Ticket ticket = new Ticket(seats.get(seatCounter + i), ticketCategory, ticketPrice.getPrice());
// getEntityManager().persist(ticket);
booking.getTickets().add(ticket);
}
Expand Down
Expand Up @@ -18,7 +18,7 @@
import javax.ws.rs.core.MultivaluedMap;

import org.jboss.jdf.example.ticketmonster.model.Show;
import org.jboss.jdf.example.ticketmonster.model.TicketPriceCategory;
import org.jboss.jdf.example.ticketmonster.model.TicketPrice;

/**
* @author Marius Bogoevici
Expand Down Expand Up @@ -54,21 +54,21 @@ protected Predicate[] extractPredicates(MultivaluedMap<String,
@GET
@Path("/{showId:[0-9][0-9]*}/pricing")
@Produces(MediaType.APPLICATION_JSON)
public Map<Long,List<TicketPriceCategory>> getPricing(@PathParam("showId") Long showId) {
Query query = getEntityManager().createQuery("select pc from PriceCategory pc where pc.show.id = :showId order by pc.section.id");
public Map<Long,List<TicketPrice>> getPricing(@PathParam("showId") Long showId) {
Query query = getEntityManager().createQuery("select tp from TicketPrice where tp.show.id = :showId order by tp.section.id");
query.setParameter("showId", showId);

@SuppressWarnings("unchecked")
List<TicketPriceCategory> priceCategories = query.getResultList();
List<TicketPrice> ticketPrices = query.getResultList();

Map<Long, List<TicketPriceCategory>> priceCategoryMap = new LinkedHashMap<Long, List<TicketPriceCategory>> ();
for (TicketPriceCategory priceCategory : priceCategories) {
if (!priceCategoryMap.containsKey(priceCategory.getSection().getId())) {
priceCategoryMap.put(priceCategory.getSection().getId(), new ArrayList<TicketPriceCategory>());
Map<Long, List<TicketPrice>> ticketPriceMap = new LinkedHashMap<Long, List<TicketPrice>> ();
for (TicketPrice ticketPrice : ticketPrices) {
if (!ticketPriceMap.containsKey(ticketPrice.getSection().getId())) {
ticketPriceMap.put(ticketPrice.getSection().getId(), new ArrayList<TicketPrice>());
}
priceCategoryMap.get(priceCategory.getSection().getId()).add(priceCategory);
ticketPriceMap.get(ticketPrice.getSection().getId()).add(ticketPrice);
}
return priceCategoryMap;
return ticketPriceMap;
}

@GET
Expand Down
Expand Up @@ -11,17 +11,17 @@
*/
public class TicketRequest {

private long priceCategory;
private long ticketPrice;

private int quantity;


public long getPriceCategory() {
return priceCategory;
public long getTicketPrice() {
return ticketPrice;
}

public void setPriceCategory(long priceCategory) {
this.priceCategory = priceCategory;
public void setTicketPrice(long ticketPrice) {
this.ticketPrice = ticketPrice;
}

public int getQuantity() {
Expand Down
76 changes: 38 additions & 38 deletions src/main/resources/import.sql
Expand Up @@ -63,41 +63,41 @@ insert into performance (id, show_id, date) values (9, 5, '2013-05-11 21:00:00')
insert into TicketCategory (id, description) values (1, 'Adult');
insert into TicketCategory (id, description) values (2, 'Child 0-14yrs');

insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (1, 2, 100, 1, 167.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (2, 2, 101, 1, 197.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (3, 2, 102, 1, 167.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (4, 2, 103, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (5, 2, 104, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (6, 2, 105, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (7, 2, 106, 1, 122.5);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (8, 2, 100, 2, 157.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (9, 2, 101, 2, 187.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (10, 2, 102, 2, 157.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (11, 2, 103, 2, 145.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (12, 2, 104, 2, 145.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (13, 2, 105, 2, 145.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (14, 2, 106, 2, 112.5);

insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (15, 1, 1, 1, 219.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (16, 1, 2, 1, 199.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (17, 1, 3, 1, 179.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (18, 1, 4, 1, 149.50);


insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (19, 4, 100, 1, 167.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (20, 4, 101, 1, 197.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (21, 4, 102, 1, 167.75);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (22, 4, 103, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (23, 4, 104, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (24, 4, 105, 1, 155.0);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (25, 4, 106, 1, 122.5);

insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (26, 3, 1, 1, 219.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (27, 3, 2, 1, 199.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (28, 3, 3, 1, 179.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (29, 3, 4, 1, 149.50);

insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (30, 5, 5, 1, 219.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (31, 5, 6, 1, 199.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (32, 5, 7, 1, 179.50);
insert into TicketPriceCategory (id, show_id, section_id, ticketcategory_id, price) values (33, 5, 8, 1, 149.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (1, 2, 100, 1, 167.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (2, 2, 101, 1, 197.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (3, 2, 102, 1, 167.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (4, 2, 103, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (5, 2, 104, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (6, 2, 105, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (7, 2, 106, 1, 122.5);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (8, 2, 100, 2, 157.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (9, 2, 101, 2, 187.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (10, 2, 102, 2, 157.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (11, 2, 103, 2, 145.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (12, 2, 104, 2, 145.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (13, 2, 105, 2, 145.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (14, 2, 106, 2, 112.5);

insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (15, 1, 1, 1, 219.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (16, 1, 2, 1, 199.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (17, 1, 3, 1, 179.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (18, 1, 4, 1, 149.50);


insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (19, 4, 100, 1, 167.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (20, 4, 101, 1, 197.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (21, 4, 102, 1, 167.75);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (22, 4, 103, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (23, 4, 104, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (24, 4, 105, 1, 155.0);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (25, 4, 106, 1, 122.5);

insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (26, 3, 1, 1, 219.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (27, 3, 2, 1, 199.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (28, 3, 3, 1, 179.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (29, 3, 4, 1, 149.50);

insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (30, 5, 5, 1, 219.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (31, 5, 6, 1, 199.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (32, 5, 7, 1, 179.50);
insert into ticketprice (id, show_id, section_id, ticketcategory_id, price) values (33, 5, 8, 1, 149.50);

0 comments on commit 253f371

Please sign in to comment.