FPPSoilParams.java [src/java/m/crp/services] Revision: 57250261f8dd22e26a3b05bbd9b109c64c04d323  Date: Fri Dec 06 13:37:31 MST 2019
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2019, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package m.crp.services;

import static csip.ModelDataService.KEY_METAINFO;
import static csip.ModelDataService.KEY_PARAMETER;
import csip.ServiceException;
import csip.utils.JSONUtils;
import gisobjects.GISObject;
import gisobjects.GISObjectException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import m.crp.utils.ServiceCall;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
public class FPPSoilParams extends ServiceCall {

    protected JSONObject _callingMetaInfo;
    protected GISObject _location;

        
    public FPPSoilParams(JSONObject metaInfo, GISObject shape, String URI) {
        super(URI);
        _callingMetaInfo = metaInfo;
        errorPrefix = "FPPSoilParams_ServiceCall";    
        _location = shape;
    }

    @Override
    protected void createRequest() throws ServiceException {
        JSONArray dataArray;

        requestMetainfoObject = new JSONObject();
        request = new JSONObject();

        dataArray = new JSONArray();
        try {
            requestMetainfoObject.put("MultipartRequest", "Bundled Service Request From csip-crp MetaModeling CliWindSoil Service");
            requestMetainfoObject.put("CliWindSoil_Metainfo", _callingMetaInfo);
            request.put(KEY_METAINFO, requestMetainfoObject);
            GISObject newLocation = _location.buffer(1.0);
            JSONObject polyLocation = null;
            if (null != newLocation) {
                polyLocation = newLocation.toJSON();
            } else {
                throwServiceCallException("Cannot get a buffer location around that centroid.");
            }

            if (null != polyLocation) {
                polyLocation.put("name", "aoa_geometry");
                dataArray.put(polyLocation);

                request.put(KEY_PARAMETER, dataArray);
            } else {
                throwServiceCallException("Cannot convert centroid buffer to JSON.");
            }
        } catch (JSONException ex) {
            throwServiceCallException("Cannot create the JSON request for WEPPSoilInput call.", ex);
        } catch (GISObjectException ex) {
             throwServiceCallException("Cannot convert centroid to buffer");
        } catch (IOException ex) {
            throwServiceCallException("Cannot convert centroid buffer to JSON.");
        }
    }

}