Subversion Repositories Integrator Subversion

Rev

Rev 771 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.sl.domain.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

import br.com.ec.core.interfaces.Alterar;
import br.com.ec.core.interfaces.Cadastrar;
import br.com.ec.core.util.StringUtil;
import br.com.ec.core.util.VerificadorUtil;
import br.com.sl.domain.model.tipos.TipoTendencia;

@Entity
@Table(name="slp_ativo", schema="sc_slp")
public class Ativo implements Serializable {

        private static final long serialVersionUID = 1L;

        private Long sequencial;
        private String nome;
        private String tipoTendencia;
        private Boolean ativo;
       
        public Ativo() {}
       
        public Ativo(Long sequencial, String nome) {
                this.sequencial = sequencial;
                this.nome = nome;
        }
       
        @Id
        @SequenceGenerator(name = "sq_ativo")
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        @Column(name="seq_ativo", nullable=false)
        public Long getSequencial() {
                return sequencial;
        }
        public void setSequencial(Long sequencial) {
                this.sequencial = sequencial;
        }
       
        @Column(name="dsc_ativo")
        @Size(max = 120, message = "Limite de caracteres ultrapassado: Nome do ativo")
        @NotEmpty(message="Obrigatório informar o nome do ativo", groups={Cadastrar.class, Alterar.class})
        public String getNome() {
                return nome;
        }
        public void setNome(String nome) {
                this.nome = StringUtil.setarUpperCaseComTrim(nome);
        }
       
        @Column(name="tip_tendencia")
        @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo de tendência", groups = {Cadastrar.class, Alterar.class})
        public String getTipoTendencia() {
                return tipoTendencia;
        }
        public void setTipoTendencia(String tipoTendencia) {
                this.tipoTendencia = tipoTendencia;
        }
       
        @Transient
        public String getDescricaoDaTendencia() {
                return VerificadorUtil.naoEstaNulo(getTipoTendencia())? TipoTendencia.parse(getTipoTendencia()).getDescricao() : "";
        }
       
        @Column(name="ind_ativo", nullable=false)
        public Boolean getAtivo() {
                return ativo;
        }
        public void setAtivo(Boolean ativo) {
                this.ativo = ativo;
        }
       
        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result
                                + ((sequencial == null) ? 0 : sequencial.hashCode());
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                Ativo other = (Ativo) obj;
                if (sequencial == null) {
                        if (other.sequencial != null)
                                return false;
                } else if (!sequencial.equals(other.sequencial))
                        return false;
                return true;
        }
       
}