Role.java 4.24 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.insomnia.bortal.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.eclipse.persistence.annotations.PrivateOwned;

/**
 * 
 */
@Entity
@Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { Role.EVENT_ID_COLUMN, Role.NAME_COLUMN }) })
public class Role extends GenericEntity {

    private static final long serialVersionUID = -4602863502464505404L;

    protected static final String NAME_COLUMN = "role_name";

    protected static final String EVENT_ID_COLUMN = "event_id";

    @Column(name = NAME_COLUMN, nullable = false)
    private String name;

    @ManyToMany(mappedBy = "roles")
    private List<User> users;

    @ManyToMany(mappedBy = "parents")
    private List<Role> children = new ArrayList<Role>();

    @OneToMany(mappedBy = "provides")
    private List<Product> productsProvide;

    @OneToMany(mappedBy = "providesRole")
    private List<Place> placesProvide;

    @ManyToMany()
    private List<Role> parents = new ArrayList<Role>();

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "role")
    @PrivateOwned
    private List<ApplicationPermission> permissions = new ArrayList<ApplicationPermission>();

    @ManyToOne
    private CardTemplate cardTemplate;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "role")
    private List<Discount> discounts;

    @OneToMany(mappedBy = "writerRole")
    private List<NewsGroup> writeNews;

    @ManyToMany(mappedBy = "readerRoles")
    private List<NewsGroup> newsGroups;

    @ManyToOne
    @JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
    private LanEvent event;

    public Role() {
        super();
    }

    public Role(LanEvent event) {
        this.event = event;
    }

    public Role(LanEvent event, String roleName) {
        this(event);
        this.name = roleName;
    }

    public String getName() {
        return name;
    }

    public void setName(String roleName) {
        this.name = roleName;
    }

    public CardTemplate getCardTemplate() {
        return cardTemplate;
    }

    public void setCardTemplate(CardTemplate cardTemplatesId) {
        this.cardTemplate = cardTemplatesId;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setDiscounts(List<Discount> discounts) {
        this.discounts = discounts;
    }

    public List<Discount> getDiscounts() {
        return discounts;
    }

    public void setParents(List<Role> parents) {
        this.parents = parents;
    }

    public List<Role> getParents() {
        return parents;
    }

    public void setChildren(List<Role> children) {
        this.children = children;
    }

    public List<Role> getChildren() {
        return children;
    }

    public void setNewsGroups(List<NewsGroup> newsGroups) {
        this.newsGroups = newsGroups;
    }

    public List<NewsGroup> getNewsGroups() {
        return newsGroups;
    }

    public LanEvent getEvent() {
        return event;
    }

    public void setProductsProvide(List<Product> productsProvide) {
        this.productsProvide = productsProvide;
    }

    public List<Product> getProductsProvide() {
        return productsProvide;
    }

    public void setPlacesProvide(List<Place> placesProvide) {
        this.placesProvide = placesProvide;
    }

    public List<Place> getPlacesProvide() {
        return placesProvide;
    }

    public void setEvent(LanEvent event) {
        this.event = event;
    }

    public void setWriteNews(List<NewsGroup> writeNews) {
        this.writeNews = writeNews;
    }

    public List<NewsGroup> getWriteNews() {
        return writeNews;

    }

    public void setPermissions(List<ApplicationPermission> permissions) {
        this.permissions = permissions;
    }

    public List<ApplicationPermission> getPermissions() {
        return permissions;
    }
}