fixes bug#14878
dev:lucas qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@96035 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
1ea0110ff9
commit
9b2e31f39a
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
|
|
||||||
|
public interface ImagemDAO extends GenericDAO<Imagem, Integer> {
|
||||||
|
|
||||||
|
public Imagem buscarPorNomeImagem(String nomeImagem);
|
||||||
|
|
||||||
|
public List<Imagem> buscar(String nombimagem);
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.criterion.Order;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.ImagemDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
|
|
||||||
|
@Repository("imagemDAO")
|
||||||
|
public class ImagemHibernateDAO extends GenericHibernateDAO<Imagem, Integer>
|
||||||
|
implements ImagemDAO {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ImagemHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
|
setSessionFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Imagem> obtenerTodos() {
|
||||||
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
c.addOrder(Order.asc("imagemId"));
|
||||||
|
|
||||||
|
return c.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Imagem buscarPorNomeImagem(String nomeImagem) {
|
||||||
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
|
||||||
|
c.add(Restrictions.eq("nombImagem", nomeImagem));
|
||||||
|
|
||||||
|
return (Imagem) c.uniqueResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Imagem> buscar(String nomeImagem) {
|
||||||
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
|
||||||
|
c.add(Restrictions.eq("nombImagem", nomeImagem));
|
||||||
|
|
||||||
|
return c.list();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.entidad;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Lob;
|
||||||
|
import javax.persistence.SequenceGenerator;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@SequenceGenerator(name = "IMAGEM_SEQ", sequenceName = "IMAGEM_SEQ", allocationSize = 1)
|
||||||
|
@Table(name = "IMAGEM")
|
||||||
|
public class Imagem implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Id
|
||||||
|
@Basic(optional = false)
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO, generator = "IMAGEM_SEQ")
|
||||||
|
@Column(name = "IMAGEM_ID")
|
||||||
|
private Integer imagemId;
|
||||||
|
@Lob
|
||||||
|
@Column(name = "IMAGEM")
|
||||||
|
private byte[] imagem;
|
||||||
|
@Column(name = "NOMBIMAGEM")
|
||||||
|
private String nombImagem;
|
||||||
|
@Column(name = "ACTIVO")
|
||||||
|
private Boolean activo;
|
||||||
|
@Column(name = "FECMODIF")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date fecmodif;
|
||||||
|
@Column(name = "USUARIO_ID")
|
||||||
|
private Integer usuarioId;
|
||||||
|
|
||||||
|
public Imagem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getImagemId() {
|
||||||
|
return imagemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImagemId(Integer imagemId) {
|
||||||
|
this.imagemId = imagemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getImagem() {
|
||||||
|
return imagem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImagem(byte[] imagem) {
|
||||||
|
this.imagem = imagem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getActivo() {
|
||||||
|
return activo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivo(Boolean activo) {
|
||||||
|
this.activo = activo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getFecmodif() {
|
||||||
|
return fecmodif;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFecmodif(Date fecmodif) {
|
||||||
|
this.fecmodif = fecmodif;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUsuarioId() {
|
||||||
|
return usuarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsuarioId(Integer usuarioId) {
|
||||||
|
this.usuarioId = usuarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombImagem() {
|
||||||
|
return nombImagem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombImagem(String nombImagem) {
|
||||||
|
this.nombImagem = nombImagem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 0;
|
||||||
|
hash += (imagemId != null ? imagemId.hashCode() : 0);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||||
|
if (!(object instanceof Imagem)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Imagem other = (Imagem) object;
|
||||||
|
if ((this.imagemId == null && other.imagemId != null) || (this.imagemId != null && !this.imagemId.equals(other.imagemId))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "com.rjconsultores.ventaboletos.entidad.Imagem[imagemId=" + imagemId + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
|
|
||||||
|
public interface ImagemService extends GenericService<Imagem, Integer> {
|
||||||
|
|
||||||
|
public Imagem buscarPorNomeImagem(String nomeImagem);
|
||||||
|
|
||||||
|
public List<Imagem> buscar(String nombimagem);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.ImagemDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
|
import com.rjconsultores.ventaboletos.service.ImagemService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
|
||||||
|
@Service("imagemService")
|
||||||
|
public class ImagemServiceImpl implements ImagemService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImagemDAO imagemDAO;
|
||||||
|
|
||||||
|
public List<Imagem> obtenerTodos() {
|
||||||
|
return imagemDAO.obtenerTodos();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Imagem obtenerID(Integer id) {
|
||||||
|
return imagemDAO.obtenerID(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
|
public Imagem suscribir(Imagem entidad) {
|
||||||
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado() != null ? UsuarioLogado.getUsuarioLogado().getUsuarioId() : null);
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
return imagemDAO.suscribir(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Imagem actualizacion(Imagem entidad) {
|
||||||
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
return imagemDAO.actualizacion(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void borrar(Imagem entidad) {
|
||||||
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.FALSE);
|
||||||
|
|
||||||
|
imagemDAO.actualizacion(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
||||||
|
public Imagem buscarPorNomeImagem(String nomeImagem) {
|
||||||
|
return imagemDAO.buscarPorNomeImagem(nomeImagem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Imagem> buscar(String nombimagem) {
|
||||||
|
return imagemDAO.buscar(nombimagem);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.rjconsultores.ventaboletos.utilerias;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
private Imagem image;
|
||||||
|
|
||||||
|
public Imagem getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(Imagem image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,16 +4,25 @@
|
||||||
*/
|
*/
|
||||||
package com.rjconsultores.ventaboletos.utilerias;
|
package com.rjconsultores.ventaboletos.utilerias;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.cxf.common.util.CollectionUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Constante;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Custom;
|
import com.rjconsultores.ventaboletos.entidad.Custom;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Imagem;
|
||||||
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||||
import com.rjconsultores.ventaboletos.service.CustomService;
|
import com.rjconsultores.ventaboletos.service.CustomService;
|
||||||
|
import com.rjconsultores.ventaboletos.service.ImagemService;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +36,7 @@ public class ApplicationProperties {
|
||||||
private static Logger log = Logger.getLogger(ApplicationProperties.class);
|
private static Logger log = Logger.getLogger(ApplicationProperties.class);
|
||||||
private static ApplicationProperties INSTANCE;
|
private static ApplicationProperties INSTANCE;
|
||||||
private static Properties p;
|
private static Properties p;
|
||||||
|
private static final String PATH_IMAGENES = "/com/rjconsultores/ventaboletos/web/cliente/imagenes/";
|
||||||
|
|
||||||
private ApplicationProperties() {
|
private ApplicationProperties() {
|
||||||
p = new Properties();
|
p = new Properties();
|
||||||
|
@ -126,4 +136,69 @@ public class ApplicationProperties {
|
||||||
String property = getValuefromCustom(key, defaultValue);
|
String property = getValuefromCustom(key, defaultValue);
|
||||||
return property.equals("1");
|
return property.equals("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InputStream readImagefromCustom(String imagene) throws FileNotFoundException, IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new ClassPathResource(PATH_IMAGENES + imagene).getInputStream();
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
throw fnfe;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadImageToDatabase(String empresa, boolean isGenerica) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String empresaNome = isGenerica ? "EMPRESA_BACKGROUND_GENERICA" : "EMPRESA_BACKGROUND";
|
||||||
|
ImagemService imagemService = (ImagemService) AppContext.getApplicationContext().getBean("imagemService");
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(imagemService.buscar(empresaNome))) {
|
||||||
|
InputStream in = readImagefromCustom(empresa);
|
||||||
|
if (in != null) {
|
||||||
|
byte[] targetArray = IOUtils.toByteArray(in);
|
||||||
|
|
||||||
|
Imagem entidad = new Imagem();
|
||||||
|
entidad.setImagem(targetArray);
|
||||||
|
entidad.setNombImagem(empresaNome);
|
||||||
|
|
||||||
|
imagemService.suscribir(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void singletonImage(){
|
||||||
|
|
||||||
|
ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService");
|
||||||
|
ImagemService imagemService = (ImagemService) AppContext.getApplicationContext().getBean("imagemService");
|
||||||
|
Constante constante = constanteService.buscarPorNomeConstante("IMAGENE_EMPRESA_GENERICA");
|
||||||
|
|
||||||
|
if ((constante != null) && StringUtils.isNotBlank(constante.getValorconstante()) && Boolean.valueOf(constante.getValorconstante())) {
|
||||||
|
Imagem imagemGenerica = imagemService.buscarPorNomeImagem("EMPRESA_BACKGROUND_GENERICA");
|
||||||
|
getApplication().setImage(imagemGenerica);
|
||||||
|
}else{
|
||||||
|
Imagem imagem = imagemService.buscarPorNomeImagem("EMPRESA_BACKGROUND");
|
||||||
|
getApplication().setImage(imagem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Application getApplication() {
|
||||||
|
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||||
|
BeanFactory factory = (BeanFactory) appContext;
|
||||||
|
Application app = (Application) factory.getBean("app");
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue