package com.capgemini.reports.common;

import com.capgemini.reports.execution.AbstractExecutionReport;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import javax.servlet.http.HttpServletRequest;

/**
 * Abstract class providing the framework for submitting and checking the necessary parameters to produce a report on an {@link ItemRevision}.
 *
 * @param <T> a subType of {@link AbstractExecutionReport}
 */
public abstract class AbstractSubmitServletForItemRevision<T extends AbstractExecutionReport<T, ?>> extends AbstractSubmitServlet<T> {

    private static final long serialVersionUID = -3114366972057429074L;

    @Override
    public T prepareReport(final HttpServletRequest request) {
        // findAll parameters for KurtItemRevision
        String partId = request.getParameter("num_article");
        String partRevision = request.getParameter("rev_article");
        return prepareReport(partId, partRevision, request);
    }

    /**
     * The main method. Builds an {@link AbstractExecutionReport} using the itemId, item Revision, and the request to eventually obtain additional parameters.
     *
     * @param itemId
     * @param itemRev
     * @param request
     * @return
     */
    protected abstract T prepareReport(final String itemId, final String itemRev, final HttpServletRequest request);

}
