Skip to content

Commit

Permalink
Se guardan los archivos xml y pdf en la base de datos [Finished#73476…
Browse files Browse the repository at this point in the history
…582]
  • Loading branch information
const3 committed Jun 19, 2014
1 parent 7128f42 commit ec335d4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Blob;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
Expand All @@ -22,6 +25,7 @@
import mx.edu.um.mateo.general.model.Usuario;
import mx.edu.um.mateo.general.utils.UtilStatus;
import mx.edu.um.mateo.rh.model.Empleado;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -83,6 +87,11 @@ public class InformeProveedorDetalle implements Serializable {
private transient MultipartFile file;
private transient MultipartFile file2;

@Column(name = "filePdf")
private byte[] pdfFile;
@Column(name = "fileXml")
private byte[] xmlFile;

public InformeProveedorDetalle() {
dctoProntoPago = BigDecimal.ZERO;
}
Expand Down Expand Up @@ -330,4 +339,20 @@ public String toString() {
+ ", dctoProntoPago=" + dctoProntoPago + ", file=" + file + ", file2=" + file2 + '}';
}

public byte[] getPdfFile() {
return pdfFile;
}

public void setPdfFile(byte[] pdfFile) {
this.pdfFile = pdfFile;
}

public byte[] getXmlFile() {
return xmlFile;
}

public void setXmlFile(byte[] xmlFile) {
this.xmlFile = xmlFile;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -42,12 +45,16 @@
import mx.edu.um.mateo.rh.model.Empleado;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.ObjectError;
Expand Down Expand Up @@ -824,10 +831,12 @@ public String uploadFile(HttpServletRequest request, @ModelAttribute("uploadFile
}
uploadFileForm.getFile().transferTo(new File(uploadDir));
sw = true;

log.debug("Archivo {} subido... ", uploadFileForm.getFile().getOriginalFilename());
if (fileName.contains(".xml")) {
detalle.setPathXMl("/home/facturas/" + año + "/" + mes + "/" + dia + "/" + request.getRemoteUser() + "/" + uploadFileForm.getFile().getOriginalFilename());
detalle.setNombreXMl(uploadFileForm.getFile().getOriginalFilename());
detalle.setXmlFile(uploadFileForm.getFile().getBytes());
manager.actualiza(detalle, usuario);
xml = true;
request.getSession().setAttribute("esPdf", xml);
Expand All @@ -837,6 +846,7 @@ public String uploadFile(HttpServletRequest request, @ModelAttribute("uploadFile
if (fileName.contains(".pdf")) {
detalle.setPathPDF("/home/facturas/" + año + "/" + mes + "/" + dia + "/" + request.getRemoteUser() + "/" + uploadFileForm.getFile().getOriginalFilename());
detalle.setNombrePDF(uploadFileForm.getFile().getOriginalFilename());
detalle.setPdfFile(uploadFileForm.getFile().getBytes());
manager.actualiza(detalle, usuario);
request.getSession().setAttribute("esPdf", false);
}
Expand Down Expand Up @@ -967,6 +977,42 @@ public ModelAndView handleRequestXML(@PathVariable Long id, Model modelo, HttpSe
return null;
}

@RequestMapping("/downloadPdfFile/{id}")
public String downloadPdfBD(@PathVariable("id") Long id, HttpServletResponse response) {

InformeProveedorDetalle doc = manager.obtiene(id);
try {
OutputStream out = response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\""
+ doc.getNombrePDF() + "\"");
FileCopyUtils.copy(doc.getPdfFile(), out);

} catch (IOException e) {
e.printStackTrace();
}

return null;
}

@RequestMapping("/downloadXmlFile/{id}")
public String downloadXmlBD(@PathVariable("id") Long id, HttpServletResponse response) {

InformeProveedorDetalle doc = manager.obtiene(id);
try {
OutputStream out = response.getOutputStream();
response.setContentType("application/xml");
response.setHeader("Content-Disposition", "attachment; filename=\""
+ doc.getNombreXMl() + "\"");
FileCopyUtils.copy(doc.getXmlFile(), out);

} catch (IOException e) {
e.printStackTrace();
}

return null;
}

@Transactional
@RequestMapping(value = "/autorizar", method = RequestMethod.GET)
public String autorizar(HttpServletRequest request, Model modelo, RedirectAttributes redirectAttributes) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
<div class="span1"><s:message code="informeEmpleado.label" /></div>
<div class="span11">${informeProveedorDetalle.informeProveedor.id}</div>
</div>

<a href="<s:url value='/factura/informeProveedorDetalle/descargarPdf/${informeProveedorDetalle.id}'/>"><img src="/mateo/images/pdf.png" width="120" height="100" /></a>
<a href="<s:url value='/factura/informeProveedorDetalle/descargarXML/${informeProveedorDetalle.id}'/>"><img src="/mateo/images/xml.png" width="120" height="100" /></a>
<p>adsasdasd</p>
<a href="<s:url value='/factura/informeProveedorDetalle/downloadPdfFile/${informeProveedorDetalle.id}'/>"><img src="/mateo/images/pdf.png" width="120" height="100" /></a>
<a href="<s:url value='/factura/informeProveedorDetalle/downloadXmlFile/${informeProveedorDetalle.id}'/>"><img src="/mateo/images/xml.png" width="120" height="100" /></a>
<c:if test="${informeProveedorDetalle.nombreProveedor=='A'}">
<p class="well">
<a href="<c:url value='/factura/informeProveedorDetalle/edita/${informeProveedorDetalle.id}' />" class="btn btn-primary btn-large"><i class="icon-edit icon-white"></i> <s:message code="editar.button" /></a>
Expand Down

0 comments on commit ec335d4

Please sign in to comment.