package usda.weru.remoteDataAccess.csip.crlmod;

import java.io.File;
import java.util.ArrayList;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import usda.weru.remoteDataAccess.exceptions.RdaConnectException;
import usda.weru.util.ConfigData;
import usda.weru.util.wepsFileChooser2.WepsFileTypes2;

/**
 *
 * @author mhaas
 */
public class CsipIfCrLmodOp  extends CsipIfCrLmodCropOpBase {
    
    public CsipIfCrLmodOp () {
        super ();
    }
    
    @Override
    public ArrayList<String> callCsipCatalog () throws RdaConnectException {
        ArrayList<String> res = callCsipCropOpCatalog (ConfigData.getDefault().getData("CD-WS-csip-crlmod-op-endpoint"));
        
        // LMOD service does not include the file extension.
        // Add it so that we match the rest of Weps.
        for (int i = 0; i < res.size(); i++) {
            res.set(i, res.get(i) + WepsFileTypes2.Operation.getExtension());
        }
        return res;
    }
    
    
    @Override
    public File callCsipGetRecord (String name, String parentPath) throws RdaConnectException {
        String nameSave = name;
        // LMOD service does not include the file extension.
        // Remove it when calling LMOD and then add it back.
        name = name.replace(WepsFileTypes2.Operation.getExtension(), "");
        File lmodFile = callGetRecordLmod (ConfigData.getDefault().getData("CD-WS-csip-crlmod-op-endpoint-rec"), name, parentPath);
        return lmodFile;
    }
    
    
    @Override
    public ArrayList<String> parseResultCatalog (JSONObject modelResults) throws JSONException {
        return parseResultCatalog (modelResults, "operations");
    }    
    
    
    @Override
    protected File parseResultRecord (JSONObject modelResults, String recordName) throws JSONException {
        return parseResultRecordLmod (modelResults, "operations", WepsFileTypes2.Operation.getExtension(), recordName, "wepsOpParamSet");
    }    
    
}
