package com.capgemini.reports.r07;

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

import com.capgemini.reports.common.AbstractSubmitServlet;
import com.capgemini.reports.definition.r07report.ExecutionR07;
import com.capgemini.reports.reports.parameters.Generics;
import com.capgemini.reports.reports.parameters.ProductUnit;

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

    private static final long serialVersionUID = -2063643392149847177L;

    @Override
    public ExecutionR07 prepareReport(final HttpServletRequest request) {
        // Obtaining report parameters configuration 1
        String productID1 = request.getParameter("product_id1");
        String unitStr1 = request.getParameter("unit1");
        String generic1 = request.getParameter("generic1");
        String genericAssemb1 = request.getParameter("generic_assemb1");

        // Obtaining report parameters configuration 2
        String productID2 = request.getParameter("product_id2");
        String unitStr2 = request.getParameter("unit2");
        String generic2 = request.getParameter("generic2");
        String genericAssemb2 = request.getParameter("generic_assemb2");

        // Checking product-unit relationship
        ProductUnit productUnit1 = new ProductUnit(productID1, unitStr1);
        ProductUnit productUnit2 = new ProductUnit(productID2, unitStr2);

        // Checking generics
        Generics genericParam1 = new Generics(productUnit1, generic1, genericAssemb1);
        Generics genericParam2 = new Generics(productUnit2, generic2, genericAssemb2);

        return new ExecutionR07(genericParam1, genericParam2);
    }
}
