package com.capgemini.reports.r03;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.common.ServletMessageHelper;
import com.capgemini.reports.common.obtaindata.AbstractObtainDataFromPartRevision;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;

import javax.servlet.annotation.WebServlet;

/** This class receives demands form ajax client to initialize values id and revision for PartPV. */
@Slf4j
@WebServlet("/report_r03/obtainDataR03")
public class ObtainDataServletR03 extends AbstractObtainDataFromPartRevision {

    private static final long serialVersionUID = 6904998551660947706L;

    private static final String SUCCES_MESSAGE = "Données obtenues avec succès pour le rapport R03";

    @Override
    public JSONObject obtainDataFromPartRevision(final String partID, final String partRevisionID, final String partType,
                                                 final TcSession session) {
        log.info("Server received a request to obtain data for R03 report.");

        // Compile the successfull JSON reponse containing all the elements required for the pickers
        JSONObject json = ServletMessageHelper.successMessage(SUCCES_MESSAGE);
        json.put("ObjectId", partID);
        json.put("ObjectRev", partRevisionID);
        json.put("ObjectType", partType);
        return json;
    }

    @Override
    protected PolicyLocation obtainLocation() {
        return PolicyLocation.make("R03_policy_full", "/xml/policies/r03report/R03_policy_full.xml");
    }

}
