PrintedCard.java 5.06 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fi.codecrew.moya.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;

import javax.faces.model.ListDataModel;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import fi.codecrew.moya.enums.CardState;

/**
 * 
 */
@Entity
@Table(name = "printed_cards", uniqueConstraints = {
        @UniqueConstraint(columnNames = { "event_id", "rfid_uid", }),
        @UniqueConstraint(columnNames = { "event_id", "barcode" }) })
public class PrintedCard extends GenericEntity {

    private static final long serialVersionUID = 8603481931116401027L;

    public static final String EVENT_ID_COLUMN = "event_id";
    @ManyToOne()
    @JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
    private LanEvent event;

    @Column(name = "print_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar printTime;


    @Column(name = "card_enabled", nullable = false)
    private boolean enabled = true;


    @OneToMany(cascade = CascadeType.ALL, mappedBy = "printedCard")
    private List<ReaderEvent> readerEvents = new ArrayList<ReaderEvent>();
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "printedCard")
    private List<CardCode> cardCodes = new ArrayList<CardCode>();

    
	@Column(name = "print_count", nullable = false)
    private int printCount = 0;

    @JoinColumn(name = "current_location_id", referencedColumnName = "id")
    @ManyToOne
    private Location currentLocation;

    @JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
    @ManyToOne(optional = false)
    private EventUser user;

    @JoinColumn(nullable = false, name = "card_template_id", referencedColumnName = CardTemplate.ID_COLUMN)
    @ManyToOne(optional = false)
    private CardTemplate template;
    
    @Column(name="card_state", nullable=false)
    @Enumerated(EnumType.STRING)
    private CardState cardState = CardState.PENDING_VALIDATION;

    public PrintedCard(EventUser usr, CardTemplate templ, Calendar printTime, boolean cardEnabled) {
        super();
        this.event = templ.getEvent();
        this.template = templ;
        this.user = usr;
        this.printTime = printTime;
        this.enabled = cardEnabled;
    }

    public PrintedCard()
    {
        super();
    }

    public LanEvent getEvent() {
        return event;
    }

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

    public Calendar getPrintTime() {
        return printTime;
    }

    public void setPrintTime(Calendar printTime) {
        this.printTime = printTime;
    }


    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean cardEnabled) {
        this.enabled = cardEnabled;
    }

    public List<ReaderEvent> getReaderEvents() {
        return readerEvents;
    }

    public void setReaderEvents(List<ReaderEvent> readerEventList) {
        this.readerEvents = readerEventList;
    }

    public Location getCurrentLocation() {
        return currentLocation;
    }

    public void setCurrentLocation(Location currentLocation) {
        this.currentLocation = currentLocation;
    }

    
    public List<CardCode> getCardCodes() {
		return cardCodes;
	}

	public void setCardCodes(List<CardCode> cardCodes) {
		this.cardCodes = cardCodes;
	}

    
    
    public EventUser getUser() {
        return user;
    }

    public void setUser(EventUser usersId) {
        this.user = usersId;
    }

    public void setTemplate(CardTemplate template) {
        this.template = template;
    }

    public CardTemplate getTemplate() {
        return template;
    }

    public void setPrintCount(int printCount) {
        this.printCount = printCount;
    }

    public int getPrintCount() {
        return printCount;
    }
   
    
    public CardState getCardState() {
        return cardState;
    }

    public void setCardState(CardState cardState) {
        this.cardState = cardState;
    }

}