/**
 *
 */
package com.capgemini.reports.r21;

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

import com.capgemini.reports.common.AbstractSubmitServlet;
import com.capgemini.reports.definition.r21report.ExecutionR21;
import com.capgemini.reports.reports.parameters.DualGenerics;
import com.capgemini.reports.reports.parameters.EffectivityDate;
import com.capgemini.reports.reports.parameters.ProductUnit;

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

    private static final long serialVersionUID = 5272895767855049459L;

    @Override
    public ExecutionR21 prepareReport(final HttpServletRequest request) {
        // Obtain report parameters
        String productID = request.getParameter("product_id");
        String unitStr = request.getParameter("unit");
        String generic = request.getParameter("generic");
        String genericAssemb = request.getParameter("generic_assemb");
        String effectivityStr = request.getParameter("datepicker");

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

        // Checking generics
        DualGenerics dualGeneric = new DualGenerics(productUnit, generic, genericAssemb);

        // Checking effectivity
        EffectivityDate effectivity = new EffectivityDate(effectivityStr);

        return new ExecutionR21(productUnit, dualGeneric, effectivity);
    }
}
