V2_1.java [src/java/m/wqm/wqm03_pesticideattributes] Revision:   Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.wqm.wqm03_pesticideattributes;

import csip.api.server.ServiceException;
import csip.annotations.Resource;
import csip.utils.JSONUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import java.util.logging.Level;
import javax.ws.rs.Path;
import csip.annotations.Description;
import csip.annotations.Name;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.json.simple.parser.ParseException;
import wqm.utils.DBResources;
import static wqm.utils.DBResources.WQM_ID;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
@Name("WQM-03:  Pesticide Product List (PestProdList) Version 2.1")
@Description("This service returns a list of pesticide products and "
        + "their active ingredients from the wqm_pesticide_products table "
        + "of the WQM Data Mart.  The list is filtered by criteria provided "
        + "in the request payload.  This version allows for specifying a search "
        + "opertor value, i.e. 'AND' or 'OR', and provides an additional search filter of database row id.")
@Path("m/wqm/pestprodlist/2.1")
@Resource(from = DBResources.class)
public class V2_1 extends csip.ModelDataService {
    private Products products;
    private PestProdListRequest request;

    @Override
    protected void preProcess() throws ServiceException, JSONException {
        request = new PestProdListRequest(getParamMap());
    }

    @Override
    protected void doProcess() throws csip.api.server.ServiceException, SQLException {
        products = new Products( request, resources().getJDBC(WQM_ID));
    }

    @Override
    protected void postProcess() throws ServiceException, ParseException, JSONException {
        products.toJSON(request.maxProducts(), results());
    }
}