/* * This file is part of SGEA - Sistema de Gestão de Eventos Acadêmicos - TADS IFNMG Campus Januária. * * SGEA 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. * * SGEA 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 SGEA. If not, see <http://www.gnu.org/licenses/>. */ package br.edu.ifnmg.GerenciamentoEventos.DomainModel; import br.edu.ifnmg.DomainModel.Pessoa; import br.edu.ifnmg.DomainModel.Entidade; import java.io.Serializable; import java.util.Date; import java.util.Objects; import javax.persistence.Cacheable; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; /** * * @author Petrônio */ @Entity @Table(name = "alocacoesrecursos") @Cacheable(true) public class Alocacao implements Entidade, Serializable, Comparable<Alocacao> { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @ManyToOne private Recurso recurso; @ManyToOne private Evento evento; @ManyToOne private Atividade atividade; @ManyToOne private Pessoa responsavel; @Temporal(TemporalType.TIMESTAMP) private Date inicio; @Temporal(TemporalType.TIMESTAMP) private Date termino; @Enumerated(EnumType.STRING) AlocacaoStatus status; public Alocacao(){ status = AlocacaoStatus.Pendente; } @Override public Long getId() { return id; } @Override public void setId(Long id) { this.id = id; } public Recurso getRecurso() { return recurso; } public void setRecurso(Recurso recurso) { this.recurso = recurso; } public Evento getEvento() { return evento; } public void setEvento(Evento evento) { this.evento = evento; } public Atividade getAtividade() { return atividade; } public void setAtividade(Atividade atividade) { this.atividade = atividade; } public Pessoa getResponsavel() { return responsavel; } public void setResponsavel(Pessoa responsavel) { this.responsavel = responsavel; } public Date getInicio() { return inicio; } public void setInicio(Date inicio) { this.inicio = inicio; } public Date getTermino() { return termino; } public void setTermino(Date termino) { this.termino = termino; } public AlocacaoStatus getStatus() { return status; } public void setStatus(AlocacaoStatus status) { this.status = status; } @Override public int hashCode() { int hash = 5; hash = 19 * hash + Objects.hashCode(this.recurso); hash = 19 * hash + Objects.hashCode(this.evento); hash = 19 * hash + Objects.hashCode(this.atividade); hash = 19 * hash + Objects.hashCode(this.inicio); hash = 19 * hash + Objects.hashCode(this.termino); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Alocacao other = (Alocacao) obj; if (!Objects.equals(this.evento, other.evento)) { return false; } if (!Objects.equals(this.atividade, other.atividade)) { return false; } if (!Objects.equals(this.inicio, other.inicio)) { return false; } if (!Objects.equals(this.termino, other.termino)) { return false; } return true; } @Override public String toString() { return "br.edu.ifnmg.GerenciamentoEventos.DomainModel.Alocacao[ id=" + id + " ]"; } @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private Pessoa criador; @Temporal(TemporalType.TIMESTAMP) private Date dataCriacao; @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private Pessoa ultimoAlterador; @Temporal(TemporalType.TIMESTAMP) private Date dataUltimaAlteracao; @Version private Long versao; @Override public Pessoa getCriador() { return criador; } @Override public void setCriador(Pessoa criador) { this.criador = criador; } @Override public Date getDataCriacao() { return dataCriacao; } @Override public void setDataCriacao(Date dataCriacao) { this.dataCriacao = dataCriacao; } @Override public Pessoa getUltimoAlterador() { return ultimoAlterador; } @Override public void setUltimoAlterador(Pessoa ultimoAlterador) { this.ultimoAlterador = ultimoAlterador; } @Override public Date getDataUltimaAlteracao() { return dataUltimaAlteracao; } @Override public void setDataUltimaAlteracao(Date dataUltimaAlteracao) { this.dataUltimaAlteracao = dataUltimaAlteracao; } @Override public Long getVersao() { return versao; } public void setVersao(Long versao) { this.versao = versao; } @Override public int compareTo(Alocacao o) { if(this.termino.before(o.inicio)) return -1; if(this.inicio.after(o.termino)) return 1; if(this.inicio.before(o.inicio) && this.termino.after(o.inicio) && this.termino.before(o.termino)) return 0; if(this.inicio.before(o.inicio) && this.termino.after(o.termino)) return 0; if(this.inicio.after(o.inicio) && this.inicio.before(o.termino) ) return 0; if(this.termino.after(o.inicio) && this.termino.before(o.termino) ) return 0; return 0; } }