package com.capgemini.reports.common.obtaindata;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes;
import com.capgemini.reports.exceptions.InvalidUserInputException;
import com.capgemini.reports.exceptions.UserInputErrorEnum;
import org.json.JSONObject;

/** This class is a servlet that handles requests to perform a report on a Part. */
public abstract class AbstractObtainDataFromPartRevision extends AbstractObtainDataFromItemRevision {

    private static final long serialVersionUID = 3679669481879532713L;

    @Override
    public JSONObject obtainDataFromItemRevision(final String itemID, final String itemRevisionID, final String itemType,
                                                 final TcSession session) throws InvalidUserInputException {

        if (!SnecmaObjectTypes.isPartRevision(itemType)) {
            throw new InvalidUserInputException(UserInputErrorEnum.THE_SELECTED_OBJECT_IS_NOT_PERMITTED_ON_THIS_REPORT);
        }
        return obtainDataFromPartRevision(itemID, itemRevisionID, itemType, session);
    }

    /**
     * The main method of this class: receives and stores information on a Part Revision.
     * 
     * @param partID the ID of the Part
     * @param partRevisionID the revision ID of the Part
     * @param partType the type of the Part
     * @param session a Tc session to validate the input
     * @return a {@link JSONObject} containing the server response that will be sent back to the browser
     * @throws InvalidUserInputException thrown when user posted invalid input parameters
     */
    public abstract JSONObject obtainDataFromPartRevision(final String partID, final String partRevisionID, final String partType,
                                                          final TcSession session) throws InvalidUserInputException;


}
