package br.com.boardnaveia.dao.bean;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import br.com.boardnaveia.constant.CanalNoticia;
import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;
/**
* @author Felipe Castellani
*
*/
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Noticia implements Serializable {
private static final long serialVersionUID = 1259406458178658440L;
public Noticia(byte[] bs) {
super();
ImagesService service = ImagesServiceFactory.getImagesService();
Transform transform = ImagesServiceFactory.makeImFeelingLucky();
Image image = service.applyTransform(transform, ImagesServiceFactory.makeImage(bs));
this.arquivo = new Blob(image.getImageData());
this.dataCadastro = new Date();
}
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long codigo;
@Persistent
private Blob arquivo;
@Persistent
private String login;
@Persistent
private String titulo;
@Persistent
private CanalNoticia canal;
@Persistent
private String descricao;
@Persistent
private Date dataCadastro;
public Long getCodigo() {
return codigo;
}
public void setCodigo(Long codigo) {
this.codigo = codigo;
}
public CanalNoticia getCanal() {
return canal;
}
public void setCanal(CanalNoticia canal) {
this.canal = canal;
}
public Date getDataCadastro() {
return dataCadastro;
}
public void setDataCadastro(Date dataCadastro) {
this.dataCadastro = dataCadastro;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public Blob getArquivo() {
return arquivo;
}
public void setArquivo(Blob arquivo) {
this.arquivo = arquivo;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public InputStream getInputStream() {
return new ByteArrayInputStream(getArquivo().getBytes());
}
}