package com.capgemini.reports.r16;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.capgemini.reports.common.AbstractSubmitServlet;
import com.capgemini.reports.definition.r15r16r17reports.r16report.ExecutionR16;
import com.capgemini.reports.reports.parameters.ProductUnit;

/**
 * This class receives demands to perform a R16 report.<br>
 * It prepares the data and creates the appropriate {@link ExecutionR16} instance that will carry out the job.
 */
@WebServlet("/report_r16/submit")
public class SubmitServletR16 extends AbstractSubmitServlet<ExecutionR16> {

    private static final long serialVersionUID = 6034599018215480837L;

    @Override
    public ExecutionR16 prepareReport(final HttpServletRequest request) {
        // Obtain report parameters
        String productID = request.getParameter("product_id");
        String unitStr = request.getParameter("unit");
        String generic = request.getParameter("generic");
        String typeImpression = request.getParameter("type_impression");
        String langue = request.getParameter("langue");

        // Building product-unit relationship
        ProductUnit productUnit = new ProductUnit(productID, unitStr);

        return new ExecutionR16(productUnit, generic, typeImpression, langue);
    }
}
