/*
 * 
 * Created on Jun 28, 2005
 * 
 * György Süveges
 * Etixpert Kft.
 * Copyright(c) 2005
 * 
 */
package com.etixpert.evolution.gui.servlets.pageactions;

import javax.servlet.http.*;

import com.etixpert.evolution.PersistableObject;

import java.util.*;
import org.hibernate.*;
import com.etixpert.evolution.*;
import java.sql.*;

/**
 * @author Suveges Gyorgy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class linkedpayment extends PDFLinker {

    /**
     * 
     */
    public linkedpayment() {
        super();
        // TODO Auto-generated constructor stub
    }

    /* (non-Javadoc)
     * @see com.etixpert.evolution.gui.servlets.pageactions.PDFLinker#getPDFs(javax.servlet.http.HttpServletRequest)
     */
    protected byte[][] getPDFs(HttpServletRequest req) throws Exception {
        Transaction tx = null;
        HttpSession session = req.getSession();
        List keys = (List) session.getAttribute("financeids");
        session.removeAttribute("financeids");
        try {
	        Session s = HibernateUtil.currentSession();
	        tx = s.beginTransaction();
	        Connection conn = s.connection();
	        Map m = new HashMap();
	        byte[][] datas = new byte[keys.size()][];
	        for (int i =0; i<keys.size(); i++) {
		 		m.put("id", keys.get(i));
				PersistableObject po = new PersistableObject("financial", new String[] {"id"}, m);
				po.load(conn);
				datas[i] = (byte[])po.get("pdf");
	        }
	        
	        tx.commit();
	        HibernateUtil.closeSession();
           return datas;
        } catch (Exception e) {
            logger.info("Error occured while generating the complex pdf of payment",e);
            if (tx!=null) 
                tx.rollback();
                
            throw e;
        }
        
    }

}
