Commit 7c14cbec by Juho Juopperi

entity reference fixes

1 parent 8f5ce3ef
......@@ -96,6 +96,10 @@ public class Bill implements EventChildInterface {
@ManyToOne(optional = false)
private User user;
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false)
private Event event;
/**
* Commodity function to calculate the total price of the bill.
*
......@@ -235,4 +239,12 @@ public class Bill implements EventChildInterface {
public int getJpaVersionField() {
return jpaVersionField;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -96,15 +96,14 @@ public class BillLine implements EventChildInterface {
public BillLine() {
}
public BillLine(Bill bill) {
this.id = new EventPk(bill.getId().getEvent());
public BillLine(Event event, Bill bill) {
this.id = new EventPk(event);
this.bill = bill;
}
public BillLine(Bill bill, String product, BigDecimal units,
public BillLine(Event event, Bill bill, String product, BigDecimal units,
BigDecimal unitPrice, BigDecimal vat) {
this.id = new EventPk(bill.getId().getEvent());
this.bill = bill;
this(event, bill);
this.name = product;
this.setQuantity(units);
this.setUnitPrice(unitPrice);
......
......@@ -45,6 +45,10 @@ public class CardTemplate implements EventChildInterface {
@OneToMany(mappedBy = "template")
private List<PrintedCard> cards;
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false)
private Event event;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -140,4 +144,12 @@ public class CardTemplate implements EventChildInterface {
return cards;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -99,6 +99,10 @@ public class Compo implements EventChildInterface {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "compo")
private List<CompoEntry> compoEntries;
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false)
private Event event;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -250,4 +254,12 @@ public class Compo implements EventChildInterface {
this.maxParticipantCount = maxParticipantCount;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -84,8 +84,8 @@ public class CompoEntryParticipant implements EventChildInterface {
this.id = new EventPk(event);
}
public CompoEntryParticipant(CompoEntry entry, User participant) {
this(entry.getId().getEvent());
public CompoEntryParticipant(Event event, CompoEntry entry, User participant) {
this(event);
this.entry = entry;
this.user = participant;
}
......
......@@ -88,10 +88,10 @@ public class Event implements ModelInterface<Integer> {
@Column(nullable = false)
private int jpaVersionField = 0;
@OneToMany(mappedBy = "event_id")
@OneToMany(mappedBy = "event")
private List<Bill> bills;
@OneToMany(mappedBy = "event_id")
@OneToMany(mappedBy = "event")
private List<Reader> readers;
public Event() {
......
......@@ -8,13 +8,14 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import javax.imageio.ImageIO;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
......@@ -48,6 +49,10 @@ public class EventMap implements EventChildInterface {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "map")
private List<Place> places;
@ManyToOne(optional = false)
@JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false, nullable = false)
private Event event;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -161,19 +166,23 @@ public class EventMap implements EventChildInterface {
this.readers = readers;
}
public BufferedImage getMapWithPlaces() throws IOException {
BufferedImage image = ImageIO.read(new ByteArrayInputStream(getMapData()));
for(Place place : getPlaces()) {
for (Place place : getPlaces()) {
place.drawPlace(image);
}
return image;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -17,15 +17,18 @@ public class EventPk implements Serializable {
@Column(name = "event_id", nullable = false, updatable = false)
private Integer eventId;
@JoinColumn(name = "event_id", referencedColumnName = "event_id")
@ManyToOne
private Event event;
// @JoinColumn(name = "event_id", referencedColumnName = "event_id")
// @ManyToOne
// private Event event;
private static final long serialVersionUID = 1L;
public EventPk() {
}
public EventPk(Event event) {
super();
this.event = event;
this.eventId = event.getId();
}
public void setId(Integer id) {
......@@ -51,11 +54,11 @@ public class EventPk implements Serializable {
return pk.id == this.id && pk.eventId == this.eventId;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
// public void setEvent(Event event) {
// this.event = event;
// }
//
// public Event getEvent() {
// return event;
// }
}
......@@ -39,7 +39,7 @@ public class FoodWaveTemplate implements EventChildInterface {
@Column(name = "template_description")
private String description;
@ManyToMany(mappedBy = "foodWaveTemplate")
@ManyToMany(mappedBy = "foodWaveTemplates")
private List<Product> products;
@Version
......
......@@ -12,7 +12,6 @@ import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
......
......@@ -10,6 +10,8 @@ import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
......@@ -49,6 +51,14 @@ public class NewsGroup implements EventChildInterface {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "group")
private List<News> news;
@ManyToMany
@JoinTable(name = "newsgroup_role", joinColumns = {
@JoinColumn(name = "newsgroup_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, inverseJoinColumns = {
@JoinColumn(name = "role_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") })
private List<Role> roles;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -159,4 +169,12 @@ public class NewsGroup implements EventChildInterface {
public void setJpaVersionField(int jpaVersionField) {
this.jpaVersionField = jpaVersionField;
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
public List<Role> getRoles() {
return roles;
}
}
......@@ -256,7 +256,8 @@ public class Place implements EventChildInterface {
}
/**
* @param height the height to set
* @param height
* the height to set
*/
public void setHeight(Integer height) {
this.height = height;
......@@ -270,7 +271,8 @@ public class Place implements EventChildInterface {
}
/**
* @param width the width to set
* @param width
* the width to set
*/
public void setWidth(Integer width) {
this.width = width;
......@@ -286,6 +288,7 @@ public class Place implements EventChildInterface {
return false;
}
private static final Color NORMAL_COLOR = Color.BLUE;
private static final Color RESERVED_COLOR = Color.RED;
private static final Color SELECTED_COLOR = Color.GREEN;
......@@ -294,7 +297,7 @@ public class Place implements EventChildInterface {
public void drawPlace(BufferedImage targetImage) {
Graphics2D g = targetImage.createGraphics();
if (placeGroup != null) {
if (group != null) {
g.setColor(RESERVED_COLOR);
g.fill(new Rectangle(mapX, mapY, width, height));
} else {
......
......@@ -11,13 +11,18 @@ import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import org.eclipse.persistence.annotations.PrimaryKey;
/**
*
*/
......@@ -58,6 +63,14 @@ public class Product implements EventChildInterface {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
private List<Discount> discounts;
@ManyToMany()
@JoinTable(name = "product_foodwavetemplate", joinColumns = {
@JoinColumn(name = "product_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, inverseJoinColumns = {
@JoinColumn(name = "food_wave_template_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "product_id", "food_wave_template_id", "event_id" }) })
private List<FoodWaveTemplate> foodWaveTemplates;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -191,4 +204,12 @@ public class Product implements EventChildInterface {
public List<Discount> getDiscounts() {
return discounts;
}
public void setFoodWaveTemplates(List<FoodWaveTemplate> foodWaveTemplates) {
this.foodWaveTemplates = foodWaveTemplates;
}
public List<FoodWaveTemplate> getFoodWaveTemplates() {
return foodWaveTemplates;
}
}
......@@ -4,9 +4,6 @@
*/
package fi.insomnia.bortal.model;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
......@@ -16,7 +13,6 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
......@@ -44,20 +40,22 @@ public class Reader implements EventChildInterface {
@Column(name = "reader_description")
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "reader")
private List<ReaderEvent> events;
@JoinColumns( {
@JoinColumn(name = "location_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false) })
@ManyToOne
private Location location;
@ManyToOne
@JoinColumns( {
@JoinColumn(name = "map_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false) })
private EventMap eventMap;
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false)
private Event event;
@Column(name = "map_x")
private Integer mapX;
@Column(name = "map_y")
......@@ -90,14 +88,6 @@ public class Reader implements EventChildInterface {
this.description = readerDescription;
}
public List<ReaderEvent> getEvents() {
return events;
}
public void setEvents(List<ReaderEvent> readerEventList) {
this.events = readerEventList;
}
public Location getLocation() {
return location;
}
......@@ -168,21 +158,6 @@ public class Reader implements EventChildInterface {
}
/**
* @return the event
*/
public Event getEvent() {
return event;
}
/**
* @param event
* the event to set
*/
public void setEvent(Event event) {
this.event = event;
}
/**
* @return the mapX
*/
public Integer getMapX() {
......@@ -226,4 +201,12 @@ public class Reader implements EventChildInterface {
public void setEventMap(EventMap eventMap) {
this.eventMap = eventMap;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -27,7 +27,7 @@ import javax.persistence.Version;
*
*/
@Entity
@Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { "events_pk_id", "role_name" }) })
@Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { "events_id", "role_name" }) })
@NamedQueries( {
@NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r"),
@NamedQuery(name = "Role.findByRoleName", query = "SELECT r FROM Role r WHERE r.name = :name") })
......@@ -74,6 +74,10 @@ public class Role implements EventChildInterface {
@ManyToMany(mappedBy = "roles")
private List<NewsGroup> newsGroups;
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false)
private Event event;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
......@@ -214,4 +218,12 @@ public class Role implements EventChildInterface {
public List<NewsGroup> getNewsGroups() {
return newsGroups;
}
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() {
return event;
}
}
......@@ -70,8 +70,8 @@ public class RoleRight implements EventChildInterface {
this.id = new EventPk(event);
}
public RoleRight(Role role, AccessRight right, boolean read, boolean write, boolean execute) {
this(role.getId().getEvent());
public RoleRight(Event event, Role role, AccessRight right, boolean read, boolean write, boolean execute) {
this(event);
this.role = role;
this.accessRight = right;
this.read = read;
......
......@@ -27,8 +27,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.PasswordFunctions;
import java.io.Serializable;
/**
*
......@@ -127,14 +125,14 @@ public class User implements ModelInterface<Integer> {
@OneToMany(mappedBy = "user")
private List<UserImage> userImageList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "users")
private List<CompoEntryParticipant> compoEntryParticipantList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<CompoEntryParticipant> compoEntryParticipants;
@OneToMany(mappedBy = "creator")
private List<CompoEntry> compoEntryList;
private List<CompoEntry> compoEntries;
@OneToMany(mappedBy = "creator")
private List<PlaceGroup> placeGroupList;
private List<PlaceGroup> placeGroups;
@OneToMany(mappedBy = "user")
private List<GroupMembership> groupMemberships;
......@@ -340,29 +338,29 @@ public class User implements ModelInterface<Integer> {
this.userImageList = userImageList;
}
public List<CompoEntryParticipant> getCompoEntryParticipantList() {
return compoEntryParticipantList;
public List<CompoEntryParticipant> getCompoEntryParticipants() {
return compoEntryParticipants;
}
public void setCompoEntryParticipantList(
public void setCompoEntryParticipants(
List<CompoEntryParticipant> compoEntryParticipantList) {
this.compoEntryParticipantList = compoEntryParticipantList;
this.compoEntryParticipants = compoEntryParticipantList;
}
public List<CompoEntry> getCompoEntryList() {
return compoEntryList;
public List<CompoEntry> getCompoEntries() {
return compoEntries;
}
public void setCompoEntryList(List<CompoEntry> compoEntryList) {
this.compoEntryList = compoEntryList;
public void setCompoEntries(List<CompoEntry> compoEntryList) {
this.compoEntries = compoEntryList;
}
public List<PlaceGroup> getPlaceGroupList() {
return placeGroupList;
public List<PlaceGroup> getPlaceGroups() {
return placeGroups;
}
public void setPlaceGroupList(List<PlaceGroup> placeGroupList) {
this.placeGroupList = placeGroupList;
public void setPlaceGroups(List<PlaceGroup> placeGroupList) {
this.placeGroups = placeGroupList;
}
public List<GroupMembership> getGroupMemberships() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!