Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.edu.cesmac.sic.core.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.persistence.Column; |
||
| 6 | import javax.persistence.Entity; |
||
| 7 | import javax.persistence.GeneratedValue; |
||
| 8 | import javax.persistence.GenerationType; |
||
| 9 | import javax.persistence.Id; |
||
| 10 | import javax.persistence.Table; |
||
| 11 | import javax.persistence.Transient; |
||
| 12 | import javax.validation.constraints.NotNull; |
||
| 13 | |||
| 14 | import org.primefaces.model.UploadedFile; |
||
| 15 | |||
| 16 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 17 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 18 | |||
| 19 | @Entity |
||
| 20 | @Table(name="sic_arquivo", schema="admsic001") |
||
| 21 | public class Arquivo implements Serializable { |
||
| 22 | |||
| 23 | private static final long serialVersionUID = 1L; |
||
| 24 | |||
| 25 | private Long sequencial; |
||
| 26 | private byte[] arquivo; |
||
| 27 | private String extensao; |
||
| 28 | |||
| 29 | public Arquivo(UploadedFile modeloParaUpload) { |
||
| 30 | setArquivo(modeloParaUpload.getContents()); |
||
| 31 | setExtensao(extensaoDoArquivo(modeloParaUpload.getFileName())); |
||
| 32 | } |
||
| 33 | |||
| 34 | public Arquivo() {} |
||
| 35 | |||
| 36 | @Id |
||
| 37 | @GeneratedValue(strategy=GenerationType.AUTO) |
||
| 38 | @Column(name="seq_arquivo", nullable=false) |
||
| 39 | public Long getSequencial() { |
||
| 40 | return sequencial; |
||
| 41 | } |
||
| 42 | |||
| 43 | public void setSequencial(Long sequencial) { |
||
| 44 | this.sequencial = sequencial; |
||
| 45 | } |
||
| 46 | |||
| 47 | @NotNull(message="Obrigatório informar o arquivo", groups={Cadastrar.class, Alterar.class}) |
||
| 48 | @Column(name="obj_arquivo", nullable=false) |
||
| 49 | public byte[] getArquivo() { |
||
| 50 | return arquivo; |
||
| 51 | } |
||
| 52 | |||
| 53 | public void setArquivo(byte[] arquivo) { |
||
| 54 | this.arquivo = arquivo; |
||
| 55 | } |
||
| 56 | |||
| 57 | @NotNull(message="Obrigatório informar a descrição da extensão do arquivo", groups={Cadastrar.class, Alterar.class}) |
||
| 58 | @Column(name="dsc_extensao", nullable=false) |
||
| 59 | public String getExtensao() { |
||
| 60 | return extensao; |
||
| 61 | } |
||
| 62 | |||
| 63 | public void setExtensao(String extensao) { |
||
| 64 | this.extensao = extensao; |
||
| 65 | } |
||
| 66 | |||
| 67 | @Override |
||
| 68 | public int hashCode() { |
||
| 69 | final int prime = 31; |
||
| 70 | int result = 1; |
||
| 71 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 72 | return result; |
||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public boolean equals(Object obj) { |
||
| 77 | if (this == obj) |
||
| 78 | return true; |
||
| 79 | if (obj == null) |
||
| 80 | return false; |
||
| 81 | if (getClass() != obj.getClass()) |
||
| 82 | return false; |
||
| 83 | Arquivo other = (Arquivo) obj; |
||
| 84 | if (sequencial == null) { |
||
| 85 | if (other.sequencial != null) |
||
| 86 | return false; |
||
| 87 | } else if (!sequencial.equals(other.sequencial)) |
||
| 88 | return false; |
||
| 89 | return true; |
||
| 90 | } |
||
| 91 | |||
| 92 | @Transient |
||
| 93 | private String extensaoDoArquivo(String nomeArquivo) { |
||
| 94 | return nomeArquivo.substring(nomeArquivo.lastIndexOf('.') + 1, nomeArquivo.length()); |
||
| 95 | } |
||
| 96 | |||
| 97 | } |