/*
* The MIT License
*
* Copyright 2012 Universidad de Montemorelos A. C.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package mx.edu.um.mateo.general.model;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import net.sf.jasperreports.engine.JasperReport;
import org.hibernate.annotations.Index;
import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author J. David Mendoza <jdmendoza@um.edu.mx>
*/
@Entity
@Table(name = "reportes")
public class Reporte implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6983734196720387073L;
private static final Logger log = LoggerFactory.getLogger(Reporte.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Version
private Integer version;
@NotBlank
@Column(nullable = false, length = 64)
@Index(name = "reporte_nombre_idx")
private String nombre;
@Column(nullable = false)
private byte[] fuente;
@Column(nullable = false)
private byte[] compilado;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false, name = "date_created")
private Date fechaCreacion;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false, name = "last_updated")
private Date fechaModificacion;
public Reporte() {
}
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the version
*/
public Integer getVersion() {
return version;
}
/**
* @param version
* the version to set
*/
public void setVersion(Integer version) {
this.version = version;
}
/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}
/**
* @param nombre
* the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}
/**
* @return the fuente
*/
public byte[] getFuente() {
return fuente;
}
/**
* @param fuente
* the fuente to set
*/
public void setFuente(byte[] fuente) {
this.fuente = fuente;
}
/**
* @return the compilado
*/
public byte[] getCompilado() {
return compilado;
}
/**
* @param compilado
* the compilado to set
*/
public void setCompilado(byte[] compilado) {
this.compilado = compilado;
}
/**
* @return the fechaCreacion
*/
public Date getFechaCreacion() {
return fechaCreacion;
}
/**
* @param fechaCreacion
* the fechaCreacion to set
*/
public void setFechaCreacion(Date fechaCreacion) {
this.fechaCreacion = fechaCreacion;
}
/**
* @return the fechaModificacion
*/
public Date getFechaModificacion() {
return fechaModificacion;
}
/**
* @param fechaModificacion
* the fechaModificacion to set
*/
public void setFechaModificacion(Date fechaModificacion) {
this.fechaModificacion = fechaModificacion;
}
public JasperReport getReporte() {
JasperReport jr = null;
try (ByteArrayInputStream bais = new ByteArrayInputStream(compilado)) {
try (ObjectInputStream in = new ObjectInputStream(bais)) {
jr = (JasperReport) in.readObject();
}
} catch (IOException | ClassNotFoundException e) {
log.error("No se pudo transformar a reporte", e);
}
return jr;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Reporte other = (Reporte) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + Objects.hashCode(this.getId());
hash = 89 * hash + Objects.hashCode(this.getVersion());
hash = 89 * hash + Objects.hashCode(this.getNombre());
return hash;
}
@Override
public String toString() {
return "Reporte{" + "id=" + getId() + ", nombre=" + getNombre() + '}';
}
}